summaryrefslogtreecommitdiff
path: root/gdb/linux-fork.c
diff options
context:
space:
mode:
authorPedro Alves <pedro@codesourcery.com>2008-12-28 16:14:56 +0000
committerPedro Alves <pedro@codesourcery.com>2008-12-28 16:14:56 +0000
commit027a0a007cabf6cb23b35c53f5cbc172904d84ba (patch)
tree35afe6599889252fd31d1c81b85944539e873abe /gdb/linux-fork.c
parent43f17405181c357d49d5193f0d16665964e6e5b0 (diff)
downloadgdb-027a0a007cabf6cb23b35c53f5cbc172904d84ba.tar.gz
* linux-fork.c (linux_fork_detach): New.
* linux-fork.h (linux_fork_detach): Declare. * linux-nat.c (linux_child_follow_fork): When following the fork child, add the child inferior before possibly detaching from the parent. Don't reinstall ourselves. (linux_nat_detach): Call linux_fork_detach if there are other forks to debug. * linux-thread-db.c (thread_db_detach): Don't call target_mourn_inferior. Instead inline the necessary bits. * inf-ptrace.c (inf_ptrace_detach): Don't unpush the target if there are other inferiors to debug.
Diffstat (limited to 'gdb/linux-fork.c')
-rw-r--r--gdb/linux-fork.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 3d649228450..4450385983a 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -387,6 +387,40 @@ linux_fork_mourn_inferior (void)
delete_fork (inferior_ptid);
}
+/* The current inferior_ptid is being detached, but there are other
+ viable forks to debug. Detach and delete it and context-switch to
+ the first available. */
+
+extern void
+linux_fork_detach (char *args, int from_tty)
+{
+ /* OK, inferior_ptid is the one we are detaching from. We need to
+ delete it from the fork_list, and switch to the next available
+ fork. */
+
+ if (ptrace (PTRACE_DETACH, PIDGET (inferior_ptid), 0, 0))
+ error (_("Unable to detach %s"), target_pid_to_str (inferior_ptid));
+
+ delete_fork (inferior_ptid);
+ /* Delete process from GDB's inferior list. */
+ delete_inferior (ptid_get_pid (inferior_ptid));
+
+ /* There should still be a fork - if there's only one left,
+ delete_fork won't remove it, because we haven't updated
+ inferior_ptid yet. */
+ gdb_assert (fork_list);
+
+ fork_load_infrun_state (fork_list);
+
+ if (from_tty)
+ printf_filtered (_("[Switching to %s]\n"),
+ target_pid_to_str (inferior_ptid));
+
+ /* If there's only one fork, switch back to non-fork mode. */
+ if (fork_list->next == NULL)
+ delete_fork (inferior_ptid);
+}
+
/* Fork list <-> user interface. */
static void