[Lldb-commits] [lldb] [lldb][test] Add a function to spawn lldb-server platforms (PR #205083)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 22 04:39:00 PDT 2026
https://github.com/DavidSpickett updated https://github.com/llvm/llvm-project/pull/205083
>From 0cb586eacc7e96fe2690d21dcdc326e161f4e5c6 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at arm.com>
Date: Mon, 22 Jun 2026 09:58:56 +0000
Subject: [PATCH 1/2] [lldb][test] Add a function to spawn lldb-server
platforms
I will be doing this in a future test and we already have
a few copies of this code in various tests.
---
.../Python/lldbsuite/test/lldbutil.py | 21 ++++++++++++++
.../platform/connect/TestPlatformConnect.py | 29 ++++---------------
.../TestPlatformLaunchGDBServer.py | 23 +--------------
.../TestAutoInstallMainExecutable.py | 25 ++--------------
4 files changed, 30 insertions(+), 68 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 7698c709858e5..05a82bce2e938 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(test, platform_exe, extra_args=[]):
+ hostname = socket.getaddrinfo("localhost", 0, proto=socket.IPPROTO_TCP)[0][4][0]
+ port_file = test.getBuildArtifact("port")
+ commandline_args = [
+ "platform",
+ "--listen",
+ f"[{hostname}]:0",
+ "--socket-file",
+ port_file,
+ ] + extra_args
+ test.spawnSubprocess(platform_exe, commandline_args)
+
+ socket_id = wait_for_file_on_target(test, port_file)
+ new_platform = lldb.SBPlatform("remote-" + test.getPlatform())
+ test.dbg.SetSelectedPlatform(new_platform)
+ test.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 3f8d81c3ab897..e611b1af598f0 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 *
@@ -25,29 +24,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 e9e6845c0f549..84a86a249dc7a 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 *
@@ -12,27 +11,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 47bbd2439434c..89e78270d7454 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
@@ -22,27 +21,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)
>From 258eadf64665d7af2e1d065900ab494332f5459e Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at arm.com>
Date: Mon, 22 Jun 2026 11:38:38 +0000
Subject: [PATCH 2/2] test -> testcase
---
lldb/packages/Python/lldbsuite/test/lldbutil.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 05a82bce2e938..91f872bce3827 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1892,9 +1892,9 @@ def get_qsupported_capabilities(test):
return reply.strip().split(";")
-def connect_to_new_remote_platform(test, platform_exe, extra_args=[]):
+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 = test.getBuildArtifact("port")
+ port_file = testcase.getBuildArtifact("port")
commandline_args = [
"platform",
"--listen",
@@ -1902,11 +1902,11 @@ def connect_to_new_remote_platform(test, platform_exe, extra_args=[]):
"--socket-file",
port_file,
] + extra_args
- test.spawnSubprocess(platform_exe, commandline_args)
+ testcase.spawnSubprocess(platform_exe, commandline_args)
- socket_id = wait_for_file_on_target(test, port_file)
- new_platform = lldb.SBPlatform("remote-" + test.getPlatform())
- test.dbg.SetSelectedPlatform(new_platform)
- test.runCmd(f"platform connect connect://[{hostname}]:{socket_id}")
+ 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
More information about the lldb-commits
mailing list