Blame SOURCES/gdb-6.8-attach-signalled-detach-stopped.patch

01917d
Index: gdb-7.5.50.20130215/gdb/linux-nat.c
01917d
===================================================================
01917d
--- gdb-7.5.50.20130215.orig/gdb/linux-nat.c	2013-02-15 22:38:05.000000000 +0100
01917d
+++ gdb-7.5.50.20130215/gdb/linux-nat.c	2013-02-15 22:44:59.638985719 +0100
01917d
@@ -181,6 +181,9 @@ blocked.  */
01917d
 static struct target_ops *linux_ops;
01917d
 static struct target_ops linux_ops_saved;
01917d
 
01917d
+/* PID of the inferior stopped by SIGSTOP before attaching (or zero).  */
01917d
+static pid_t pid_was_stopped;
01917d
+
01917d
 /* The method to call, if any, when a new thread is attached.  */
01917d
 static void (*linux_nat_new_thread) (struct lwp_info *);
01917d
 
01917d
@@ -914,7 +917,14 @@ holding the child stopped.  Try \"set de
01917d
 	  parent_inf->waiting_for_vfork_done = 0;
01917d
 	}
01917d
       else if (detach_fork)
01917d
-	target_detach (NULL, 0);
01917d
+	{
01917d
+	  /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
01917d
+	     In this point of code it cannot be 1 as we would not get FORK
01917d
+	     executed without CONTINUE first which resets PID_WAS_STOPPED.
01917d
+	     We would have to first TARGET_STOP and WAITPID it as with running
01917d
+	     inferior PTRACE_DETACH, SIGSTOP will ignore the signal.  */
01917d
+	  target_detach (NULL, 0);
01917d
+	}
01917d
 
01917d
       /* Note that the detach above makes PARENT_INF dangling.  */
01917d
 
01917d
@@ -1362,6 +1372,7 @@ linux_nat_post_attach_wait (ptid_t ptid,
01917d
       if (debug_linux_nat)
01917d
 	fprintf_unfiltered (gdb_stdlog,
01917d
 			    "LNPAW: Attaching to a stopped process\n");
01917d
+      pid_was_stopped = GET_PID (ptid);
01917d
 
01917d
       /* The process is definitely stopped.  It is in a job control
01917d
 	 stop, unless the kernel predates the TASK_STOPPED /
01917d
@@ -1790,6 +1801,9 @@ get_pending_status (struct lwp_info *lp,
01917d
 			    gdb_signal_to_string (signo));
01917d
     }
01917d
 
01917d
+  if (*status == 0 && GET_PID (lp->ptid) == pid_was_stopped)
01917d
+    *status = W_STOPCODE (SIGSTOP);
01917d
+
01917d
   return 0;
01917d
 }
01917d
 
01917d
@@ -1900,6 +1914,8 @@ linux_nat_detach (struct target_ops *ops
01917d
     }
01917d
   else
01917d
     linux_ops->to_detach (ops, args, from_tty);
01917d
+
01917d
+  pid_was_stopped = 0;
01917d
 }
01917d
 
01917d
 /* Resume LP.  */
01917d
@@ -2086,6 +2102,14 @@ linux_nat_resume (struct target_ops *ops
01917d
      linux_nat_resume_callback.  */
01917d
   lp->stopped = 0;
01917d
 
01917d
+  /* At this point, we are going to resume the inferior and if we
01917d
+     have attached to a stopped process, we no longer should leave
01917d
+     it as stopped if the user detaches.  PTID variable has PID set to LWP
01917d
+     while we need to check the real PID here.  */
01917d
+
01917d
+  if (!step && lp && pid_was_stopped == GET_PID (lp->ptid))
01917d
+    pid_was_stopped = 0;
01917d
+
01917d
   if (resume_many)
01917d
     iterate_over_lwps (ptid, linux_nat_resume_callback, NULL);
01917d
 
01917d
@@ -4137,6 +4161,8 @@ linux_nat_mourn_inferior (struct target_
01917d
 
01917d
   /* Let the arch-specific native code know this process is gone.  */
01917d
   linux_nat_forget_process (pid);
01917d
+
01917d
+  pid_was_stopped = 0;
01917d
 }
01917d
 
01917d
 /* Convert a native/host siginfo object, into/from the siginfo in the
01917d
Index: gdb-7.5.50.20130215/gdb/testsuite/gdb.threads/attach-stopped.exp
01917d
===================================================================
01917d
--- gdb-7.5.50.20130215.orig/gdb/testsuite/gdb.threads/attach-stopped.exp	2013-01-01 07:41:27.000000000 +0100
01917d
+++ gdb-7.5.50.20130215/gdb/testsuite/gdb.threads/attach-stopped.exp	2013-02-15 22:44:23.262930312 +0100
01917d
@@ -61,7 +61,65 @@ proc corefunc { threadtype } {
01917d
     gdb_reinitialize_dir $srcdir/$subdir
01917d
     gdb_load ${binfile}
01917d
 
01917d
-    # Verify that we can attach to the stopped process.
01917d
+    # Verify that we can attach to the process by first giving its
01917d
+    # executable name via the file command, and using attach with the
01917d
+    # process ID.
01917d
+
01917d
+    set test "$threadtype: set file, before attach1 to stopped process"
01917d
+    gdb_test_multiple "file $binfile" "$test" {
01917d
+       -re "Load new symbol table from.*y or n. $" {
01917d
+	    gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
01917d
+		    "$test (re-read)"
01917d
+	}
01917d
+	-re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
01917d
+	    pass "$test"
01917d
+	}
01917d
+    }
01917d
+
01917d
+    set test "$threadtype: attach1 to stopped, after setting file"
01917d
+    gdb_test_multiple "attach $testpid" "$test" {
01917d
+	-re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
01917d
+	    pass "$test"
01917d
+	}
01917d
+    }
01917d
+
01917d
+    # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
01917d
+    if {[string equal $threadtype threaded]} {
01917d
+	gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
01917d
+    } else {
01917d
+	gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
01917d
+    }
01917d
+
01917d
+    # Exit and detach the process.
01917d
+       
01917d
+    gdb_exit
01917d
+
01917d
+    # Avoid some race:
01917d
+    sleep 2
01917d
+
01917d
+    if [catch {open /proc/${testpid}/status r} fileid] {
01917d
+	set line2 "NOTFOUND"
01917d
+    } else {
01917d
+	gets $fileid line1;
01917d
+	gets $fileid line2;
01917d
+	close $fileid;
01917d
+    }
01917d
+
01917d
+    set test "$threadtype: attach1, exit leaves process stopped"
01917d
+    if {[string match "*(stopped)*" $line2]} {
01917d
+      pass $test
01917d
+    } else {
01917d
+      fail $test
01917d
+    }
01917d
+
01917d
+    # At this point, the process should still be stopped
01917d
+
01917d
+    gdb_start
01917d
+    gdb_reinitialize_dir $srcdir/$subdir
01917d
+    gdb_load ${binfile}
01917d
+
01917d
+    # Verify that we can attach to the process just by giving the
01917d
+    # process ID.
01917d
        
01917d
     set test "$threadtype: attach2 to stopped, after setting file"
01917d
     gdb_test_multiple "attach $testpid" "$test" {