- if (debug_fork)
- sleep (debug_fork);
-
- /* The child (i.e., the cloned debugger) must now attach to
- CHILD_PID. inferior_pid 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_pid,
- because that would allow it to run free. The original
- debugger wants to retain control of the process. So, we
- just reset inferior_pid 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]);
-}