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

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