From: "Ulrich Weigand" <uweigand@de.ibm.com>
To: drow@false.org (Daniel Jacobowitz)
Cc: gdb-patches@sourceware.org
Subject: Re: [gdbserver] Problems trying to resume dead threads
Date: Tue, 05 Aug 2008 21:06:00 -0000 [thread overview]
Message-ID: <200808052105.m75L5FEJ003528@d12av02.megacenter.de.ibm.com> (raw)
In-Reply-To: <20080804195434.GA28917@caradoc.them.org> from "Daniel Jacobowitz" at Aug 04, 2008 03:54:34 PM
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
next prev parent reply other threads:[~2008-08-05 21:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-19 17:17 Ulrich Weigand
2008-08-04 13:40 ` Daniel Jacobowitz
2008-08-04 18:25 ` Ulrich Weigand
2008-08-04 18:30 ` Daniel Jacobowitz
2008-08-04 19:46 ` Ulrich Weigand
2008-08-04 19:55 ` Daniel Jacobowitz
2008-08-05 21:06 ` Ulrich Weigand [this message]
2008-08-05 21:59 ` Daniel Jacobowitz
2008-08-05 22:15 ` Ulrich Weigand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200808052105.m75L5FEJ003528@d12av02.megacenter.de.ibm.com \
--to=uweigand@de.ibm.com \
--cc=drow@false.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox