diff options
author | Joel Brobecker <brobecker@gnat.com> | 2011-07-01 18:36:28 +0000 |
---|---|---|
committer | Joel Brobecker <brobecker@gnat.com> | 2011-07-01 18:36:28 +0000 |
commit | a7aa0d73a26241ba616f42563bfe19bd0077312c (patch) | |
tree | f2780e6c8edb39feedd0581b8137d50e05dc720f | |
parent | 5e9bc145ee7e5d1e5651a996bcf81d9888b34cf1 (diff) | |
download | gdb-a7aa0d73a26241ba616f42563bfe19bd0077312c.zip gdb-a7aa0d73a26241ba616f42563bfe19bd0077312c.tar.gz gdb-a7aa0d73a26241ba616f42563bfe19bd0077312c.tar.bz2 |
[Darwin] Do not crash (failed assertion) after PT_KILL ptrace error
It might not be a debugger bug that caused the PT_KILL ptrace operation
to fail. So emit a warning instead, and try to continue.
This patch also tries to handle the case where ptrace return -1,
but left errno set to zero. According to the ptrace man page,
it is possible for some ptrace operations to return -1 in non-error
situations, and to detect those situations, it explains that errno
should be set prior to calling ptrace, and then checked again after.
gdb/ChangeLog:
* darwin-nat.c (darwin_ptrace): Add documentation.
Set errno to zero before calling ptrace. If ptrace returns
-1 and errno is zero, then change then return zero.
(darwin_kill_inferior): Issue a warning instead of triggering
a failed assertion when the PT_KILL ptrace operations returned
nonzero.
-rw-r--r-- | gdb/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/darwin-nat.c | 17 |
2 files changed, 25 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 423ada3..197d2eb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2011-07-01 Joel Brobecker <brobecker@adacore.com> + * darwin-nat.c (darwin_ptrace): Add documentation. + Set errno to zero before calling ptrace. If ptrace returns + -1 and errno is zero, then change then return zero. + (darwin_kill_inferior): Issue a warning instead of triggering + a failed assertion when the PT_KILL ptrace operations returned + nonzero. + +2011-07-01 Joel Brobecker <brobecker@adacore.com> + * darwin-nat.c (darwin_detach): Call darwin_resume_inferior only when inf->private->no_ptrace. diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index fc5263a..27c6e2c 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -233,13 +233,25 @@ unparse_exception_type (unsigned int i) } } +/* Set errno to zero, and then call ptrace with the given arguments. + If inferior debugging traces are on, then also print a debug + trace. + + The returned value is the same as the value returned by ptrace, + except in the case where that value is -1 but errno is zero. + This case is documented to be a non-error situation, so we + return zero in that case. */ + static int darwin_ptrace (const char *name, int request, int pid, PTRACE_TYPE_ARG3 arg3, int arg4) { int ret; + errno = 0; ret = ptrace (request, pid, (caddr_t) arg3, arg4); + if (ret == -1 && errno == 0) + ret = 0; inferior_debug (4, _("ptrace (%s, %d, 0x%x, %d): %d (%s)\n"), name, pid, arg3, arg4, ret, @@ -1301,7 +1313,10 @@ darwin_kill_inferior (struct target_ops *ops) darwin_stop_inferior (inf); res = PTRACE (PT_KILL, inf->pid, 0, 0); - gdb_assert (res == 0); + if (res != 0) + warning (_("Failed to kill inferior: ptrace returned %d " + "[%s] (pid=%d)"), + res, safe_strerror (errno), inf->pid); darwin_reply_to_all_pending_messages (inf); |