@@ -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