Skip to content

Commit 47c7e73

Browse files
committed
Revert "[lldb-dap] Change the launch sequence (#138219)"
This reverts commit ba29e60. As it broke tests on Windows on Arm: https://lab.llvm.org/buildbot/#/builders/141/builds/8500 ******************** Unresolved Tests (2): lldb-api :: tools/lldb-dap/completions/TestDAP_completions.py lldb-api :: tools/lldb-dap/startDebugging/TestDAP_startDebugging.py ******************** Timed Out Tests (1): lldb-api :: tools/lldb-dap/send-event/TestDAP_sendEvent.py ******************** Failed Tests (6): lldb-api :: tools/lldb-dap/console/TestDAP_console.py lldb-api :: tools/lldb-dap/console/TestDAP_redirection_to_console.py lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py lldb-api :: tools/lldb-dap/stackTrace/TestDAP_stackTrace.py lldb-api :: tools/lldb-dap/stackTraceDisassemblyDisplay/TestDAP_stackTraceDisassemblyDisplay.py lldb-api :: tools/lldb-dap/variables/children/TestDAP_variables_children.py
1 parent b643a52 commit 47c7e73

24 files changed

+219
-252
lines changed

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

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def __init__(self, recv, send, init_commands, log_file=None):
132132
self.exit_status = None
133133
self.initialize_body = None
134134
self.thread_stop_reasons = {}
135+
self.breakpoint_events = []
135136
self.progress_events = []
136137
self.reverse_requests = []
137138
self.module_events = []
@@ -243,6 +244,13 @@ def handle_recv_packet(self, packet):
243244
self._process_stopped()
244245
tid = body["threadId"]
245246
self.thread_stop_reasons[tid] = body
247+
elif event == "breakpoint":
248+
# Breakpoint events come in when a breakpoint has locations
249+
# added or removed. Keep track of them so we can look for them
250+
# in tests.
251+
self.breakpoint_events.append(packet)
252+
# no need to add 'breakpoint' event packets to our packets list
253+
return keepGoing
246254
elif event.startswith("progress"):
247255
# Progress events come in as 'progressStart', 'progressUpdate',
248256
# and 'progressEnd' events. Keep these around in case test
@@ -404,15 +412,6 @@ def wait_for_stopped(self, timeout=None):
404412
self.threads = []
405413
return stopped_events
406414

407-
def wait_for_breakpoint_events(self, timeout=None):
408-
breakpoint_events = []
409-
while True:
410-
event = self.wait_for_event("breakpoint", timeout=timeout)
411-
if not event:
412-
break
413-
breakpoint_events.append(event)
414-
return breakpoint_events
415-
416415
def wait_for_exited(self):
417416
event_dict = self.wait_for_event("exited")
418417
if event_dict is None:
@@ -592,7 +591,6 @@ def request_attach(
592591
attachCommands=None,
593592
terminateCommands=None,
594593
coreFile=None,
595-
stopOnAttach=True,
596594
postRunCommands=None,
597595
sourceMap=None,
598596
gdbRemotePort=None,
@@ -622,8 +620,6 @@ def request_attach(
622620
args_dict["attachCommands"] = attachCommands
623621
if coreFile:
624622
args_dict["coreFile"] = coreFile
625-
if stopOnAttach:
626-
args_dict["stopOnEntry"] = stopOnAttach
627623
if postRunCommands:
628624
args_dict["postRunCommands"] = postRunCommands
629625
if sourceMap:
@@ -636,7 +632,7 @@ def request_attach(
636632
response = self.send_recv(command_dict)
637633

638634
if response["success"]:
639-
self.wait_for_event("process")
635+
self.wait_for_events(["process", "initialized"])
640636
return response
641637

642638
def request_breakpointLocations(
@@ -670,6 +666,10 @@ def request_configurationDone(self):
670666
response = self.send_recv(command_dict)
671667
if response:
672668
self.configuration_done_sent = True
669+
# Client requests the baseline of currently existing threads after
670+
# a successful launch or attach.
671+
# Kick off the threads request that follows
672+
self.request_threads()
673673
return response
674674

675675
def _process_stopped(self):
@@ -887,7 +887,7 @@ def request_launch(
887887
response = self.send_recv(command_dict)
888888

889889
if response["success"]:
890-
self.wait_for_event("process")
890+
self.wait_for_events(["process", "initialized"])
891891
return response
892892

893893
def request_next(self, threadId, granularity="statement"):
@@ -1325,26 +1325,6 @@ def attach_options_specified(options):
13251325

13261326
def run_vscode(dbg, args, options):
13271327
dbg.request_initialize(options.sourceInitFile)
1328-
1329-
if options.sourceBreakpoints:
1330-
source_to_lines = {}
1331-
for file_line in options.sourceBreakpoints:
1332-
(path, line) = file_line.split(":")
1333-
if len(path) == 0 or len(line) == 0:
1334-
print('error: invalid source with line "%s"' % (file_line))
1335-
1336-
else:
1337-
if path in source_to_lines:
1338-
source_to_lines[path].append(int(line))
1339-
else:
1340-
source_to_lines[path] = [int(line)]
1341-
for source in source_to_lines:
1342-
dbg.request_setBreakpoints(source, source_to_lines[source])
1343-
if options.funcBreakpoints:
1344-
dbg.request_setFunctionBreakpoints(options.funcBreakpoints)
1345-
1346-
dbg.request_configurationDone()
1347-
13481328
if attach_options_specified(options):
13491329
response = dbg.request_attach(
13501330
program=options.program,
@@ -1373,6 +1353,23 @@ def run_vscode(dbg, args, options):
13731353
)
13741354

13751355
if response["success"]:
1356+
if options.sourceBreakpoints:
1357+
source_to_lines = {}
1358+
for file_line in options.sourceBreakpoints:
1359+
(path, line) = file_line.split(":")
1360+
if len(path) == 0 or len(line) == 0:
1361+
print('error: invalid source with line "%s"' % (file_line))
1362+
1363+
else:
1364+
if path in source_to_lines:
1365+
source_to_lines[path].append(int(line))
1366+
else:
1367+
source_to_lines[path] = [int(line)]
1368+
for source in source_to_lines:
1369+
dbg.request_setBreakpoints(source, source_to_lines[source])
1370+
if options.funcBreakpoints:
1371+
dbg.request_setFunctionBreakpoints(options.funcBreakpoints)
1372+
dbg.request_configurationDone()
13761373
dbg.wait_for_stopped()
13771374
else:
13781375
if "message" in response:

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ def attach(
340340
exitCommands=None,
341341
attachCommands=None,
342342
coreFile=None,
343-
stopOnAttach=True,
344343
disconnectAutomatically=True,
345344
terminateCommands=None,
346345
postRunCommands=None,
@@ -365,8 +364,6 @@ def cleanup():
365364
self.addTearDownHook(cleanup)
366365
# Initialize and launch the program
367366
self.dap_server.request_initialize(sourceInitFile)
368-
self.dap_server.wait_for_event("initialized")
369-
self.dap_server.request_configurationDone()
370367
response = self.dap_server.request_attach(
371368
program=program,
372369
pid=pid,
@@ -379,7 +376,6 @@ def cleanup():
379376
attachCommands=attachCommands,
380377
terminateCommands=terminateCommands,
381378
coreFile=coreFile,
382-
stopOnAttach=stopOnAttach,
383379
postRunCommands=postRunCommands,
384380
sourceMap=sourceMap,
385381
gdbRemotePort=gdbRemotePort,
@@ -438,9 +434,6 @@ def cleanup():
438434

439435
# Initialize and launch the program
440436
self.dap_server.request_initialize(sourceInitFile)
441-
self.dap_server.wait_for_event("initialized")
442-
self.dap_server.request_configurationDone()
443-
444437
response = self.dap_server.request_launch(
445438
program,
446439
args=args,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ def spawn_and_wait(program, delay):
2727
@skip
2828
class TestDAP_attach(lldbdap_testcase.DAPTestCaseBase):
2929
def set_and_hit_breakpoint(self, continueToExit=True):
30-
self.dap_server.wait_for_stopped()
31-
3230
source = "main.c"
3331
breakpoint1_line = line_number(source, "// breakpoint 1")
3432
lines = [breakpoint1_line]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
import socket
1919

2020

21+
@skip
2122
class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
2223
default_timeout = 20
2324

2425
def set_and_hit_breakpoint(self, continueToExit=True):
25-
self.dap_server.wait_for_stopped()
26-
2726
source = "main.c"
28-
breakpoint1_line = line_number(source, "// breakpoint 1")
27+
main_source_path = os.path.join(os.getcwd(), source)
28+
breakpoint1_line = line_number(main_source_path, "// breakpoint 1")
2929
lines = [breakpoint1_line]
3030
# Set breakpoint in the thread function so we can step the threads
31-
breakpoint_ids = self.set_source_breakpoints(source, lines)
31+
breakpoint_ids = self.set_source_breakpoints(main_source_path, lines)
3232
self.assertEqual(
3333
len(breakpoint_ids), len(lines), "expect correct number of breakpoints"
3434
)

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

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,52 @@ def test_breakpoint_events(self):
8181
breakpoint["verified"], "expect foo breakpoint to not be verified"
8282
)
8383

84-
# Make sure we're stopped.
85-
self.dap_server.wait_for_stopped()
84+
# Get the stop at the entry point
85+
self.continue_to_next_stop()
8686

87-
# Flush the breakpoint events.
88-
self.dap_server.wait_for_breakpoint_events(timeout=5)
87+
# We are now stopped at the entry point to the program. Shared
88+
# libraries are not loaded yet (at least on macOS they aren't) and only
89+
# the breakpoint in the main executable should be resolved.
90+
self.assertEqual(len(self.dap_server.breakpoint_events), 1)
91+
event = self.dap_server.breakpoint_events[0]
92+
body = event["body"]
93+
self.assertEqual(
94+
body["reason"], "changed", "breakpoint event should say changed"
95+
)
96+
breakpoint = body["breakpoint"]
97+
self.assertEqual(breakpoint["id"], main_bp_id)
98+
self.assertTrue(breakpoint["verified"], "main breakpoint should be resolved")
99+
100+
# Clear the list of breakpoint events so we don't see this one again.
101+
self.dap_server.breakpoint_events.clear()
89102

90103
# Continue to the breakpoint
91104
self.continue_to_breakpoints(dap_breakpoint_ids)
92105

93-
verified_breakpoint_ids = []
94-
unverified_breakpoint_ids = []
95-
for breakpoint_event in self.dap_server.wait_for_breakpoint_events(timeout=5):
96-
breakpoint = breakpoint_event["body"]["breakpoint"]
97-
id = breakpoint["id"]
98-
if breakpoint["verified"]:
99-
verified_breakpoint_ids.append(id)
100-
else:
101-
unverified_breakpoint_ids.append(id)
102-
103-
self.assertIn(main_bp_id, unverified_breakpoint_ids)
104-
self.assertIn(foo_bp_id, unverified_breakpoint_ids)
106+
# When the process launches, we first expect to see both the main and
107+
# foo breakpoint as unresolved.
108+
for event in self.dap_server.breakpoint_events[:2]:
109+
body = event["body"]
110+
self.assertEqual(
111+
body["reason"], "changed", "breakpoint event should say changed"
112+
)
113+
breakpoint = body["breakpoint"]
114+
self.assertIn(str(breakpoint["id"]), dap_breakpoint_ids)
115+
self.assertFalse(breakpoint["verified"], "breakpoint should be unresolved")
105116

106-
self.assertIn(main_bp_id, verified_breakpoint_ids)
107-
self.assertIn(foo_bp_id, verified_breakpoint_ids)
117+
# Then, once the dynamic loader has given us a load address, they
118+
# should show up as resolved again.
119+
for event in self.dap_server.breakpoint_events[3:]:
120+
body = event["body"]
121+
self.assertEqual(
122+
body["reason"], "changed", "breakpoint event should say changed"
123+
)
124+
breakpoint = body["breakpoint"]
125+
self.assertIn(str(breakpoint["id"]), dap_breakpoint_ids)
126+
self.assertTrue(breakpoint["verified"], "breakpoint should be resolved")
127+
self.assertNotIn(
128+
"source",
129+
breakpoint,
130+
"breakpoint event should not return a source object",
131+
)
132+
self.assertIn("line", breakpoint, "breakpoint event should have line")

lldb/test/API/tools/lldb-dap/completions/TestDAP_completions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def verify_completions(self, actual_list, expected_list, not_expected_list=[]):
4444
self.assertNotIn(not_expected_item, actual_list)
4545

4646

47-
def setup_debugee(self, stopOnEntry=False):
47+
def setup_debugee(self):
4848
program = self.getBuildArtifact("a.out")
49-
self.build_and_launch(program, stopOnEntry=stopOnEntry)
49+
self.build_and_launch(program)
5050

5151
source = "main.cpp"
5252
breakpoint1_line = line_number(source, "// breakpoint 1")
@@ -235,7 +235,7 @@ def test_auto_completions(self):
235235
"""
236236
Tests completion requests in "repl-mode=auto"
237237
"""
238-
self.setup_debugee(stopOnEntry=True)
238+
self.setup_debugee()
239239

240240
res = self.dap_server.request_evaluate(
241241
"`lldb-dap repl-mode auto", context="repl"

lldb/test/API/tools/lldb-dap/console/TestDAP_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_exit_status_message_ok(self):
167167

168168
def test_diagnositcs(self):
169169
program = self.getBuildArtifact("a.out")
170-
self.build_and_launch(program, stopOnEntry=True)
170+
self.build_and_launch(program)
171171

172172
core = self.getBuildArtifact("minidump.core")
173173
self.yaml2obj("minidump.yaml", core)

lldb/test/API/tools/lldb-dap/disconnect/TestDAP_disconnect.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ def test_launch(self):
3131
created.
3232
"""
3333
program = self.getBuildArtifact("a.out")
34-
self.build_and_launch(program, stopOnEntry=True, disconnectAutomatically=False)
34+
self.build_and_launch(program, disconnectAutomatically=False)
3535

3636
# We set a breakpoint right before the side effect file is created
3737
self.set_source_breakpoints(
3838
self.source, [line_number(self.source, "// breakpoint")]
3939
)
4040
self.continue_to_next_stop()
4141

42-
# verify we haven't produced the side effect file yet
43-
self.assertFalse(os.path.exists(program + ".side_effect"))
44-
4542
self.dap_server.request_disconnect()
46-
4743
# verify we didn't produce the side effect file
4844
time.sleep(1)
4945
self.assertFalse(os.path.exists(program + ".side_effect"))

lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from lldbsuite.test.decorators import *
1111
from lldbsuite.test.lldbtest import *
1212

13-
1413
# DAP tests are flakey, see https://github.com/llvm/llvm-project/issues/137660.
1514
@skip
1615
class TestDAP_evaluate(lldbdap_testcase.DAPTestCaseBase):
@@ -43,9 +42,7 @@ def run_test_evaluate_expressions(
4342
self.context = context
4443
program = self.getBuildArtifact("a.out")
4544
self.build_and_launch(
46-
program,
47-
enableAutoVariableSummaries=enableAutoVariableSummaries,
48-
stopOnEntry=True,
45+
program, enableAutoVariableSummaries=enableAutoVariableSummaries
4946
)
5047
source = "main.cpp"
5148
self.set_source_breakpoints(

lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def test_stopOnEntry(self):
8888
"""
8989
program = self.getBuildArtifact("a.out")
9090
self.build_and_launch(program, stopOnEntry=True)
91-
92-
stopped_events = self.dap_server.wait_for_stopped()
91+
self.set_function_breakpoints(["main"])
92+
stopped_events = self.continue_to_next_stop()
9393
for stopped_event in stopped_events:
9494
if "body" in stopped_event:
9595
body = stopped_event["body"]

lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def verify_progress_events(
5050
@skipIfWindows
5151
def test(self):
5252
program = self.getBuildArtifact("a.out")
53-
self.build_and_launch(program, stopOnEntry=True)
53+
self.build_and_launch(program)
5454
progress_emitter = os.path.join(os.getcwd(), "Progress_emitter.py")
5555
self.dap_server.request_evaluate(
5656
f"`command script import {progress_emitter}", context="repl"

lldb/test/API/tools/lldb-dap/repl-mode/TestDAP_repl_mode_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def assertEvaluate(self, expression, regex):
2020

2121
def test_completions(self):
2222
program = self.getBuildArtifact("a.out")
23-
self.build_and_launch(program, stopOnEntry=True)
23+
self.build_and_launch(program)
2424

2525
source = "main.cpp"
2626
breakpoint1_line = line_number(source, "// breakpoint 1")

lldb/test/API/tools/lldb-dap/restart/TestDAP_restart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_basic_functionality(self):
2222
[bp_A, bp_B] = self.set_source_breakpoints("main.c", [line_A, line_B])
2323

2424
# Verify we hit A, then B.
25+
self.dap_server.request_configurationDone()
2526
self.verify_breakpoint_hit([bp_A])
2627
self.dap_server.request_continue()
2728
self.verify_breakpoint_hit([bp_B])

lldb/test/API/tools/lldb-dap/restart/TestDAP_restart_runInTerminal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def test_stopOnEntry(self):
7474
program = self.getBuildArtifact("a.out")
7575
self.build_and_launch(program, runInTerminal=True, stopOnEntry=True)
7676
[bp_main] = self.set_function_breakpoints(["main"])
77+
self.dap_server.request_configurationDone()
7778

7879
# When using stopOnEntry, configurationDone doesn't result in a running
7980
# process, we should immediately get a stopped event instead.

lldb/test/API/tools/lldb-dap/stop-hooks/TestDAP_stop_hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_stop_hooks_before_run(self):
1919
self.build_and_launch(program, stopOnEntry=True, preRunCommands=preRunCommands)
2020

2121
# The first stop is on entry.
22-
self.dap_server.wait_for_stopped()
22+
self.continue_to_next_stop()
2323

2424
breakpoint_ids = self.set_function_breakpoints(["main"])
2525
# This request hangs if the race happens, because, in that case, the

0 commit comments

Comments
 (0)