]> git.ipfire.org Git - people/arne_f/ipfire-3.x.git/blob - gdb/patches/gdb-6.8-attach-signalled-detach-stopped.patch
wget: LDFLAGS were accidentially overwritten
[people/arne_f/ipfire-3.x.git] / gdb / patches / gdb-6.8-attach-signalled-detach-stopped.patch
1 Index: gdb-7.0.50.20100115/gdb/linux-nat.c
2 ===================================================================
3 --- gdb-7.0.50.20100115.orig/gdb/linux-nat.c 2010-01-15 11:53:34.000000000 +0100
4 +++ gdb-7.0.50.20100115/gdb/linux-nat.c 2010-01-15 12:13:53.000000000 +0100
5 @@ -208,6 +208,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) (ptid_t);
14
15 @@ -933,7 +936,14 @@ Attaching after process %d fork to child
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 @@ -1427,6 +1437,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 @@ -1757,6 +1768,9 @@ GPT: lwp %s had signal %s, but it is in
40 target_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 @@ -1866,6 +1880,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 @@ -2031,6 +2047,14 @@ linux_nat_resume (struct target_ops *ops
59 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, resume_callback, NULL);
72
73 @@ -3923,6 +3947,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
82 Index: gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attach-stopped.exp
83 ===================================================================
84 --- gdb-7.0.50.20100115.orig/gdb/testsuite/gdb.threads/attach-stopped.exp 2010-01-01 08:32:06.000000000 +0100
85 +++ gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attach-stopped.exp 2010-01-15 11:54:57.000000000 +0100
86 @@ -62,7 +62,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" {
153 Index: gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attachstop-mt.exp
154 ===================================================================
155 --- gdb-7.0.50.20100115.orig/gdb/testsuite/gdb.threads/attachstop-mt.exp 2010-01-01 08:32:06.000000000 +0100
156 +++ gdb-7.0.50.20100115/gdb/testsuite/gdb.threads/attachstop-mt.exp 2010-01-15 11:54:57.000000000 +0100
157 @@ -176,12 +176,23 @@ gdb_test "bt" ".*sleep.*(func|main).*" "
158 # Exit and detach the process.
159 gdb_exit
160
161 -# Stop the program
162 -remote_exec build "kill -s STOP ${testpid}"
163 -
164 # No race
165 sleep 2
166
167 +set fileid3 [open $status2 r];
168 +gets $fileid3 line1;
169 +gets $fileid3 line2;
170 +close $fileid3;
171 +
172 +set test "attach3, exit leaves process stopped"
173 +if {[string match "*(stopped)*" $line2]} {
174 + pass $test
175 +} else {
176 + fail $test
177 +}
178 +
179 +# At this point, the process should still be stopped
180 +
181 # Continue the test as we would hit another expected bug regarding
182 # Program received signal SIGSTOP, Stopped (signal).
183 # across NPTL threads.