Restart remote application

Daniel Jacobowitz drow@false.org
Wed Aug 8 14:24:00 GMT 2007


On Wed, Aug 08, 2007 at 03:29:56PM +0200, Petr Koloros wrote:
> Hi all,
> 
> I'm having problems with restarting the remote application. Some time ago it
> was advised to use extended protocol and 'run' command but it doesn't work.

The extended protocol doesn't work very well.  I have a sketch for
improvements to running more than one remote application, and some
code, which I hope I'll be working on for the next release of GDB
after 6.7.  However, what you're describing here normally works.

Here's some bits of that code plus another related fix I noticed;
does it help for you?

-- 
Daniel Jacobowitz
CodeSourcery

2007-08-08  Daniel Jacobowitz  <dan@codesourcery.com>

	* remote.c (remote_wait, remote_async_wait): Stop if we receive
	an error.
	(extended_remote_mourn): Mourn the target and reset inferior_ptid.

	* linux-low.c (linux_kill): Clear the inferior list.
	(linux_detach): Clear the process list.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.265
diff -u -p -r1.265 remote.c
--- remote.c	3 Jul 2007 15:58:42 -0000	1.265
+++ remote.c	8 Aug 2007 14:21:59 -0000
@@ -3219,8 +3219,12 @@ remote_wait (ptid_t ptid, struct target_
       switch (buf[0])
 	{
 	case 'E':		/* Error of some sort.  */
+	  /* We're out of sync with the target now.  Did it continue or not?
+	     Not is more likely, so report a stop.  */
 	  warning (_("Remote failure reply: %s"), buf);
-	  continue;
+	  status->kind = TARGET_WAITKIND_STOPPED;
+	  status->value.sig = TARGET_SIGNAL_0;
+	  goto got_status;
 	case 'F':		/* File-I/O request.  */
 	  remote_fileio_request (buf);
 	  continue;
@@ -3432,8 +3436,12 @@ remote_async_wait (ptid_t ptid, struct t
       switch (buf[0])
 	{
 	case 'E':		/* Error of some sort.  */
+	  /* We're out of sync with the target now.  Did it continue or not?
+	     Not is more likely, so report a stop.  */
 	  warning (_("Remote failure reply: %s"), buf);
-	  continue;
+	  status->kind = TARGET_WAITKIND_STOPPED;
+	  status->value.sig = TARGET_SIGNAL_0;
+	  goto got_status;
 	case 'F':		/* File-I/O request.  */
 	  remote_fileio_request (buf);
 	  continue;
@@ -5135,14 +5143,16 @@ remote_async_mourn (void)
 static void
 extended_remote_mourn (void)
 {
-  /* We do _not_ want to mourn the target like this; this will
-     remove the extended remote target  from the target stack,
-     and the next time the user says "run" it'll fail.
+  /* Unlike "target remote", we do not want to unpush the target; then
+     the next time the user says "run", we won't be connected.  */
 
-     FIXME: What is the right thing to do here?  */
-#if 0
-  remote_mourn_1 (&extended_remote_ops);
-#endif
+  /* Call common code to mark the inferior as not running.  */
+  generic_mourn_inferior ();
+
+  /* Assume that the target has been restarted.  Set inferior_ptid
+     so that bits of core GDB realizes there's something here, e.g.,
+     so that the user can say "kill" again.  */
+  inferior_ptid = pid_to_ptid (MAGIC_NULL_PID);
 }
 
 /* Worker function for remote_mourn.  */
Index: gdbserver/linux-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
retrieving revision 1.59
diff -u -p -r1.59 linux-low.c
--- gdbserver/linux-low.c	2 Jul 2007 15:35:36 -0000	1.59
+++ gdbserver/linux-low.c	8 Aug 2007 14:21:59 -0000
@@ -280,6 +280,10 @@ linux_kill (void)
       /* Make sure it died.  The loop is most likely unnecessary.  */
       wstat = linux_wait_for_event (thread);
     } while (WIFSTOPPED (wstat));
+
+  clear_inferiors ();
+  free (all_processes.head);
+  all_processes.head = all_processes.tail = NULL;
 }
 
 static void
@@ -318,6 +322,8 @@ linux_detach (void)
   delete_all_breakpoints ();
   for_each_inferior (&all_threads, linux_detach_one_process);
   clear_inferiors ();
+  free (all_processes.head);
+  all_processes.head = all_processes.tail = NULL;
   return 0;
 }
 



More information about the Gdb mailing list