[PATCH 0/6] Fix problems if inferior disappears while being debugged

Pedro Alves palves@redhat.com
Fri Mar 6 19:58:00 GMT 2015


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



More information about the Gdb-patches mailing list