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]

RFC: Do not try g-packet-guess algorithm on exited targets


We got a bug report indicating that gdbserver --multi didn't work on
MIPS.  We'd connect to the target, try to read the XML description -
gdbserver reports an error because there's no process yet - and then
try to guess the description from the g packet length instead.  Of
course we can't do that; there's no process yet.

This patch fixes the problem.  We try qXfer on connection, then try
'g' only if (A) there was no XML description, and (B) there is a
running process, and (C) we are not in non-stop mode; assume that
non-stop targets can provide a description explicitly.

Pedro, could you take a look at this before I commit it?  Tested on
x86 with various local changes to make sure the new code was covered;
it fixes ext-attach.exp there.  I'll try it on MIPS now.

-- 
Daniel Jacobowitz
CodeSourcery

2008-11-23  Daniel Jacobowitz  <dan@codesourcery.com>

	PR gdb/2474
	* remote.c (remote_read_description_p): New function.
	(struct remote_state): New field tdesc_no_register_access.
	(remote_start_remote): Try to fetch the target description without
	any register access, then try with register access if the target
	is running.
	(remote_read_description): Honor tdesc_no_register_access.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.329
diff -u -p -r1.329 remote.c
--- remote.c	19 Nov 2008 14:45:09 -0000	1.329
+++ remote.c	23 Nov 2008 21:09:02 -0000
@@ -234,6 +234,8 @@ static void remote_async_get_pending_eve
 
 static void remote_terminal_ours (void);
 
+static int remote_read_description_p (struct target_ops *target);
+
 /* The non-stop remote protocol provisions for one pending stop reply.
    This is where we keep it until it is acknowledged.  */
 
@@ -303,6 +305,10 @@ struct remote_state
 
   /* True if the stub reports support for vCont;t.  */
   int support_vCont_t;
+
+  /* True if we are just connecting, and should not try fetching registers
+     yet.  */
+  int tdesc_no_register_access;
 };
 
 /* Returns true if the multi-process extensions are in effect.  */
@@ -2549,15 +2555,19 @@ remote_start_remote (struct ui_out *uiou
       getpkt (&rs->buf, &rs->buf_size, 0);
     }
 
+  /* Next, if the target can specify a description, read it.  We do
+     this before anything involving memory or registers.  At this
+     point, do not try to read registers from the target - it might
+     not be running, or it might be running and not stopped.  */
+  rs->tdesc_no_register_access = 1;
+  target_find_description ();
+  rs->tdesc_no_register_access = 0;
+
   /* On OSs where the list of libraries is global to all
      processes, we fetch them early.  */
   if (gdbarch_has_global_solist (target_gdbarch))
     solib_add (NULL, args->from_tty, args->target, auto_solib_add);
 
-  /* Next, if the target can specify a description, read it.  We do
-     this before anything involving memory or registers.  */
-  target_find_description ();
-
   if (non_stop)
     {
       if (!rs->non_stop_aware)
@@ -2643,6 +2653,17 @@ remote_start_remote (struct ui_out *uiou
 
       get_offsets ();		/* Get text, data & bss offsets.  */
 
+      /* If we could not find a description using qXfer, and we know
+	 how to do it some other way, try again.  This is not
+	 supported for non-stop; it could be, but it is tricky if
+	 there are no stopped threads when we connect.  */
+      if (remote_read_description_p (args->target)
+	  && gdbarch_target_desc (target_gdbarch) == NULL)
+	{
+	  target_clear_description ();
+	  target_find_description ();
+	}
+
       /* Use the previously fetched status.  */
       gdb_assert (wait_status != NULL);
       strcpy (rs->buf, wait_status);
@@ -7852,12 +7873,32 @@ register_remote_g_packet_guess (struct g
   VEC_safe_push (remote_g_packet_guess_s, data->guesses, &new_guess);
 }
 
+/* Return 1 if remote_read_description would do anything on this target
+   and architecture, 0 otherwise.  */
+
+static int
+remote_read_description_p (struct target_ops *target)
+{
+  struct remote_g_packet_data *data
+    = gdbarch_data (target_gdbarch, remote_g_packet_data_handle);
+
+  if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
+    return 1;
+
+  return 0;
+}
+
 static const struct target_desc *
 remote_read_description (struct target_ops *target)
 {
+  struct remote_state *rs = get_remote_state ();
   struct remote_g_packet_data *data
     = gdbarch_data (target_gdbarch, remote_g_packet_data_handle);
 
+  /* Do not try this during initial connection.  */
+  if (rs->tdesc_no_register_access)
+    return NULL;
+
   if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
     {
       struct remote_g_packet_guess *guess;


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