Skip to content

Commit 265cb6e

Browse files
committed
Add basic startDebugging test
1 parent f534c55 commit 265cb6e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ def request_attach(
785785
*,
786786
program: Optional[str] = None,
787787
pid: Optional[int] = None,
788+
debuggerId: Optional[int] = None,
788789
targetId: Optional[int] = None,
789790
waitFor=False,
790791
initCommands: Optional[list[str]] = None,
@@ -805,6 +806,8 @@ def request_attach(
805806
args_dict["pid"] = pid
806807
if program is not None:
807808
args_dict["program"] = program
809+
if debuggerId is not None:
810+
args_dict["debuggerId"] = debuggerId
808811
if targetId is not None:
809812
args_dict["targetId"] = targetId
810813
if waitFor:

lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,48 @@ def test_startDebugging(self):
3636
request = self.dap_server.reverse_requests[0]
3737
self.assertEqual(request["arguments"]["configuration"]["pid"], 321)
3838
self.assertEqual(request["arguments"]["request"], "attach")
39+
40+
def test_startDebugging_debugger_reuse(self):
41+
"""
42+
Tests that debugger and target IDs can be passed through startDebugging
43+
for debugger reuse. This verifies the infrastructure for child DAP
44+
sessions to reuse the parent's debugger and attach to an existing target.
45+
"""
46+
program = self.getBuildArtifact("a.out")
47+
source = "main.c"
48+
self.build_and_launch(program)
49+
50+
breakpoint_line = line_number(source, "// breakpoint")
51+
self.set_source_breakpoints(source, [breakpoint_line])
52+
self.continue_to_next_stop()
53+
54+
# Use mock IDs to test the infrastructure
55+
# In a real scenario, these would come from the parent session
56+
test_debugger_id = 1
57+
test_target_id = 100
58+
59+
# Send a startDebugging request with debuggerId and targetId
60+
# This simulates creating a child DAP session that reuses the debugger
61+
self.dap_server.request_evaluate(
62+
f"`lldb-dap start-debugging attach '{{\"debuggerId\":{test_debugger_id},\"targetId\":{test_target_id}}}'",
63+
context="repl"
64+
)
65+
66+
self.continue_to_exit()
67+
68+
# Verify the reverse request was sent with the correct IDs
69+
self.assertEqual(
70+
len(self.dap_server.reverse_requests),
71+
1,
72+
"Should have received one startDebugging reverse request",
73+
)
74+
75+
request = self.dap_server.reverse_requests[0]
76+
self.assertEqual(request["command"], "startDebugging")
77+
self.assertEqual(request["arguments"]["request"], "attach")
78+
79+
config = request["arguments"]["configuration"]
80+
self.assertEqual(config["debuggerId"], test_debugger_id,
81+
"Reverse request should include debugger ID")
82+
self.assertEqual(config["targetId"], test_target_id,
83+
"Reverse request should include target ID")

0 commit comments

Comments
 (0)