RFC: Convert some remote connection errors to warnings

Daniel Jacobowitz dan@codesourcery.com
Thu Feb 25 15:08:00 GMT 2010


The patch I posted yesterday for AT_ENTRY support fixed an error that
occurred during initial connection to the target.  I'd type "target
remote host:port" and get "Can not read memory at 0xBADADD00."  At
this point, I was no longer connected to the target; remote.c detects
that something has gone wrong, and cleans up.  This makes debugging
the problem extraordinarily frustrating.

I talked with Pedro about where to draw the line between fatal and
non-fatal errors.  This patch makes two changes:

* Any time after the basic remote connection has been established,
including working out what if any inferiors are on the remote end,
errors do not need to pop the connection.  So I convert them to
warnings instead.

* A memory error reading the shared library list should not call
error, because whatever command the user typed probably did not fail.
A corrupt shared library table is not an error connecting to the
remote target.

So with this patch applied, I get "warning: reading shared library
list: Can not read memory at 0xBADADD00".  There's a follow-on error,
which aborts remote_start_remote_late (trying to set the shared
library breakpoint), which also gets converted to a warning.
Then the target is still connected.

Any comments on my choices of location?  Otherwise, I'll commit this
in a few days.

-- 
Daniel Jacobowitz
CodeSourcery

2010-02-25  Daniel Jacobowitz  <dan@codesourcery.com>

	* remote.c (remote_start_remote): Always decrement immediate_quit
	before returning.  Move start_remote call and other late
	initialization from here...
	(remote_start_remote_late): ...to here.  New function.
	(remote_open_1): Call remote_start_remote_late.  Convert any
	exceptions to warnings.
	* solib.c (update_solib_list): Convert errors reading the shared
	library list to warnings.

Index: remote.c
===================================================================
--- remote.c	(revision 276825)
+++ remote.c	(working copy)
@@ -3190,6 +3190,7 @@ remote_start_remote (struct ui_out *uiou
 
 	  /* We're connected, but not running.  Drop out before we
 	     call start_remote.  */
+	  immediate_quit--;
 	  return;
 	}
       else
@@ -3236,9 +3237,6 @@ remote_start_remote (struct ui_out *uiou
       gdb_assert (wait_status != NULL);
       strcpy (rs->buf, wait_status);
       rs->cached_wait_status = 1;
-
-      immediate_quit--;
-      start_remote (args->from_tty); /* Initialize gdb process mechanisms.  */
     }
   else
     {
@@ -3285,6 +3283,7 @@ remote_start_remote (struct ui_out *uiou
 
 	  /* We're connected, but not running.  Drop out before we
 	     call start_remote.  */
+	  immediate_quit--;
 	  return;
 	}
 
@@ -3305,6 +3304,22 @@ remote_start_remote (struct ui_out *uiou
       gdb_assert (wait_status == NULL);
     }
 
+  immediate_quit--;
+}
+
+/* Continue setting up the target.  Errors at this point are
+   non-fatal; for instance, we do not need to disconnect from the
+   target if a memory read fails.  */
+
+static void
+remote_start_remote_late (struct ui_out *uiout, void *opaque)
+{
+  struct start_remote_args *args = opaque;
+  struct remote_state *rs = get_remote_state ();
+
+  if (!non_stop && rs->cached_wait_status)
+    start_remote (args->from_tty); /* Initialize gdb process mechanisms.  */
+
   /* If we connected to a live target, do some additional setup.  */
   if (target_has_execution)
     {
@@ -3949,6 +3964,11 @@ remote_open_1 (char *name, int from_tty,
 	  wait_forever_enabled_p = 1;
 	throw_exception (ex);
       }
+
+    ex = catch_exception (uiout, remote_start_remote_late, &args,
+			  RETURN_MASK_ERROR);
+    if (ex.reason < 0)
+      exception_fprintf (gdb_stderr, ex, _("warning: "));
   }
 
   if (target_async_permitted)
Index: solib.c
===================================================================
--- solib.c	(revision 276825)
+++ solib.c	(working copy)
@@ -555,8 +555,19 @@ static void
 update_solib_list (int from_tty, struct target_ops *target)
 {
   struct target_so_ops *ops = solib_ops (target_gdbarch);
-  struct so_list *inferior = ops->current_sos();
+  struct so_list *inferior;
   struct so_list *gdb, **gdb_link;
+  struct gdb_exception ex;
+
+  TRY_CATCH (ex, RETURN_MASK_ERROR)
+    inferior = ops->current_sos();
+  if (ex.reason < 0)
+    {
+      /* An error occurred.  Convert it to a warning and try again
+	 later.  */
+      exception_fprintf (gdb_stderr, ex, _("warning: reading shared library list: "));
+      return;
+    }
 
   /* We can reach here due to changing solib-search-path or the
      sysroot, before having any inferior.  */



More information about the Gdb-patches mailing list