From patchwork Tue Jul 15 15:33:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 2061 Received: (qmail 9247 invoked by alias); 15 Jul 2014 15:33:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9223 invoked by uid 89); 15 Jul 2014 15:33:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-we0-f181.google.com Received: from mail-we0-f181.google.com (HELO mail-we0-f181.google.com) (74.125.82.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 15 Jul 2014 15:33:10 +0000 Received: by mail-we0-f181.google.com with SMTP id q59so5837531wes.40 for ; Tue, 15 Jul 2014 08:33:07 -0700 (PDT) X-Received: by 10.180.79.202 with SMTP id l10mr6435074wix.18.1405438387688; Tue, 15 Jul 2014 08:33:07 -0700 (PDT) Received: from [192.168.0.102] (bl6-77-113.dsl.telepac.pt. [82.155.77.113]) by mx.google.com with ESMTPSA id es1sm16568508wib.16.2014.07.15.08.33.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jul 2014 08:33:06 -0700 (PDT) Message-ID: <53C549B0.70602@gmail.com> Date: Tue, 15 Jul 2014 16:33:04 +0100 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Pedro Alves , GDB Patches Subject: [OB/PUSHED PATCH][GDB/Linux] Avoid stale errno References: <53C53CE1.6010903@redhat.com> In-Reply-To: <53C53CE1.6010903@redhat.com> X-IsSubscribed: yes ... and I knew I was forgetting something. The same fix is needed on the GDB side. Pushed. --------- From: Pedro Alves Subject: [PATCH] [GDB/Linux] Avoid stale errno The fix that went into GDBserver is also needed on the GDB side. Although most compilers follow right-to-left evaluation order, the order of evaluation of a function call's arguments is really unspecified. target_pid_to_str may well clobber errno when we get to evaluate the third argument to fprintf_unfiltered. gdb/ 2014-07-15 Pedro Alves * linux-nat.c (kill_callback): Save errno and work with saved copy. --- gdb/ChangeLog | 5 +++++ gdb/linux-nat.c | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 157dc49..2b6604b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2014-07-15 Pedro Alves + + * linux-nat.c (kill_callback): Save errno and work with saved + copy. + 2014-07-15 Simon Marchi * expprint.c (dump_subexp_body_standard): Handle OP_STRING. diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 0ab0362..c738abf 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3706,20 +3706,28 @@ kill_callback (struct lwp_info *lp, void *data) errno = 0; kill (ptid_get_lwp (lp->ptid), SIGKILL); if (debug_linux_nat) - fprintf_unfiltered (gdb_stdlog, - "KC: kill (SIGKILL) %s, 0, 0 (%s)\n", - target_pid_to_str (lp->ptid), - errno ? safe_strerror (errno) : "OK"); + { + int save_errno = errno; + + fprintf_unfiltered (gdb_stdlog, + "KC: kill (SIGKILL) %s, 0, 0 (%s)\n", + target_pid_to_str (lp->ptid), + save_errno ? safe_strerror (save_errno) : "OK"); + } /* Some kernels ignore even SIGKILL for processes under ptrace. */ errno = 0; ptrace (PTRACE_KILL, ptid_get_lwp (lp->ptid), 0, 0); if (debug_linux_nat) - fprintf_unfiltered (gdb_stdlog, - "KC: PTRACE_KILL %s, 0, 0 (%s)\n", - target_pid_to_str (lp->ptid), - errno ? safe_strerror (errno) : "OK"); + { + int save_errno = errno; + + fprintf_unfiltered (gdb_stdlog, + "KC: PTRACE_KILL %s, 0, 0 (%s)\n", + target_pid_to_str (lp->ptid), + save_errno ? safe_strerror (save_errno) : "OK"); + } return 0; }