This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Fork event updates, part the third


This patch removes follow_fork_mode_both: attach one debugger to the parent
and another to the child.  This should be the last of the large removals.  I
don't know of any operating system which can readily handle this; I could
probably finagle Linux into doing it but there's the interface problem of
getting a new terminal.  It was written specifically for HP/UX, and around
10.20 (according to comments) it stopped working.  Oops.

This code has all been disabled for a long time - sine it was brought in
during the merge as far as I can tell.  HP didn't fix it in WDB either. I
feel not the slightest remorse to see it go...  With it it takes two
sizeable functions, two target hooks, and a general collection of other
gunk.

(There's also a compilation fix for the preceeding patch on HP/UX, which
I'll group with the right patch when I commit it.)

I'll commit this on Friday with the others unless someone actually feels
any grief at seeing this incomplete feature leave us.  May it go on to a
happy, feature-filled afterlife.  Etc.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-11-14  Daniel Jacobowitz  <drow@mvista.com>

	* config/pa/nm-hppah.h (CHILD_POST_FOLLOW_INFERIOR_BY_CLONE): Don't
	define.
	(struct target_waitstatus): Add opaque definition.
	* corelow.c (init_core_ops): Don't set to_clone_and_follow_inferior.
	* exec.c (init_exec_ops): Likewise.
	* fork-child.c (clone_and_follow_inferior): Remove.
	* hppah-nat.c (child_post_follow_inferior_by_clone): Remove.
	* inferior.h (clone_and_follow_inferior): Remove prototype.
	* infrun.c (follow_fork_mode_both): Remove.
	(follow_fork_mode_kind_names): Remove commented out "both".
	(follow_inferior_fork): Remove follow_fork_mode_both support.
	* inftarg.c (child_clone_and_follow_inferior): Remove.
	(child_post_follow_inferior_by_clone): Remove.
	(init_child_ops): Don't set to_clone_and_follow_inferior
	or to_post_follow_inferior_by_clone.
	* target.c (default_clone_and_follow_inferior): Remove.
	(cleanup_target): Don't set to_clone_and_follow_inferior
	or to_post_follow_inferior_by_clone.
	(find_default_clone_and_follow_inferior): Remove.
	(init_dummy_target): Don't set to_clone_and_follow_inferior.
	(debug_to_clone_and_follow_inferior): Remove.
	(debug_to_post_follow_inferior_by_clone): Remove.
	(setup_target_debug): Don't set to_clone_and_follow_inferior
	or to_post_follow_inferior_by_clone.
	* target.h (struct target_ops): Remove to_clone_and_follow_inferior
	and to_post_follow_inferior_by_clone.
	(child_clone_and_follow_inferior): Remove prototype.
	(child_post_follow_inferior_by_clone): Remove prototype.
	(target_clone_and_follow_inferior): Remove macro.
	(target_post_follow_inferior_by_clone): Remove macro.
	(find_default_clone_and_follow_inferior): Remove prototype.

diff -urp gdb.work2/config/pa/nm-hppah.h gdb.work3/config/pa/nm-hppah.h
--- gdb.work2/config/pa/nm-hppah.h	2002-11-13 16:18:26.000000000 -0500
+++ gdb.work3/config/pa/nm-hppah.h	2002-11-14 15:33:41.000000000 -0500
@@ -65,7 +65,6 @@
 /* In hppah-nat.c: */
 #define FETCH_INFERIOR_REGISTERS
 #define CHILD_XFER_MEMORY
-#define CHILD_POST_FOLLOW_INFERIOR_BY_CLONE
 #define CHILD_POST_FOLLOW_VFORK
 
 /* While this is for use by threaded programs, it doesn't appear
@@ -88,6 +87,7 @@ extern int hppa_prepare_to_proceed (void
 #define CHILD_THREAD_ALIVE
 #define CHILD_PID_TO_STR
 #define CHILD_WAIT
+struct target_waitstatus;
 extern ptid_t child_wait (ptid_t, struct target_waitstatus *);
 
 #define REQUIRE_ATTACH(pid) hppa_require_attach(pid)
diff -urp gdb.work2/corelow.c gdb.work3/corelow.c
--- gdb.work2/corelow.c	2002-11-07 12:00:25.000000000 -0500
+++ gdb.work3/corelow.c	2002-11-14 15:20:20.000000000 -0500
@@ -518,7 +518,6 @@ init_core_ops (void)
   core_ops.to_insert_breakpoint = ignore;
   core_ops.to_remove_breakpoint = ignore;
   core_ops.to_create_inferior = find_default_create_inferior;
-  core_ops.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
   core_ops.to_thread_alive = core_file_thread_alive;
   core_ops.to_stratum = core_stratum;
   core_ops.to_has_memory = 1;
diff -urp gdb.work2/exec.c gdb.work3/exec.c
--- gdb.work2/exec.c	2002-09-13 18:54:36.000000000 -0400
+++ gdb.work3/exec.c	2002-11-14 15:21:37.000000000 -0500
@@ -721,7 +721,6 @@ Specify the filename of the executable f
   exec_ops.to_insert_breakpoint = ignore;
   exec_ops.to_remove_breakpoint = ignore;
   exec_ops.to_create_inferior = find_default_create_inferior;
-  exec_ops.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
   exec_ops.to_stratum = file_stratum;
   exec_ops.to_has_memory = 1;
   exec_ops.to_make_corefile_notes = exec_make_note_section;
diff -urp gdb.work2/fork-child.c gdb.work3/fork-child.c
--- gdb.work2/fork-child.c	2002-02-08 11:24:37.000000000 -0500
+++ gdb.work3/fork-child.c	2002-11-14 15:20:44.000000000 -0500
@@ -379,131 +379,6 @@ fork_inferior (char *exec_file_arg, char
 #endif
 }
 
-/* An inferior Unix process CHILD_PID has been created by a call to
-   fork() (or variants like vfork).  It is presently stopped, and waiting
-   to be resumed.  clone_and_follow_inferior will fork the debugger,
-   and that clone will "follow" (attach to) CHILD_PID.  The original copy
-   of the debugger will not touch CHILD_PID again.
-
-   Also, the original debugger will set FOLLOWED_CHILD FALSE, while the
-   clone will set it TRUE.
- */
-void
-clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  int debugger_pid;
-  int status;
-  char pid_spelling[100];	/* Arbitrary but sufficient length. */
-
-  /* This semaphore is used to coordinate the two debuggers' handoff
-     of CHILD_PID.  The original debugger will detach from CHILD_PID,
-     and then the clone debugger will attach to it.  (It must be done
-     this way because on some targets, only one process at a time can
-     trace another.  Thus, the original debugger must relinquish its
-     tracing rights before the clone can pick them up.)
-   */
-#define SEM_TALK (1)
-#define SEM_LISTEN (0)
-  int handoff_semaphore[2];	/* Original "talks" to [1], clone "listens" to [0] */
-  int talk_value = 99;
-  int listen_value;
-
-  /* Set debug_fork then attach to the child while it sleeps, to debug. */
-  static int debug_fork = 0;
-
-  /* It is generally good practice to flush any possible pending stdio
-     output prior to doing a fork, to avoid the possibility of both the
-     parent and child flushing the same data after the fork. */
-
-  gdb_flush (gdb_stdout);
-  gdb_flush (gdb_stderr);
-
-  /* Open the semaphore pipes.
-   */
-  status = pipe (handoff_semaphore);
-  if (status < 0)
-    error ("error getting pipe for handoff semaphore");
-
-  /* Clone the debugger.  Note that the apparent call to vfork()
-     below *might* actually be a call to fork() due to the fact that
-     autoconf will ``#define vfork fork'' on certain platforms.  */
-  if (debug_fork)
-    debugger_pid = fork ();
-  else
-    debugger_pid = vfork ();
-
-  if (debugger_pid < 0)
-    perror_with_name ("fork");
-
-  /* Are we the original debugger?  If so, we must relinquish all claims
-     to CHILD_PID. */
-  if (debugger_pid != 0)
-    {
-      char signal_spelling[100];	/* Arbitrary but sufficient length */
-
-      /* Detach from CHILD_PID.  Deliver a "stop" signal when we do, though,
-         so that it remains stopped until the clone debugger can attach
-         to it.
-       */
-      detach_breakpoints (child_pid);
-
-      sprintf (signal_spelling, "%d", target_signal_to_host (TARGET_SIGNAL_STOP));
-      target_require_detach (child_pid, signal_spelling, 1);
-
-      /* Notify the clone debugger that it should attach to CHILD_PID. */
-      write (handoff_semaphore[SEM_TALK], &talk_value, sizeof (talk_value));
-
-      *followed_child = 0;
-    }
-
-  /* We're the child. */
-  else
-    {
-      if (debug_fork)
-	sleep (debug_fork);
-
-      /* The child (i.e., the cloned debugger) must now attach to
-         CHILD_PID.  inferior_ptid is presently set to the parent process
-         of the fork, while CHILD_PID should be the child process of the
-         fork.
-
-         Wait until the original debugger relinquishes control of CHILD_PID,
-         though.
-       */
-      read (handoff_semaphore[SEM_LISTEN], &listen_value, sizeof (listen_value));
-
-      /* Note that we DON'T want to actually detach from inferior_ptid,
-         because that would allow it to run free.  The original
-         debugger wants to retain control of the process.  So, we
-         just reset inferior_ptid to CHILD_PID, and then ensure that all
-         breakpoints are really set in CHILD_PID.
-       */
-      target_mourn_inferior ();
-
-      /* Ask the tty subsystem to switch to the one we specified earlier
-         (or to share the current terminal, if none was specified).  */
-
-      new_tty ();
-
-      dont_repeat ();
-      sprintf (pid_spelling, "%d", child_pid);
-      target_require_attach (pid_spelling, 1);
-
-      /* Perform any necessary cleanup, after attachment.  (This form
-         of attaching can behave differently on some targets than the
-         standard method, where a process formerly not under debugger
-         control was suddenly attached to..)
-       */
-      target_post_follow_inferior_by_clone ();
-
-      *followed_child = 1;
-    }
-
-  /* Discard the handoff sempahore. */
-  (void) close (handoff_semaphore[SEM_LISTEN]);
-  (void) close (handoff_semaphore[SEM_TALK]);
-}
-
 /* Accept NTRAPS traps from the inferior.  */
 
 void
diff -urp gdb.work2/hppah-nat.c gdb.work3/hppah-nat.c
--- gdb.work2/hppah-nat.c	2002-11-13 14:43:37.000000000 -0500
+++ gdb.work3/hppah-nat.c	2002-11-14 15:24:31.000000000 -0500
@@ -386,24 +386,6 @@ child_xfer_memory (CORE_ADDR memaddr, ch
 
 
 void
-child_post_follow_inferior_by_clone (void)
-{
-  int status;
-
-  /* This function is used when following both the parent and child
-     of a fork.  In this case, the debugger clones itself.  The original
-     debugger follows the parent, the clone follows the child.  The
-     original detaches from the child, delivering a SIGSTOP to it to
-     keep it from running away until the clone can attach itself.
-
-     At this point, the clone has attached to the child.  Because of
-     the SIGSTOP, we must now deliver a SIGCONT to the child, or it
-     won't behave properly. */
-  status = kill (PIDGET (inferior_ptid), SIGCONT);
-}
-
-
-void
 child_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
 			 int followed_child)
 {
diff -urp gdb.work2/inferior.h gdb.work3/inferior.h
--- gdb.work2/inferior.h	2002-10-04 10:06:02.000000000 -0400
+++ gdb.work3/inferior.h	2002-11-14 15:21:28.000000000 -0500
@@ -270,8 +270,6 @@ extern void fork_inferior (char *, char 
 			   void (*)(int), void (*)(void), char *);
 
 
-extern void clone_and_follow_inferior (int, int *);
-
 extern void startup_inferior (int);
 
 extern char *construct_inferior_arguments (struct gdbarch *, int, char **);
diff -urp gdb.work2/infrun.c gdb.work3/infrun.c
--- gdb.work2/infrun.c	2002-11-13 15:03:12.000000000 -0500
+++ gdb.work3/infrun.c	2002-11-14 15:21:19.000000000 -0500
@@ -371,17 +371,11 @@ static struct
 pending_follow;
 
 static const char follow_fork_mode_ask[] = "ask";
-static const char follow_fork_mode_both[] = "both";
 static const char follow_fork_mode_child[] = "child";
 static const char follow_fork_mode_parent[] = "parent";
 
 static const char *follow_fork_mode_kind_names[] = {
   follow_fork_mode_ask,
-  /* ??rehrauer: The "both" option is broken, by what may be a 10.20
-     kernel problem.  It's also not terribly useful without a GUI to
-     help the user drive two debuggers.  So for now, I'm disabling the
-     "both" option. */
-  /* follow_fork_mode_both, */
   follow_fork_mode_child,
   follow_fork_mode_parent,
   NULL
@@ -486,24 +480,6 @@ follow_inferior_fork (int parent_pid, in
       insert_breakpoints ();
     }
 
-  /* If we're to be following both parent and child, then fork ourselves,
-     and attach the debugger clone to the child. */
-  else if (follow_mode == follow_fork_mode_both)
-    {
-      char pid_suffix[100];	/* Arbitrary length. */
-
-      /* Clone ourselves to follow the child.  This is the end of our
-         involvement with child_pid; our clone will take it from here... */
-      dont_repeat ();
-      target_clone_and_follow_inferior (child_pid, &followed_child);
-      followed_parent = !followed_child;
-
-      /* We continue to follow the parent.  To help distinguish the two
-         debuggers, though, both we and our clone will reset our prompts. */
-      sprintf (pid_suffix, "[%d] ", PIDGET (inferior_ptid));
-      set_prompt (strcat (get_prompt (), pid_suffix));
-    }
-
   /* The parent and child of a vfork share the same address space.
      Also, on some targets the order in which vfork and exec events
      are received for parent in child requires some delicate handling
diff -urp gdb.work2/inftarg.c gdb.work3/inftarg.c
--- gdb.work2/inftarg.c	2002-11-13 14:56:24.000000000 -0500
+++ gdb.work3/inftarg.c	2002-11-14 15:45:32.000000000 -0500
@@ -433,27 +433,6 @@ child_acknowledge_created_inferior (int 
 #endif
 
 
-void
-child_clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  clone_and_follow_inferior (child_pid, followed_child);
-
-  /* Don't resume CHILD_PID; it's stopped where it ought to be, until
-     the decision gets made elsewhere how to continue it.
-   */
-}
-
-
-#if !defined(CHILD_POST_FOLLOW_INFERIOR_BY_CLONE)
-void
-child_post_follow_inferior_by_clone (void)
-{
-  /* This version of Unix doesn't require a meaningful "post follow inferior"
-     operation by a clone debugger.
-   */
-}
-#endif
-
 #if !defined(CHILD_INSERT_FORK_CATCHPOINT)
 int
 child_insert_fork_catchpoint (int pid)
@@ -662,8 +641,6 @@ init_child_ops (void)
   child_ops.to_create_inferior = child_create_inferior;
   child_ops.to_post_startup_inferior = child_post_startup_inferior;
   child_ops.to_acknowledge_created_inferior = child_acknowledge_created_inferior;
-  child_ops.to_clone_and_follow_inferior = child_clone_and_follow_inferior;
-  child_ops.to_post_follow_inferior_by_clone = child_post_follow_inferior_by_clone;
   child_ops.to_insert_fork_catchpoint = child_insert_fork_catchpoint;
   child_ops.to_remove_fork_catchpoint = child_remove_fork_catchpoint;
   child_ops.to_insert_vfork_catchpoint = child_insert_vfork_catchpoint;
diff -urp gdb.work2/target.c gdb.work3/target.c
--- gdb.work2/target.c	2002-11-13 14:53:04.000000000 -0500
+++ gdb.work3/target.c	2002-11-14 15:23:41.000000000 -0500
@@ -44,8 +44,6 @@ static void cleanup_target (struct targe
 
 static void maybe_kill_then_create_inferior (char *, char *, char **);
 
-static void default_clone_and_follow_inferior (int, int *);
-
 static void maybe_kill_then_attach (char *, int);
 
 static void kill_or_be_killed (int);
@@ -348,12 +346,6 @@ maybe_kill_then_create_inferior (char *e
   target_create_inferior (exec, args, env);
 }
 
-static void
-default_clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  target_clone_and_follow_inferior (child_pid, followed_child);
-}
-
 /* Clean up a target struct so it no longer has any zero pointers in it.
    We default entries, at least to stubs that print error messages.  */
 
@@ -469,11 +461,6 @@ cleanup_target (struct target_ops *t)
   de_fault (to_acknowledge_created_inferior, 
 	    (void (*) (int)) 
 	    target_ignore);
-  de_fault (to_clone_and_follow_inferior, 
-	    default_clone_and_follow_inferior);
-  de_fault (to_post_follow_inferior_by_clone, 
-	    (void (*) (void)) 
-	    target_ignore);
   de_fault (to_insert_fork_catchpoint, 
 	    (int (*) (int)) 
 	    tcomplain);
@@ -606,8 +593,6 @@ update_current_target (void)
       INHERIT (to_create_inferior, t);
       INHERIT (to_post_startup_inferior, t);
       INHERIT (to_acknowledge_created_inferior, t);
-      INHERIT (to_clone_and_follow_inferior, t);
-      INHERIT (to_post_follow_inferior_by_clone, t);
       INHERIT (to_insert_fork_catchpoint, t);
       INHERIT (to_remove_fork_catchpoint, t);
       INHERIT (to_insert_vfork_catchpoint, t);
@@ -1254,16 +1239,6 @@ find_default_create_inferior (char *exec
   return;
 }
 
-void
-find_default_clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  struct target_ops *t;
-
-  t = find_default_run_target ("run");
-  (t->to_clone_and_follow_inferior) (child_pid, followed_child);
-  return;
-}
-
 static int
 default_region_size_ok_for_hw_watchpoint (int byte_count)
 {
@@ -1564,7 +1539,6 @@ init_dummy_target (void)
   dummy_target.to_require_attach = find_default_require_attach;
   dummy_target.to_require_detach = find_default_require_detach;
   dummy_target.to_create_inferior = find_default_create_inferior;
-  dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
   dummy_target.to_pid_to_str = normal_pid_to_str;
   dummy_target.to_stratum = dummy_stratum;
   dummy_target.to_find_memory_regions = dummy_find_memory_regions;
@@ -2038,24 +2012,6 @@ debug_to_acknowledge_created_inferior (i
 		      pid);
 }
 
-static void
-debug_to_clone_and_follow_inferior (int child_pid, int *followed_child)
-{
-  debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
-
-  fprintf_unfiltered (gdb_stdlog,
-		      "target_clone_and_follow_inferior (%d, %d)\n",
-		      child_pid, *followed_child);
-}
-
-static void
-debug_to_post_follow_inferior_by_clone (void)
-{
-  debug_target.to_post_follow_inferior_by_clone ();
-
-  fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
-}
-
 static int
 debug_to_insert_fork_catchpoint (int pid)
 {
@@ -2325,8 +2281,6 @@ setup_target_debug (void)
   current_target.to_create_inferior = debug_to_create_inferior;
   current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
   current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
-  current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
-  current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
   current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
   current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
   current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
diff -urp gdb.work2/target.h gdb.work3/target.h
--- gdb.work2/target.h	2002-11-13 15:05:07.000000000 -0500
+++ gdb.work3/target.h	2002-11-14 15:23:55.000000000 -0500
@@ -272,8 +272,6 @@ struct target_ops
     void (*to_create_inferior) (char *, char *, char **);
     void (*to_post_startup_inferior) (ptid_t);
     void (*to_acknowledge_created_inferior) (int);
-    void (*to_clone_and_follow_inferior) (int, int *);
-    void (*to_post_follow_inferior_by_clone) (void);
     int (*to_insert_fork_catchpoint) (int);
     int (*to_remove_fork_catchpoint) (int);
     int (*to_insert_vfork_catchpoint) (int);
@@ -540,10 +538,6 @@ extern void child_post_startup_inferior 
 
 extern void child_acknowledge_created_inferior (int);
 
-extern void child_clone_and_follow_inferior (int, int *);
-
-extern void child_post_follow_inferior_by_clone (void);
-
 extern int child_insert_fork_catchpoint (int);
 
 extern int child_remove_fork_catchpoint (int);
@@ -695,33 +689,6 @@ extern void target_load (char *arg, int 
 #define target_acknowledge_created_inferior(pid) \
      (*current_target.to_acknowledge_created_inferior) (pid)
 
-/* An inferior process has been created via a fork() or similar
-   system call.  This function will clone the debugger, then ensure
-   that CHILD_PID is attached to by that debugger.
-
-   FOLLOWED_CHILD is set TRUE on return *for the clone debugger only*,
-   and FALSE otherwise.  (The original and clone debuggers can use this
-   to determine which they are, if need be.)
-
-   (This is not a terribly useful feature without a GUI to prevent
-   the two debuggers from competing for shell input.)  */
-
-#define target_clone_and_follow_inferior(child_pid,followed_child) \
-     (*current_target.to_clone_and_follow_inferior) (child_pid, followed_child)
-
-/* This operation is intended to be used as the last in a sequence of
-   steps taken when following both parent and child of a fork.  This
-   is used by a clone of the debugger, which will follow the child.
-
-   The original debugger has detached from this process, and the
-   clone has attached to it.
-
-   On some targets, this requires a bit of cleanup to make it work
-   correctly.  */
-
-#define target_post_follow_inferior_by_clone() \
-     (*current_target.to_post_follow_inferior_by_clone) ()
-
 /* On some targets, we can catch an inferior fork or vfork event when
    it occurs.  These functions insert/remove an already-created
    catchpoint for such events.  */
@@ -1200,8 +1167,6 @@ extern void find_default_require_detach 
 
 extern void find_default_create_inferior (char *, char *, char **);
 
-extern void find_default_clone_and_follow_inferior (int, int *);
-
 extern struct target_ops *find_run_target (void);
 
 extern struct target_ops *find_core_target (void);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]