From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27085 invoked by alias); 19 Jul 2008 17:17:16 -0000 Received: (qmail 27077 invoked by uid 22791); 19 Jul 2008 17:17:15 -0000 X-Spam-Check-By: sourceware.org Received: from mtagate5.de.ibm.com (HELO mtagate5.de.ibm.com) (195.212.29.154) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 19 Jul 2008 17:16:54 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate5.de.ibm.com (8.13.8/8.13.8) with ESMTP id m6JHGnLN080854 for ; Sat, 19 Jul 2008 17:16:49 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v9.0) with ESMTP id m6JHGnIs4259944 for ; Sat, 19 Jul 2008 19:16:49 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m6JHGmJQ013961 for ; Sat, 19 Jul 2008 19:16:48 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id m6JHGmsA013958 for ; Sat, 19 Jul 2008 19:16:48 +0200 Message-Id: <200807191716.m6JHGmsA013958@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Sat, 19 Jul 2008 19:16:48 +0200 Subject: [gdbserver] Problems trying to resume dead threads To: gdb-patches@sourceware.org Date: Sat, 19 Jul 2008 17:17:00 -0000 From: "Ulrich Weigand" X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-07/txt/msg00375.txt.bz2 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 #include #include #include 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