From 27ab33357a061db794254afee4cfabbac5d5668a Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Tue, 17 Jun 2003 20:28:14 +0000 Subject: gdb/ * NEWS: Mention gdbserver detach change and "disconnect" command. * infcmd.c (disconnect_command): New function. (_initialize_infcmd): Add ``disconnect'' command. * remote.c (remote_async_detach): Delete. (remote_detach): Merge remote_async_detach. (remote_disconnect): New. (init_remote_ops): Set to_disconnect. (init_remote_cisco_ops): Likewise. (init_remote_async_ops): Likewise. Use remote_detach. * target.c (cleanup_target): Default to_disconnect. (update_current_target): Inherit to_disconnect. (target_disconnect, debug_to_disconnect): New functions. (setup_target_debug): Set to_disconnect. * target.h (struct target_ops): Add to_disconnect. (target_disconnect): Add prototype. gdbserver/ * linux-low.c: Move comment to linux_thread_alive where it belonged. (linux_detach_one_process, linux_detach): New functions. (linux_target_ops): Add linux_detach. * server.c (main): Handle 'D' packet. * target.h (struct target_ops): Add "detach" member. (detach_inferior): Define. mi/ * mi-cmds.c (mi_cmds): Add "-target-disconnect". --- gdb/gdbserver/ChangeLog | 9 +++++++++ gdb/gdbserver/linux-low.c | 18 +++++++++++++++++- gdb/gdbserver/server.c | 22 ++++++++++++++++++++++ gdb/gdbserver/target.h | 7 +++++++ 4 files changed, 55 insertions(+), 1 deletion(-) (limited to 'gdb/gdbserver') diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index 8e9551715aa..c86533457e2 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,12 @@ +2003-06-17 Daniel Jacobowitz + + * linux-low.c: Move comment to linux_thread_alive where it belonged. + (linux_detach_one_process, linux_detach): New functions. + (linux_target_ops): Add linux_detach. + * server.c (main): Handle 'D' packet. + * target.h (struct target_ops): Add "detach" member. + (detach_inferior): Define. + 2003-06-13 Mark Kettenis From Kelley Cook : diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 4ad204ed3ac..c700d40ba3a 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -234,13 +234,28 @@ linux_kill_one_process (struct inferior_list_entry *entry) } 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) { @@ -1249,6 +1264,7 @@ static struct target_ops linux_target_ops = { linux_create_inferior, linux_attach, linux_kill, + linux_detach, linux_thread_alive, linux_resume, linux_wait, diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index d0963ba9de9..81fde5b7f73 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -217,6 +217,28 @@ main (int argc, char *argv[]) case 'd': remote_debug = !remote_debug; break; + case 'D': + fprintf (stderr, "Detaching from inferior\n"); + detach_inferior (); + write_ok (own_buf); + putpkt (own_buf); + remote_close (); + + /* If we are attached, then we can exit. Otherwise, we need to + hang around doing nothing, until the child is gone. */ + if (!attached) + { + int status, ret; + + do { + ret = waitpid (signal_pid, &status, 0); + if (WIFEXITED (status) || WIFSIGNALED (status)) + break; + } while (ret != -1 || errno != ECHILD); + } + + exit (0); + case '!': if (attached == 0) { diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h index c09ac8da73d..1c47a3aedb3 100644 --- a/gdb/gdbserver/target.h +++ b/gdb/gdbserver/target.h @@ -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); @@ -122,6 +126,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) -- cgit v1.2.1