2017-12-10 22:00:49 +00:00
|
|
|
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
|
2017-12-04 19:24:00 +00:00
|
|
|
From: Fedora GDB patches <invalid@email.com>
|
|
|
|
Date: Fri, 27 Oct 2017 21:07:50 +0200
|
|
|
|
Subject: gdb-6.8-attach-signalled-detach-stopped.patch
|
|
|
|
|
|
|
|
FileName: gdb-6.8-attach-signalled-detach-stopped.patch
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
;; [RHEL5,RHEL6] Fix attaching to stopped processes.
|
|
|
|
;; [RHEL5] Workaround kernel for detaching SIGSTOPped processes (BZ 809382).
|
|
|
|
;;=fedora
|
|
|
|
|
|
|
|
diff --git a/gdb/infrun.c b/gdb/infrun.c
|
2018-01-31 22:47:02 +00:00
|
|
|
index b468d02fd6..16561dd119 100644
|
2017-12-08 04:31:26 +00:00
|
|
|
--- a/gdb/infrun.c
|
|
|
|
+++ b/gdb/infrun.c
|
|
|
|
@@ -606,6 +606,13 @@ holding the child stopped. Try \"set detach-on-fork\" or \
|
2016-01-09 14:11:44 +00:00
|
|
|
target_pid_to_str (process_ptid));
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
|
+ /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
|
|
|
|
+ In this point of code it cannot be 1 as we would not get FORK
|
|
|
|
+ executed without CONTINUE first which resets PID_WAS_STOPPED.
|
|
|
|
+ We would have to first TARGET_STOP and WAITPID it as with running
|
|
|
|
+ inferior PTRACE_DETACH, SIGSTOP will ignore the signal. */
|
|
|
|
+#endif
|
|
|
|
target_detach (NULL, 0);
|
|
|
|
}
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
|
2018-01-10 19:21:10 +00:00
|
|
|
index 1570a2bcb6..a101fbbe33 100644
|
2017-12-08 04:31:26 +00:00
|
|
|
--- a/gdb/linux-nat.c
|
|
|
|
+++ b/gdb/linux-nat.c
|
|
|
|
@@ -194,6 +194,11 @@ enum tribool have_ptrace_getregset = TRIBOOL_UNKNOWN;
|
2012-04-04 14:35:40 +00:00
|
|
|
static struct target_ops *linux_ops;
|
|
|
|
static struct target_ops linux_ops_saved;
|
|
|
|
|
2016-01-09 14:11:44 +00:00
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
2012-04-04 14:35:40 +00:00
|
|
|
+/* PID of the inferior stopped by SIGSTOP before attaching (or zero). */
|
|
|
|
+static pid_t pid_was_stopped;
|
|
|
|
+
|
2016-01-09 14:11:44 +00:00
|
|
|
+#endif
|
2012-04-04 14:35:40 +00:00
|
|
|
/* The method to call, if any, when a new thread is attached. */
|
|
|
|
static void (*linux_nat_new_thread) (struct lwp_info *);
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -1065,6 +1070,9 @@ linux_nat_post_attach_wait (ptid_t ptid, int *signalled)
|
2012-04-04 14:35:40 +00:00
|
|
|
if (debug_linux_nat)
|
|
|
|
fprintf_unfiltered (gdb_stdlog,
|
|
|
|
"LNPAW: Attaching to a stopped process\n");
|
2016-01-09 14:11:44 +00:00
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
2014-02-09 18:23:04 +00:00
|
|
|
+ pid_was_stopped = ptid_get_pid (ptid);
|
2016-01-09 14:11:44 +00:00
|
|
|
+#endif
|
2012-04-04 14:35:40 +00:00
|
|
|
|
|
|
|
/* The process is definitely stopped. It is in a job control
|
|
|
|
stop, unless the kernel predates the TASK_STOPPED /
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -1420,6 +1428,25 @@ get_detach_signal (struct lwp_info *lp)
|
2016-07-17 14:35:49 +00:00
|
|
|
return gdb_signal_to_host (signo);
|
2012-04-04 14:35:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-09 14:11:44 +00:00
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
2016-01-09 14:02:21 +00:00
|
|
|
+ /* Workaround RHEL-5 kernel which has unreliable PTRACE_DETACH, SIGSTOP (that
|
|
|
|
+ many TIDs are left unstopped). See RH Bug 496732. */
|
|
|
|
+ if (ptid_get_pid (lp->ptid) == pid_was_stopped)
|
|
|
|
+ {
|
|
|
|
+ int err;
|
|
|
|
+
|
|
|
|
+ errno = 0;
|
|
|
|
+ err = kill_lwp (ptid_get_lwp (lp->ptid), SIGSTOP);
|
|
|
|
+ if (debug_linux_nat)
|
|
|
|
+ {
|
|
|
|
+ fprintf_unfiltered (gdb_stdlog,
|
|
|
|
+ "SC: lwp kill %d %s\n",
|
|
|
|
+ err,
|
|
|
|
+ errno ? safe_strerror (errno) : "ERRNO-OK");
|
|
|
|
+ }
|
|
|
|
+ }
|
2012-04-04 14:35:40 +00:00
|
|
|
+
|
2016-01-09 14:11:44 +00:00
|
|
|
+#endif
|
2012-04-04 14:35:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -1578,6 +1605,10 @@ linux_nat_detach (struct target_ops *ops, const char *args, int from_tty)
|
2016-07-17 14:35:49 +00:00
|
|
|
detach_one_lwp (main_lwp, &signo);
|
|
|
|
|
|
|
|
inf_ptrace_detach_success (ops);
|
2012-04-04 14:35:40 +00:00
|
|
|
+
|
2016-07-17 14:35:49 +00:00
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
|
|
|
+ pid_was_stopped = 0;
|
2016-01-09 14:11:44 +00:00
|
|
|
+#endif
|
2016-07-17 14:35:49 +00:00
|
|
|
}
|
2012-04-04 14:35:40 +00:00
|
|
|
}
|
2017-04-21 12:47:41 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -1838,6 +1869,16 @@ linux_nat_resume (struct target_ops *ops,
|
2014-06-19 20:14:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-04-04 14:35:40 +00:00
|
|
|
|
2016-01-09 14:11:44 +00:00
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
2012-04-04 14:35:40 +00:00
|
|
|
+ /* At this point, we are going to resume the inferior and if we
|
|
|
|
+ have attached to a stopped process, we no longer should leave
|
|
|
|
+ it as stopped if the user detaches. PTID variable has PID set to LWP
|
|
|
|
+ while we need to check the real PID here. */
|
|
|
|
+
|
2014-02-09 18:23:04 +00:00
|
|
|
+ if (!step && lp && pid_was_stopped == ptid_get_pid (lp->ptid))
|
2012-04-04 14:35:40 +00:00
|
|
|
+ pid_was_stopped = 0;
|
|
|
|
+
|
2016-01-09 14:11:44 +00:00
|
|
|
+#endif
|
2012-04-04 14:35:40 +00:00
|
|
|
if (resume_many)
|
2014-06-19 20:14:32 +00:00
|
|
|
iterate_over_lwps (ptid, linux_nat_resume_callback, lp);
|
2012-04-04 14:35:40 +00:00
|
|
|
|
2017-12-08 04:31:26 +00:00
|
|
|
@@ -3830,6 +3871,10 @@ linux_nat_mourn_inferior (struct target_ops *ops)
|
2013-02-18 17:14:00 +00:00
|
|
|
|
|
|
|
/* Let the arch-specific native code know this process is gone. */
|
|
|
|
linux_nat_forget_process (pid);
|
2016-01-09 14:11:44 +00:00
|
|
|
+#ifdef NEED_DETACH_SIGSTOP
|
2012-04-04 14:35:40 +00:00
|
|
|
+
|
|
|
|
+ pid_was_stopped = 0;
|
2016-01-09 14:11:44 +00:00
|
|
|
+#endif
|
2012-04-04 14:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert a native/host siginfo object, into/from the siginfo in the
|
2017-12-08 04:31:26 +00:00
|
|
|
diff --git a/gdb/testsuite/gdb.threads/attach-stopped.exp b/gdb/testsuite/gdb.threads/attach-stopped.exp
|
2018-01-10 19:21:10 +00:00
|
|
|
index 6c8c8bf10e..c953a9c60d 100644
|
2017-12-08 04:31:26 +00:00
|
|
|
--- a/gdb/testsuite/gdb.threads/attach-stopped.exp
|
|
|
|
+++ b/gdb/testsuite/gdb.threads/attach-stopped.exp
|
|
|
|
@@ -56,7 +56,65 @@ proc corefunc { threadtype } {
|
2012-04-04 14:35:40 +00:00
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load ${binfile}
|
|
|
|
|
|
|
|
- # Verify that we can attach to the stopped process.
|
|
|
|
+ # Verify that we can attach to the process by first giving its
|
|
|
|
+ # executable name via the file command, and using attach with the
|
|
|
|
+ # process ID.
|
|
|
|
+
|
|
|
|
+ set test "$threadtype: set file, before attach1 to stopped process"
|
|
|
|
+ gdb_test_multiple "file $binfile" "$test" {
|
|
|
|
+ -re "Load new symbol table from.*y or n. $" {
|
|
|
|
+ gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
|
|
|
|
+ "$test (re-read)"
|
|
|
|
+ }
|
|
|
|
+ -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
|
|
|
|
+ pass "$test"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ set test "$threadtype: attach1 to stopped, after setting file"
|
|
|
|
+ gdb_test_multiple "attach $testpid" "$test" {
|
|
|
|
+ -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
|
|
|
|
+ pass "$test"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
|
|
|
|
+ if {[string equal $threadtype threaded]} {
|
|
|
|
+ gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
|
|
|
|
+ } else {
|
|
|
|
+ gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # Exit and detach the process.
|
|
|
|
+
|
|
|
|
+ gdb_exit
|
|
|
|
+
|
|
|
|
+ # Avoid some race:
|
|
|
|
+ sleep 2
|
|
|
|
+
|
|
|
|
+ if [catch {open /proc/${testpid}/status r} fileid] {
|
|
|
|
+ set line2 "NOTFOUND"
|
|
|
|
+ } else {
|
|
|
|
+ gets $fileid line1;
|
|
|
|
+ gets $fileid line2;
|
|
|
|
+ close $fileid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ set test "$threadtype: attach1, exit leaves process stopped"
|
|
|
|
+ if {[string match "*(stopped)*" $line2]} {
|
|
|
|
+ pass $test
|
|
|
|
+ } else {
|
|
|
|
+ fail $test
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ # At this point, the process should still be stopped
|
|
|
|
+
|
|
|
|
+ gdb_start
|
|
|
|
+ gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
+ gdb_load ${binfile}
|
|
|
|
+
|
|
|
|
+ # Verify that we can attach to the process just by giving the
|
|
|
|
+ # process ID.
|
|
|
|
|
|
|
|
set test "$threadtype: attach2 to stopped, after setting file"
|
|
|
|
gdb_test_multiple "attach $testpid" "$test" {
|