[lldb/linux] Fix a bug in wait status handling

The MonitorCallback function was assuming that the "exited" argument is
set whenever a thread exits, but the caller was only setting that flag
for the main thread.

This patch deletes the argument altogether, and lets MonitorCallback
compute what it needs itself.

This is almost NFC, since previously we would end up in the
"GetSignalInfo failed for unknown reasons" branch, which was doing the
same thing -- forgetting about the thread.
This commit is contained in:
Pavel Labath 2021-12-29 10:54:46 +01:00
parent 633b002944
commit fdd741dd31
2 changed files with 10 additions and 17 deletions

View File

@ -426,8 +426,7 @@ Status NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid) {
} }
// Handles all waitpid events from the inferior process. // Handles all waitpid events from the inferior process.
void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited, void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, WaitStatus status) {
WaitStatus status) {
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
// Certain activities differ based on whether the pid is the tid of the main // Certain activities differ based on whether the pid is the tid of the main
@ -435,7 +434,7 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
const bool is_main_thread = (pid == GetID()); const bool is_main_thread = (pid == GetID());
// Handle when the thread exits. // Handle when the thread exits.
if (exited) { if (status.type == WaitStatus::Exit || status.type == WaitStatus::Signal) {
LLDB_LOG(log, LLDB_LOG(log,
"got exit status({0}) , tid = {1} ({2} main thread), process " "got exit status({0}) , tid = {1} ({2} main thread), process "
"state = {3}", "state = {3}",
@ -485,7 +484,7 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
if (info.si_signo == SIGTRAP) if (info.si_signo == SIGTRAP)
MonitorSIGTRAP(info, *thread_sp); MonitorSIGTRAP(info, *thread_sp);
else else
MonitorSignal(info, *thread_sp, exited); MonitorSignal(info, *thread_sp);
} else { } else {
if (info_err.GetError() == EINVAL) { if (info_err.GetError() == EINVAL) {
// This is a group stop reception for this tid. We can reach here if we // This is a group stop reception for this tid. We can reach here if we
@ -753,7 +752,7 @@ void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
default: default:
LLDB_LOG(log, "received unknown SIGTRAP stop event ({0}, pid {1} tid {2}", LLDB_LOG(log, "received unknown SIGTRAP stop event ({0}, pid {1} tid {2}",
info.si_code, GetID(), thread.GetID()); info.si_code, GetID(), thread.GetID());
MonitorSignal(info, thread, false); MonitorSignal(info, thread);
break; break;
} }
} }
@ -801,7 +800,7 @@ void NativeProcessLinux::MonitorWatchpoint(NativeThreadLinux &thread,
} }
void NativeProcessLinux::MonitorSignal(const siginfo_t &info, void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
NativeThreadLinux &thread, bool exited) { NativeThreadLinux &thread) {
const int signo = info.si_signo; const int signo = info.si_signo;
const bool is_from_llgs = info.si_pid == getpid(); const bool is_from_llgs = info.si_pid == getpid();
@ -1962,16 +1961,11 @@ void NativeProcessLinux::SigchldHandler() {
} }
WaitStatus wait_status = WaitStatus::Decode(status); WaitStatus wait_status = WaitStatus::Decode(status);
bool exited = wait_status.type == WaitStatus::Exit ||
(wait_status.type == WaitStatus::Signal &&
wait_pid == static_cast<::pid_t>(GetID()));
LLDB_LOG( LLDB_LOG(log, "waitpid (-1, &status, _) => pid = {0}, status = {1}",
log, wait_pid, wait_status);
"waitpid (-1, &status, _) => pid = {0}, status = {1}, exited = {2}",
wait_pid, wait_status, exited);
MonitorCallback(wait_pid, exited, wait_status); MonitorCallback(wait_pid, wait_status);
} }
} }

View File

@ -164,7 +164,7 @@ private:
static Status SetDefaultPtraceOpts(const lldb::pid_t); static Status SetDefaultPtraceOpts(const lldb::pid_t);
void MonitorCallback(lldb::pid_t pid, bool exited, WaitStatus status); void MonitorCallback(lldb::pid_t pid, WaitStatus status);
void WaitForCloneNotification(::pid_t pid); void WaitForCloneNotification(::pid_t pid);
@ -176,8 +176,7 @@ private:
void MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index); void MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index);
void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread, void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread);
bool exited);
bool HasThreadNoLock(lldb::tid_t thread_id); bool HasThreadNoLock(lldb::tid_t thread_id);