From patchwork Tue Jul 15 14:38:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 2058 Received: (qmail 17398 invoked by alias); 15 Jul 2014 14:38:32 -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 17377 invoked by uid 89); 15 Jul 2014 14:38:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 15 Jul 2014 14:38:29 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6FEcRvS000844 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 15 Jul 2014 10:38:27 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6FEcPUZ019254 for ; Tue, 15 Jul 2014 10:38:26 -0400 Message-ID: <53C53CE1.6010903@redhat.com> Date: Tue, 15 Jul 2014 15:38:25 +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: GDB Patches Subject: [OB/PUSHED PATCH][GDBserver] Avoid stale errno Noticed this by inspection the other day. Pushed. ---------------- From: Pedro Alves Subject: [PATCH] [GDBserver] Avoid stale errno 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 or ptid_of may well clobber errno when we get to evaluate the third argument to debug_printf. gdb/gdbserver/ 2014-07-15 Pedro Alves * linux-low.c (linux_kill_one_lwp): Save errno and work with saved copy. --- gdb/gdbserver/ChangeLog | 5 +++++ gdb/gdbserver/linux-low.c | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index e6b0a84..4658abf 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,8 @@ +2014-07-15 Pedro Alves + + * linux-low.c (linux_kill_one_lwp): Save errno and work with saved + copy. + 2014-07-11 Pedro Alves * linux-low.c (kill_wait_lwp): New function, based on diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 215a80c..0f4dbe2 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -897,16 +897,24 @@ linux_kill_one_lwp (struct lwp_info *lwp) errno = 0; kill (pid, SIGKILL); if (debug_threads) - debug_printf ("LKL: kill (SIGKILL) %s, 0, 0 (%s)\n", - target_pid_to_str (ptid_of (thr)), - errno ? strerror (errno) : "OK"); + { + int save_errno = errno; + + debug_printf ("LKL: kill_lwp (SIGKILL) %s, 0, 0 (%s)\n", + target_pid_to_str (ptid_of (thr)), + save_errno ? strerror (save_errno) : "OK"); + } errno = 0; ptrace (PTRACE_KILL, pid, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 0); if (debug_threads) - debug_printf ("LKL: PTRACE_KILL %s, 0, 0 (%s)\n", - target_pid_to_str (ptid_of (thr)), - errno ? strerror (errno) : "OK"); + { + int save_errno = errno; + + debug_printf ("LKL: PTRACE_KILL %s, 0, 0 (%s)\n", + target_pid_to_str (ptid_of (thr)), + save_errno ? strerror (save_errno) : "OK"); + } } /* Kill LWP and wait for it to die. */