aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2022-08-02 13:34:24 +0200
committerPavel Labath <pavel@labath.sk>2022-08-03 15:44:19 +0200
commit69c39e2abc311aa226d54b82a2cc8fa648902c7d (patch)
treedf3beb0905f74410f1b3da8df44248b0b4789abe /lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
parentfb65b17932e1163adeda943a3a36f9b482b97f47 (diff)
downloadllvm-69c39e2abc311aa226d54b82a2cc8fa648902c7d.zip
llvm-69c39e2abc311aa226d54b82a2cc8fa648902c7d.tar.gz
llvm-69c39e2abc311aa226d54b82a2cc8fa648902c7d.tar.bz2
[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
Diffstat (limited to 'lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp')
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp31
1 files changed, 12 insertions, 19 deletions
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index f7f52de..ec2aebc 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<StringError>("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<ArchSpec> arch_or =
+ NativeRegisterContextLinux::DetermineArchitecture(pid);
+ if (!arch_or)
+ return arch_or.takeError();
+
return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate,
- Info.GetArchitecture(), mainloop, {pid}));
+ *arch_or, mainloop, {pid}));
}
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
@@ -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<StringError>("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<ArchSpec> arch_or =
+ NativeRegisterContextLinux::DetermineArchitecture(tids[0]);
+ if (!arch_or)
+ return arch_or.takeError();
return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
- pid, -1, native_delegate, Info.GetArchitecture(), mainloop, *tids_or));
+ pid, -1, native_delegate, *arch_or, mainloop, tids));
}
NativeProcessLinux::Extension