This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Split out follow-fork code in inf-ptrace.c
- From: Mark Kettenis <mark dot kettenis at xs4all dot nl>
- To: gdb-patches at sourceware dot org
- Date: Sun, 14 Aug 2005 00:23:42 +0200 (CEST)
- Subject: [commit] Split out follow-fork code in inf-ptrace.c
This puts some of the #ifdef PT_GET_PROCESS_STATE in its own
functions. The reason is that on OpenBSD the process has to be
stopped to be able to set the event mask, wheras this apparently
wasn't necessary on HP-UX. Fortunately the new code works just as
well for HP-UX.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* inf-ptrace.c (inf_ptrace_him) [PT_GET_PROCESS_STATE]: Move
code...
(inf_ptrace_post_startup_inferior): ...here. New function.
(inf_ptrace_attach) [PT_GET_PROCESS_STATE]: Move code...
(inf_ptrace_post_attach): ...here.
(inf_ptrace_target) [PT_GET_PROCESS_STATE]: Set
to_post_startup_inferior and to_post_attch.
Index: inf-ptrace.c
===================================================================
RCS file: /cvs/src/src/gdb/inf-ptrace.c,v
retrieving revision 1.23
diff -u -p -r1.23 inf-ptrace.c
--- inf-ptrace.c 25 Jul 2005 21:11:02 -0000 1.23
+++ inf-ptrace.c 13 Aug 2005 22:19:53 -0000
@@ -108,19 +108,6 @@ inf_ptrace_me (void)
static void
inf_ptrace_him (int pid)
{
-#ifdef PT_GET_PROCESS_STATE
- {
- ptrace_event_t pe;
-
- /* Set the initial event mask. */
- memset (&pe, 0, sizeof pe);
- pe.pe_set_event |= PTRACE_FORK;
- if (ptrace (PT_SET_EVENT_MASK, pid,
- (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
- perror_with_name (("ptrace"));
- }
-#endif
-
push_target (ptrace_ops_hack);
/* On some targets, there must be some explicit synchronization
@@ -159,6 +146,23 @@ inf_ptrace_create_inferior (char *exec_f
proceed ((CORE_ADDR) -1, TARGET_SIGNAL_0, 0);
}
+#ifdef PT_GET_PROCESS_STATE
+
+static void
+inf_ptrace_post_startup_inferior (ptid_t pid)
+{
+ ptrace_event_t pe;
+
+ /* Set the initial event mask. */
+ memset (&pe, 0, sizeof pe);
+ pe.pe_set_event |= PTRACE_FORK;
+ if (ptrace (PT_SET_EVENT_MASK, ptid_get_pid (pid),
+ (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+ perror_with_name (("ptrace"));
+}
+
+#endif
+
/* Clean up a rotting corpse of an inferior after it died. */
static void
@@ -222,19 +226,6 @@ inf_ptrace_attach (char *args, int from_
error (_("This system does not support attaching to a process"));
#endif
-#ifdef PT_GET_PROCESS_STATE
- {
- ptrace_event_t pe;
-
- /* Set the initial event mask. */
- memset (&pe, 0, sizeof pe);
- pe.pe_set_event |= PTRACE_FORK;
- if (ptrace (PT_SET_EVENT_MASK, pid,
- (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
- perror_with_name (("ptrace"));
- }
-#endif
-
inferior_ptid = pid_to_ptid (pid);
push_target (ptrace_ops_hack);
@@ -243,6 +234,23 @@ inf_ptrace_attach (char *args, int from_
observer_notify_inferior_created (¤t_target, from_tty);
}
+#ifdef PT_GET_PROCESS_STATE
+
+void
+inf_ptrace_post_attach (int pid)
+{
+ ptrace_event_t pe;
+
+ /* Set the initial event mask. */
+ memset (&pe, 0, sizeof pe);
+ pe.pe_set_event |= PTRACE_FORK;
+ if (ptrace (PT_SET_EVENT_MASK, pid,
+ (PTRACE_TYPE_ARG3)&pe, sizeof pe) == -1)
+ perror_with_name (("ptrace"));
+}
+
+#endif
+
/* Detach from the inferior, optionally passing it the signal
specified ARGS. If FROM_TTY is non-zero, be chatty about it. */
@@ -590,6 +598,8 @@ inf_ptrace_target (void)
t->to_create_inferior = inf_ptrace_create_inferior;
#ifdef PT_GET_PROCESS_STATE
t->to_follow_fork = inf_ptrace_follow_fork;
+ t->to_post_startup_inferior = inf_ptrace_post_startup_inferior;
+ t->to_post_attach = inf_ptrace_post_attach;
#endif
t->to_mourn_inferior = inf_ptrace_mourn_inferior;
t->to_thread_alive = inf_ptrace_thread_alive;