[GDB/Linux] Avoid stale errno
authorPedro Alves <palves@redhat.com>
Tue, 15 Jul 2014 15:22:14 +0000 (16:22 +0100)
committerPedro Alves <palves@redhat.com>
Tue, 15 Jul 2014 15:22:14 +0000 (16:22 +0100)
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
gdb/linux-nat.c

index 157dc4933e85c73e2f1cb0e0346279a433bab613..2b6604bf3c6e9764f8d412bbbd9d4500efb40370 100644 (file)
@@ -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.
index 0ab0362f1ec3dc981a44482bf411666e7985dde4..c738abf9f3e7c13e61edb2a10498bc48acbd3d2c 100644 (file)
@@ -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;
 }
This page took 0.02993 seconds and 4 git commands to generate.