]> git.pld-linux.org Git - packages/gdb.git/blame - gdb-6.8-attach-signalled-detach-stopped.patch
- typo
[packages/gdb.git] / gdb-6.8-attach-signalled-detach-stopped.patch
CommitLineData
a7de96f0
PS
1Index: gdb-7.4.50.20120703/gdb/linux-nat.c
2===================================================================
3--- gdb-7.4.50.20120703.orig/gdb/linux-nat.c 2012-07-03 17:46:55.000000000 +0200
4+++ gdb-7.4.50.20120703/gdb/linux-nat.c 2012-07-03 17:57:29.608734933 +0200
5@@ -180,6 +180,9 @@ blocked. */
6 static struct target_ops *linux_ops;
7 static struct target_ops linux_ops_saved;
8
9+/* PID of the inferior stopped by SIGSTOP before attaching (or zero). */
10+static pid_t pid_was_stopped;
11+
12 /* The method to call, if any, when a new thread is attached. */
13 static void (*linux_nat_new_thread) (struct lwp_info *);
14
15@@ -909,7 +912,14 @@ holding the child stopped. Try \"set de
16 parent_inf->waiting_for_vfork_done = 0;
17 }
18 else if (detach_fork)
19- target_detach (NULL, 0);
20+ {
21+ /* We should check PID_WAS_STOPPED and detach it stopped accordingly.
22+ In this point of code it cannot be 1 as we would not get FORK
23+ executed without CONTINUE first which resets PID_WAS_STOPPED.
24+ We would have to first TARGET_STOP and WAITPID it as with running
25+ inferior PTRACE_DETACH, SIGSTOP will ignore the signal. */
26+ target_detach (NULL, 0);
27+ }
28
29 /* Note that the detach above makes PARENT_INF dangling. */
30
31@@ -1377,6 +1387,7 @@ linux_nat_post_attach_wait (ptid_t ptid,
32 if (debug_linux_nat)
33 fprintf_unfiltered (gdb_stdlog,
34 "LNPAW: Attaching to a stopped process\n");
35+ pid_was_stopped = GET_PID (ptid);
36
37 /* The process is definitely stopped. It is in a job control
38 stop, unless the kernel predates the TASK_STOPPED /
39@@ -1805,6 +1816,9 @@ get_pending_status (struct lwp_info *lp,
40 gdb_signal_to_string (signo));
41 }
42
43+ if (*status == 0 && GET_PID (lp->ptid) == pid_was_stopped)
44+ *status = W_STOPCODE (SIGSTOP);
45+
46 return 0;
47 }
48
49@@ -1918,6 +1932,8 @@ linux_nat_detach (struct target_ops *ops
50 }
51 else
52 linux_ops->to_detach (ops, args, from_tty);
53+
54+ pid_was_stopped = 0;
55 }
56
57 /* Resume LP. */
58@@ -2104,6 +2120,14 @@ linux_nat_resume (struct target_ops *ops
59 linux_nat_resume_callback. */
60 lp->stopped = 0;
61
62+ /* At this point, we are going to resume the inferior and if we
63+ have attached to a stopped process, we no longer should leave
64+ it as stopped if the user detaches. PTID variable has PID set to LWP
65+ while we need to check the real PID here. */
66+
67+ if (!step && lp && pid_was_stopped == GET_PID (lp->ptid))
68+ pid_was_stopped = 0;
69+
70 if (resume_many)
71 iterate_over_lwps (ptid, linux_nat_resume_callback, NULL);
72
73@@ -4129,6 +4153,8 @@ linux_nat_mourn_inferior (struct target_
74 there are other viable forks to debug. Delete the exiting
75 one and context-switch to the first available. */
76 linux_fork_mourn_inferior ();
77+
78+ pid_was_stopped = 0;
79 }
80
81 /* Convert a native/host siginfo object, into/from the siginfo in the
82Index: gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/attach-stopped.exp
83===================================================================
84--- gdb-7.4.50.20120703.orig/gdb/testsuite/gdb.threads/attach-stopped.exp 2012-06-26 21:23:20.000000000 +0200
85+++ gdb-7.4.50.20120703/gdb/testsuite/gdb.threads/attach-stopped.exp 2012-07-03 17:56:43.797790120 +0200
86@@ -61,7 +61,65 @@ proc corefunc { threadtype } {
87 gdb_reinitialize_dir $srcdir/$subdir
88 gdb_load ${binfile}
89
90- # Verify that we can attach to the stopped process.
91+ # Verify that we can attach to the process by first giving its
92+ # executable name via the file command, and using attach with the
93+ # process ID.
94+
95+ set test "$threadtype: set file, before attach1 to stopped process"
96+ gdb_test_multiple "file $binfile" "$test" {
97+ -re "Load new symbol table from.*y or n. $" {
98+ gdb_test "y" "Reading symbols from $escapedbinfile\.\.\.*done." \
99+ "$test (re-read)"
100+ }
101+ -re "Reading symbols from $escapedbinfile\.\.\.*done.*$gdb_prompt $" {
102+ pass "$test"
103+ }
104+ }
105+
106+ set test "$threadtype: attach1 to stopped, after setting file"
107+ gdb_test_multiple "attach $testpid" "$test" {
108+ -re "Attaching to program.*`?$escapedbinfile'?, process $testpid.*$gdb_prompt $" {
109+ pass "$test"
110+ }
111+ }
112+
113+ # ".*sleep.*clone.*" would fail on s390x as bt stops at START_THREAD there.
114+ if {[string equal $threadtype threaded]} {
115+ gdb_test "thread apply all bt" ".*sleep.*start_thread.*" "$threadtype: attach1 to stopped bt"
116+ } else {
117+ gdb_test "bt" ".*sleep.*main.*" "$threadtype: attach1 to stopped bt"
118+ }
119+
120+ # Exit and detach the process.
121+
122+ gdb_exit
123+
124+ # Avoid some race:
125+ sleep 2
126+
127+ if [catch {open /proc/${testpid}/status r} fileid] {
128+ set line2 "NOTFOUND"
129+ } else {
130+ gets $fileid line1;
131+ gets $fileid line2;
132+ close $fileid;
133+ }
134+
135+ set test "$threadtype: attach1, exit leaves process stopped"
136+ if {[string match "*(stopped)*" $line2]} {
137+ pass $test
138+ } else {
139+ fail $test
140+ }
141+
142+ # At this point, the process should still be stopped
143+
144+ gdb_start
145+ gdb_reinitialize_dir $srcdir/$subdir
146+ gdb_load ${binfile}
147+
148+ # Verify that we can attach to the process just by giving the
149+ # process ID.
150
151 set test "$threadtype: attach2 to stopped, after setting file"
152 gdb_test_multiple "attach $testpid" "$test" {
This page took 0.08267 seconds and 4 git commands to generate.