Avoid potencially-stale errno usage.
authorPedro Alves <palves@redhat.com>
Tue, 9 Apr 2013 12:18:34 +0000 (12:18 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 9 Apr 2013 12:18:34 +0000 (12:18 +0000)
The current throw_perror_with_name/TARGET_CLOSE_ERROR calls assume
errno is still set to the right error, although remote_unpush_target
is called in between, which may well change errno.

Tested on x86_64 Fedora 17 w/ gdbserver.

gdb/
2013-04-09  Pedro Alves  <palves@redhat.com>

* remote.c (unpush_and_perror): New function.
(readchar, remote_serial_write): Use it.

gdb/ChangeLog
gdb/remote.c

index f18ab969112ad981d64254347c6191349e0eb134..21aebc323fa8ff7790ca17b4234c4aca8cde358e 100644 (file)
@@ -1,3 +1,8 @@
+2013-04-09  Pedro Alves  <palves@redhat.com>
+
+       * remote.c (unpush_and_perror): New function.
+       (readchar, remote_serial_write): Use it.
+
 2013-04-09  Markus Metzger  <markus.t.metzger@intel.com>
 
        * NEWS: Mention new btrace RSP packets.
index 740324b546166076167695dcb8b45ba4ca78ae24..de075c88e3b24ead5fa0aa8063e2c982871d3484 100644 (file)
@@ -7033,6 +7033,23 @@ remote_files_info (struct target_ops *ignore)
 /* Stuff for dealing with the packets which are part of this protocol.
    See comment at top of file for details.  */
 
+/* Close/unpush the remote target, and throw a TARGET_CLOSE_ERROR
+   error to higher layers.  Called when a serial error is detected.
+   The exception message is STRING, followed by a colon and a blank,
+   then the system error message for errno at function entry.  */
+
+static void
+unpush_and_perror (const char *string)
+{
+  char *errstr;
+
+  errstr = xstrprintf ("%s: %s", string, safe_strerror (errno));
+  make_cleanup (xfree, errstr);
+
+  remote_unpush_target ();
+  throw_error (TARGET_CLOSE_ERROR, "%s", errstr);
+}
+
 /* Read a single character from the remote end.  */
 
 static int
@@ -7052,10 +7069,8 @@ readchar (int timeout)
       throw_error (TARGET_CLOSE_ERROR, _("Remote connection closed"));
       /* no return */
     case SERIAL_ERROR:
-      remote_unpush_target ();
-      throw_perror_with_name (TARGET_CLOSE_ERROR,
-                             _("Remote communication error.  "
-                               "Target disconnected."));
+      unpush_and_perror (_("Remote communication error.  "
+                          "Target disconnected."));
       /* no return */
     case SERIAL_TIMEOUT:
       break;
@@ -7071,10 +7086,8 @@ remote_serial_write (const char *str, int len)
 {
   if (serial_write (remote_desc, str, len))
     {
-      remote_unpush_target ();
-      throw_perror_with_name (TARGET_CLOSE_ERROR,
-                             _("Remote communication error.  "
-                               "Target disconnected."));
+      unpush_and_perror (_("Remote communication error.  "
+                          "Target disconnected."));
     }
 }
 
This page took 0.033536 seconds and 4 git commands to generate.