From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29407 invoked by alias); 5 Aug 2008 21:06:17 -0000 Received: (qmail 29397 invoked by uid 22791); 5 Aug 2008 21:06:17 -0000 X-Spam-Check-By: sourceware.org Received: from mtagate4.de.ibm.com (HELO mtagate4.de.ibm.com) (195.212.29.153) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 05 Aug 2008 21:05:34 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate4.de.ibm.com (8.13.8/8.13.8) with ESMTP id m75L5FA4072050 for ; Tue, 5 Aug 2008 21:05:15 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 m75L5FS61958082 for ; Tue, 5 Aug 2008 23:05:15 +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 m75L5FCw003531 for ; Tue, 5 Aug 2008 23:05:15 +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 m75L5FEJ003528; Tue, 5 Aug 2008 23:05:15 +0200 Message-Id: <200808052105.m75L5FEJ003528@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Tue, 5 Aug 2008 23:05:15 +0200 Subject: Re: [gdbserver] Problems trying to resume dead threads To: drow@false.org (Daniel Jacobowitz) Date: Tue, 05 Aug 2008 21:06:00 -0000 From: "Ulrich Weigand" Cc: gdb-patches@sourceware.org In-Reply-To: <20080804195434.GA28917@caradoc.them.org> from "Daniel Jacobowitz" at Aug 04, 2008 03:54:34 PM 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-08/txt/msg00092.txt.bz2 Daniel Jacobowitz wrote: > On Mon, Aug 04, 2008 at 09:45:46PM +0200, Ulrich Weigand wrote: > > I'd propose to just silently ignore ESRCH errors while writing registers > > (in addition to your patch). What do you think? > > I think that's acceptable, though not ideal. ESRCH can mean "the > program is gone", or for ptrace it can mean "the program is not > stopped". So there are a class of bugs in gdbserver which can lead to > the ESRCH error path. But distinguishing them from this case is quite > difficult. The following patch implements this approach, fixing the problem for me. Tested on powerpc-linux in local gdbserver mode. OK? Bye, Ulrich ChangeLog: * linux-low.c (linux_resume_one_process): Ignore ESRCH. (usr_store_inferior_registers): Likewise. (regsets_store_inferior_registers): Likewise. diff -urNp src-orig/gdb/gdbserver/linux-low.c src/gdb/gdbserver/linux-low.c --- src-orig/gdb/gdbserver/linux-low.c 2008-08-05 19:44:47.000000000 +0200 +++ src/gdb/gdbserver/linux-low.c 2008-08-05 19:53:44.000000000 +0200 @@ -1195,7 +1195,19 @@ linux_resume_one_process (struct inferio current_inferior = saved_inferior; if (errno) - perror_with_name ("ptrace"); + { + /* ESRCH from ptrace either means that the thread was already + running (an error) or that it is gone (a race condition). If + it's gone, we will get a notification the next time we wait, + so we can ignore the error. We could differentiate these + two, but it's tricky without waiting; the thread still exists + as a zombie, so sending it signal 0 would succeed. So just + ignore ESRCH. */ + if (errno == ESRCH) + return; + + perror_with_name ("ptrace"); + } } static struct thread_resume *resume_ptr; @@ -1464,6 +1476,12 @@ usr_store_inferior_registers (int regno) *(PTRACE_XFER_TYPE *) (buf + i)); if (errno != 0) { + /* At this point, ESRCH should mean the process is already gone, + in which case we simply ignore attempts to change its registers. + See also the related comment in linux_resume_one_process. */ + if (errno == ESRCH) + return; + if ((*the_low_target.cannot_store_register) (regno) == 0) { char *err = strerror (errno); @@ -1580,6 +1598,13 @@ regsets_store_inferior_registers () disabled_regsets[regset - target_regsets] = 1; continue; } + else if (errno == ESRCH) + { + /* At this point, ESRCH should mean the process is already gone, + in which case we simply ignore attempts to change its registers. + See also the related comment in linux_resume_one_process. */ + return 0; + } else { perror ("Warning: ptrace(regsets_store_inferior_registers)"); -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com