This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[gdbserver] Problems trying to resume dead threads
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: gdb-patches at sourceware dot org
- Date: Sat, 19 Jul 2008 19:16:48 +0200 (CEST)
- Subject: [gdbserver] Problems trying to resume dead threads
Hello,
gdbserver on Linux seems to have difficulties handling
the case where a thread dies while it is stopped. This can
happen during the loop over all threads in linux_resume:
1. Thread A is resumed and starts running
2. Thread A causes Thread B to be killed (e.g. by simply
calling exit ())
3. gdbserver tries and fails to resume Thread B
The appended test case shows an extreme example of this:
If you run it under gdb/gdbserver, interrupt with Ctrl-C,
and then issue "set terminate = 1" before continuing,
you'll notice the failure:
(gdb) target remote :1234
Remote debugging using :1234
[Switching to Thread 14663]
0x00002af301f82b60 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) c
Continuing.
Program received signal SIGINT, Interrupt.
0x00002af30247c491 in clone () from /lib64/libc.so.6
(gdb) set terminate = 1
(gdb) c
Continuing.
warning: Remote failure reply: E01
Program received signal 0, Signal 0.
Cannot remove breakpoints because program is no longer writable.
It might be running in another process.
Further execution is probably impossible.
0x0000000000000000 in ?? ()
uweigand@upg1:~/fsf/gdb-head-build/gdb> ./gdbserver/gdbserver :1234 ./test
Process ./test created; pid = 14246
Listening on port 1234
Remote debugging from host 127.0.0.1
Warning: ptrace(regsets_store_inferior_registers): No such process
Warning: ptrace(regsets_store_inferior_registers): No such process
ptrace: No such process.
input_interrupt, count = 1 c = 36 ('$')
ptrace(regsets_fetch_inferior_registers) PID=14246: No such process
ptrace(regsets_fetch_inferior_registers) PID=14246: No such process
Killing inferior
Interestingly enough, running the same test case under the
GDB native target works most of time (although I did get it
to fail at least once) -- even though on inspection it appeared
the loop over threads in linux_nat_resume should have the same
problem ...
Any suggestions how to fix this?
Bye,
Ulrich
#include <pthread.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
volatile int terminate = 0;
void *
thread_function (void *arg)
{
int x = * (int *) arg;
while (!terminate)
;
exit (x);
return NULL;
}
int
main (int argc, char **argv)
{
pthread_attr_t attr;
pthread_t threads[256];
int args[256];
int i, j;
pthread_attr_init (&attr);
pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
for (j = 0; j < 256; ++j)
{
args[j] = j;
pthread_create (&threads[j], &attr, thread_function, &args[j]);
}
pthread_attr_destroy (&attr);
return 0;
}
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com