This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Prepare for building gdbserver with -Werror


I've just been bitten by gdbserver not being built with -Werror
(missed an important warning), so, I think I'm going to enable it.

Here's the first step: make it actually build warning free
on ubuntu machines, where we get warn_unused_result warnings...

I've applied it, after testing on x86_64-unknown-linux-gnu,
and, confirming that gdbreplay still works, and that it does
now report an appropriate error when reading/writing to the gdb
remote connection fails (I killed GDB when connected to replay
to check that).

-- 
Pedro Alves

2010-08-26  Pedro Alves  <pedro@codesourcery.com>

	* gdbreplay.c (remote_error): New.
	(gdbchar): New.
	(expect): Use gdbchar.  Check for error reading from GDB.
	Clarify sync error output.
	(play): Check for errors writing to GDB.
	* remote-utils.c (getpkt): Check for errors writing to the remote
	descriptor.
	* linux-low.c (sigchld_handler): Really ignore `write' errors.

---
 gdb/gdbserver/gdbreplay.c    |   35 ++++++++++++++++++++++++++++-------
 gdb/gdbserver/linux-low.c    |   12 ++++++++++--
 gdb/gdbserver/remote-utils.c |    6 ++++--
 3 files changed, 42 insertions(+), 11 deletions(-)

Index: src/gdb/gdbserver/gdbreplay.c
===================================================================
--- src.orig/gdb/gdbserver/gdbreplay.c	2010-08-26 17:04:27.000000000 +0100
+++ src/gdb/gdbserver/gdbreplay.c	2010-08-26 17:06:52.000000000 +0100
@@ -163,6 +163,14 @@ sync_error (FILE *fp, char *desc, int ex
 }
 
 static void
+remote_error (const char *desc)
+{
+  fprintf (stderr, "\n%s\n", desc);
+  fflush (stderr);
+  exit (1);
+}
+
+static void
 remote_close (void)
 {
 #ifdef USE_WIN32API
@@ -339,6 +347,17 @@ logchar (FILE *fp)
   return (ch);
 }
 
+static int
+gdbchar (int desc)
+{
+  unsigned char fromgdb;
+
+  if (read (desc, &fromgdb, 1) != 1)
+    return -1;
+  else
+    return fromgdb;
+}
+
 /* Accept input from gdb and match with chars from fp (after skipping one
    blank) up until a \n is read from fp (which is not matched) */
 
@@ -346,7 +365,7 @@ static void
 expect (FILE *fp)
 {
   int fromlog;
-  unsigned char fromgdb;
+  int fromgdb;
 
   if ((fromlog = logchar (fp)) != ' ')
     {
@@ -357,15 +376,16 @@ expect (FILE *fp)
     {
       fromlog = logchar (fp);
       if (fromlog == EOL)
-	{
-	  break;
-	}
-      read (remote_desc, &fromgdb, 1);
+	break;
+      fromgdb = gdbchar (remote_desc);
+      if (fromgdb < 0)
+	remote_error ("Error during read from gdb");
     }
   while (fromlog == fromgdb);
+
   if (fromlog != EOL)
     {
-      sync_error (fp, "Sync error during read of gdb packet", fromlog,
+      sync_error (fp, "Sync error during read of gdb packet from log", fromlog,
 		  fromgdb);
     }
 }
@@ -387,7 +407,8 @@ play (FILE *fp)
   while ((fromlog = logchar (fp)) != EOL)
     {
       ch = fromlog;
-      write (remote_desc, &ch, 1);
+      if (write (remote_desc, &ch, 1) != 1)
+	remote_error ("Error during write to gdb");
     }
 }
 
Index: src/gdb/gdbserver/remote-utils.c
===================================================================
--- src.orig/gdb/gdbserver/remote-utils.c	2010-08-26 17:04:27.000000000 +0100
+++ src/gdb/gdbserver/remote-utils.c	2010-08-26 17:06:52.000000000 +0100
@@ -1091,7 +1091,8 @@ getpkt (char *buf)
 
       fprintf (stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
 	       (c1 << 4) + c2, csum, buf);
-      write (remote_desc, "-", 1);
+      if (write (remote_desc, "-", 1) != 1)
+	return -1;
     }
 
   if (!noack_mode)
@@ -1102,7 +1103,8 @@ getpkt (char *buf)
 	  fflush (stderr);
 	}
 
-      write (remote_desc, "+", 1);
+      if (write (remote_desc, "+", 1) != 1)
+	return -1;
 
       if (remote_debug)
 	{
Index: src/gdb/gdbserver/linux-low.c
===================================================================
--- src.orig/gdb/gdbserver/linux-low.c	2010-08-26 17:04:27.000000000 +0100
+++ src/gdb/gdbserver/linux-low.c	2010-08-26 17:06:52.000000000 +0100
@@ -4713,8 +4713,16 @@ sigchld_handler (int signo)
   int old_errno = errno;
 
   if (debug_threads)
-    /* fprintf is not async-signal-safe, so call write directly.  */
-    write (2, "sigchld_handler\n", sizeof ("sigchld_handler\n") - 1);
+    {
+      do
+	{
+	  /* fprintf is not async-signal-safe, so call write
+	     directly.  */
+	  if (write (2, "sigchld_handler\n",
+		     sizeof ("sigchld_handler\n") - 1) < 0)
+	    break; /* just ignore */
+	} while (0);
+    }
 
   if (target_is_async_p ())
     async_file_mark (); /* trigger a linux_wait */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]