aboutsummaryrefslogtreecommitdiff
path: root/gdb/linux-nat.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2008-12-28 16:14:57 +0000
committerPedro Alves <palves@redhat.com>2008-12-28 16:14:57 +0000
commit7a7d33537f13d7556f60efb202b0895712e8ad7d (patch)
tree67cad6faf375248f4f5a93e38872f4cd1ef55367 /gdb/linux-nat.c
parent262452ec451590e24be1f034f4fe7fad92eefa9a (diff)
downloadgdb-7a7d33537f13d7556f60efb202b0895712e8ad7d.zip
gdb-7a7d33537f13d7556f60efb202b0895712e8ad7d.tar.gz
gdb-7a7d33537f13d7556f60efb202b0895712e8ad7d.tar.bz2
* 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-nat.c')
-rw-r--r--gdb/linux-nat.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index d90fb07..ac5a375 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -826,6 +826,11 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
child_pid);
}
+ /* Add the new inferior first, so that the target_detach below
+ doesn't unpush the target. */
+
+ add_inferior (child_pid);
+
/* If we're vforking, we may want to hold on to the parent until
the child exits or execs. At exec time we can remove the old
breakpoints from the parent and detach it; at exit time we
@@ -868,12 +873,7 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
target_detach (NULL, 0);
inferior_ptid = ptid_build (child_pid, child_pid, 0);
- add_inferior (child_pid);
-
- /* Reinstall ourselves, since we might have been removed in
- target_detach (which does other necessary cleanup). */
- push_target (ops);
linux_nat_switch_fork (inferior_ptid);
check_for_thread_db ();
@@ -1621,12 +1621,24 @@ linux_nat_detach (struct target_ops *ops, char *args, int from_tty)
/* Destroy LWP info; it's no longer valid. */
init_lwp_list ();
- pid = GET_PID (inferior_ptid);
- inferior_ptid = pid_to_ptid (pid);
- linux_ops->to_detach (ops, args, from_tty);
+ pid = ptid_get_pid (inferior_ptid);
if (target_can_async_p ())
drain_queued_events (pid);
+
+ if (forks_exist_p ())
+ {
+ /* Multi-fork case. The current inferior_ptid is being detached
+ from, but there are other viable forks to debug. Detach from
+ the current fork, and context-switch to the first
+ available. */
+ linux_fork_detach (args, from_tty);
+
+ if (non_stop && target_can_async_p ())
+ target_async (inferior_event_handler, 0);
+ }
+ else
+ linux_ops->to_detach (ops, args, from_tty);
}
/* Resume LP. */