From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18460 invoked by alias); 1 Jul 2011 19:03:54 -0000 Received: (qmail 18437 invoked by uid 22791); 1 Jul 2011 19:03:52 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jul 2011 19:03:35 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 037A42BB58C; Fri, 1 Jul 2011 15:03:35 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id uCb5mGrc3thp; Fri, 1 Jul 2011 15:03:34 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id C2C992BB4CF; Fri, 1 Jul 2011 15:03:34 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 051D2145615; Fri, 1 Jul 2011 12:03:33 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [Darwin 2/4] Do not crash (failed assertion) after PT_KILL ptrace error Date: Fri, 01 Jul 2011 19:03:00 -0000 Message-Id: <1309547006-21412-3-git-send-email-brobecker@adacore.com> In-Reply-To: <1309547006-21412-1-git-send-email-brobecker@adacore.com> References: <1309547006-21412-1-git-send-email-brobecker@adacore.com> 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: 2011-07/txt/msg00051.txt.bz2 This is something I noticed while reading the code. Putting an assertion that the PT_KILL ptrace call never returns an error is too strong. It might not be a debugger bug that caused the PT_KILL ptrace operation to fail, so a failed-assertion "crash" would not be justified. It also seems easy enough to continue and get ready for the next debugging session. So this patch changes the assertion into a warning. 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. Tested on x86_64-darwin. Checked in. --- gdb/ChangeLog | 9 +++++++++ gdb/darwin-nat.c | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5be8066..ce522fb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2011-07-01 Joel Brobecker + * 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 + * 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); -- 1.7.1