-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb-dap] Add support for data breakpoint. #81541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CXX_SOURCES := main.cpp | ||
|
||
include Makefile.rules |
123 changes: 123 additions & 0 deletions
123
lldb/test/API/tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
""" | ||
Test lldb-dap dataBreakpointInfo and setDataBreakpoints requests | ||
""" | ||
|
||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
import lldbdap_testcase | ||
|
||
|
||
class TestDAP_setDataBreakpoints(lldbdap_testcase.DAPTestCaseBase): | ||
def setUp(self): | ||
lldbdap_testcase.DAPTestCaseBase.setUp(self) | ||
self.accessTypes = ["read", "write", "readWrite"] | ||
|
||
@skipIfWindows | ||
@skipIfRemote | ||
def test_expression(self): | ||
"""Tests setting data breakpoints on expression.""" | ||
program = self.getBuildArtifact("a.out") | ||
self.build_and_launch(program) | ||
source = "main.cpp" | ||
first_loop_break_line = line_number(source, "// first loop breakpoint") | ||
self.set_source_breakpoints(source, [first_loop_break_line]) | ||
self.continue_to_next_stop() | ||
self.dap_server.get_stackFrame() | ||
# Test setting write watchpoint using expressions: &x, arr+2 | ||
response_x = self.dap_server.request_dataBreakpointInfo(0, "4@&x") | ||
response_arr_2 = self.dap_server.request_dataBreakpointInfo(0, "1@arr+2") | ||
# Test response from dataBreakpointInfo request. | ||
self.assertEquals(response_x["body"]["dataId"].split("/")[1], "4") | ||
self.assertEquals(response_x["body"]["accessTypes"], self.accessTypes) | ||
self.assertEquals(response_arr_2["body"]["dataId"].split("/")[1], "1") | ||
self.assertEquals(response_arr_2["body"]["accessTypes"], self.accessTypes) | ||
dataBreakpoints = [ | ||
{"dataId": response_x["body"]["dataId"], "accessType": "write"}, | ||
{"dataId": response_arr_2["body"]["dataId"], "accessType": "write"}, | ||
] | ||
self.dap_server.request_setDataBreakpoint(dataBreakpoints) | ||
|
||
self.dap_server.request_continue() | ||
self.dap_server.wait_for_stopped() | ||
x_val = self.dap_server.get_local_variable_value("x") | ||
i_val = self.dap_server.get_local_variable_value("i") | ||
self.assertEquals(x_val, "2") | ||
self.assertEquals(i_val, "1") | ||
|
||
self.dap_server.request_continue() | ||
self.dap_server.wait_for_stopped() | ||
arr_2 = self.dap_server.get_local_variable_child("arr", "[2]") | ||
i_val = self.dap_server.get_local_variable_value("i") | ||
self.assertEquals(arr_2["value"], "'z'") | ||
self.assertEquals(i_val, "2") | ||
|
||
@skipIfWindows | ||
@skipIfRemote | ||
def test_functionality(self): | ||
"""Tests setting data breakpoints on variable.""" | ||
program = self.getBuildArtifact("a.out") | ||
self.build_and_launch(program) | ||
source = "main.cpp" | ||
first_loop_break_line = line_number(source, "// first loop breakpoint") | ||
self.set_source_breakpoints(source, [first_loop_break_line]) | ||
self.continue_to_next_stop() | ||
self.dap_server.get_local_variables() | ||
# Test write watchpoints on x, arr[2] | ||
response_x = self.dap_server.request_dataBreakpointInfo(1, "x") | ||
arr = self.dap_server.get_local_variable("arr") | ||
response_arr_2 = self.dap_server.request_dataBreakpointInfo( | ||
arr["variablesReference"], "[2]" | ||
) | ||
|
||
# Test response from dataBreakpointInfo request. | ||
self.assertEquals(response_x["body"]["dataId"].split("/")[1], "4") | ||
self.assertEquals(response_x["body"]["accessTypes"], self.accessTypes) | ||
self.assertEquals(response_arr_2["body"]["dataId"].split("/")[1], "1") | ||
self.assertEquals(response_arr_2["body"]["accessTypes"], self.accessTypes) | ||
dataBreakpoints = [ | ||
{"dataId": response_x["body"]["dataId"], "accessType": "write"}, | ||
{"dataId": response_arr_2["body"]["dataId"], "accessType": "write"}, | ||
] | ||
self.dap_server.request_setDataBreakpoint(dataBreakpoints) | ||
|
||
self.continue_to_next_stop() | ||
x_val = self.dap_server.get_local_variable_value("x") | ||
i_val = self.dap_server.get_local_variable_value("i") | ||
self.assertEquals(x_val, "2") | ||
self.assertEquals(i_val, "1") | ||
|
||
self.continue_to_next_stop() | ||
arr_2 = self.dap_server.get_local_variable_child("arr", "[2]") | ||
i_val = self.dap_server.get_local_variable_value("i") | ||
self.assertEquals(arr_2["value"], "'z'") | ||
self.assertEquals(i_val, "2") | ||
self.dap_server.request_setDataBreakpoint([]) | ||
|
||
# Test hit condition | ||
second_loop_break_line = line_number(source, "// second loop breakpoint") | ||
breakpoint_ids = self.set_source_breakpoints(source, [second_loop_break_line]) | ||
self.continue_to_breakpoints(breakpoint_ids) | ||
dataBreakpoints = [ | ||
{ | ||
"dataId": response_x["body"]["dataId"], | ||
"accessType": "write", | ||
"hitCondition": "2", | ||
} | ||
] | ||
self.dap_server.request_setDataBreakpoint(dataBreakpoints) | ||
self.continue_to_next_stop() | ||
x_val = self.dap_server.get_local_variable_value("x") | ||
self.assertEquals(x_val, "3") | ||
|
||
# Test condition | ||
dataBreakpoints = [ | ||
{ | ||
"dataId": response_x["body"]["dataId"], | ||
"accessType": "write", | ||
"condition": "x==10", | ||
} | ||
] | ||
self.dap_server.request_setDataBreakpoint(dataBreakpoints) | ||
self.continue_to_next_stop() | ||
x_val = self.dap_server.get_local_variable_value("x") | ||
self.assertEquals(x_val, "10") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
int main(int argc, char const *argv[]) { | ||
// Test for data breakpoint | ||
int x = 0; | ||
char arr[4] = {'a', 'b', 'c', 'd'}; | ||
for (int i = 0; i < 5; ++i) { // first loop breakpoint | ||
if (i == 1) { | ||
x = i + 1; | ||
} else if (i == 2) { | ||
arr[i] = 'z'; | ||
} | ||
} | ||
|
||
x = 1; | ||
for (int i = 0; i < 10; ++i) { // second loop breakpoint | ||
++x; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===-- Watchpoint.cpp ------------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "Watchpoint.h" | ||
#include "DAP.h" | ||
#include "JSONUtils.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
|
||
namespace lldb_dap { | ||
Watchpoint::Watchpoint(const llvm::json::Object &obj) : BreakpointBase(obj) { | ||
llvm::StringRef dataId = GetString(obj, "dataId"); | ||
std::string accessType = GetString(obj, "accessType").str(); | ||
auto [addr_str, size_str] = dataId.split('/'); | ||
lldb::addr_t addr; | ||
size_t size; | ||
llvm::to_integer(addr_str, addr, 16); | ||
llvm::to_integer(size_str, size); | ||
lldb::SBWatchpointOptions options; | ||
options.SetWatchpointTypeRead(accessType != "write"); | ||
if (accessType != "read") | ||
options.SetWatchpointTypeWrite(lldb::eWatchpointWriteTypeOnModify); | ||
wp = g_dap.target.WatchpointCreateByAddress(addr, size, options, error); | ||
SetCondition(); | ||
SetHitCondition(); | ||
} | ||
|
||
void Watchpoint::SetCondition() { wp.SetCondition(condition.c_str()); } | ||
|
||
void Watchpoint::SetHitCondition() { | ||
uint64_t hitCount = 0; | ||
if (llvm::to_integer(hitCondition, hitCount)) | ||
wp.SetIgnoreCount(hitCount - 1); | ||
} | ||
|
||
void Watchpoint::CreateJsonObject(llvm::json::Object &object) { | ||
if (error.Success()) { | ||
object.try_emplace("verified", true); | ||
} else { | ||
object.try_emplace("verified", false); | ||
EmplaceSafeString(object, "message", error.GetCString()); | ||
} | ||
} | ||
} // namespace lldb_dap |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===-- Watchpoint.h --------------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_TOOLS_LLDB_DAP_WATCHPOINT_H | ||
#define LLDB_TOOLS_LLDB_DAP_WATCHPOINT_H | ||
|
||
#include "BreakpointBase.h" | ||
#include "lldb/API/SBError.h" | ||
#include "lldb/API/SBWatchpoint.h" | ||
#include "lldb/API/SBWatchpointOptions.h" | ||
|
||
namespace lldb_dap { | ||
|
||
struct Watchpoint : public BreakpointBase { | ||
// The LLDB breakpoint associated wit this watchpoint. | ||
lldb::SBWatchpoint wp; | ||
lldb::SBError error; | ||
|
||
Watchpoint() = default; | ||
Watchpoint(const llvm::json::Object &obj); | ||
Watchpoint(lldb::SBWatchpoint wp) : wp(wp) {} | ||
|
||
void SetCondition() override; | ||
void SetHitCondition() override; | ||
void CreateJsonObject(llvm::json::Object &object) override; | ||
}; | ||
} // namespace lldb_dap | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list of dictionary
sounds very weird. Did you mean something else?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataBreakpoints
is a list of the dataBreakpoint which has following format: