[Lldb-commits] [lldb] [lldb] Use correct path for debugserver (PR #131609)
Yuval Deutscher via lldb-commits
lldb-commits at lists.llvm.org
Thu Apr 3 05:00:14 PDT 2025
https://github.com/yuvald-sweet-security updated https://github.com/llvm/llvm-project/pull/131609
>From 6f2d070facaced221295a5b0c48ccb3a41a5048d Mon Sep 17 00:00:00 2001
From: Yuval Deutscher <yuvald at sweet.security>
Date: Mon, 17 Mar 2025 14:37:26 +0200
Subject: [PATCH 1/2] [lldb] Use correct path for debugserver
---
lldb/tools/lldb-server/SystemInitializerLLGS.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lldb/tools/lldb-server/SystemInitializerLLGS.h b/lldb/tools/lldb-server/SystemInitializerLLGS.h
index 4469a8ba5f60a..c6020b0dd37da 100644
--- a/lldb/tools/lldb-server/SystemInitializerLLGS.h
+++ b/lldb/tools/lldb-server/SystemInitializerLLGS.h
@@ -11,10 +11,17 @@
#include "lldb/Initialization/SystemInitializer.h"
#include "lldb/Initialization/SystemInitializerCommon.h"
+#include "lldb/Utility/FileSpec.h"
class SystemInitializerLLGS : public lldb_private::SystemInitializerCommon {
public:
- SystemInitializerLLGS() : SystemInitializerCommon(nullptr) {}
+ SystemInitializerLLGS()
+ : SystemInitializerCommon(
+ // Finding the shared libraries directory on lldb-server is broken
+ // since lldb-server isn't dynamically linked with liblldb.so.
+ // Clearing the filespec here causes GetShlibDir to fail and
+ // GetSupportExeDir to fall-back to using the binary path instead.
+ [](lldb_private::FileSpec &file) { file.Clear(); }) {}
llvm::Error Initialize() override;
void Terminate() override;
>From 1b04782c9db3647d1379346ce36009dc077dddfc Mon Sep 17 00:00:00 2001
From: Yuval Deutscher <yuvald at sweet.security>
Date: Thu, 3 Apr 2025 14:52:43 +0300
Subject: [PATCH 2/2] [lldb] Test running lldb-server through symlink
---
.../TestPlatformLaunchGDBServer.py | 51 +++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
index c365bc993e338..e332035d0c767 100644
--- a/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
+++ b/lldb/test/API/commands/platform/launchgdbserver/TestPlatformLaunchGDBServer.py
@@ -58,3 +58,54 @@ def test_platform_process_launch_gdb_server(self):
self.runCmd("target create {}".format(self.getBuildArtifact("a.out")))
self.expect("run", substrs=["unable to launch a GDB server on"], error=True)
+
+ @skipIfRemote
+ # Windows cannot delete the executable while it is running.
+ # On Darwin we may be using debugserver.
+ @skipUnlessPlatform(["linux"])
+ @add_test_categories(["lldb-server"])
+ def test_platform_process_launch_gdb_server(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",
+ ]
+
+ # Run lldb-server from a symlink without any binary called "lldb-server" in the directory.
+ llgs_hiding_directory = self.getBuildArtifact("hiding-directory")
+ new_lldb_server_link = self.getBuildArtifact(
+ "lldb-server-with-an-unconventional-name"
+ )
+ new_lldb_server = os.path.join(llgs_hiding_directory, "lldb-server")
+ os.makedirs(llgs_hiding_directory)
+ shutil.copy(lldbgdbserverutils.get_lldb_server_exe(), new_lldb_server)
+ os.symlink(new_lldb_server, new_lldb_server_link)
+
+ self.spawnSubprocess(new_lldb_server_link, 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)
+
+ # First connect to lldb-server which spawn a process to handle the connection.
+ # Then remove our new lldb-server so that when it tries to invoke itself as a
+ # gdbserver, it fails.
+ os.remove(new_lldb_server_link)
+ shutil.rmtree(llgs_hiding_directory)
+
+ self.runCmd("target create {}".format(self.getBuildArtifact("a.out")))
+ self.expect("run", substrs=["unable to launch a GDB server on"], error=True)
More information about the lldb-commits
mailing list