[Lldb-commits] [lldb] ac3816e - [lldb-dap] Migrate the startDebugging tests (#232753)

via lldb-commits lldb-commits at lists.llvm.org
Sat Oct 17 19:33:29 PDT 2026


Author: Ebuka Ezike
Date: 2026-10-18T03:33:24+01:00
New Revision: ac3816e3c005535ac15557f1b2353b7bb84382f1

URL: https://github.com/llvm/llvm-project/commit/ac3816e3c005535ac15557f1b2353b7bb84382f1
DIFF: https://github.com/llvm/llvm-project/commit/ac3816e3c005535ac15557f1b2353b7bb84382f1.diff

LOG: [lldb-dap] Migrate the startDebugging tests (#232753)

Port TestDAP_startDebugging to the new test infrastructure

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session.py
    lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
    lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session.py b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session.py
index 5709f78ec749b5..72beb2b0885e09 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session.py
@@ -22,6 +22,7 @@
     CapabilitiesEvent,
     ContinueArgs,
     DAPError,
+    EmptyBodyResponse,
     ErrorResponse,
     Event,
     ExitedEvent,
@@ -40,6 +41,7 @@
     ReverseResponse,
     RunInTerminalRequest,
     RunInTerminalResponse,
+    StartDebuggingRequest,
     StepInArgs,
     StepOutArgs,
     TerminateArgs,
@@ -319,6 +321,10 @@ def _on_protocol_reverse_request(self, request: RawMessage):
             terminal_request = dict_to_message(RunInTerminalRequest, request)
             self._reverse_requests.append(terminal_request)
             self._handle_run_in_terminal(terminal_request)
+        elif request_type == "startDebugging":
+            start_request = dict_to_message(StartDebuggingRequest, request)
+            self._reverse_requests.append(start_request)
+            self._handle_start_debugging(start_request)
         else:
             raise NotImplementedError(
                 f"no reverse request handler for '{request_type}'"
@@ -383,6 +389,16 @@ def _handle_run_in_terminal(self, request: RunInTerminalRequest):
 
         self._send_response(response)
 
+    def _handle_start_debugging(self, request: StartDebuggingRequest):
+        resp = EmptyBodyResponse(
+            type=MessageType.RESPONSE,
+            seq=self._next_sequence(),
+            command=request.command,
+            request_seq=request.seq,
+            success=True,
+        )
+        self._send_response(resp)
+
     def ensure_initialized(self):
         if self._state.is_initialized:
             return

diff  --git a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
index 310a9f01131d5c..18c23a5ca859b8 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/types.py
@@ -1052,15 +1052,6 @@ class RunInTerminalRequest(Request):
 """Possible Responses from a reverse Request"""
 
 
- at dataclass(frozen=True)
-class StartDebuggingRequestArgs:
-    configuration: Dict[str, Any] = field(default_factory=dict)
-    request: StartDebuggingRequestType = StartDebuggingRequestType.LAUNCH
-
-    command_ = "startDebugging"
-    response_class_ = EmptyBodyResponse
-
-
 @dataclass(frozen=True)
 class InitializeResponse(Response):
     body: Capabilities
@@ -1200,6 +1191,31 @@ class Session:
     response_class_ = EmptyBodyResponse
 
 
+ at dataclass(frozen=True)
+class StartDebuggingRequestArgs:
+    configuration: Union[LaunchArgs, AttachArgs]
+    request: StartDebuggingRequestType
+
+    command_ = "startDebugging"
+    response_class_ = EmptyBodyResponse
+
+    def __post_init__(self):
+        if self.request == StartDebuggingRequestType.LAUNCH:
+            assert isinstance(
+                self.configuration, LaunchArgs
+            ), "request should match the configuration"
+
+        elif self.request == StartDebuggingRequestType.ATTACH:
+            assert isinstance(
+                self.configuration, AttachArgs
+            ), "request should match the configuration"
+
+
+ at dataclass(frozen=True)
+class StartDebuggingRequest(Request):
+    arguments: StartDebuggingRequestArgs
+
+
 @dataclass(frozen=True)
 @args_protocol
 class RestartArgs:

diff  --git a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
index f1b753517080ff..ea3ce1bb95a550 100644
--- a/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
+++ b/lldb/test/API/tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
@@ -2,40 +2,39 @@
 Test lldb-dap start-debugging reverse requests.
 """
 
+import json
+from typing import cast
+
 from lldbsuite.test.decorators import *
 from lldbsuite.test.lldbtest import *
-import lldbdap_testcase
+from lldbsuite.test.tools.lldb_dap import DAPTestCaseBase
+from lldbsuite.test.tools.lldb_dap.types import *
 
 
-class TestDAP_startDebugging(lldbdap_testcase.DAPTestCaseBase):
+class TestDAP_startDebugging(DAPTestCaseBase):
     def test_startDebugging(self):
         """
         Tests the "startDebugging" reverse request. It makes sure that the IDE can
         start a child debug session.
         """
         program = self.getBuildArtifact("a.out")
-        source = "main.c"
-        self.build_and_launch(program)
-
-        breakpoint_line = line_number(source, "// breakpoint")
-
-        self.set_source_breakpoints(source, [breakpoint_line])
-        self.continue_to_next_stop()
-        self.dap_server.request_evaluate(
+        session = self.build_and_create_session()
+        with session.configure(LaunchArgs(program)) as ctx:
+            source = "main.c"
+            breakpoint_line = line_number(source, "// breakpoint")
+            [bp_id] = session.resolve_source_breakpoints(source, [breakpoint_line])
+
+        session.verify_stopped_on_breakpoint(bp_id, after=ctx.process_event)
+        session.evaluate(
             "`lldb-dap start-debugging attach '{\"pid\":321}'", context="repl"
         )
+        session.continue_to_exit()
 
-        self.continue_to_exit()
-
-        self.assertEqual(
-            len(self.dap_server.reverse_requests),
-            1,
-            "make sure we got a reverse request",
-        )
-
-        request = self.dap_server.reverse_requests[0]
-        self.assertEqual(request["arguments"]["configuration"]["pid"], 321)
-        self.assertEqual(request["arguments"]["request"], "attach")
+        args = self.start_debugging_args(session)
+        self.assertIsInstance(args.configuration, AttachArgs)
+        configuration = cast(AttachArgs, args.configuration)
+        self.assertEqual(configuration.pid, 321)
+        self.assertEqual(args.request, StartDebuggingRequestType.ATTACH)
 
     def test_startDebugging_debugger_reuse(self):
         """
@@ -45,46 +44,46 @@ def test_startDebugging_debugger_reuse(self):
         """
         program = self.getBuildArtifact("a.out")
         source = "main.c"
-        self.build_and_launch(program)
+        session = self.build_and_create_session()
 
-        breakpoint_line = line_number(source, "// breakpoint")
-        self.set_source_breakpoints(source, [breakpoint_line])
-        self.continue_to_next_stop()
+        with session.configure(LaunchArgs(program)) as ctx:
+            breakpoint_line = line_number(source, "// breakpoint")
+            [bp_id] = session.resolve_source_breakpoints(source, [breakpoint_line])
+        session.verify_stopped_on_breakpoint(bp_id, after=ctx.process_event)
 
-        # Use mock IDs to test the infrastructure
-        # In a real scenario, these would come from the parent session
+        # Use mock IDs to test the infrastructure.
+        # In a real scenario, these would come from the parent session.
         debugger_id = 1
         target_id = 100
 
         # Send a startDebugging request with debuggerId and targetId
         # This simulates creating a child DAP session that reuses the debugger
-        session = {"session": {"debuggerId": debugger_id, "targetId": target_id}}
-        self.dap_server.request_evaluate(
-            f"`lldb-dap start-debugging attach '{json.dumps(session)}'",
+        attach_args = {"session": {"debuggerId": debugger_id, "targetId": target_id}}
+        session.evaluate(
+            f"`lldb-dap start-debugging attach '{json.dumps(attach_args)}'",
             context="repl",
         )
+        session.continue_to_exit()
 
-        self.continue_to_exit()
-
-        # Verify the reverse request was sent with the correct IDs
-        self.assertEqual(
-            len(self.dap_server.reverse_requests),
-            1,
-            "Should have received one startDebugging reverse request",
-        )
-
-        request = self.dap_server.reverse_requests[0]
-        self.assertEqual(request["command"], "startDebugging")
-        self.assertEqual(request["arguments"]["request"], "attach")
+        args = self.start_debugging_args(session)
+        self.assertEqual(args.request, StartDebuggingRequestType.ATTACH)
+        self.assertIsInstance(args.configuration, AttachArgs)
+        configuration = cast(AttachArgs, args.configuration)
 
-        session = request["arguments"]["configuration"]["session"]
+        child_session = self.expect_not_none(configuration.session)
         self.assertEqual(
-            session["debuggerId"],
+            child_session.debuggerId,
             debugger_id,
             "Reverse request should include debugger ID",
         )
         self.assertEqual(
-            session["targetId"],
+            child_session.targetId,
             target_id,
             "Reverse request should include target ID",
         )
+
+    def start_debugging_args(self, session) -> StartDebuggingRequestArgs:
+        request = session.last_reverse_request()
+        self.assertIsInstance(request, StartDebuggingRequest)
+        self.assertEqual(request.command, "startDebugging")
+        return cast(StartDebuggingRequest, request).arguments


        


More information about the lldb-commits mailing list