Skip to content

Commit fdd741d

Browse files
committed
[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.
1 parent 633b002 commit fdd741d

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,15 @@ Status NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid) {
426426
}
427427

428428
// Handles all waitpid events from the inferior process.
429-
void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
430-
WaitStatus status) {
429+
void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, WaitStatus status) {
431430
Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
432431

433432
// Certain activities differ based on whether the pid is the tid of the main
434433
// thread.
435434
const bool is_main_thread = (pid == GetID());
436435

437436
// Handle when the thread exits.
438-
if (exited) {
437+
if (status.type == WaitStatus::Exit || status.type == WaitStatus::Signal) {
439438
LLDB_LOG(log,
440439
"got exit status({0}) , tid = {1} ({2} main thread), process "
441440
"state = {3}",
@@ -485,7 +484,7 @@ void NativeProcessLinux::MonitorCallback(lldb::pid_t pid, bool exited,
485484
if (info.si_signo == SIGTRAP)
486485
MonitorSIGTRAP(info, *thread_sp);
487486
else
488-
MonitorSignal(info, *thread_sp, exited);
487+
MonitorSignal(info, *thread_sp);
489488
} else {
490489
if (info_err.GetError() == EINVAL) {
491490
// 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,
753752
default:
754753
LLDB_LOG(log, "received unknown SIGTRAP stop event ({0}, pid {1} tid {2}",
755754
info.si_code, GetID(), thread.GetID());
756-
MonitorSignal(info, thread, false);
755+
MonitorSignal(info, thread);
757756
break;
758757
}
759758
}
@@ -801,7 +800,7 @@ void NativeProcessLinux::MonitorWatchpoint(NativeThreadLinux &thread,
801800
}
802801

803802
void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
804-
NativeThreadLinux &thread, bool exited) {
803+
NativeThreadLinux &thread) {
805804
const int signo = info.si_signo;
806805
const bool is_from_llgs = info.si_pid == getpid();
807806

@@ -1962,16 +1961,11 @@ void NativeProcessLinux::SigchldHandler() {
19621961
}
19631962

19641963
WaitStatus wait_status = WaitStatus::Decode(status);
1965-
bool exited = wait_status.type == WaitStatus::Exit ||
1966-
(wait_status.type == WaitStatus::Signal &&
1967-
wait_pid == static_cast<::pid_t>(GetID()));
19681964

1969-
LLDB_LOG(
1970-
log,
1971-
"waitpid (-1, &status, _) => pid = {0}, status = {1}, exited = {2}",
1972-
wait_pid, wait_status, exited);
1965+
LLDB_LOG(log, "waitpid (-1, &status, _) => pid = {0}, status = {1}",
1966+
wait_pid, wait_status);
19731967

1974-
MonitorCallback(wait_pid, exited, wait_status);
1968+
MonitorCallback(wait_pid, wait_status);
19751969
}
19761970
}
19771971

lldb/source/Plugins/Process/Linux/NativeProcessLinux.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class NativeProcessLinux : public NativeProcessELF,
164164

165165
static Status SetDefaultPtraceOpts(const lldb::pid_t);
166166

167-
void MonitorCallback(lldb::pid_t pid, bool exited, WaitStatus status);
167+
void MonitorCallback(lldb::pid_t pid, WaitStatus status);
168168

169169
void WaitForCloneNotification(::pid_t pid);
170170

@@ -176,8 +176,7 @@ class NativeProcessLinux : public NativeProcessELF,
176176

177177
void MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index);
178178

179-
void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread,
180-
bool exited);
179+
void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread);
181180

182181
bool HasThreadNoLock(lldb::tid_t thread_id);
183182

0 commit comments

Comments
 (0)