[Lldb-commits] [lldb] [lldb-dap] Let tests run under both stdio and server adapter modes (PR #227435)

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 29 11:53:33 PDT 2026


https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/227435

Add create_debug_adapter(), which picks stdio or server mode based on self.run_as_server. This allows tests to run under both modes when toggling `LLDBDAP_RUN_AS_SERVER`, rather than being pinned to stdio.

>From 7a2949660da1aaa39b322bcc3524261f232647f8 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <e_ezike at apple.com>
Date: Tue, 29 Sep 2026 19:48:09 +0100
Subject: [PATCH] [lldb-dap] Let tests run under both stdio and server adapter
 modes

Add create_debug_adapter(), which picks stdio or server mode based on
self.run_as_server. This allows tests to run under both modes when toggling
LLDBDAP_RUN_AS_SERVER, rather than being pinned to stdio.
---
 .../lldbsuite/test/tools/lldb_dap/testcase.py | 44 +++++++++----------
 .../TestDAP_breakpointAssembly.py             |  2 +-
 .../launch/TestDAP_launch_no_lldbinit_flag.py |  2 +-
 .../launch/TestDAP_launch_termination.py      |  5 +--
 .../lldb-dap/save-core/TestDAP_save_core.py   |  2 +-
 5 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/testcase.py
index 86e781a9be9f5..8016a9f8d0aae 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/testcase.py
@@ -75,18 +75,8 @@ def close_log():
         self.addTearDownHook(close_log)
 
     def __create_default_debug_adapter(self):
-        self.assertFalse(hasattr(self, "adapter"), "A default adapter already exists.")
-
-        if self.run_as_server:
-            self.adapter = self.create_server_debug_adapter(
-                DebugAdapterOptions(cwd=self.getBuildDir()),
-                connection="listen://localhost:0",
-                connection_timeout=10,
-            )
-        else:
-            self.adapter = self.create_stdio_debug_adapter(
-                DebugAdapterOptions(cwd=self.getBuildDir())
-            )
+        self.assertFalse(hasattr(self, "_adapter"), "A default adapter already exists.")
+        self._adapter = self.create_debug_adapter()
 
     def create_session(
         self,
@@ -94,8 +84,8 @@ def create_session(
         disconnect_automatically: bool = True,
     ) -> DAPTestSession:
         if adapter is None:
-            self.assertIsNotNone(self.adapter, "expected we already have an adapter.")
-            adapter = self.adapter
+            self.assertIsNotNone(self._adapter, "expected we already have an adapter.")
+            adapter = self._adapter
         self.assertTrue(adapter.is_alive, "expected adapter process is alive.")
 
         build_dir = Path(self.getBuildDir())
@@ -131,7 +121,7 @@ def build_and_create_session(
         self.build()
         return self.create_session(adapter, disconnect_automatically)
 
-    def create_debug_adapter(
+    def __do_create_debug_adapter(
         self, adapter_options: DebugAdapterOptions
     ) -> DebugAdapter:
         self.assertTrue(
@@ -172,6 +162,16 @@ def cleanup_adapter():
         self.addTearDownHook(cleanup_adapter)
         return adapter
 
+    def create_debug_adapter(
+        self, options: Optional[DebugAdapterOptions] = None
+    ) -> DebugAdapter:
+        """Create a debug adapter, picking either stdio or server depending
+        on the LLDBDAP_RUN_AS_SERVER env flag."""
+        if self.run_as_server:
+            return self.create_server_debug_adapter(options)
+
+        return self.create_stdio_debug_adapter(options)
+
     def create_stdio_debug_adapter(
         self, adapter_options: Optional[DebugAdapterOptions] = None
     ) -> DebugAdapter:
@@ -181,24 +181,20 @@ def create_stdio_debug_adapter(
             adapter_options.connection, "'connection' cannot be used with stdio mode."
         )
 
-        adapter = self.create_debug_adapter(adapter_options)
+        adapter = self.__do_create_debug_adapter(adapter_options)
         self.assertFalse(adapter.is_server, "adapter should be using stdio.")
         return adapter
 
     def create_server_debug_adapter(
-        self,
-        adapter_options: Optional[DebugAdapterOptions] = None,
-        *,
-        connection: str,
-        connection_timeout: int,
+        self, adapter_options: Optional[DebugAdapterOptions] = None
     ) -> DebugAdapter:
         """Forces the adapter to server mode. the DebugAdapter class handles the validation."""
         adapter_options = adapter_options or DebugAdapterOptions()
         adapter_options = adapter_options.clone(
-            connection=connection,
-            connection_timeout=connection_timeout,
+            connection=adapter_options.connection or "listen://localhost:0",
+            connection_timeout=adapter_options.connection_timeout or 10,
         )
-        adapter = self.create_debug_adapter(adapter_options)
+        adapter = self.__do_create_debug_adapter(adapter_options)
         self.assertTrue(adapter.is_server, "adapter should run as a server.")
         return adapter
 
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py b/lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py
index 992bd32522b0d..0ba30a183d037 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint-assembly/TestDAP_breakpointAssembly.py
@@ -98,7 +98,7 @@ def test_persistent_assembly_breakpoint(self):
         session.stop()
 
         # Session 2: replay the persisted source and verify the breakpoint hits.
-        adapter = self.create_stdio_debug_adapter()
+        adapter = self.create_debug_adapter()
         session2 = self.create_session(adapter=adapter)
         with session2.configure(LaunchArgs(program)) as ctx:
             response = session2.set_assembly_breakpoints(
diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_no_lldbinit_flag.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_no_lldbinit_flag.py
index 1704129344295..da8fbd36aed59 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_no_lldbinit_flag.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_no_lldbinit_flag.py
@@ -31,7 +31,7 @@ def test(self):
             # temp dir and the --no-lldbinit flag.
             self.build()
             program = self.getBuildArtifact("a.out")
-            adapter = self.create_stdio_debug_adapter(
+            adapter = self.create_debug_adapter(
                 DebugAdapterOptions(
                     env={"HOME": temp_home},
                     args=["--no-lldbinit"],
diff --git a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_termination.py b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_termination.py
index 13962b8cd47c0..8144bcf78a8b7 100644
--- a/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_termination.py
+++ b/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch_termination.py
@@ -4,7 +4,7 @@
 
 from lldbsuite.test.decorators import requireSocketPermission
 from lldbsuite.test.tools.lldb_dap import DAPTestCaseBase
-from lldbsuite.test.tools.lldb_dap.utils import DebugAdapter
+from lldbsuite.test.tools.lldb_dap.utils import DebugAdapter, DebugAdapterOptions
 
 
 class TestDAP_launch_termination(DAPTestCaseBase):
@@ -17,8 +17,7 @@ class TestDAP_launch_termination(DAPTestCaseBase):
     @requireSocketPermission
     def test_termination_socket(self):
         adapter = self.create_server_debug_adapter(
-            connection="listen://localhost:0",
-            connection_timeout=1,
+            DebugAdapterOptions(connection="listen://localhost:0", connection_timeout=1)
         )
         self.do_test_termination(adapter)
 
diff --git a/lldb/test/API/tools/lldb-dap/save-core/TestDAP_save_core.py b/lldb/test/API/tools/lldb-dap/save-core/TestDAP_save_core.py
index 92e4385db4005..5bee8300a6ec8 100644
--- a/lldb/test/API/tools/lldb-dap/save-core/TestDAP_save_core.py
+++ b/lldb/test/API/tools/lldb-dap/save-core/TestDAP_save_core.py
@@ -55,7 +55,7 @@ def verify_core(
         """Attach to a saved core and verify the reloaded process state
         matches what was captured live: current frame, thread count,
         module count."""
-        session = self.create_session(adapter=self.create_stdio_debug_adapter())
+        session = self.create_session(adapter=self.create_debug_adapter())
         process_event = session.attach(AttachArgs(coreFile=str(core_path)))
 
         stop_event = session.verify_stopped_on_exception(after=process_event)



More information about the lldb-commits mailing list