[Lldb-commits] [lldb] ba8e423 - [lldb][test] Add a function to spawn lldb-server platforms (#205083)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jul 3 02:27:18 PDT 2026
Author: David Spickett
Date: 2026-07-03T10:27:14+01:00
New Revision: ba8e423be48d3505b89f27348faaad3e810168fa
URL: https://github.com/llvm/llvm-project/commit/ba8e423be48d3505b89f27348faaad3e810168fa
DIFF: https://github.com/llvm/llvm-project/commit/ba8e423be48d3505b89f27348faaad3e810168fa.diff
LOG: [lldb][test] Add a function to spawn lldb-server platforms (#205083)
I will be doing this in a future test and we already have a few copies of this code in various tests.
Added:
Modified:
lldb/packages/Python/lldbsuite/test/lldbutil.py
lldb/test/API/commands/platform/connect/TestPlatformConnect.py
lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
Removed:
################################################################################
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 7698c709858e5..91f872bce3827 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -10,6 +10,7 @@
import json
import os
import re
+import socket
import sys
import subprocess
import time
@@ -1889,3 +1890,23 @@ def send_packet_get_reply(test, packet_str):
def get_qsupported_capabilities(test):
reply = send_packet_get_reply(test, "qSupported")
return reply.strip().split(";")
+
+
+def connect_to_new_remote_platform(testcase, platform_exe, extra_args=[]):
+ hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
+ port_file = testcase.getBuildArtifact("port")
+ commandline_args = [
+ "platform",
+ "--listen",
+ f"[{hostname}]:0",
+ "--socket-file",
+ port_file,
+ ] + extra_args
+ testcase.spawnSubprocess(platform_exe, commandline_args)
+
+ socket_id = wait_for_file_on_target(testcase, port_file)
+ new_platform = lldb.SBPlatform("remote-" + testcase.getPlatform())
+ testcase.dbg.SetSelectedPlatform(new_platform)
+ testcase.runCmd(f"platform connect connect://[{hostname}]:{socket_id}")
+
+ return new_platform
diff --git a/lldb/test/API/commands/platform/connect/TestPlatformConnect.py b/lldb/test/API/commands/platform/connect/TestPlatformConnect.py
index 93fa5a5da45ea..15c1bff44e93b 100644
--- a/lldb/test/API/commands/platform/connect/TestPlatformConnect.py
+++ b/lldb/test/API/commands/platform/connect/TestPlatformConnect.py
@@ -1,4 +1,3 @@
-import socket
import gdbremote_testcase
import lldbgdbserverutils
from lldbsuite.test.decorators import *
@@ -26,29 +25,11 @@ class TestPlatformProcessConnect(TestBase):
def test_platform_process_connect(self):
self.build()
- hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
- listen_url = "[%s]:0" % hostname
-
- port_file = self.getBuildArtifact("port")
- commandline_args = [
- "platform",
- "--listen",
- listen_url,
- "--socket-file",
- port_file,
- "--",
- self.getBuildArtifact("a.out"),
- "foo",
- ]
- self.spawnSubprocess(lldbgdbserverutils.get_lldb_server_exe(), commandline_args)
-
- socket_id = lldbutil.wait_for_file_on_target(self, port_file)
-
- new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
- self.dbg.SetSelectedPlatform(new_platform)
-
- connect_url = "connect://[%s]:%s" % (hostname, socket_id)
- self.runCmd("platform connect %s" % connect_url)
+ lldbutil.connect_to_new_remote_platform(
+ self,
+ lldbgdbserverutils.get_lldb_server_exe(),
+ extra_args=["--", self.getBuildArtifact("a.out"), "foo"],
+ )
lldbutil.run_break_set_by_symbol(self, "main")
process = self.process()
diff --git a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
index 5d318e8d8bd20..93f9d9a4f6948 100644
--- a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
+++ b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
@@ -1,5 +1,4 @@
import os
-import socket
import shutil
import lldbgdbserverutils
from lldbsuite.test.decorators import *
@@ -13,27 +12,7 @@ class TestPlatformProcessLaunchGDBServer(TestBase):
SHARED_BUILD_TESTCASE = False
def _launch_and_connect(self, exe):
- hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
- listen_url = "[%s]:0" % hostname
-
- port_file = self.getBuildArtifact("port")
- commandline_args = [
- "platform",
- "--listen",
- listen_url,
- "--socket-file",
- port_file,
- ]
-
- self.spawnSubprocess(exe, commandline_args)
- socket_id = lldbutil.wait_for_file_on_target(self, port_file)
-
- new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
- self.dbg.SetSelectedPlatform(new_platform)
-
- connect_url = "connect://[%s]:%s" % (hostname, socket_id)
- self.runCmd("platform connect %s" % connect_url)
-
+ new_platform = lldbutil.connect_to_new_remote_platform(self, exe)
wd = self.getBuildArtifact("wd")
os.mkdir(wd)
new_platform.SetWorkingDirectory(wd)
diff --git a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
index f0bb450fb65e6..72143837f711f 100644
--- a/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
+++ b/lldb/test/API/commands/target/auto-install-main-executable/TestAutoInstallMainExecutable.py
@@ -2,7 +2,6 @@
Test target commands: target.auto-install-main-executable.
"""
-import socket
import time
import lldbgdbserverutils
@@ -23,27 +22,9 @@ def test_target_auto_install_main_executable(self):
self.skipTest("lldb-server not found")
self.build()
- hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
- listen_url = "[%s]:0" % hostname
-
- port_file = self.getBuildArtifact("port")
- commandline_args = [
- "platform",
- "--listen",
- listen_url,
- "--socket-file",
- port_file,
- ]
- self.spawnSubprocess(lldbgdbserverutils.get_lldb_server_exe(), commandline_args)
-
- socket_id = lldbutil.wait_for_file_on_target(self, port_file)
-
- new_platform = lldb.SBPlatform("remote-" + self.getPlatform())
- self.dbg.SetSelectedPlatform(new_platform)
-
- connect_url = "connect://[%s]:%s" % (hostname, socket_id)
- connect_opts = lldb.SBPlatformConnectOptions(connect_url)
- self.assertSuccess(new_platform.ConnectRemote(connect_opts))
+ new_platform = lldbutil.connect_to_new_remote_platform(
+ self, lldbgdbserverutils.get_lldb_server_exe()
+ )
wd = self.getBuildArtifact("wd")
os.mkdir(wd)
More information about the lldb-commits
mailing list