This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[OB/PUSHED PATCH][GDB/Linux] Avoid stale errno
- From: Pedro Alves <alves dot ped at gmail dot com>
- To: Pedro Alves <palves at redhat dot com>, GDB Patches <gdb-patches at sourceware dot org>
- Date: Tue, 15 Jul 2014 16:33:04 +0100
- Subject: [OB/PUSHED PATCH][GDB/Linux] Avoid stale errno
- Authentication-results: sourceware.org; auth=none
- References: <53C53CE1 dot 6010903 at redhat dot com>
... and I knew I was forgetting something. The same fix is needed
on the GDB side.
Pushed.
---------
From: Pedro Alves <palves@redhat.com>
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 <palves@redhat.com>
* 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 <palves@redhat.com>
+
+ * linux-nat.c (kill_callback): Save errno and work with saved
+ copy.
+
2014-07-15 Simon Marchi <simon.marchi@ericsson.com>
* 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;
}
--
1.9.3