This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
copy attach_flag to fork children
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 26 Jan 2009 22:42:36 +0000
- Subject: copy attach_flag to fork children
This restores the behaviour gdb had when attach_flag was a global, instead
of beeing an inferior property. This way, both terminal_inferior/terminal_ours
will behave identically in fork children, and, gdb will default to want to
detach from forked children of attached inferiors too.
While testing on OpenBSD, I noticed that the detach_breakpoints call
was asserting, because it was now being done before updating inferior_ptid.
Fixed that, did a testrun on x86_64-linux, and checked in.
--
Pedro Alves
2009-01-26 Pedro Alves <pedro@codesourcery.com>
* linux-nat.c (linux_child_follow_fork): Copy attach_flag from the
parent to the child.
* inf-ttrace.c (inf_ttrace_follow_fork): Likewise.
* inf-ptrace.c (inf_ptrace_follow_fork): Likewise. Use
remove_breakpoints to remove breakpoints from the parent.
---
gdb/inf-ptrace.c | 10 ++++++----
gdb/inf-ttrace.c | 5 ++++-
gdb/linux-nat.c | 12 ++++++++++--
3 files changed, 20 insertions(+), 7 deletions(-)
Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c 2009-01-23 19:17:46.000000000 +0000
+++ src/gdb/linux-nat.c 2009-01-26 20:01:50.000000000 +0000
@@ -730,9 +730,13 @@ linux_child_follow_fork (struct target_o
else
{
struct fork_info *fp;
+ struct inferior *parent_inf, *child_inf;
/* Add process to GDB's tables. */
- add_inferior (child_pid);
+ child_inf = add_inferior (child_pid);
+
+ parent_inf = find_inferior_pid (GET_PID (last_ptid));
+ child_inf->attach_flag = parent_inf->attach_flag;
/* Retain child fork in ptrace (stopped) state. */
fp = find_fork_pid (child_pid);
@@ -800,6 +804,7 @@ linux_child_follow_fork (struct target_o
struct thread_info *last_tp = find_thread_pid (last_ptid);
struct thread_info *tp;
char child_pid_spelling[40];
+ struct inferior *parent_inf, *child_inf;
/* Copy user stepping state to the new inferior thread. */
struct breakpoint *step_resume_breakpoint = last_tp->step_resume_breakpoint;
@@ -829,7 +834,10 @@ linux_child_follow_fork (struct target_o
/* Add the new inferior first, so that the target_detach below
doesn't unpush the target. */
- add_inferior (child_pid);
+ child_inf = add_inferior (child_pid);
+
+ parent_inf = find_inferior_pid (GET_PID (last_ptid));
+ child_inf->attach_flag = parent_inf->attach_flag;
/* 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
Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c 2009-01-26 20:46:15.000000000 +0000
+++ src/gdb/inf-ttrace.c 2009-01-26 20:55:54.000000000 +0000
@@ -458,6 +458,8 @@ inf_ttrace_follow_fork (struct target_op
if (follow_child)
{
+ struct inferior *inf;
+
/* Copy user stepping state to the new inferior thread. */
step_resume_breakpoint = last_tp->step_resume_breakpoint;
step_range_start = last_tp->step_range_start;
@@ -469,7 +471,8 @@ inf_ttrace_follow_fork (struct target_op
last_tp->step_resume_breakpoint = NULL;
inferior_ptid = ptid_build (fpid, flwpid, 0);
- add_inferior (fpid);
+ inf = add_inferior (fpid);
+ inf->attach_flag = find_inferior_pid (pid)->attach_flag;
detach_breakpoints (pid);
target_terminal_ours ();
Index: src/gdb/inf-ptrace.c
===================================================================
--- src.orig/gdb/inf-ptrace.c 2009-01-26 19:59:21.000000000 +0000
+++ src/gdb/inf-ptrace.c 2009-01-26 22:12:23.000000000 +0000
@@ -73,7 +73,8 @@ inf_ptrace_follow_fork (struct target_op
CORE_ADDR step_range_start = last_tp->step_range_start;
CORE_ADDR step_range_end = last_tp->step_range_end;
struct frame_id step_frame_id = last_tp->step_frame_id;
-
+ int attach_flag = find_inferior_pid (pid)->attach_flag;
+ struct inferior *inf;
struct thread_info *tp;
/* Otherwise, deleting the parent would get rid of this
@@ -81,8 +82,8 @@ inf_ptrace_follow_fork (struct target_op
last_tp->step_resume_breakpoint = NULL;
/* Before detaching from the parent, remove all breakpoints from
- it. */
- detach_breakpoints (pid);
+ it. */
+ remove_breakpoints ();
if (ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
perror_with_name (("ptrace"));
@@ -94,7 +95,8 @@ inf_ptrace_follow_fork (struct target_op
detach_inferior (pid);
/* Add the child. */
- add_inferior (fpid);
+ inf = add_inferior (fpid);
+ inf->attach_flag = attach_flag;
tp = add_thread_silent (inferior_ptid);
tp->step_resume_breakpoint = step_resume_breakpoint;