From 126a2607a8458c7928aa1da880d45c36560017a6 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Mon, 21 Feb 2022 15:38:52 +0100 Subject: [PATCH] [lldb] Remove HostProcess:GetMainModule the function is unused, and the posix implementation is only really correct on linux. --- .../include/lldb/Host/HostNativeProcessBase.h | 1 - lldb/include/lldb/Host/HostProcess.h | 1 - .../lldb/Host/posix/HostProcessPosix.h | 1 - .../lldb/Host/windows/HostProcessWindows.h | 1 - lldb/source/Host/common/HostProcess.cpp | 4 --- lldb/source/Host/posix/HostProcessPosix.cpp | 25 ------------------- .../Host/windows/HostProcessWindows.cpp | 18 ------------- 7 files changed, 51 deletions(-) diff --git a/lldb/include/lldb/Host/HostNativeProcessBase.h b/lldb/include/lldb/Host/HostNativeProcessBase.h index 5469f8a50e26..349e3349183b 100644 --- a/lldb/include/lldb/Host/HostNativeProcessBase.h +++ b/lldb/include/lldb/Host/HostNativeProcessBase.h @@ -30,7 +30,6 @@ public: virtual ~HostNativeProcessBase() = default; virtual Status Terminate() = 0; - virtual Status GetMainModule(FileSpec &file_spec) const = 0; virtual lldb::pid_t GetProcessId() const = 0; virtual bool IsRunning() const = 0; diff --git a/lldb/include/lldb/Host/HostProcess.h b/lldb/include/lldb/Host/HostProcess.h index 0b7c30364223..00cb6a212736 100644 --- a/lldb/include/lldb/Host/HostProcess.h +++ b/lldb/include/lldb/Host/HostProcess.h @@ -37,7 +37,6 @@ public: ~HostProcess(); Status Terminate(); - Status GetMainModule(FileSpec &file_spec) const; lldb::pid_t GetProcessId() const; bool IsRunning() const; diff --git a/lldb/include/lldb/Host/posix/HostProcessPosix.h b/lldb/include/lldb/Host/posix/HostProcessPosix.h index 5def1b77eefe..eec19b621a89 100644 --- a/lldb/include/lldb/Host/posix/HostProcessPosix.h +++ b/lldb/include/lldb/Host/posix/HostProcessPosix.h @@ -27,7 +27,6 @@ public: static Status Signal(lldb::process_t process, int signo); Status Terminate() override; - Status GetMainModule(FileSpec &file_spec) const override; lldb::pid_t GetProcessId() const override; bool IsRunning() const override; diff --git a/lldb/include/lldb/Host/windows/HostProcessWindows.h b/lldb/include/lldb/Host/windows/HostProcessWindows.h index 925d565c275e..dc27bdc46bb8 100644 --- a/lldb/include/lldb/Host/windows/HostProcessWindows.h +++ b/lldb/include/lldb/Host/windows/HostProcessWindows.h @@ -25,7 +25,6 @@ public: void SetOwnsHandle(bool owns); Status Terminate() override; - Status GetMainModule(FileSpec &file_spec) const override; lldb::pid_t GetProcessId() const override; bool IsRunning() const override; diff --git a/lldb/source/Host/common/HostProcess.cpp b/lldb/source/Host/common/HostProcess.cpp index 06dd192013ba..83b856df36eb 100644 --- a/lldb/source/Host/common/HostProcess.cpp +++ b/lldb/source/Host/common/HostProcess.cpp @@ -22,10 +22,6 @@ HostProcess::~HostProcess() = default; Status HostProcess::Terminate() { return m_native_process->Terminate(); } -Status HostProcess::GetMainModule(FileSpec &file_spec) const { - return m_native_process->GetMainModule(file_spec); -} - lldb::pid_t HostProcess::GetProcessId() const { return m_native_process->GetProcessId(); } diff --git a/lldb/source/Host/posix/HostProcessPosix.cpp b/lldb/source/Host/posix/HostProcessPosix.cpp index 8599a94d2241..9889be07bca8 100644 --- a/lldb/source/Host/posix/HostProcessPosix.cpp +++ b/lldb/source/Host/posix/HostProcessPosix.cpp @@ -49,31 +49,6 @@ Status HostProcessPosix::Signal(lldb::process_t process, int signo) { Status HostProcessPosix::Terminate() { return Signal(SIGKILL); } -Status HostProcessPosix::GetMainModule(FileSpec &file_spec) const { - Status error; - - // Use special code here because proc/[pid]/exe is a symbolic link. - char link_path[PATH_MAX]; - if (snprintf(link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_process) != 1) { - error.SetErrorString("Unable to build /proc//exe string"); - return error; - } - - error = FileSystem::Instance().Readlink(FileSpec(link_path), file_spec); - if (!error.Success()) - return error; - - // If the binary has been deleted, the link name has " (deleted)" appended. - // Remove if there. - if (file_spec.GetFilename().GetStringRef().endswith(" (deleted)")) { - const char *filename = file_spec.GetFilename().GetCString(); - static const size_t deleted_len = strlen(" (deleted)"); - const size_t len = file_spec.GetFilename().GetLength(); - file_spec.GetFilename().SetCStringWithLength(filename, len - deleted_len); - } - return error; -} - lldb::pid_t HostProcessPosix::GetProcessId() const { return m_process; } bool HostProcessPosix::IsRunning() const { diff --git a/lldb/source/Host/windows/HostProcessWindows.cpp b/lldb/source/Host/windows/HostProcessWindows.cpp index 0dc23e1a6562..741ec68d1d1e 100644 --- a/lldb/source/Host/windows/HostProcessWindows.cpp +++ b/lldb/source/Host/windows/HostProcessWindows.cpp @@ -48,24 +48,6 @@ Status HostProcessWindows::Terminate() { return error; } -Status HostProcessWindows::GetMainModule(FileSpec &file_spec) const { - Status error; - if (m_process == nullptr) - error.SetError(ERROR_INVALID_HANDLE, lldb::eErrorTypeWin32); - - std::vector wpath(PATH_MAX); - if (::GetProcessImageFileNameW(m_process, wpath.data(), wpath.size())) { - std::string path; - if (llvm::convertWideToUTF8(wpath.data(), path)) - file_spec.SetFile(path, FileSpec::Style::native); - else - error.SetErrorString("Error converting path to UTF-8"); - } else - error.SetError(::GetLastError(), lldb::eErrorTypeWin32); - - return error; -} - lldb::pid_t HostProcessWindows::GetProcessId() const { return (m_process == LLDB_INVALID_PROCESS) ? -1 : ::GetProcessId(m_process); }