Skip to content

Commit 0bb4631

Browse files
committed
[lldb-dap] Attempt to synchronously wait for breakpoints resolve in lldb-dap tests in order to stabilize the tests
1 parent 3360a23 commit 0bb4631

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,15 +1187,17 @@ def request_locations(self, locationReference):
11871187
}
11881188
return self.send_recv(command_dict)
11891189

1190-
def request_testGetTargetBreakpoints(self):
1190+
def request_testGetTargetBreakpoints(self, only_resolved=False):
11911191
"""A request packet used in the LLDB test suite to get all currently
11921192
set breakpoint infos for all breakpoints currently set in the
11931193
target.
11941194
"""
11951195
command_dict = {
11961196
"command": "_testGetTargetBreakpoints",
11971197
"type": "request",
1198-
"arguments": {},
1198+
"arguments": {
1199+
"onlyResolved": only_resolved,
1200+
},
11991201
}
12001202
return self.send_recv(command_dict)
12011203

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def build_and_create_debug_adapter_for_attach(self):
4848
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
4949
return self.getBuildArtifact(unique_name)
5050

51-
def set_source_breakpoints(self, source_path, lines, data=None):
51+
def set_source_breakpoints(self, source_path, lines, data=None, wait_for_resolve=True):
5252
"""Sets source breakpoints and returns an array of strings containing
5353
the breakpoint IDs ("1", "2") for each breakpoint that was set.
5454
Parameter data is array of data objects for breakpoints.
@@ -62,9 +62,11 @@ def set_source_breakpoints(self, source_path, lines, data=None):
6262
breakpoint_ids = []
6363
for breakpoint in breakpoints:
6464
breakpoint_ids.append("%i" % (breakpoint["id"]))
65+
if wait_for_resolve:
66+
self.wait_for_breakpoints_to_resolve(breakpoint_ids, timeout=10)
6567
return breakpoint_ids
6668

67-
def set_function_breakpoints(self, functions, condition=None, hitCondition=None):
69+
def set_function_breakpoints(self, functions, condition=None, hitCondition=None, wait_for_resolve=True):
6870
"""Sets breakpoints by function name given an array of function names
6971
and returns an array of strings containing the breakpoint IDs
7072
("1", "2") for each breakpoint that was set.
@@ -78,7 +80,27 @@ def set_function_breakpoints(self, functions, condition=None, hitCondition=None)
7880
breakpoint_ids = []
7981
for breakpoint in breakpoints:
8082
breakpoint_ids.append("%i" % (breakpoint["id"]))
83+
if wait_for_resolve:
84+
self.wait_for_breakpoints_to_resolve(breakpoint_ids, timeout=10)
8185
return breakpoint_ids
86+
87+
def wait_for_breakpoints_to_resolve(self, breakpoint_ids: list[str], timeout: Optional[float] = None):
88+
unresolved_breakpoints = set(breakpoint_ids)
89+
90+
# Check already resolved breakpoints
91+
resolved_breakpoints = self.dap_server.request_testGetTargetBreakpoints(only_resolved=True)["body"]["breakpoints"]
92+
for resolved_breakpoint in resolved_breakpoints:
93+
unresolved_breakpoints.discard(str(resolved_breakpoint["id"]))
94+
95+
while len(unresolved_breakpoints) > 0:
96+
breakpoint_event = self.dap_server.wait_for_event("breakpoint", timeout=timeout)
97+
if breakpoint_event is None:
98+
break
99+
100+
if breakpoint_event["body"]["reason"] in ["changed", "new"]:
101+
unresolved_breakpoints.discard(str(breakpoint_event["body"]["breakpoint"]["id"]))
102+
103+
self.assertEqual(len(unresolved_breakpoints), 0, f"Expected to resolve all breakpoints. Unresolved breakpoint ids: {unresolved_breakpoints}")
82104

83105
def waitUntil(self, condition_callback):
84106
for _ in range(20):

lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import os
1313

1414

15-
@skip("Temporarily disable the breakpoint tests")
1615
class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
1716
def setUp(self):
1817
lldbdap_testcase.DAPTestCaseBase.setUp(self)

lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lldbdap_testcase
1111

1212

13-
@skip("Temporarily disable the breakpoint tests")
1413
class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
1514
@skipIfWindows
1615
def test_set_and_clear(self):

lldb/test/API/tools/lldb-dap/module/TestDAP_module.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def run_test(self, symbol_basename, expect_debug_info_size):
1616
program = self.getBuildArtifact(program_basename)
1717
self.build_and_launch(program)
1818
functions = ["foo"]
19-
breakpoint_ids = self.set_function_breakpoints(functions)
19+
20+
# This breakpoint will be resolved only when the libfoo module is loaded
21+
breakpoint_ids = self.set_function_breakpoints(functions, wait_for_resolve=False)
2022
self.assertEqual(len(breakpoint_ids), len(functions), "expect one breakpoint")
2123
self.continue_to_breakpoints(breakpoint_ids)
2224
active_modules = self.dap_server.get_modules()

lldb/test/API/tools/lldb-dap/terminated-event/TestDAP_terminatedEvent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def test_terminated_event(self):
3535
self.build_and_launch(program)
3636
# Set breakpoints
3737
functions = ["foo"]
38-
breakpoint_ids = self.set_function_breakpoints(functions)
38+
39+
# This breakpoint will be resolved only when the libfoo module is loaded
40+
breakpoint_ids = self.set_function_breakpoints(functions, wait_for_resolve=False)
3941
self.assertEqual(len(breakpoint_ids), len(functions), "expect one breakpoint")
4042
main_bp_line = line_number("main.cpp", "// main breakpoint 1")
4143
breakpoint_ids.append(self.set_source_breakpoints("main.cpp", [main_bp_line]))

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ namespace lldb_dap {
1515

1616
void TestGetTargetBreakpointsRequestHandler::operator()(
1717
const llvm::json::Object &request) const {
18+
const auto *arguments = request.getObject("arguments");
19+
bool only_resolved = GetBoolean(arguments, "onlyResolved").value_or(false);
20+
1821
llvm::json::Object response;
1922
FillResponse(request, response);
2023
llvm::json::Array response_breakpoints;
2124
for (uint32_t i = 0; dap.target.GetBreakpointAtIndex(i).IsValid(); ++i) {
22-
auto bp = Breakpoint(dap, dap.target.GetBreakpointAtIndex(i));
23-
response_breakpoints.push_back(bp.ToProtocolBreakpoint());
25+
const auto target_bp = dap.target.GetBreakpointAtIndex(i);
26+
if (!only_resolved || target_bp.GetNumResolvedLocations() > 0) {
27+
auto bp = Breakpoint(dap, target_bp);
28+
response_breakpoints.push_back(bp.ToProtocolBreakpoint());
29+
}
2430
}
2531
llvm::json::Object body;
2632
body.try_emplace("breakpoints", std::move(response_breakpoints));

0 commit comments

Comments
 (0)