From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20534 invoked by alias); 13 Nov 2008 21:59:48 -0000 Received: (qmail 19944 invoked by uid 22791); 13 Nov 2008 21:59:44 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 13 Nov 2008 21:58:59 +0000 Received: (qmail 20625 invoked from network); 13 Nov 2008 21:58:57 -0000 Received: from unknown (HELO wind.localnet) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 13 Nov 2008 21:58:57 -0000 From: Vladimir Prus To: Pedro Alves Subject: Re: [RFA] Implement 'detach pid'. Date: Fri, 14 Nov 2008 01:55:00 -0000 User-Agent: KMail/1.10.90 (Linux/2.6.24-21-generic; KDE/4.1.73; i686; svn-883826; 2008-11-13) Cc: gdb-patches@sourceware.org References: <200811122339.02463.vladimir@codesourcery.com> <200811122319.57637.pedro@codesourcery.com> In-Reply-To: <200811122319.57637.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_ZMKHJ7uPgII0odW" Message-Id: <200811140058.49275.vladimir@codesourcery.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-11/txt/msg00306.txt.bz2 --Boundary-00=_ZMKHJ7uPgII0odW Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 996 On Thursday 13 November 2008 02:19:57 Pedro Alves wrote: > On Wednesday 12 November 2008 20:39:02, Vladimir Prus wrote: > > This patch makes CLI 'detach' and MI '-target-detach' accept the PID > > of the process to detach from. > > I see several issues with this patch: > > - The target is not the right layer to do this. Before you reach here, > you've already done things to the current inferior. E.g., > target.c:target_detach will call remove_breakpoints before reaching > remote_detach_1. This means that, if you have e.g., selected inferior 1, > and do detach 3, you'll remove breakpoints from inferior 1, and detach > process 3. Breakpoints are an example. Other example is that before you > reach the process stratum, you can pass by the thread_stratum, which again > would do anything to the wrong detachee, since it's usually the > process_statum that does the final real detach. That's bad. How about the attached -- where mostly everything is done on MI side? - Volodya --Boundary-00=_ZMKHJ7uPgII0odW Content-Type: text/x-patch; charset="UTF-8"; name="detach.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="detach.diff" Content-length: 4512 commit da4c2b7d1163dfd36c492f9f793c04f9bdb36d2b Author: vladimir Date: Thu Jul 31 13:23:59 2008 +0000 Implement '-target-detach pid'. * gdbthread.h (thread_callback_func): Clarify comment. * infcmd.c (detach_command): Make nonstatic. * inferior.h (detach_command): Declare. * mi/mi-cmds.c (mi_cmds): Don't route -target-detach via CLI. * mi/mi-cmds.h (mi_cmd_target_detach): Declare. * /mi/mi-main.c (find_thread_of_process, mi_cmd_target_detach): New. diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index cac20f7..1a65aa8 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -229,7 +229,9 @@ struct thread_info *find_thread_id (int num); void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid); /* Iterator function to call a user-provided callback function - once for each known thread. */ + once for each known thread. Returns 0 to continue iteration, + and 1 to stop -- which causes iterate_over_threads to return + the current thread_info. */ typedef int (*thread_callback_func) (struct thread_info *, void *); extern struct thread_info *iterate_over_threads (thread_callback_func, void *); diff --git a/gdb/infcmd.c b/gdb/infcmd.c index b3af31f..810b3b7 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -86,8 +86,6 @@ static void unset_command (char *, int); static void float_info (char *, int); -static void detach_command (char *, int); - static void disconnect_command (char *, int); static void unset_environment_command (char *, int); @@ -2344,7 +2342,7 @@ attach_command (char *args, int from_tty) * started via the normal ptrace (PTRACE_TRACEME). */ -static void +void detach_command (char *args, int from_tty) { dont_repeat (); /* Not for the faint of heart. */ diff --git a/gdb/inferior.h b/gdb/inferior.h index 1be6cc5..f004d44 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -269,6 +269,8 @@ extern void interrupt_target_command (char *args, int from_tty); extern void interrupt_target_1 (int all_threads); +extern void detach_command (char *, int); + /* Address at which inferior stopped. */ extern CORE_ADDR stop_pc; diff --git a/gdb/mi/mi-cmds.c b/gdb/mi/mi-cmds.c index d38de35..51c720e 100644 --- a/gdb/mi/mi-cmds.c +++ b/gdb/mi/mi-cmds.c @@ -121,7 +121,7 @@ struct mi_cmd mi_cmds[] = { "symbol-type", { NULL, 0 }, NULL }, { "target-attach", { "attach", 1 }, NULL }, { "target-compare-sections", { NULL, 0 }, NULL }, - { "target-detach", { "detach", 0 }, 0 }, + { "target-detach", { NULL, 0 }, mi_cmd_target_detach }, { "target-disconnect", { "disconnect", 0 }, 0 }, { "target-download", { "load", 1 }, NULL}, { "target-exec-status", { NULL, 0 }, NULL }, diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h index a9bb1e0..a399b9e 100644 --- a/gdb/mi/mi-cmds.h +++ b/gdb/mi/mi-cmds.h @@ -75,6 +75,7 @@ extern mi_cmd_argv_ftype mi_cmd_stack_list_frames; extern mi_cmd_argv_ftype mi_cmd_stack_list_locals; extern mi_cmd_argv_ftype mi_cmd_stack_select_frame; extern mi_cmd_argv_ftype mi_cmd_symbol_list_lines; +extern mi_cmd_argv_ftype mi_cmd_target_detach; extern mi_cmd_argv_ftype mi_cmd_target_file_get; extern mi_cmd_argv_ftype mi_cmd_target_file_put; extern mi_cmd_argv_ftype mi_cmd_target_file_delete; diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 43ec0b4..36c0223 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -199,6 +199,42 @@ mi_cmd_exec_interrupt (char *command, char **argv, int argc) error ("Usage: -exec-interrupt [--all]"); } +static int +find_thread_of_process (struct thread_info *ti, void *p) +{ + int pid = *(int *)p; + if (PIDGET (ti->ptid) == pid && !is_exited (ti->ptid)) + return 1; + + return 0; +} + +void +mi_cmd_target_detach (char *command, char **argv, int argc) +{ + if (argc != 0 && argc != 1) + error ("Usage: -target-detach [thread-group]"); + + if (argc == 1) + { + struct thread_info *tp; + char *end = argv[0]; + int pid = strtol (argv[0], &end, 10); + if (*end != '\0') + error (_("Cannot parse thread group id '%s'"), argv[0]); + + /* Pick any thread in the desired process. Current + target_detach deteches from the parent of inferior_ptid. */ + tp = iterate_over_threads (find_thread_of_process, &pid); + if (!tp) + error (_("Thread group is empty")); + + switch_to_thread (tp->ptid); + } + + detach_command (NULL, 0); +} + void mi_cmd_thread_select (char *command, char **argv, int argc) { --Boundary-00=_ZMKHJ7uPgII0odW--