joostv / rpms / gdb

Forked from rpms/gdb 4 years ago
Clone
3f52bbd
2008-01-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
3f52bbd
3f52bbd
	Support attaching to stopped processes/threads and/or with pending
3f52bbd
	signals.  This ChangeLog entry is OBSOLETE:
3f52bbd
	* linux-nat.c (STRINGIFY, STRINGIFY_ARG): New macros.
3f52bbd
	(kill_lwp): New declaration.
3f52bbd
	(linux_ptrace_post_attach, pid_is_stopped): New function.
3f52bbd
	(linux_child_follow_fork): New comment about WAS_STOPPED.
3f52bbd
	(lin_lwp_attach_lwp): Variable PID removed.  Part replaced by a call to
3f52bbd
	LINUX_PTRACE_POST_ATTACH.
3f52bbd
	(linux_nat_attach): Likewise.
3f52bbd
	(linux_nat_detach): Optionally stop the detached process.
3f52bbd
	(linux_nat_resume): Clear WAS_STOPPED if appropriate.
3f52bbd
	* NEWS: Document the new behaviour.
3f52bbd
3f52bbd
2007-06-30  Jan Kratochvil  <jan.kratochvil@redhat.com>
3f52bbd
3f52bbd
	* gdb.texinfo (Attach): Document the ATTACH and DETACH commands for
3f52bbd
	stopped processes.  Document the messages on the seen pending signals.
3f52bbd
25ff8a1
2008-02-24  Jan Kratochvil  <jan.kratochvil@redhat.com>
25ff8a1
25ff8a1
	Port to GDB-6.8pre.
25ff8a1
25ff8a1
Index: gdb-6.8cvs20080219/gdb/NEWS
25ff8a1
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/NEWS	2008-02-24 19:35:37.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/NEWS	2008-02-24 19:36:26.000000000 +0100
25ff8a1
@@ -412,6 +412,9 @@ Renesas M32C/M16C		m32c-elf
3f52bbd
 
3f52bbd
 Morpho Technologies ms1		ms1-elf
3f52bbd
 
3f52bbd
+* On GNU/Linux, stopped processes may get attached to now.  Signals being
3f52bbd
+delivered at the time of the attach command no longer get lost.
3f52bbd
+
3f52bbd
 * New commands
3f52bbd
 
3f52bbd
 init-if-undefined		Initialize a convenience variable, but
25ff8a1
Index: gdb-6.8cvs20080219/gdb/linux-nat.c
25ff8a1
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/linux-nat.c	2008-02-24 19:36:26.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/linux-nat.c	2008-02-24 19:45:01.000000000 +0100
25ff8a1
@@ -89,6 +89,15 @@
25ff8a1
 #define PTRACE_GETSIGINFO    0x4202
3f52bbd
 #endif
3f52bbd
 
3f52bbd
+#define STRINGIFY_ARG(x) #x
3f52bbd
+#define STRINGIFY(x) STRINGIFY_ARG (x)
3f52bbd
+
25ff8a1
+static int linux_ptrace_post_attach (ptid_t ptid, int *cloned_return);
3f52bbd
+static int kill_lwp (int lwpid, int signo);
3f52bbd
+
3f52bbd
+/* PID of the inferior stopped by SIGSTOP before attaching (or zero).  */
3f52bbd
+static pid_t pid_was_stopped;
3f52bbd
+
25ff8a1
 /* The single-threaded native GNU/Linux target_ops.  We save a pointer for
25ff8a1
    the use of the multi-threaded target.  */
25ff8a1
 static struct target_ops *linux_ops;
25ff8a1
@@ -539,6 +548,11 @@ linux_child_follow_fork (struct target_o
3f52bbd
 	}
3f52bbd
       else
3f52bbd
 	{
3f52bbd
+	  /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
3f52bbd
+	     In this point of code it cannot be 1 as we would not get FORK
3f52bbd
+	     executed without CONTINUE first which resets PID_WAS_STOPPED.
3f52bbd
+	     We would have to first TARGET_STOP and WAITPID it as with running
3f52bbd
+	     inferior PTRACE_DETACH, SIGSTOP will ignore the signal.  */
3f52bbd
 	  target_detach (NULL, 0);
3f52bbd
 	}
3f52bbd
 
25ff8a1
@@ -942,9 +956,8 @@ lin_lwp_attach_lwp (ptid_t ptid)
3f52bbd
      to happen.  */
3f52bbd
   if (GET_LWP (ptid) != GET_PID (ptid) && lp == NULL)
3f52bbd
     {
3f52bbd
-      pid_t pid;
3f52bbd
       int status;
25ff8a1
-      int cloned = 0;
25ff8a1
+      int cloned;
3f52bbd
 
3f52bbd
       if (ptrace (PTRACE_ATTACH, GET_LWP (ptid), 0, 0) < 0)
25ff8a1
 	{
25ff8a1
@@ -958,37 +971,20 @@ lin_lwp_attach_lwp (ptid_t ptid)
25ff8a1
 	  return -1;
25ff8a1
 	}
3f52bbd
 
3f52bbd
-      if (debug_linux_nat)
3f52bbd
-	fprintf_unfiltered (gdb_stdlog,
3f52bbd
-			    "LLAL: PTRACE_ATTACH %s, 0, 0 (OK)\n",
3f52bbd
-			    target_pid_to_str (ptid));
25ff8a1
-
25ff8a1
-      pid = my_waitpid (GET_LWP (ptid), &status, 0);
25ff8a1
-      if (pid == -1 && errno == ECHILD)
25ff8a1
-	{
25ff8a1
-	  /* Try again with __WCLONE to check cloned processes.  */
25ff8a1
-	  pid = my_waitpid (GET_LWP (ptid), &status, __WCLONE);
25ff8a1
-	  cloned = 1;
25ff8a1
+      status = linux_ptrace_post_attach (ptid, &cloned);
3f52bbd
+      if (status != 0)
3f52bbd
+        {
3f52bbd
+	  error (_("Thread %s exited: %s"), target_pid_to_str (ptid),
3f52bbd
+		 status_to_str (status));
25ff8a1
 	}
25ff8a1
 
25ff8a1
-      gdb_assert (pid == GET_LWP (ptid)
25ff8a1
-		  && WIFSTOPPED (status) && WSTOPSIG (status));
25ff8a1
-
25ff8a1
-      if (lp == NULL)
25ff8a1
-	lp = add_lwp (ptid);
25ff8a1
+      /* ADD_LWP with TID only already after the WAITPID.  */
25ff8a1
+      lp = add_lwp (ptid);
25ff8a1
       lp->cloned = cloned;
25ff8a1
 
25ff8a1
-      target_post_attach (pid);
3f52bbd
+      target_post_attach (GET_LWP (ptid));
25ff8a1
 
25ff8a1
       lp->stopped = 1;
25ff8a1
-
25ff8a1
-      if (debug_linux_nat)
25ff8a1
-	{
25ff8a1
-	  fprintf_unfiltered (gdb_stdlog,
25ff8a1
-			      "LLAL: waitpid %s received %s\n",
25ff8a1
-			      target_pid_to_str (ptid),
25ff8a1
-			      status_to_str (status));
25ff8a1
-	}
25ff8a1
     }
25ff8a1
   else
25ff8a1
     {
25ff8a1
@@ -998,44 +994,202 @@ lin_lwp_attach_lwp (ptid_t ptid)
25ff8a1
          threads.  Note that this won't have already been done since
25ff8a1
          the main thread will have, we assume, been stopped by an
25ff8a1
          attach from a different layer.  */
25ff8a1
-      if (lp == NULL)
25ff8a1
-	lp = add_lwp (ptid);
25ff8a1
       lp->stopped = 1;
25ff8a1
     }
25ff8a1
 
25ff8a1
   return 0;
25ff8a1
 }
25ff8a1
 
3f52bbd
+/* Detect `T (stopped)' in `/proc/PID/status'.
3f52bbd
+   Other states including `T (tracing stop)' are reported as false.  */
3f52bbd
+
3f52bbd
+static int
3f52bbd
+pid_is_stopped (pid_t pid)
3f52bbd
+{
3f52bbd
+  FILE *status_file;
25ff8a1
+  char buf[100];
3f52bbd
+  int retval = 0;
3f52bbd
+
3f52bbd
+  snprintf (buf, sizeof (buf), "/proc/%d/status", (int) pid);
3f52bbd
+  status_file = fopen (buf, "r");
3f52bbd
+  if (status_file != NULL)
3f52bbd
+    {
3f52bbd
+      int have_state = 0;
3f52bbd
+
3f52bbd
+      while (fgets (buf, sizeof (buf), status_file))
3f52bbd
+	{
3f52bbd
+	  if (strncmp (buf, "State:", 6) == 0)
3f52bbd
+	    {
3f52bbd
+	      have_state = 1;
3f52bbd
+	      break;
3f52bbd
+	    }
25ff8a1
+	}
3f52bbd
+      if (have_state && strstr (buf, "T (stopped)") != NULL)
3f52bbd
+	retval = 1;
3f52bbd
+      fclose (status_file);
3f52bbd
+    }
3f52bbd
+  return retval;
3f52bbd
+}
3f52bbd
+
3f52bbd
+/* Handle the processing after PTRACE_ATTACH, the first WAITPID -> SIGSTOP.
3f52bbd
+   Returns STATUS if the thread has exited, 0 otherwise.
3f52bbd
+   Sets PID_WAS_STOPPED if the process was originally stopped.
3f52bbd
+   Sets LP->CLONED if the given LWP is not the thread leader.
3f52bbd
+
3f52bbd
+   Scenario for a standard unstopped inferior:
3f52bbd
+    * `S (sleeping)' or `R (running)' or similiar states.
3f52bbd
+    * PTRACE_ATTACH is called.
3f52bbd
+    * `S (sleeping)' (or similiar) for some while.
3f52bbd
+    * `T (tracing stop)'.
3f52bbd
+    * WAITPID succeeds here returning SIGSTOP (signalled by PTRACE_ATTACH).
3f52bbd
+
3f52bbd
+   Scenario for a formerly stopped inferior:
3f52bbd
+    * `T (stopped)'.
3f52bbd
+    * PTRACE_ATTACH is called.
3f52bbd
+    * `T (stopped)' would stay indefinitely
3f52bbd
+      Note since this moment the `TracerPid' field gets filled
3f52bbd
+      (by PTRACE_ATTACH), it is no longer just the common `T (stopped)' state.
3f52bbd
+       * If no one did WAITPID since sending SIGSTOP our WAITPID would return
3f52bbd
+         SIGSTOP.  The state still would not turn to `T (tracing stop)'.
3f52bbd
+       * Usually its original parent (before PTRACE_ATTACH was applied) already
3f52bbd
+         did WAITPID.  The original parent already received our SIGSTOP
3f52bbd
+         sinalled by our PTRACE_ATTACH.
3f52bbd
+         In this case our own WAITPID would hang.  Therefore...
3f52bbd
+    * ... we do artificial: tkill (SIGCONT);
3f52bbd
+      `PTRACE_CONT, SIGSTOP' does not work in 100% cases as sometimes SIGSTOP
3f52bbd
+      gets remembered by kernel during the first PTRACE_CONT later and we get
3f52bbd
+      spurious SIGSTOP event.  Expecting the signal may get delivered to
3f52bbd
+      a different task of the thread group.
3f52bbd
+      `kill_lwp (SIGSTOP)' has no effect in this moment (it is already stopped).
3f52bbd
+    * WAITPID returns the artifical SIGCONT.
3f52bbd
+      (The possibly pending SIGSTOP gets vanished by specifically SIGCONT.)
3f52bbd
+    * State turns `T (tracing stop)'.
3f52bbd
+   In this moment everything is almost fine but we need a workaround as final
3f52bbd
+   `PTRACE_DETACH, SIGSTOP' would leave the process unstopped otherwise:
3f52bbd
+    * tkill (SIGSTOP);
3f52bbd
+    * `PTRACE_CONT, 0'
3f52bbd
+    * WAITPID returns the artifical SIGSTOP.
3f52bbd
+
3f52bbd
+   With the pending (unwaited for) SIGSTOP the artifical signal effects are:
3f52bbd
+   kill (SIGSTOP)
3f52bbd
+   PTRACE_ATTACH
3f52bbd
+    /-tkill (SIGCONT), WAITPID: SIGCONT, WAITPID: hang !
3f52bbd
+   //-tkill (SIGCONT), WAITPID: SIGCONT, PTRACE_CONT (SIG_0), WAITPID: wait (OK)
3f52bbd
+   \\-tkill (SIGALRM), WAITPID: SIGSTOP, WAITPID: hang !
3f52bbd
+    \-tkill (SIGALRM), WAITPID: SIGSTOP, PTRACE_CONT (SIG_0), WAITPID: SIGALRM !
3f52bbd
+   Therefore we signal artifical SIGCONT and stop waiting after its reception.
3f52bbd
+
3f52bbd
+   For the detection whether the process was formerly stopped we need to
3f52bbd
+   read `/proc/PID/status'.  `PTRACE_CONT, SIGSTOP' returns ESRCH
3f52bbd
+   for `S (sleeping)' and succeeds for `T (stopped)' but it unfortunately
3f52bbd
+   succeeds even for `T (tracing stop)'.  Depending on PTRACE_CONT, SIGSTOP
3f52bbd
+   success value for formerly stopped processes would mean a race condition
3f52bbd
+   as we would get false stopped processes detection if we get too slow.
3f52bbd
+
3f52bbd
+   `waitid (..., WSTOPPED)' hangs the same way as WAITPID.
3f52bbd
+
3f52bbd
+   Signals get queued for WAITPID.  PTRACE_ATTACH (or TKILL) enqueues SIGSTOP
3f52bbd
+   there but WAITPID may return an already pending signal.
3f52bbd
+   Redeliver it by PTRACE_CONT, SIGxxx as otherwise it would get lost.
3f52bbd
+   Similiar processing is being done in this file by WAIT_LWP.  */
3f52bbd
+
3f52bbd
+static int
25ff8a1
+linux_ptrace_post_attach (ptid_t ptid, int *cloned_return)
3f52bbd
+{
3f52bbd
+  unsigned long sig;
3f52bbd
+  int this_thread_was_stopped;
25ff8a1
+  int cloned = 0;
3f52bbd
+
3f52bbd
+  if (debug_linux_nat)
3f52bbd
+    fprintf_unfiltered (gdb_stdlog,
3f52bbd
+			"LLAL: PTRACE_ATTACH %s, 0, 0 (OK)\n",
3f52bbd
+			target_pid_to_str (ptid));
3f52bbd
+
3f52bbd
+  /* This code should not be run for the threads being attached after the first
3f52bbd
+     thread (process) as we would get later spurious SIGCONT otherwise.  */
3f52bbd
+
3f52bbd
+  this_thread_was_stopped = pid_is_stopped (GET_LWP (ptid));
3f52bbd
+  if (this_thread_was_stopped)
3f52bbd
+    {
3f52bbd
+      pid_was_stopped = GET_PID (ptid);
3f52bbd
+      if (kill_lwp (GET_LWP (ptid), SIGCONT) != 0)
3f52bbd
+	perror_with_name (("kill_lwp (SIGCONT)"));
3f52bbd
+    }
3f52bbd
+
3f52bbd
+  for (;;)
3f52bbd
+    {
3f52bbd
+      pid_t pid;
3f52bbd
+      int status;
25ff8a1
+
25ff8a1
+      pid = my_waitpid (GET_LWP (ptid), &status, 0);
25ff8a1
+      if (pid == -1 && errno == ECHILD)
25ff8a1
+	{
25ff8a1
+	  /* Try again with __WCLONE to check cloned processes.  */
25ff8a1
+	  pid = my_waitpid (GET_LWP (ptid), &status, __WCLONE);
25ff8a1
+	  cloned = 1;
25ff8a1
+	}
25ff8a1
+
3f52bbd
+      gdb_assert (pid == GET_LWP (ptid));
25ff8a1
+
25ff8a1
+      if (debug_linux_nat)
25ff8a1
+	{
25ff8a1
+	  fprintf_unfiltered (gdb_stdlog,
25ff8a1
+			      "LLAL: waitpid %s received %s\n",
25ff8a1
+			      target_pid_to_str (ptid),
25ff8a1
+			      status_to_str (status));
25ff8a1
+	}
25ff8a1
+
3f52bbd
+      /* Check if the thread has exited.  */
3f52bbd
+      if (WIFEXITED (status) || WIFSIGNALED (status))
25ff8a1
+	return status;
3f52bbd
+      gdb_assert (WIFSTOPPED (status));
3f52bbd
+      sig = WSTOPSIG (status);
3f52bbd
+      gdb_assert (sig != 0);
3f52bbd
+      if (sig == SIGSTOP)
25ff8a1
+	break;
3f52bbd
+
3f52bbd
+      /* As the second signal for stopped processes we send SIGSTOP.  */
3f52bbd
+      if (this_thread_was_stopped && sig == SIGCONT)
3f52bbd
+	sig = SIGSTOP;
3f52bbd
+
3f52bbd
+      printf_unfiltered (_("Redelivering pending %s.\n"),
3f52bbd
+		 target_signal_to_string (target_signal_from_host (sig)));
3f52bbd
+      if (sig == SIGSTOP)
3f52bbd
+	{
3f52bbd
+	  if (kill_lwp (GET_LWP (ptid), sig) != 0)
3f52bbd
+	    perror_with_name (("kill_lwp"));
3f52bbd
+	  /* We now must resume the inferior to get SIGSTOP delivered.  */
3f52bbd
+	  sig = 0;
3f52bbd
+	}
3f52bbd
+      if (ptrace (PTRACE_CONT, GET_LWP (ptid), NULL, (void *) sig) != 0)
3f52bbd
+	perror_with_name (("ptrace"));
3f52bbd
+    }
25ff8a1
+  *cloned_return = cloned;
25ff8a1
+  return 0;
25ff8a1
+}
25ff8a1
+
25ff8a1
 static void
3f52bbd
 linux_nat_attach (char *args, int from_tty)
3f52bbd
 {
3f52bbd
   struct lwp_info *lp;
3f52bbd
-  pid_t pid;
3f52bbd
   int status;
25ff8a1
-  int cloned = 0;
25ff8a1
+  int cloned;
3f52bbd
 
3f52bbd
   /* FIXME: We should probably accept a list of process id's, and
25ff8a1
      attach all of them.  */
25ff8a1
   linux_ops->to_attach (args, from_tty);
3f52bbd
 
3f52bbd
-  /* Make sure the initial process is stopped.  The user-level threads
3f52bbd
-     layer might want to poke around in the inferior, and that won't
3f52bbd
-     work if things haven't stabilized yet.  */
3f52bbd
-  pid = my_waitpid (GET_PID (inferior_ptid), &status, 0);
3f52bbd
-  if (pid == -1 && errno == ECHILD)
3f52bbd
-    {
3f52bbd
-      warning (_("%s is a cloned process"), target_pid_to_str (inferior_ptid));
3f52bbd
-
3f52bbd
-      /* Try again with __WCLONE to check cloned processes.  */
3f52bbd
-      pid = my_waitpid (GET_PID (inferior_ptid), &status, __WCLONE);
25ff8a1
-      cloned = 1;
3f52bbd
-    }
3f52bbd
-
3f52bbd
-  gdb_assert (pid == GET_PID (inferior_ptid)
3f52bbd
-	      && WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP);
25ff8a1
-
25ff8a1
   /* Add the initial process as the first LWP to the list.  */
25ff8a1
   inferior_ptid = BUILD_LWP (GET_PID (inferior_ptid), GET_PID (inferior_ptid));
25ff8a1
+
25ff8a1
+  status = linux_ptrace_post_attach (inferior_ptid, &cloned);
3f52bbd
+  if (status != 0)
3f52bbd
+    error (_("Program %s exited: %s\n"), target_pid_to_str (inferior_ptid),
3f52bbd
+	   status_to_str (status));
25ff8a1
+  if (cloned)
3f52bbd
+    warning (_("%s is a cloned process"), target_pid_to_str (inferior_ptid));
25ff8a1
+
25ff8a1
+  /* ADD_LWP with TID only already after the WAITPID.  */
25ff8a1
   lp = add_lwp (inferior_ptid);
25ff8a1
   lp->cloned = cloned;
3f52bbd
 
25ff8a1
@@ -1046,8 +1200,8 @@ linux_nat_attach (char *args, int from_t
3f52bbd
   lp->resumed = 1;
3f52bbd
   if (debug_linux_nat)
3f52bbd
     {
3f52bbd
-      fprintf_unfiltered (gdb_stdlog,
3f52bbd
-			  "LLA: waitpid %ld, faking SIGSTOP\n", (long) pid);
3f52bbd
+      fprintf_unfiltered (gdb_stdlog, "LLA: waitpid %d, faking SIGSTOP\n",
3f52bbd
+			  GET_PID (inferior_ptid));
3f52bbd
     }
3f52bbd
 }
3f52bbd
 
25ff8a1
@@ -1092,6 +1246,9 @@ detach_callback (struct lwp_info *lp, vo
3f52bbd
      overall process id just yet.  */
3f52bbd
   if (GET_LWP (lp->ptid) != GET_PID (lp->ptid))
3f52bbd
     {
3f52bbd
+      /* None of these threads should be stopped for PID_WAS_STOPPED.  Only the
3f52bbd
+         last thread (process) will be stopped by LINUX_NAT_DETACH.  */
3f52bbd
+
3f52bbd
       errno = 0;
3f52bbd
       if (ptrace (PTRACE_DETACH, GET_LWP (lp->ptid), 0,
3f52bbd
 		  WSTOPSIG (lp->status)) < 0)
25ff8a1
@@ -1120,6 +1277,9 @@ linux_nat_detach (char *args, int from_t
3f52bbd
 
3f52bbd
   trap_ptid = null_ptid;
3f52bbd
 
3f52bbd
+  if (pid_was_stopped == GET_PID (lwp_list->ptid))
3f52bbd
+    args = STRINGIFY (SIGSTOP);
3f52bbd
+
3f52bbd
   /* Destroy LWP info; it's no longer valid.  */
3f52bbd
   init_lwp_list ();
3f52bbd
 
25ff8a1
@@ -1255,6 +1415,14 @@ linux_nat_resume (ptid_t ptid, int step_
25ff8a1
      resume_callback.  */
25ff8a1
   lp->stopped = 0;
3f52bbd
 
3f52bbd
+  /* At this point, we are going to resume the inferior and if we
3f52bbd
+     have attached to a stopped process, we no longer should leave
3f52bbd
+     it as stopped if the user detaches.  PTID variable has PID set to LWP
3f52bbd
+     while we need to check the real PID here.  */
3f52bbd
+
3f52bbd
+  if (!step && lp && pid_was_stopped == GET_PID (lp->ptid))
3f52bbd
+    pid_was_stopped = 0;
3f52bbd
+
3f52bbd
   if (resume_all)
3f52bbd
     iterate_over_lwps (resume_callback, NULL);
3f52bbd
 
25ff8a1
Index: gdb-6.8cvs20080219/gdb/doc/gdb.texinfo
25ff8a1
===================================================================
25ff8a1
--- gdb-6.8cvs20080219.orig/gdb/doc/gdb.texinfo	2008-02-24 19:36:24.000000000 +0100
25ff8a1
+++ gdb-6.8cvs20080219/gdb/doc/gdb.texinfo	2008-02-24 19:36:26.000000000 +0100
25ff8a1
@@ -2176,16 +2176,29 @@ can step and continue; you can modify st
3f52bbd
 process continue running, you may use the @code{continue} command after
3f52bbd
 attaching @value{GDBN} to the process.
3f52bbd
 
3f52bbd
+For a process already being stopped before the @code{attach} command executed
3f52bbd
+you get the informational message below.  Other signals may be occasionally
3f52bbd
+shown if they were being delivered right the time the @code{attach} command
3f52bbd
+executed.  Such process is left still stopped after the @code{detach} command
3f52bbd
+as long as you have not used the @code{continue} command (or similiar one)
3f52bbd
+during your debugging session.
3f52bbd
+
3f52bbd
+@smallexample
3f52bbd
+Attaching to program: /bin/sleep, process 16289
3f52bbd
+Redelivering pending Stopped (signal).
3f52bbd
+@end smallexample
3f52bbd
+
3f52bbd
 @table @code
3f52bbd
 @kindex detach
3f52bbd
 @item detach
3f52bbd
 When you have finished debugging the attached process, you can use the
3f52bbd
-@code{detach} command to release it from @value{GDBN} control.  Detaching
3f52bbd
-the process continues its execution.  After the @code{detach} command,
3f52bbd
-that process and @value{GDBN} become completely independent once more, and you
3f52bbd
-are ready to @code{attach} another process or start one with @code{run}.
3f52bbd
-@code{detach} does not repeat if you press @key{RET} again after
3f52bbd
-executing the command.
3f52bbd
+@code{detach} command to release it from @value{GDBN} control.  Detaching the
3f52bbd
+process continues its execution unless it was already stopped before the
3f52bbd
+attachment and a @code{continue} type command has not been executed.  After the
3f52bbd
+@code{detach} command, that process and @value{GDBN} become completely
3f52bbd
+independent once more, and you are ready to @code{attach} another process or
3f52bbd
+start one with @code{run}.  @code{detach} does not repeat if you press
3f52bbd
+@key{RET} again after executing the command.
3f52bbd
 @end table
3f52bbd
 
25ff8a1
 If you exit @value{GDBN} while you have an attached process, you detach