From 69c39e2abc311aa226d54b82a2cc8fa648902c7d Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 2 Aug 2022 13:34:24 +0200 Subject: [lldb] Fix TestDeletedExecutable on linux Currently, lldb-server was opening the executable file to determine the process architecture (to differentiate between 32 and 64 bit architecture flavours). This isn't a particularly trustworthy source of information (the file could have been changed since the process was started) and it is not always available (file could be deleted or otherwise inaccessible). Unfortunately, ptrace does not give us a direct API to access the process architecture, but we can still infer it via some of its responses -- given that the general purpose register set of 64-bit applications is larger [citation needed] than the GPR set of 32-bit ones, we can just ask for the application GPR set and check its size. This is what this patch does. Differential Revision: https://reviews.llvm.org/D130985 --- .../Plugins/Process/Linux/NativeProcessLinux.cpp | 31 +++++++++------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp') diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index f7f52deb173f..ec2aebc4ec19 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -246,25 +246,20 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info, } LLDB_LOG(log, "inferior started, now in stopped state"); - ProcessInstanceInfo Info; - if (!Host::GetProcessInfo(pid, Info)) { - return llvm::make_error("Cannot get process architecture", - llvm::inconvertibleErrorCode()); - } - - // Set the architecture to the exe architecture. - LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid, - Info.GetArchitecture().GetArchitectureName()); - status = SetDefaultPtraceOpts(pid); if (status.Fail()) { LLDB_LOG(log, "failed to set default ptrace options: {0}", status); return status.ToError(); } + llvm::Expected arch_or = + NativeRegisterContextLinux::DetermineArchitecture(pid); + if (!arch_or) + return arch_or.takeError(); + return std::unique_ptr(new NativeProcessLinux( pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate, - Info.GetArchitecture(), mainloop, {pid})); + *arch_or, mainloop, {pid})); } llvm::Expected> @@ -274,19 +269,17 @@ NativeProcessLinux::Factory::Attach( Log *log = GetLog(POSIXLog::Process); LLDB_LOG(log, "pid = {0:x}", pid); - // Retrieve the architecture for the running process. - ProcessInstanceInfo Info; - if (!Host::GetProcessInfo(pid, Info)) { - return llvm::make_error("Cannot get process architecture", - llvm::inconvertibleErrorCode()); - } - auto tids_or = NativeProcessLinux::Attach(pid); if (!tids_or) return tids_or.takeError(); + ArrayRef<::pid_t> tids = *tids_or; + llvm::Expected arch_or = + NativeRegisterContextLinux::DetermineArchitecture(tids[0]); + if (!arch_or) + return arch_or.takeError(); return std::unique_ptr(new NativeProcessLinux( - pid, -1, native_delegate, Info.GetArchitecture(), mainloop, *tids_or)); + pid, -1, native_delegate, *arch_or, mainloop, tids)); } NativeProcessLinux::Extension -- cgit v1.2.3