================ @@ -444,6 +461,88 @@ NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd, SetState(StateType::eStateStopped, false); } +llvm::Expected<std::vector<::pid_t>> NativeProcessLinux::Seize(::pid_t pid) { + Log *log = GetLog(POSIXLog::Process); + + uint64_t options = GetDefaultPtraceOpts(); + Status status; + // Use a map to keep track of the threads which we have attached/need to + // attach. + Host::TidMap tids_to_attach; + while (Host::FindProcessThreads(pid, tids_to_attach)) { + for (Host::TidMap::iterator it = tids_to_attach.begin(); + it != tids_to_attach.end();) { + if (it->second == true) { + continue; + } + lldb::tid_t tid = it->first; + if ((status = PtraceWrapper(PTRACE_SEIZE, tid, nullptr, (void *)options)) + .Fail()) { + // No such thread. The thread may have exited. More error handling + // may be needed. + if (status.GetError() == ESRCH) { + it = tids_to_attach.erase(it); + continue; + } + if (status.GetError() == EPERM) { + // Depending on the value of ptrace_scope, we can return a + // different error that suggests how to fix it. + return AddPtraceScopeNote(status.ToError()); + } + return status.ToError(); + } + + if ((status = PtraceWrapper(PTRACE_INTERRUPT, tid)).Fail()) { ---------------- DavidSpickett wrote:
Shame that we can't do these two PtraceWrapper calls like: ``` if (status = PtraceWrapper(PTRACE_SEIZE).Fail() || status = PTraceWrapper(PTRACE_INTERRUPT).Fail()) <the error handling bit> ``` Maybe something with `,` could do it, I'm not too familiar with that. Another way to do it is: ``` status = PTraceWrapper(PPTRACE_SEIZE); if (!status.Fail()) status = PTraceWrapper(PTRACE_INTERRUPT) if (status.Fail()) <common error handling> ``` https://github.com/llvm/llvm-project/pull/137041 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits