================ @@ -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()) { + // 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(); + } + + int wpid = + llvm::sys::RetryAfterSignal(-1, ::waitpid, tid, nullptr, __WALL); + // Need to use __WALL otherwise we receive an error with errno=ECHLD At ---------------- DavidSpickett wrote:
Move this comment to before `wpid =`. Usual practice is to comment before doing something. 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