[review] [gdb/threads] Fix hang in stop_all_threads after killing inferior
Tom de Vries (Code Review)
gerrit@gnutoolchain-gerrit.osci.io
Wed Jan 29 14:11:00 GMT 2020
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/759
......................................................................
[gdb/threads] Fix hang in stop_all_threads after killing inferior
Consider a two-threaded testcase a.out, sleeping in both its threads:
...
$ gdb -ex r --args a.out
Reading symbols from a.out...
Starting program: /data/gdb_versions/devel/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff77fe700 (LWP 31268)]
...
Typing ^C causing stop_all_threads to be executed, and if an external SIGKILL
(such as caused by killall -9 a.out) arrives at the start of stop_all_threads,
gdb hangs in stop_all_threads after giving this warning:
...
warning: unable to open /proc file '/proc/24938/status'
...
Using "set debug infrun 1" we can see in more detail where we hang:
...
infrun: stop_all_threads
infrun: stop_all_threads, pass=0, iterations=0
infrun: Thread 0x7ffff7fa6740 (LWP 10264) not executing
infrun: Thread 0x7ffff77fe700 (LWP 10268) executing, need stop
infrun: target_wait (-1.0.0, status) =
infrun: 10264.10268.0 [Thread 0x7ffff77fe700 (LWP 10268)],
infrun: status->kind = signalled, signal = GDB_SIGNAL_KILL
infrun: stop_all_threads status->kind = signalled, signal = GDB_SIGNAL_KILL \
Thread 0x7ffff77fe700 (LWP 10268)
infrun: Thread 0x7ffff7fa6740 (LWP 10264) not executing
infrun: Thread 0x7ffff77fe700 (LWP 10268) executing, already stopping
warning: unable to open /proc file '/proc/10264/status'
infrun: target_wait (-1.0.0, status) =
infrun: -1.0.0 [process -1],
infrun: status->kind = no-resumed
infrun: infrun_async(0)
infrun: stop_all_threads status->kind = no-resumed process -1
infrun: Thread 0x7ffff7fa6740 (LWP 10264) not executing
infrun: Thread 0x7ffff77fe700 (LWP 10268) executing, already stopping
infrun: stop_all_threads status->kind = no-resumed process -1
infrun: Thread 0x7ffff7fa6740 (LWP 10264) not executing
infrun: Thread 0x7ffff77fe700 (LWP 10268) executing, already stopping
infrun: stop_all_threads status->kind = no-resumed process -1
infrun: Thread 0x7ffff7fa6740 (LWP 10264) not executing
infrun: Thread 0x7ffff77fe700 (LWP 10268) executing, already stopping
<repeat>
......
So, we're hanging in the 'while (1)' loop in stop_all_threads as follows:
- thread t is tested, and both t->executing and t->stop_requested are found
to be 1
- consequently need_wait is set 1
- consequently wait_one is executed
- wait_one returns a TARGET_WAITKIND_NO_RESUMED event, which is handled by
continuing at the start of the loop
The loop actually starts with update_thread_list (), but that doesn't seem
to change the state of the threads.
Fix the hang by detecting the first sign of trouble: the
TARGET_WAITKIND_SIGNALLED event with signal GDB_SIGNAL_KILL, and breaking out
of the loop.
Build and reg-tested on x86_64-linux.
gdb/ChangeLog:
2020-01-29 Tom de Vries <tdevries@suse.de>
PR threads/25478
* infrun.c (stop_all_threads): Return when detecting event
TARGET_WAITKIND_SIGNALLED with signal GDB_SIGNAL_KILL.
Change-Id: Ibe1f29251fe2ff1c1991f041babbe18373c113b1
---
M gdb/infrun.c
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 22de42c..e34ddc8 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4772,7 +4772,10 @@
target_pid_to_str (event.ptid).c_str ());
}
- if (event.ws.kind == TARGET_WAITKIND_NO_RESUMED
+ if (event.ws.kind == TARGET_WAITKIND_SIGNALLED
+ && event.ws.value.sig == GDB_SIGNAL_KILL)
+ goto done;
+ else if (event.ws.kind == TARGET_WAITKIND_NO_RESUMED
|| event.ws.kind == TARGET_WAITKIND_THREAD_EXITED
|| event.ws.kind == TARGET_WAITKIND_EXITED
|| event.ws.kind == TARGET_WAITKIND_SIGNALLED)
@@ -4872,6 +4875,7 @@
}
}
+ done:
if (debug_infrun)
fprintf_unfiltered (gdb_stdlog, "infrun: stop_all_threads done\n");
}
--
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ibe1f29251fe2ff1c1991f041babbe18373c113b1
Gerrit-Change-Number: 759
Gerrit-PatchSet: 1
Gerrit-Owner: Tom de Vries <tdevries@suse.de>
Gerrit-MessageType: newchange
More information about the Gdb-patches
mailing list