Skip to content

Commit e9134d0

Browse files
committed
[lldb][lldb-dap] review changes.
[lldb][lldb-dap] add review changes
1 parent 0240468 commit e9134d0

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/dap_server.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,10 +1044,10 @@ def request_setFunctionBreakpoints(self, names, condition=None, hitCondition=Non
10441044
def request_dataBreakpointInfo(
10451045
self,
10461046
name: str,
1047-
variablesReference: int = None,
1048-
frameIndex: int = 0,
1049-
bytes_: int = None,
1050-
asAddress: bool = None,
1047+
variablesReference: Optional[int] | None = None,
1048+
frameIndex: Optional[int] = 0,
1049+
bytes_: Optional[int] = None,
1050+
asAddress: Optional[bool] = None,
10511051
):
10521052
args_dict = {}
10531053
if asAddress is not None:
@@ -1057,9 +1057,12 @@ def request_dataBreakpointInfo(
10571057
"bytes": bytes_,
10581058
}
10591059
else:
1060-
stackFrame = self.get_stackFrame(frameIndex=frameIndex, threadId=None)
1060+
thread_id = self.get_thread_id()
1061+
stackFrame = self.get_stackFrame(frameIndex=frameIndex, threadId=thread_id)
10611062
if stackFrame is None:
1062-
return []
1063+
raise ValueError(
1064+
f"could not get stackframe for frameIndex: {frameIndex} and threadId: {thread_id}"
1065+
)
10631066
args_dict = {
10641067
"variablesReference": variablesReference,
10651068
"name": name,

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def waitUntil(self, condition_callback):
105105
return False
106106

107107
def verify_breakpoint_hit(
108-
self, breakpoint_ids, timeout=DEFAULT_TIMEOUT, is_watchpoint=False
108+
self, breakpoint_ids, timeout=DEFAULT_TIMEOUT, reason: Optional[str] = None
109109
):
110110
"""Wait for the process we are debugging to stop, and verify we hit
111111
any breakpoint location in the "breakpoint_ids" array.
@@ -118,9 +118,10 @@ def verify_breakpoint_hit(
118118
body = stopped_event["body"]
119119
if "reason" not in body:
120120
continue
121-
if (
122-
body["reason"] != "breakpoint"
123-
and body["reason"] != "instruction breakpoint"
121+
if body["reason"] not in (
122+
"breakpoint",
123+
"instruction breakpoint",
124+
"data breakpoint",
124125
):
125126
continue
126127
if "description" not in body:
@@ -133,7 +134,7 @@ def verify_breakpoint_hit(
133134
# So when looking at the description we just want to make sure
134135
# the right breakpoint matches and not worry about the actual
135136
# location.
136-
type_name = "watchpoint" if is_watchpoint else "breakpoint"
137+
type_name = reason or "breakpoint"
137138
description = body["description"]
138139
for breakpoint_id in breakpoint_ids:
139140
match_desc = f"{type_name} {breakpoint_id}"
@@ -333,15 +334,15 @@ def continue_to_next_stop(self, timeout=DEFAULT_TIMEOUT):
333334
return self.dap_server.wait_for_stopped(timeout)
334335

335336
def continue_to_breakpoint(
336-
self, breakpoint_id: str, timeout=DEFAULT_TIMEOUT, is_watchpoint=False
337+
self, breakpoint_id: str, timeout=DEFAULT_TIMEOUT, reason: Optional[str] = None
337338
):
338-
self.continue_to_breakpoints([breakpoint_id], timeout, is_watchpoint)
339+
self.continue_to_breakpoints([breakpoint_id], timeout, reason)
339340

340341
def continue_to_breakpoints(
341-
self, breakpoint_ids, timeout=DEFAULT_TIMEOUT, is_watchpoint=False
342+
self, breakpoint_ids, timeout=DEFAULT_TIMEOUT, reason: Optional[str] = None
342343
):
343344
self.do_continue()
344-
self.verify_breakpoint_hit(breakpoint_ids, timeout, is_watchpoint)
345+
self.verify_breakpoint_hit(breakpoint_ids, timeout, reason)
345346

346347
def continue_to_exception_breakpoint(self, filter_label, timeout=DEFAULT_TIMEOUT):
347348
self.do_continue()

lldb/test/API/tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ def test_breakpoint_info_bytes(self):
7777
bp_resp = self.dap_server.request_dataBreakpointInfo(
7878
var_address, asAddress=True, bytes_=var_byte_watch_size
7979
)
80-
resp_data_id = bp_resp["body"]["dataId"]
8180
self.assertTrue(
8281
bp_resp["success"], f"dataBreakpointInfo request failed: {bp_resp}"
8382
)
83+
resp_data_id = bp_resp["body"]["dataId"]
8484
self.assertEqual(resp_data_id.split("/")[1], str(var_byte_watch_size))
8585

8686
data_breakpoints = [{"dataId": resp_data_id, "accessType": "write"}]
8787
self.dap_server.request_setDataBreakpoint(data_breakpoints)
8888

89-
self.continue_to_breakpoint(breakpoint_id=1, is_watchpoint=True)
89+
self.continue_to_breakpoint(breakpoint_id=1, reason="data breakpoint")
9090
eval_response = self.dap_server.request_evaluate("var", context="watch")
9191
self.assertTrue(eval_response["success"])
9292
var_value = eval_response["body"]["result"]

lldb/tools/lldb-dap/Handler/DataBreakpointInfoRequestHandler.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ namespace lldb_dap {
1818
static llvm::Expected<protocol::DataBreakpointInfoResponseBody>
1919
HandleDataBreakpointBytes(DAP &dap,
2020
const protocol::DataBreakpointInfoArguments &args) {
21-
llvm::StringRef address = args.name;
21+
llvm::StringRef raw_address = args.name;
2222

23-
unsigned long long load_addr = LLDB_INVALID_ADDRESS;
24-
if (llvm::getAsUnsignedInteger(address, 0, load_addr)) {
23+
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
24+
if (raw_address.getAsInteger<lldb::addr_t>(0, load_addr)) {
2525
return llvm::make_error<DAPError>(llvm::formatv("invalid address"),
2626
llvm::inconvertibleErrorCode(), false);
2727
}
2828

29-
lldb::SBAddress sb_addr(load_addr, dap.target);
30-
if (!sb_addr.IsValid()) {
29+
if (lldb::SBAddress address(load_addr, dap.target); !address.IsValid()) {
3130
return llvm::make_error<DAPError>(
3231
llvm::formatv("address {:x} does not exist in the debuggee", load_addr),
3332
llvm::inconvertibleErrorCode(), false);

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,16 @@ llvm::json::Value CreateThreadStopped(DAP &dap, lldb::SBThread &thread,
893893
EmplaceSafeString(body, "description", desc_str);
894894
}
895895
} break;
896-
case lldb::eStopReasonWatchpoint:
896+
case lldb::eStopReasonWatchpoint: {
897+
lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(0);
898+
lldb::break_id_t bp_loc_id = thread.GetStopReasonDataAtIndex(1);
899+
std::string desc_str =
900+
llvm::formatv("data breakpoint {0}.{1}", bp_id, bp_loc_id);
901+
body.try_emplace("hitBreakpointIds",
902+
llvm::json::Array{llvm::json::Value(bp_id)});
903+
body.try_emplace("reason", "data breakpoint");
904+
EmplaceSafeString(body, "description", desc_str);
905+
} break;
897906
case lldb::eStopReasonInstrumentation:
898907
body.try_emplace("reason", "breakpoint");
899908
break;

0 commit comments

Comments
 (0)