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)