diff options
author | Pavel Labath <pavel@labath.sk> | 2025-06-27 11:16:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-27 11:16:57 +0200 |
commit | 2c90c0b90cbdfbd069b2e79d6a2c3e3b160bf896 (patch) | |
tree | 78ef76376e2dc2c23607e883aa57dd8b540a599f /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | |
parent | 7255c3aee3ebd94d51067d4682400444a97a8faa (diff) | |
download | llvm-2c90c0b90cbdfbd069b2e79d6a2c3e3b160bf896.zip llvm-2c90c0b90cbdfbd069b2e79d6a2c3e3b160bf896.tar.gz llvm-2c90c0b90cbdfbd069b2e79d6a2c3e3b160bf896.tar.bz2 |
[lldb] Extract debug server location code (#145706)
.. from the guts of GDBRemoteCommunication to ~top level.
This is motivated by #131519 and by the fact that's impossible to guess
whether the author of a symlink intended it to be a "convenience
shortcut" -- meaning it should be resolved before looking for related
files; or an "implementation detail" -- meaning the related files should
be located near the symlink itself.
This debate is particularly ridiculous when it comes to lldb-server
running in platform mode, because it also functions as a debug server,
so what we really just need to do is to pass /proc/self/exe in a
platform-independent manner.
Moving the location logic higher up achieves that as lldb-platform (on
non-macos) can pass `HostInfo::GetProgramFileSpec`, while liblldb can
use the existing complex logic (which only worked on liblldb anyway as
lldb-platform doesn't have a lldb_private::Platform instance).
Another benefit of this patch is a reduction in dependency from
GDBRemoteCommunication to the rest of liblldb (achieved by avoiding the
Platform dependency).
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp')
-rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp | 77 |
1 files changed, 1 insertions, 76 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 4bb85f5..d7e4b2b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -11,7 +11,6 @@ #include "lldb/Host/Config.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/Host.h" -#include "lldb/Host/HostInfo.h" #include "lldb/Host/Pipe.h" #include "lldb/Host/ProcessLaunchInfo.h" #include "lldb/Host/Socket.h" @@ -33,14 +32,6 @@ #include <sys/stat.h> #include <variant> -#if defined(__APPLE__) -#define DEBUGSERVER_BASENAME "debugserver" -#elif defined(_WIN32) -#define DEBUGSERVER_BASENAME "lldb-server.exe" -#else -#define DEBUGSERVER_BASENAME "lldb-server" -#endif - #if HAVE_LIBCOMPRESSION #include <compression.h> #endif @@ -836,77 +827,11 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, return GDBRemoteCommunication::PacketType::Invalid; } -FileSpec GDBRemoteCommunication::GetDebugserverPath(Platform *platform) { - Log *log = GetLog(GDBRLog::Process); - // If we locate debugserver, keep that located version around - static FileSpec g_debugserver_file_spec; - FileSpec debugserver_file_spec; - - Environment host_env = Host::GetEnvironment(); - - // Always check to see if we have an environment override for the path to the - // debugserver to use and use it if we do. - std::string env_debugserver_path = host_env.lookup("LLDB_DEBUGSERVER_PATH"); - if (!env_debugserver_path.empty()) { - debugserver_file_spec.SetFile(env_debugserver_path, - FileSpec::Style::native); - LLDB_LOGF(log, - "GDBRemoteCommunication::%s() gdb-remote stub exe path set " - "from environment variable: %s", - __FUNCTION__, env_debugserver_path.c_str()); - } else - debugserver_file_spec = g_debugserver_file_spec; - bool debugserver_exists = - FileSystem::Instance().Exists(debugserver_file_spec); - if (!debugserver_exists) { - // The debugserver binary is in the LLDB.framework/Resources directory. - debugserver_file_spec = HostInfo::GetSupportExeDir(); - if (debugserver_file_spec) { - debugserver_file_spec.AppendPathComponent(DEBUGSERVER_BASENAME); - debugserver_exists = FileSystem::Instance().Exists(debugserver_file_spec); - if (debugserver_exists) { - LLDB_LOGF(log, - "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'", - __FUNCTION__, debugserver_file_spec.GetPath().c_str()); - - g_debugserver_file_spec = debugserver_file_spec; - } else { - if (platform) - debugserver_file_spec = - platform->LocateExecutable(DEBUGSERVER_BASENAME); - else - debugserver_file_spec.Clear(); - if (debugserver_file_spec) { - // Platform::LocateExecutable() wouldn't return a path if it doesn't - // exist - debugserver_exists = true; - } else { - LLDB_LOGF(log, - "GDBRemoteCommunication::%s() could not find " - "gdb-remote stub exe '%s'", - __FUNCTION__, debugserver_file_spec.GetPath().c_str()); - } - // Don't cache the platform specific GDB server binary as it could - // change from platform to platform - g_debugserver_file_spec.Clear(); - } - } - } - return debugserver_file_spec; -} - Status GDBRemoteCommunication::StartDebugserverProcess( - std::variant<llvm::StringRef, shared_fd_t> comm, Platform *platform, + std::variant<llvm::StringRef, shared_fd_t> comm, ProcessLaunchInfo &launch_info, const Args *inferior_args) { Log *log = GetLog(GDBRLog::Process); - FileSpec debugserver_file_spec = GetDebugserverPath(platform); - if (!debugserver_file_spec) - return Status::FromErrorString("unable to locate " DEBUGSERVER_BASENAME); - - launch_info.SetExecutableFile(debugserver_file_spec, - /*add_exe_file_as_first_arg=*/true); - Args &debugserver_args = launch_info.GetArguments(); #if !defined(__APPLE__) |