From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28452 invoked by alias); 6 Aug 2002 21:00:08 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 28443 invoked from network); 6 Aug 2002 21:00:06 -0000 Received: from unknown (HELO crack.them.org) (65.125.64.184) by sources.redhat.com with SMTP; 6 Aug 2002 21:00:06 -0000 Received: from dsl254-114-118.nyc1.dsl.speakeasy.net ([216.254.114.118] helo=nevyn.them.org ident=mail) by crack.them.org with asmtp (Exim 3.12 #1 (Debian)) id 17cBR1-000415-00 for ; Tue, 06 Aug 2002 16:00:07 -0500 Received: from drow by nevyn.them.org with local (Exim 3.35 #1 (Debian)) id 17cBR5-0000zH-00 for ; Tue, 06 Aug 2002 17:00:11 -0400 Date: Tue, 06 Aug 2002 14:00:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sources.redhat.com Subject: RFC: ``detach remote'' Message-ID: <20020806210009.GA29965@nevyn.them.org> Mail-Followup-To: gdb-patches@sources.redhat.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline User-Agent: Mutt/1.5.1i X-SW-Source: 2002-08/txt/msg00138.txt.bz2 --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 822 So, the GDB manual has this to say about remote debugging: To resume the remote program and stop debugging it, use the `detach' command. This is not how gdbserver works, and it isn't how any stubs I've worked with behave, either. They'll sit and wait for a reconnection. Rather than change the status quo, I would like to update the documentation and provide a way to get the previously documented behavior. This uses the "K" packet described in my email to gdb@ last week. The new command is `detach remote' which I'm not thrilled with but I'm a little short on ideas. It's hard to find something to call this. GDB and gdbserver patches attached. Comments? -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="detach-2.client.patch" Content-length: 4364 2002-08-06 Daniel Jacobowitz * remote.c (remote_detach): Support `detach remote'. (remote_async_detach): Likewise. 2002-08-06 Daniel Jacobowitz * gdb.texinfo: Document `detach remote'. (Remote Protocol): Document `K' packet. Index: remote.c =================================================================== RCS file: /cvs/src/src/gdb/remote.c,v retrieving revision 1.89 diff -u -p -r1.89 remote.c --- remote.c 23 Jul 2002 18:55:06 -0000 1.89 +++ remote.c 6 Aug 2002 20:49:59 -0000 @@ -2496,17 +2496,28 @@ remote_detach (char *args, int from_tty) struct remote_state *rs = get_remote_state (); char *buf = alloca (rs->remote_packet_size); - if (args) - error ("Argument given to \"detach\" when remotely debugging."); - - /* Tell the remote target to detach. */ - strcpy (buf, "D"); - remote_send (buf, (rs->remote_packet_size)); + if (args && strcmp (args, "remote") == 0) + { + /* Tell the target to detach and resume the inferior. */ + putpkt ("K"); + getpkt (buf, rs->remote_packet_size, 0); + if (strcmp (buf, "ERR") == 0) + error ("Remote target refused to detach."); + else if (strcmp (buf, "OK") != 0) + error ("Remote target does not support detaching."); + } + else if (args) + error ("Unknown argument given to \"detach\"."); + else + { + /* Tell the remote target to detach. */ + strcpy (buf, "D"); + remote_send (buf, (rs->remote_packet_size)); + } target_mourn_inferior (); if (from_tty) puts_filtered ("Ending remote debugging.\n"); - } /* Same as remote_detach, but with async support. */ @@ -2516,12 +2527,24 @@ remote_async_detach (char *args, int fro struct remote_state *rs = get_remote_state (); char *buf = alloca (rs->remote_packet_size); - if (args) - error ("Argument given to \"detach\" when remotely debugging."); - - /* Tell the remote target to detach. */ - strcpy (buf, "D"); - remote_send (buf, (rs->remote_packet_size)); + if (args && strcmp (args, "remote") == 0) + { + /* Tell the target to detach and resume the inferior. */ + putpkt ("K"); + getpkt (buf, rs->remote_packet_size, 0); + if (strcmp (buf, "ERR") == 0) + error ("Remote target refused to detach."); + else if (strcmp (buf, "OK") != 0) + error ("Remote target does not support detaching."); + } + else if (args) + error ("Unknown argument given to \"detach\"."); + else + { + /* Tell the remote target to detach. */ + strcpy (buf, "D"); + remote_send (buf, (rs->remote_packet_size)); + } /* Unregister the file descriptor from the event loop. */ if (target_is_async_p ()) Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.107 diff -u -p -r1.107 gdb.texinfo --- doc/gdb.texinfo 3 Aug 2002 23:37:07 -0000 1.107 +++ doc/gdb.texinfo 6 Aug 2002 20:50:03 -0000 @@ -10784,8 +10784,11 @@ session. Now you can use all the usual commands to examine and change data and to step and continue the remote program. -To resume the remote program and stop debugging it, use the @code{detach} -command. +To end remote debugging, use the @code{detach} command. Most remote stubs +will wait for @value{GDBN} to reconnect; for some stubs, you can use +@code{detach remote} to cause the stub to resume the remote program. +Depending on the remote stub, this may cause the stub to exit or become +unavailable. @cindex interrupting remote programs @cindex remote programs, interrupting @@ -14502,6 +14505,20 @@ See @samp{i} and @samp{S} for likely syn @tab FIXME: @emph{There is no description of how to operate when a specific thread context has been selected (i.e.@: does 'k' kill only that thread?)}. + +@item Detach request +@tab @code{K} +@tab +Detach @value{GDBN} from the remote system. Sent to the remote target before +@value{GDBN} disconnects. This packet indicates that the inferior should +be resumed instead of kept stopped, waiting for @value{GDBN} to reconnect. +The stub may exit after replying to this packet, or may wait for @value{GDBN}. +@item +@tab reply @code{ERR} +@tab The stub should return failure if it can not detach or refuses to detach. +@item +@tab reply @code{OK} +@tab Success @item reserved @tab @code{l} --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="detach-2.server.patch" Content-length: 3062 2002-08-06 Daniel Jacobowitz * gdbserver/linux-low.c (linux_detach_one_process) (linux_detach): New. (linux_target_ops): Add linux_detach. * gdbserver/server.c (main): Recognize `K' packet. * gdbserver/target.h (struct target_ops): Add ``detach'' member. (detach_inferior): New. Index: gdbserver/linux-low.c =================================================================== RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v retrieving revision 1.18 diff -u -p -r1.18 linux-low.c --- gdbserver/linux-low.c 18 Jul 2002 15:18:02 -0000 1.18 +++ gdbserver/linux-low.c 6 Aug 2002 20:50:03 -0000 @@ -232,13 +232,28 @@ linux_kill_one_process (struct inferior_ } while (WIFSTOPPED (wstat)); } -/* Return nonzero if the given thread is still alive. */ static void linux_kill (void) { for_each_inferior (&all_threads, linux_kill_one_process); } +static void +linux_detach_one_process (struct inferior_list_entry *entry) +{ + struct thread_info *thread = (struct thread_info *) entry; + struct process_info *process = get_thread_process (thread); + + ptrace (PTRACE_DETACH, pid_of (process), 0, 0); +} + +static void +linux_detach (void) +{ + for_each_inferior (&all_threads, linux_detach_one_process); +} + +/* Return nonzero if the given thread is still alive. */ static int linux_thread_alive (int tid) { @@ -1261,6 +1276,7 @@ static struct target_ops linux_target_op linux_create_inferior, linux_attach, linux_kill, + linux_detach, linux_thread_alive, linux_resume, linux_wait, Index: gdbserver/server.c =================================================================== RCS file: /cvs/src/src/gdb/gdbserver/server.c,v retrieving revision 1.13 diff -u -p -r1.13 server.c --- gdbserver/server.c 11 Jun 2002 17:32:40 -0000 1.13 +++ gdbserver/server.c 6 Aug 2002 20:50:03 -0000 @@ -310,6 +310,19 @@ main (int argc, char *argv[]) exit (0); break; } + case 'K': + if (attached) + { + fprintf (stderr, "Detaching from inferior\n"); + detach_inferior (); + write_ok (own_buf); + putpkt (own_buf); + remote_close (); + exit (0); + } + else + write_enn (own_buf); + break; case 'T': if (mythread_alive (strtol (&own_buf[1], NULL, 16))) write_ok (own_buf); Index: gdbserver/target.h =================================================================== RCS file: /cvs/src/src/gdb/gdbserver/target.h,v retrieving revision 1.4 diff -u -p -r1.4 target.h --- gdbserver/target.h 11 Jun 2002 17:32:40 -0000 1.4 +++ gdbserver/target.h 6 Aug 2002 20:50:03 -0000 @@ -48,6 +48,10 @@ struct target_ops void (*kill) (void); + /* Detach from all inferiors. */ + + void (*detach) (void); + /* Return 1 iff the thread with process ID PID is alive. */ int (*thread_alive) (int pid); @@ -123,6 +127,9 @@ void set_target_ops (struct target_ops * #define kill_inferior() \ (*the_target->kill) () + +#define detach_inferior() \ + (*the_target->detach) () #define mythread_alive(pid) \ (*the_target->thread_alive) (pid) --HcAYCG3uE/tztfnV--