Skip to content

Commit afd0475

Browse files
committed
[lldb-dap] Change the launch sequence
This PR changes how we treat the launch sequence in lldb-dap. - Send the initialized event after we finish handling the initialize request, rather than after we finish attaching or launching. - Delay handling the launch and attach request until we have handled the configurationDone request. The latter is now largely a NO-OP and only exists to signal lldb-dap that it can handle the launch and attach requests. - Delay handling the initial threads requests until we have handled the launch or attach request. - Make all attaching and launching asynchronous, including when we have attach or launch commands. That removes the need to synchronize between the request and event thread. Background: https://discourse.llvm.org/t/reliability-of-the-lldb-dap-tests/86125
1 parent e1cff21 commit afd0475

29 files changed

+222
-176
lines changed

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ def request_attach(
591591
attachCommands=None,
592592
terminateCommands=None,
593593
coreFile=None,
594+
stopOnAttach=True,
594595
postRunCommands=None,
595596
sourceMap=None,
596597
gdbRemotePort=None,
@@ -620,6 +621,8 @@ def request_attach(
620621
args_dict["attachCommands"] = attachCommands
621622
if coreFile:
622623
args_dict["coreFile"] = coreFile
624+
if stopOnAttach:
625+
args_dict["stopOnEntry"] = stopOnAttach
623626
if postRunCommands:
624627
args_dict["postRunCommands"] = postRunCommands
625628
if sourceMap:
@@ -632,7 +635,7 @@ def request_attach(
632635
response = self.send_recv(command_dict)
633636

634637
if response["success"]:
635-
self.wait_for_events(["process", "initialized"])
638+
self.wait_for_event("process")
636639
return response
637640

638641
def request_breakpointLocations(
@@ -666,10 +669,6 @@ def request_configurationDone(self):
666669
response = self.send_recv(command_dict)
667670
if response:
668671
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()
673672
return response
674673

675674
def _process_stopped(self):
@@ -887,7 +886,7 @@ def request_launch(
887886
response = self.send_recv(command_dict)
888887

889888
if response["success"]:
890-
self.wait_for_events(["process", "initialized"])
889+
self.wait_for_event("process")
891890
return response
892891

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

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

13551374
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()
13731375
dbg.wait_for_stopped()
13741376
else:
13751377
if "message" in response:

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def attach(
333333
exitCommands=None,
334334
attachCommands=None,
335335
coreFile=None,
336+
stopOnAttach=True,
336337
disconnectAutomatically=True,
337338
terminateCommands=None,
338339
postRunCommands=None,
@@ -357,6 +358,8 @@ def cleanup():
357358
self.addTearDownHook(cleanup)
358359
# Initialize and launch the program
359360
self.dap_server.request_initialize(sourceInitFile)
361+
self.dap_server.wait_for_event("initialized")
362+
self.dap_server.request_configurationDone()
360363
response = self.dap_server.request_attach(
361364
program=program,
362365
pid=pid,
@@ -369,6 +372,7 @@ def cleanup():
369372
attachCommands=attachCommands,
370373
terminateCommands=terminateCommands,
371374
coreFile=coreFile,
375+
stopOnAttach=stopOnAttach,
372376
postRunCommands=postRunCommands,
373377
sourceMap=sourceMap,
374378
gdbRemotePort=gdbRemotePort,
@@ -427,6 +431,9 @@ def cleanup():
427431

428432
# Initialize and launch the program
429433
self.dap_server.request_initialize(sourceInitFile)
434+
self.dap_server.wait_for_event("initialized")
435+
self.dap_server.request_configurationDone()
436+
430437
response = self.dap_server.request_launch(
431438
program,
432439
args=args,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def spawn_and_wait(program, delay):
2525
process.wait()
2626

2727

28-
@skipIf
2928
class TestDAP_attach(lldbdap_testcase.DAPTestCaseBase):
3029
def set_and_hit_breakpoint(self, continueToExit=True):
30+
self.dap_server.wait_for_stopped()
31+
3132
source = "main.c"
3233
breakpoint1_line = line_number(source, "// breakpoint 1")
3334
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
@@ -19,17 +19,17 @@
1919
import socket
2020

2121

22-
@skip
2322
class TestDAP_attachByPortNum(lldbdap_testcase.DAPTestCaseBase):
2423
default_timeout = 20
2524

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import lldbdap_testcase
1212
import os
1313

14-
# DAP tests are flakey, see https://github.com/llvm/llvm-project/issues/137660.
15-
@skip
14+
1615
class TestDAP_breakpointLocations(lldbdap_testcase.DAPTestCaseBase):
1716
def setUp(self):
1817
lldbdap_testcase.DAPTestCaseBase.setUp(self)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import lldbdap_testcase
1212
import os
1313

14-
# DAP tests are flakey, see https://github.com/llvm/llvm-project/issues/137660.
15-
@skip
14+
1615
class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
1716
def setUp(self):
1817
lldbdap_testcase.DAPTestCaseBase.setUp(self)

lldb/test/API/tools/lldb-dap/commands/TestDAP_commands.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from lldbsuite.test import lldbtest, lldbutil
66
from lldbsuite.test.decorators import *
77

8-
# DAP tests are flakey, see https://github.com/llvm/llvm-project/issues/137660.
9-
@skip
8+
109
class TestDAP_commands(lldbdap_testcase.DAPTestCaseBase):
1110
def test_command_directive_quiet_on_success(self):
1211
program = self.getBuildArtifact("a.out")

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):
47+
def setup_debugee(self, stopOnEntry=False):
4848
program = self.getBuildArtifact("a.out")
49-
self.build_and_launch(program)
49+
self.build_and_launch(program, stopOnEntry=stopOnEntry)
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()
238+
self.setup_debugee(stopOnEntry=True)
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)
170+
self.build_and_launch(program, stopOnEntry=True)
171171

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

lldb/test/API/tools/lldb-dap/disassemble/TestDAP_disassemble.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import lldbdap_testcase
1111
import os
1212

13-
# DAP tests are flakey, see https://github.com/llvm/llvm-project/issues/137660.
14-
@skip
13+
1514
class TestDAP_disassemble(lldbdap_testcase.DAPTestCaseBase):
1615
@skipIfWindows
1716
def test_disassemble(self):

0 commit comments

Comments
 (0)