+ child_ops.to_attach (args, from_tty);
+
+ /* Add the initial process as the first LWP to the list. */
+ lp = add_lwp (BUILD_LWP (inferior_ptid, inferior_ptid));
+
+ /* Make sure the initial process is stopped. The user-level threads
+ layer might want to poke around in the inferior, and that won't
+ work if things haven't stabilized yet. */
+ lp->signalled = 1;
+ stop_wait_callback (lp, NULL);
+ gdb_assert (lp->status == 0);
+
+ /* Fake the SIGSTOP that core GDB expects. */
+ lp->status = W_STOPCODE (SIGSTOP);
+}
+
+static int
+detach_callback (struct lwp_info *lp, void *data)
+{
+ gdb_assert (lp->status == 0 || WIFSTOPPED (lp->status));
+
+ if (debug_lin_lwp && lp->status)
+ fprintf_unfiltered (gdb_stdlog, "Pending %s for LWP %d on detach.\n",
+ strsignal (WSTOPSIG (lp->status)), GET_LWP (lp->ptid));
+
+ while (lp->signalled && lp->stopped)
+ {
+ if (ptrace (PTRACE_CONT, GET_LWP (lp->ptid), 0,
+ WSTOPSIG (lp->status)) < 0)
+ error ("Can't continue %s: %s", target_pid_to_str (lp->ptid),
+ strerror (errno));
+
+ lp->stopped = 0;
+ lp->status = 0;
+ stop_wait_callback (lp, NULL);
+
+ gdb_assert (lp->status == 0 || WIFSTOPPED (lp->status));
+ }
+
+ if (is_cloned (lp->ptid))
+ {
+ if (ptrace (PTRACE_DETACH, GET_LWP (lp->ptid), 0,
+ WSTOPSIG (lp->status)) < 0)
+ error ("Can't detach %s: %s", target_pid_to_str (lp->ptid),
+ strerror (errno));
+
+ delete_lwp (lp->ptid);
+ }
+
+ return 0;