|
|
7a6771 |
Index: gdb-7.11.50.20160716/gdb/infrun.c
|
|
|
7a6771 |
===================================================================
|
|
|
7a6771 |
--- gdb-7.11.50.20160716.orig/gdb/infrun.c 2016-07-16 14:37:09.317178150 +0200
|
|
|
7a6771 |
+++ gdb-7.11.50.20160716/gdb/infrun.c 2016-07-16 14:37:10.636188765 +0200
|
|
|
7a6771 |
@@ -620,6 +620,13 @@
|
|
|
7a6771 |
target_pid_to_str (process_ptid));
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+ /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
|
|
|
7a6771 |
+ In this point of code it cannot be 1 as we would not get FORK
|
|
|
7a6771 |
+ executed without CONTINUE first which resets PID_WAS_STOPPED.
|
|
|
7a6771 |
+ We would have to first TARGET_STOP and WAITPID it as with running
|
|
|
7a6771 |
+ inferior PTRACE_DETACH, SIGSTOP will ignore the signal. */
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
target_detach (NULL, 0);
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
Index: gdb-7.11.50.20160716/gdb/linux-nat.c
|
|
|
7a6771 |
===================================================================
|
|
|
7a6771 |
--- gdb-7.11.50.20160716.orig/gdb/linux-nat.c 2016-07-16 14:37:09.320178174 +0200
|
|
|
7a6771 |
+++ gdb-7.11.50.20160716/gdb/linux-nat.c 2016-07-16 14:38:09.574663094 +0200
|
|
|
7a6771 |
@@ -194,6 +194,11 @@
|
|
|
7a6771 |
static struct target_ops *linux_ops;
|
|
|
7a6771 |
static struct target_ops linux_ops_saved;
|
|
|
7a6771 |
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+/* PID of the inferior stopped by SIGSTOP before attaching (or zero). */
|
|
|
7a6771 |
+static pid_t pid_was_stopped;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
/* The method to call, if any, when a new thread is attached. */
|
|
|
7a6771 |
static void (*linux_nat_new_thread) (struct lwp_info *);
|
|
|
7a6771 |
|
|
|
7a6771 |
@@ -1047,6 +1052,9 @@
|
|
|
7a6771 |
if (debug_linux_nat)
|
|
|
7a6771 |
fprintf_unfiltered (gdb_stdlog,
|
|
|
7a6771 |
"LNPAW: Attaching to a stopped process\n");
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+ pid_was_stopped = ptid_get_pid (ptid);
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
|
|
|
7a6771 |
/* The process is definitely stopped. It is in a job control
|
|
|
7a6771 |
stop, unless the kernel predates the TASK_STOPPED /
|
|
|
7a6771 |
@@ -1404,6 +1412,25 @@
|
|
|
7a6771 |
return gdb_signal_to_host (signo);
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+ /* Workaround RHEL-5 kernel which has unreliable PTRACE_DETACH, SIGSTOP (that
|
|
|
7a6771 |
+ many TIDs are left unstopped). See RH Bug 496732. */
|
|
|
7a6771 |
+ if (ptid_get_pid (lp->ptid) == pid_was_stopped)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ int err;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ errno = 0;
|
|
|
7a6771 |
+ err = kill_lwp (ptid_get_lwp (lp->ptid), SIGSTOP);
|
|
|
7a6771 |
+ if (debug_linux_nat)
|
|
|
7a6771 |
+ {
|
|
|
7a6771 |
+ fprintf_unfiltered (gdb_stdlog,
|
|
|
7a6771 |
+ "SC: lwp kill %d %s\n",
|
|
|
7a6771 |
+ err,
|
|
|
7a6771 |
+ errno ? safe_strerror (errno) : "ERRNO-OK");
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
return 0;
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
@@ -1562,6 +1589,10 @@
|
|
|
7a6771 |
detach_one_lwp (main_lwp, &signo);
|
|
|
7a6771 |
|
|
|
7a6771 |
inf_ptrace_detach_success (ops);
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+ pid_was_stopped = 0;
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
}
|
|
|
7a6771 |
delete_lwp (main_lwp->ptid);
|
|
|
7a6771 |
}
|
|
|
7a6771 |
@@ -1823,6 +1854,16 @@
|
|
|
7a6771 |
return;
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+ /* At this point, we are going to resume the inferior and if we
|
|
|
7a6771 |
+ have attached to a stopped process, we no longer should leave
|
|
|
7a6771 |
+ it as stopped if the user detaches. PTID variable has PID set to LWP
|
|
|
7a6771 |
+ while we need to check the real PID here. */
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if (!step && lp && pid_was_stopped == ptid_get_pid (lp->ptid))
|
|
|
7a6771 |
+ pid_was_stopped = 0;
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
if (resume_many)
|
|
|
7a6771 |
iterate_over_lwps (ptid, linux_nat_resume_callback, lp);
|
|
|
7a6771 |
|
|
|
7a6771 |
@@ -3819,6 +3860,10 @@
|
|
|
7a6771 |
|
|
|
7a6771 |
/* Let the arch-specific native code know this process is gone. */
|
|
|
7a6771 |
linux_nat_forget_process (pid);
|
|
|
7a6771 |
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ pid_was_stopped = 0;
|
|
|
7a6771 |
+#endif
|
|
|
7a6771 |
}
|
|
|
7a6771 |
|
|
|
7a6771 |
/* Convert a native/host siginfo object, into/from the siginfo in the
|
|
|
7a6771 |
Index: gdb-7.11.50.20160716/gdb/testsuite/gdb.threads/attach-stopped.exp
|
|
|
7a6771 |
===================================================================
|
|
|
7a6771 |
--- gdb-7.11.50.20160716.orig/gdb/testsuite/gdb.threads/attach-stopped.exp 2016-07-16 14:37:09.321178182 +0200
|
|
|
7a6771 |
+++ gdb-7.11.50.20160716/gdb/testsuite/gdb.threads/attach-stopped.exp 2016-07-16 14:37:10.640188797 +0200
|
|
|
7a6771 |
@@ -56,7 +56,65 @@
|
|
|
7a6771 |
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
7a6771 |
gdb_load ${binfile}
|
|
|
7a6771 |
|
|
|
7a6771 |
- # Verify that we can attach to the stopped process.
|
|
|
7a6771 |
+ # Verify that we can attach to the process by first giving its
|
|
|
7a6771 |
+ # executable name via the file command, and using attach with the
|
|
|
7a6771 |
+ # process ID.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ set test "$threadtype: set file, before attach1 to stopped process"
|
|
|
7a6771 |
+ gdb_test_multiple "file $binfile" "$test" {
|
|
|
7a6771 |
+ -re "Load new symbol table from.*y or n. $" {
|
|
|
7a6771 |
+ gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
|
|
|
7a6771 |
+ "$test (re-read)"
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
|
|
7a6771 |
+ pass "$test"
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ set test "$threadtype: attach1 to stopped, after setting file"
|
|
|
7a6771 |
+ gdb_test_multiple "attach $testpid" "$test" {
|
|
|
7a6771 |
+ -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
|
|
|
7a6771 |
+ pass "$test"
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
|
|
|
7a6771 |
+ if {[string equal $threadtype threaded]} {
|
|
|
7a6771 |
+ gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
|
|
|
7a6771 |
+ } else {
|
|
|
7a6771 |
+ gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # Exit and detach the process.
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ gdb_exit
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # Avoid some race:
|
|
|
7a6771 |
+ sleep 2
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ if [catch {open /proc/${testpid}/status r} fileid] {
|
|
|
7a6771 |
+ set line2 "NOTFOUND"
|
|
|
7a6771 |
+ } else {
|
|
|
7a6771 |
+ gets $fileid line1;
|
|
|
7a6771 |
+ gets $fileid line2;
|
|
|
7a6771 |
+ close $fileid;
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ set test "$threadtype: attach1, exit leaves process stopped"
|
|
|
7a6771 |
+ if {[string match "*(stopped)*" $line2]} {
|
|
|
7a6771 |
+ pass $test
|
|
|
7a6771 |
+ } else {
|
|
|
7a6771 |
+ fail $test
|
|
|
7a6771 |
+ }
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # At this point, the process should still be stopped
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ gdb_start
|
|
|
7a6771 |
+ gdb_reinitialize_dir $srcdir/$subdir
|
|
|
7a6771 |
+ gdb_load ${binfile}
|
|
|
7a6771 |
+
|
|
|
7a6771 |
+ # Verify that we can attach to the process just by giving the
|
|
|
7a6771 |
+ # process ID.
|
|
|
7a6771 |
|
|
|
7a6771 |
set test "$threadtype: attach2 to stopped, after setting file"
|
|
|
7a6771 |
gdb_test_multiple "attach $testpid" "$test" {
|