Skip to content

Commit 0f33b90

Browse files
Revert "[lldb-dap] Re-land refactor of DebugCommunication. (#147787)"
This reverts commit 13eca52. This change broke greendragon lldb test: lldb-api.tools/lldb-dap/moduleSymbols.TestDAP_moduleSymbols.py
1 parent 424521f commit 0f33b90

File tree

15 files changed

+467
-579
lines changed

15 files changed

+467
-579
lines changed

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

Lines changed: 345 additions & 457 deletions
Large diffs are not rendered by default.

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

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import time
3-
from typing import Optional, Callable, Any, List, Union
3+
from typing import Optional
44
import uuid
55

66
import dap_server
@@ -67,10 +67,7 @@ def set_source_breakpoints_assembly(
6767
self, source_reference, lines, data=None, wait_for_resolve=True
6868
):
6969
return self.set_source_breakpoints_from_source(
70-
Source.build(source_reference=source_reference),
71-
lines,
72-
data,
73-
wait_for_resolve,
70+
Source(source_reference=source_reference), lines, data, wait_for_resolve
7471
)
7572

7673
def set_source_breakpoints_from_source(
@@ -123,19 +120,11 @@ def wait_for_breakpoints_to_resolve(
123120
f"Expected to resolve all breakpoints. Unresolved breakpoint ids: {unresolved_breakpoints}",
124121
)
125122

126-
def wait_until(
127-
self,
128-
predicate: Callable[[], bool],
129-
delay: float = 0.5,
130-
timeout: float = DEFAULT_TIMEOUT,
131-
) -> bool:
132-
"""Repeatedly run the predicate until either the predicate returns True
133-
or a timeout has occurred."""
134-
deadline = time.monotonic() + timeout
135-
while deadline > time.monotonic():
136-
if predicate():
123+
def waitUntil(self, condition_callback):
124+
for _ in range(20):
125+
if condition_callback():
137126
return True
138-
time.sleep(delay)
127+
time.sleep(0.5)
139128
return False
140129

141130
def assertCapabilityIsSet(self, key: str, msg: Optional[str] = None) -> None:
@@ -148,16 +137,13 @@ def assertCapabilityIsNotSet(self, key: str, msg: Optional[str] = None) -> None:
148137
if key in self.dap_server.capabilities:
149138
self.assertEqual(self.dap_server.capabilities[key], False, msg)
150139

151-
def verify_breakpoint_hit(
152-
self, breakpoint_ids: List[Union[int, str]], timeout: float = DEFAULT_TIMEOUT
153-
):
140+
def verify_breakpoint_hit(self, breakpoint_ids, timeout=DEFAULT_TIMEOUT):
154141
"""Wait for the process we are debugging to stop, and verify we hit
155142
any breakpoint location in the "breakpoint_ids" array.
156143
"breakpoint_ids" should be a list of breakpoint ID strings
157144
(["1", "2"]). The return value from self.set_source_breakpoints()
158145
or self.set_function_breakpoints() can be passed to this function"""
159146
stopped_events = self.dap_server.wait_for_stopped(timeout)
160-
normalized_bp_ids = [str(b) for b in breakpoint_ids]
161147
for stopped_event in stopped_events:
162148
if "body" in stopped_event:
163149
body = stopped_event["body"]
@@ -168,16 +154,22 @@ def verify_breakpoint_hit(
168154
and body["reason"] != "instruction breakpoint"
169155
):
170156
continue
171-
if "hitBreakpointIds" not in body:
157+
if "description" not in body:
172158
continue
173-
hit_breakpoint_ids = body["hitBreakpointIds"]
174-
for bp in hit_breakpoint_ids:
175-
if str(bp) in normalized_bp_ids:
159+
# Descriptions for breakpoints will be in the form
160+
# "breakpoint 1.1", so look for any description that matches
161+
# ("breakpoint 1.") in the description field as verification
162+
# that one of the breakpoint locations was hit. DAP doesn't
163+
# allow breakpoints to have multiple locations, but LLDB does.
164+
# So when looking at the description we just want to make sure
165+
# the right breakpoint matches and not worry about the actual
166+
# location.
167+
description = body["description"]
168+
for breakpoint_id in breakpoint_ids:
169+
match_desc = f"breakpoint {breakpoint_id}."
170+
if match_desc in description:
176171
return
177-
self.assertTrue(
178-
False,
179-
f"breakpoint not hit, wanted breakpoint_ids {breakpoint_ids} in stopped_events {stopped_events}",
180-
)
172+
self.assertTrue(False, f"breakpoint not hit, stopped_events={stopped_events}")
181173

182174
def verify_all_breakpoints_hit(self, breakpoint_ids, timeout=DEFAULT_TIMEOUT):
183175
"""Wait for the process we are debugging to stop, and verify we hit
@@ -221,7 +213,7 @@ def verify_stop_exception_info(self, expected_description, timeout=DEFAULT_TIMEO
221213
return True
222214
return False
223215

224-
def verify_commands(self, flavor: str, output: str, commands: list[str]):
216+
def verify_commands(self, flavor, output, commands):
225217
self.assertTrue(output and len(output) > 0, "expect console output")
226218
lines = output.splitlines()
227219
prefix = "(lldb) "
@@ -234,11 +226,10 @@ def verify_commands(self, flavor: str, output: str, commands: list[str]):
234226
found = True
235227
break
236228
self.assertTrue(
237-
found,
238-
f"Command '{flavor}' - '{cmd}' not found in output: {output}",
229+
found, "verify '%s' found in console output for '%s'" % (cmd, flavor)
239230
)
240231

241-
def get_dict_value(self, d: dict, key_path: list[str]) -> Any:
232+
def get_dict_value(self, d, key_path):
242233
"""Verify each key in the key_path array is in contained in each
243234
dictionary within "d". Assert if any key isn't in the
244235
corresponding dictionary. This is handy for grabbing values from VS
@@ -307,34 +298,28 @@ def get_source_and_line(self, threadId=None, frameIndex=0):
307298
return (source["path"], stackFrame["line"])
308299
return ("", 0)
309300

310-
def get_stdout(self):
311-
return self.dap_server.get_output("stdout")
301+
def get_stdout(self, timeout=0.0):
302+
return self.dap_server.get_output("stdout", timeout=timeout)
312303

313-
def get_console(self):
314-
return self.dap_server.get_output("console")
304+
def get_console(self, timeout=0.0):
305+
return self.dap_server.get_output("console", timeout=timeout)
315306

316-
def get_important(self):
317-
return self.dap_server.get_output("important")
307+
def get_important(self, timeout=0.0):
308+
return self.dap_server.get_output("important", timeout=timeout)
318309

319-
def collect_stdout(
320-
self, timeout: float = DEFAULT_TIMEOUT, pattern: Optional[str] = None
321-
) -> str:
310+
def collect_stdout(self, timeout_secs, pattern=None):
322311
return self.dap_server.collect_output(
323-
"stdout", timeout=timeout, pattern=pattern
312+
"stdout", timeout_secs=timeout_secs, pattern=pattern
324313
)
325314

326-
def collect_console(
327-
self, timeout: float = DEFAULT_TIMEOUT, pattern: Optional[str] = None
328-
) -> str:
315+
def collect_console(self, timeout_secs, pattern=None):
329316
return self.dap_server.collect_output(
330-
"console", timeout=timeout, pattern=pattern
317+
"console", timeout_secs=timeout_secs, pattern=pattern
331318
)
332319

333-
def collect_important(
334-
self, timeout: float = DEFAULT_TIMEOUT, pattern: Optional[str] = None
335-
) -> str:
320+
def collect_important(self, timeout_secs, pattern=None):
336321
return self.dap_server.collect_output(
337-
"important", timeout=timeout, pattern=pattern
322+
"important", timeout_secs=timeout_secs, pattern=pattern
338323
)
339324

340325
def get_local_as_int(self, name, threadId=None):

lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_commands(self):
153153
breakpoint_ids = self.set_function_breakpoints(functions)
154154
self.assertEqual(len(breakpoint_ids), len(functions), "expect one breakpoint")
155155
self.continue_to_breakpoints(breakpoint_ids)
156-
output = self.collect_console(timeout=10, pattern=stopCommands[-1])
156+
output = self.collect_console(timeout_secs=10, pattern=stopCommands[-1])
157157
self.verify_commands("stopCommands", output, stopCommands)
158158

159159
# Continue after launch and hit the "pause()" call and stop the target.
@@ -163,7 +163,7 @@ def test_commands(self):
163163
time.sleep(0.5)
164164
self.dap_server.request_pause()
165165
self.dap_server.wait_for_stopped()
166-
output = self.collect_console(timeout=10, pattern=stopCommands[-1])
166+
output = self.collect_console(timeout_secs=10, pattern=stopCommands[-1])
167167
self.verify_commands("stopCommands", output, stopCommands)
168168

169169
# Continue until the program exits
@@ -172,7 +172,7 @@ def test_commands(self):
172172
# "exitCommands" that were run after the second breakpoint was hit
173173
# and the "terminateCommands" due to the debugging session ending
174174
output = self.collect_console(
175-
timeout=10.0,
175+
timeout_secs=10.0,
176176
pattern=terminateCommands[0],
177177
)
178178
self.verify_commands("exitCommands", output, exitCommands)
@@ -223,7 +223,7 @@ def test_terminate_commands(self):
223223
# "terminateCommands"
224224
self.dap_server.request_disconnect(terminateDebuggee=True)
225225
output = self.collect_console(
226-
timeout=1.0,
226+
timeout_secs=1.0,
227227
pattern=terminateCommands[0],
228228
)
229229
self.verify_commands("terminateCommands", output, terminateCommands)

lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test lldb-dap setBreakpoints request in assembly source references.
33
"""
44

5+
56
from lldbsuite.test.decorators import *
67
from dap_server import Source
78
import lldbdap_testcase
@@ -51,7 +52,7 @@ def test_break_on_invalid_source_reference(self):
5152

5253
# Verify that setting a breakpoint on an invalid source reference fails
5354
response = self.dap_server.request_setBreakpoints(
54-
Source.build(source_reference=-1), [1]
55+
Source(source_reference=-1), [1]
5556
)
5657
self.assertIsNotNone(response)
5758
breakpoints = response["body"]["breakpoints"]
@@ -68,7 +69,7 @@ def test_break_on_invalid_source_reference(self):
6869

6970
# Verify that setting a breakpoint on a source reference that is not created fails
7071
response = self.dap_server.request_setBreakpoints(
71-
Source.build(source_reference=200), [1]
72+
Source(source_reference=200), [1]
7273
)
7374
self.assertIsNotNone(response)
7475
breakpoints = response["body"]["breakpoints"]
@@ -115,7 +116,7 @@ def test_persistent_assembly_breakpoint(self):
115116

116117
persistent_breakpoint_source = self.dap_server.resolved_breakpoints[
117118
persistent_breakpoint_ids[0]
118-
]["source"]
119+
].source()
119120
self.assertIn(
120121
"adapterData",
121122
persistent_breakpoint_source,
@@ -138,7 +139,7 @@ def test_persistent_assembly_breakpoint(self):
138139
self.dap_server.request_initialize()
139140
self.dap_server.request_launch(program)
140141
new_session_breakpoints_ids = self.set_source_breakpoints_from_source(
141-
Source(persistent_breakpoint_source),
142+
Source(raw_dict=persistent_breakpoint_source),
142143
[persistent_breakpoint_line],
143144
)
144145

lldb/test/API/tools/lldb-dap/breakpoint-events/TestDAP_breakpointEvents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_breakpoint_events(self):
5858
# Set breakpoints and verify that they got set correctly
5959
dap_breakpoint_ids = []
6060
response = self.dap_server.request_setBreakpoints(
61-
Source.build(path=main_source_path), [main_bp_line]
61+
Source(main_source_path), [main_bp_line]
6262
)
6363
self.assertTrue(response["success"])
6464
breakpoints = response["body"]["breakpoints"]
@@ -70,7 +70,7 @@ def test_breakpoint_events(self):
7070
)
7171

7272
response = self.dap_server.request_setBreakpoints(
73-
Source.build(path=foo_source_path), [foo_bp1_line]
73+
Source(foo_source_path), [foo_bp1_line]
7474
)
7575
self.assertTrue(response["success"])
7676
breakpoints = response["body"]["breakpoints"]

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test lldb-dap setBreakpoints request
33
"""
44

5+
56
from dap_server import Source
67
import shutil
78
from lldbsuite.test.decorators import *
@@ -57,7 +58,7 @@ def test_source_map(self):
5758

5859
# breakpoint in main.cpp
5960
response = self.dap_server.request_setBreakpoints(
60-
Source.build(path=new_main_path), [main_line]
61+
Source(new_main_path), [main_line]
6162
)
6263
breakpoints = response["body"]["breakpoints"]
6364
self.assertEqual(len(breakpoints), 1)
@@ -69,7 +70,7 @@ def test_source_map(self):
6970

7071
# 2nd breakpoint, which is from a dynamically loaded library
7172
response = self.dap_server.request_setBreakpoints(
72-
Source.build(path=new_other_path), [other_line]
73+
Source(new_other_path), [other_line]
7374
)
7475
breakpoints = response["body"]["breakpoints"]
7576
breakpoint = breakpoints[0]
@@ -84,7 +85,7 @@ def test_source_map(self):
8485

8586
# 2nd breakpoint again, which should be valid at this point
8687
response = self.dap_server.request_setBreakpoints(
87-
Source.build(path=new_other_path), [other_line]
88+
Source(new_other_path), [other_line]
8889
)
8990
breakpoints = response["body"]["breakpoints"]
9091
breakpoint = breakpoints[0]
@@ -128,9 +129,7 @@ def test_set_and_clear(self):
128129
self.build_and_launch(program)
129130

130131
# Set 3 breakpoints and verify that they got set correctly
131-
response = self.dap_server.request_setBreakpoints(
132-
Source.build(path=self.main_path), lines
133-
)
132+
response = self.dap_server.request_setBreakpoints(Source(self.main_path), lines)
134133
line_to_id = {}
135134
breakpoints = response["body"]["breakpoints"]
136135
self.assertEqual(
@@ -155,9 +154,7 @@ def test_set_and_clear(self):
155154
lines.remove(second_line)
156155
# Set 2 breakpoints and verify that the previous breakpoints that were
157156
# set above are still set.
158-
response = self.dap_server.request_setBreakpoints(
159-
Source.build(path=self.main_path), lines
160-
)
157+
response = self.dap_server.request_setBreakpoints(Source(self.main_path), lines)
161158
breakpoints = response["body"]["breakpoints"]
162159
self.assertEqual(
163160
len(breakpoints),
@@ -202,9 +199,7 @@ def test_set_and_clear(self):
202199
# Now clear all breakpoints for the source file by passing down an
203200
# empty lines array
204201
lines = []
205-
response = self.dap_server.request_setBreakpoints(
206-
Source.build(path=self.main_path), lines
207-
)
202+
response = self.dap_server.request_setBreakpoints(Source(self.main_path), lines)
208203
breakpoints = response["body"]["breakpoints"]
209204
self.assertEqual(
210205
len(breakpoints),
@@ -224,9 +219,7 @@ def test_set_and_clear(self):
224219
# Now set a breakpoint again in the same source file and verify it
225220
# was added.
226221
lines = [second_line]
227-
response = self.dap_server.request_setBreakpoints(
228-
Source.build(path=self.main_path), lines
229-
)
222+
response = self.dap_server.request_setBreakpoints(Source(self.main_path), lines)
230223
if response:
231224
breakpoints = response["body"]["breakpoints"]
232225
self.assertEqual(
@@ -277,9 +270,7 @@ def test_clear_breakpoints_unset_breakpoints(self):
277270
self.build_and_launch(program)
278271

279272
# Set one breakpoint and verify that it got set correctly.
280-
response = self.dap_server.request_setBreakpoints(
281-
Source.build(path=self.main_path), lines
282-
)
273+
response = self.dap_server.request_setBreakpoints(Source(self.main_path), lines)
283274
line_to_id = {}
284275
breakpoints = response["body"]["breakpoints"]
285276
self.assertEqual(
@@ -295,9 +286,7 @@ def test_clear_breakpoints_unset_breakpoints(self):
295286
# Now clear all breakpoints for the source file by not setting the
296287
# lines array.
297288
lines = None
298-
response = self.dap_server.request_setBreakpoints(
299-
Source.build(path=self.main_path), lines
300-
)
289+
response = self.dap_server.request_setBreakpoints(Source(self.main_path), lines)
301290
breakpoints = response["body"]["breakpoints"]
302291
self.assertEqual(len(breakpoints), 0, "expect no source breakpoints")
303292

@@ -373,7 +362,7 @@ def test_column_breakpoints(self):
373362
# Set two breakpoints on the loop line at different columns.
374363
columns = [13, 39]
375364
response = self.dap_server.request_setBreakpoints(
376-
Source.build(path=self.main_path),
365+
Source(self.main_path),
377366
[loop_line, loop_line],
378367
list({"column": c} for c in columns),
379368
)

0 commit comments

Comments
 (0)