Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 0/6] Fix problems if inferior disappears while being debugged
Date: Fri, 06 Mar 2015 19:58:00 -0000	[thread overview]
Message-ID: <1425671886-7798-1-git-send-email-palves@redhat.com> (raw)

The gdb.threads/killed.exp test has a race that happened to trigger
more often with my all-stop-non-stop series.

On GNU/Linux, this test sometimes FAILs like this:

 (gdb) run
 Starting program: /home/pedro/gdb/mygit/build/gdb/testsuite/gdb.threads/killed
 [Thread debugging using libthread_db enabled]
 Using host libthread_db library "/lib64/libthread_db.so.1".
 ptrace: No such process.
 (gdb)
 Program terminated with signal SIGKILL, Killed.
 The program no longer exists.
 FAIL: gdb.threads/killed.exp: run program to completion (timeout)

This is ptrace erroring out with ESRCH (thread is gone).  We ignore
this error explicitly in some places (more in GDBserver than in GDB),
but not everywhere that it's needed.  And it's not clear that ignoring
is the best thing to do everywhere.  So I thought of a different
approach.

Currently, when ptrace errors, we usually call perror_with_name, which
just throws a generic error.  The series replaces the perror_with_name
calls with calls to a new throw_ptrace_error function that converts
ESRCH to a new error/exception (THREAD_NOT_FOUND_ERROR), which then
higher layers can catch and handle as appropriate.

I then wrote a test that explicitly kills the inferior while it is
being debugged, with "kill -9", and that uncovered even more
problems...  Both GDB and GDBserver internal error in some cases,
like this on native/Linux:

 src/gdb/linux-nat.c:2590: internal-error: status_callback: Assertion `lp->status != 0' failed.

and this on gdbserver/Linux:

 src/gdb/gdbserver/linux-low.c:972: A problem internal to GDBserver has been detected.
 kill_wait_lwp: Assertion `res > 0' failed.

This series also addresses those issues.

Pedro Alves (6):
  Move throw_perror_with_name to common/
  Introduce throw_ptrace_error
  Fix race exposed by gdb.threads/killed.exp
  native/Linux: internal error if inferior disappears after stopped by
    breakpoint
  gdbserver/Linux: internal error when killing a process that is already
    gone
  Add test that exercises the inferior being killed while stopped under
    GDB

 gdb/Makefile.in                           |   6 +-
 gdb/aarch64-linux-nat.c                   |  13 +--
 gdb/alphabsd-nat.c                        |  13 +--
 gdb/amd64-linux-nat.c                     |  19 ++---
 gdb/amd64bsd-nat.c                        |  19 ++---
 gdb/arm-linux-nat.c                       |   9 ++-
 gdb/common/common-exceptions.h            |   3 +
 gdb/common/errors.c                       |   8 ++
 gdb/common/errors.h                       |  13 ++-
 gdb/config/aarch64/linux.mh               |   2 +-
 gdb/config/alpha/alpha-linux.mh           |   2 +-
 gdb/config/alpha/fbsd.mh                  |   2 +-
 gdb/config/alpha/nbsd.mh                  |   2 +-
 gdb/config/arm/linux.mh                   |   2 +-
 gdb/config/arm/nbsdelf.mh                 |   2 +-
 gdb/config/i386/fbsd.mh                   |   2 +-
 gdb/config/i386/fbsd64.mh                 |   2 +-
 gdb/config/i386/linux.mh                  |   2 +-
 gdb/config/i386/linux64.mh                |   2 +-
 gdb/config/i386/nbsd64.mh                 |   2 +-
 gdb/config/i386/nbsdelf.mh                |   2 +-
 gdb/config/i386/obsd.mh                   |   2 +-
 gdb/config/i386/obsd64.mh                 |   2 +-
 gdb/config/ia64/linux.mh                  |   2 +-
 gdb/config/m32r/linux.mh                  |   2 +-
 gdb/config/m68k/linux.mh                  |   2 +-
 gdb/config/m68k/nbsdelf.mh                |   2 +-
 gdb/config/m68k/obsd.mh                   |   2 +-
 gdb/config/m88k/obsd.mh                   |   2 +-
 gdb/config/mips/linux.mh                  |   2 +-
 gdb/config/mips/nbsd.mh                   |   2 +-
 gdb/config/mips/obsd64.mh                 |   2 +-
 gdb/config/pa/hpux.mh                     |   2 +-
 gdb/config/pa/linux.mh                    |   2 +-
 gdb/config/pa/nbsd.mh                     |   2 +-
 gdb/config/pa/obsd.mh                     |   2 +-
 gdb/config/powerpc/aix.mh                 |   2 +-
 gdb/config/powerpc/fbsd.mh                |   2 +-
 gdb/config/powerpc/linux.mh               |   2 +-
 gdb/config/powerpc/nbsd.mh                |   2 +-
 gdb/config/powerpc/obsd.mh                |   2 +-
 gdb/config/powerpc/ppc64-linux.mh         |   2 +-
 gdb/config/powerpc/spu-linux.mh           |   2 +-
 gdb/config/s390/linux.mh                  |   2 +-
 gdb/config/sh/nbsd.mh                     |   2 +-
 gdb/config/sparc/fbsd.mh                  |   2 +-
 gdb/config/sparc/linux.mh                 |   2 +-
 gdb/config/sparc/linux64.mh               |   2 +-
 gdb/config/sparc/nbsd64.mh                |   2 +-
 gdb/config/sparc/nbsdelf.mh               |   2 +-
 gdb/config/sparc/obsd64.mh                |   2 +-
 gdb/config/tilegx/linux.mh                |   2 +-
 gdb/config/vax/nbsdelf.mh                 |   2 +-
 gdb/config/vax/obsd.mh                    |   2 +-
 gdb/config/xtensa/linux.mh                |   2 +-
 gdb/gdbserver/Makefile.in                 |   6 +-
 gdb/gdbserver/configure.srv               |   2 +-
 gdb/gdbserver/linux-low.c                 |  59 ++++++++++----
 gdb/gdbserver/utils.c                     |   6 +-
 gdb/hppanbsd-nat.c                        |  13 +--
 gdb/hppaobsd-nat.c                        |  13 +--
 gdb/i386-linux-nat.c                      |  27 ++++---
 gdb/i386bsd-nat.c                         |  23 +++---
 gdb/i386fbsd-nat.c                        |   3 +-
 gdb/inf-ptrace.c                          |  19 ++---
 gdb/linux-nat.c                           |  43 ++++++++--
 gdb/m32r-linux-nat.c                      |   7 +-
 gdb/m68kbsd-nat.c                         |  13 +--
 gdb/m68klinux-nat.c                       |  12 +--
 gdb/m88kbsd-nat.c                         |   7 +-
 gdb/mips-linux-nat.c                      |  19 ++---
 gdb/mips64obsd-nat.c                      |   7 +-
 gdb/mipsnbsd-nat.c                        |  13 +--
 gdb/nat/ptrace-utils.c                    |  49 +++++++++++
 gdb/nat/ptrace-utils.h                    |  28 +++++++
 gdb/obsd-nat.c                            |   9 ++-
 gdb/ppc-linux-nat.c                       |  63 ++++++++-------
 gdb/ppcfbsd-nat.c                         |  13 +--
 gdb/ppcnbsd-nat.c                         |  13 +--
 gdb/ppcobsd-nat.c                         |  13 +--
 gdb/rs6000-nat.c                          |   3 +-
 gdb/s390-linux-nat.c                      |  26 +++---
 gdb/shnbsd-nat.c                          |   7 +-
 gdb/sparc-nat.c                           |  15 ++--
 gdb/spu-linux-nat.c                       |   3 +-
 gdb/testsuite/gdb.base/killed-outside.c   |  34 ++++++++
 gdb/testsuite/gdb.base/killed-outside.exp | 130 ++++++++++++++++++++++++++++++
 gdb/tilegx-linux-nat.c                    |   6 +-
 gdb/utils.c                               |   8 --
 gdb/vaxbsd-nat.c                          |   7 +-
 gdb/x86-linux-nat.c                       |   9 ++-
 gdb/xtensa-linux-nat.c                    |  12 +--
 92 files changed, 642 insertions(+), 293 deletions(-)
 create mode 100644 gdb/nat/ptrace-utils.c
 create mode 100644 gdb/nat/ptrace-utils.h
 create mode 100644 gdb/testsuite/gdb.base/killed-outside.c
 create mode 100644 gdb/testsuite/gdb.base/killed-outside.exp

-- 
1.9.3


             reply	other threads:[~2015-03-06 19:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-06 19:58 Pedro Alves [this message]
2015-03-06 19:58 ` [PATCH 1/6] Move throw_perror_with_name to common/ Pedro Alves
2015-03-06 19:58 ` [PATCH 4/6] native/Linux: internal error if inferior disappears after stopped by breakpoint Pedro Alves
2015-03-19 12:37   ` [pushed] native/Linux: internal error if resume is short-circuited (Re: [PATCH 4/6] native/Linux: internal error if inferior disappears after stopped by breakpoint) Pedro Alves
2015-03-19 12:49     ` [pushed] gdbserver/Linux: unbreak thread event randomization (Re: [pushed] native/Linux: internal error if resume is short-circuited) Pedro Alves
2015-03-19 16:14       ` [PATCH] gdbserver/Linux: Unbreak non-stop (Re: [pushed] gdbserver/Linux: unbreak thread event randomization) Pedro Alves
2015-03-19 16:54         ` [pushed] " Pedro Alves
2015-03-06 19:58 ` [PATCH 3/6] Fix race exposed by gdb.threads/killed.exp Pedro Alves
2015-03-19 17:39   ` Pedro Alves
2015-03-06 19:58 ` [PATCH 5/6] gdbserver/Linux: internal error when killing a process that is already gone Pedro Alves
2015-03-06 19:58 ` [PATCH 2/6] Introduce throw_ptrace_error Pedro Alves
2015-03-06 21:04   ` Mark Kettenis
2015-03-06 21:40     ` Pedro Alves
2015-03-08 20:30       ` Mark Kettenis
2015-03-08 21:48         ` Pedro Alves
2015-03-10 14:53           ` Mark Kettenis
2015-03-11 15:44             ` Pedro Alves
2015-03-19 17:33               ` [pushed] Fix race exposed by gdb.threads/killed.exp (Re: [PATCH 2/6] Introduce throw_ptrace_error) Pedro Alves
2015-03-06 20:27 ` [PATCH 6/6] Add test that exercises the inferior being killed while stopped under GDB Pedro Alves
2015-07-14 10:22   ` Pedro Alves

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=1425671886-7798-1-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --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