]>
Commit | Line | Data |
---|---|---|
0b302171 | 1 | # Copyright 1997, 1999, 2007-2012 Free Software Foundation, Inc. |
74cf1395 JM |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
74cf1395 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
74cf1395 JM |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
74cf1395 | 13 | # You should have received a copy of the GNU General Public License |
e85a822c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
74cf1395 | 15 | |
e85a822c | 16 | if { [is_remote target] || ![isnative] } then { |
5a2468f5 JM |
17 | continue |
18 | } | |
19 | ||
74cf1395 | 20 | |
e85a822c | 21 | global srcfile |
74cf1395 JM |
22 | set testfile "foll-fork" |
23 | set srcfile ${testfile}.c | |
24 | set binfile ${objdir}/${subdir}/${testfile} | |
25 | ||
26 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
27 | untested foll-fork.exp |
28 | return -1 | |
74cf1395 JM |
29 | } |
30 | ||
31 | ||
32 | ||
33 | # Until "set follow-fork-mode" and "catch fork" are implemented on | |
34 | # other targets... | |
35 | # | |
e85a822c | 36 | if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then { |
74cf1395 JM |
37 | continue |
38 | } | |
39 | ||
e85a822c DJ |
40 | proc check_fork_catchpoints {} { |
41 | global gdb_prompt | |
42 | ||
43 | # Verify that the system supports "catch fork". | |
44 | gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint" | |
45 | set has_fork_catchpoints 0 | |
46 | gdb_test_multiple "continue" "continue to first fork catchpoint" { | |
77b06cd7 | 47 | -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" { |
e85a822c DJ |
48 | unsupported "continue to first fork catchpoint" |
49 | } | |
50 | -re ".*Catchpoint.*$gdb_prompt $" { | |
51 | set has_fork_catchpoints 1 | |
52 | pass "continue to first fork catchpoint" | |
53 | } | |
54 | } | |
55 | ||
56 | if {$has_fork_catchpoints == 0} { | |
57 | unsupported "fork catchpoints" | |
58 | return -code return | |
59 | } | |
60 | } | |
61 | ||
74cf1395 | 62 | proc default_fork_parent_follow {} { |
a76e022a MS |
63 | global gdb_prompt |
64 | ||
65 | gdb_test "show follow-fork" \ | |
66 | "Debugger response to a program call of fork or vfork is \"parent\".*" \ | |
67 | "default show parent follow, no catchpoints" | |
68 | ||
69 | gdb_test "next 2" \ | |
70 | "Detaching after fork from.*" \ | |
71 | "default parent follow, no catchpoints" | |
72 | ||
73 | # The child has been detached; allow time for any output it might | |
74 | # generate to arrive, so that output doesn't get confused with | |
75 | # any expected debugger output from a subsequent testpoint. | |
76 | # | |
77 | exec sleep 1 | |
74cf1395 JM |
78 | } |
79 | ||
80 | proc explicit_fork_parent_follow {} { | |
a76e022a MS |
81 | global gdb_prompt |
82 | ||
83 | gdb_test_no_output "set follow-fork parent" | |
84 | ||
85 | gdb_test "show follow-fork" \ | |
86 | "Debugger response to a program call of fork or vfork is \"parent\"." \ | |
87 | "explicit show parent follow, no catchpoints" | |
88 | ||
89 | gdb_test "next 2" "Detaching after fork from.*" \ | |
90 | "explicit parent follow, no catchpoints" | |
91 | ||
92 | # The child has been detached; allow time for any output it might | |
93 | # generate to arrive, so that output doesn't get confused with | |
94 | # any expected debugger output from a subsequent testpoint. | |
95 | # | |
96 | exec sleep 1 | |
74cf1395 JM |
97 | } |
98 | ||
99 | proc explicit_fork_child_follow {} { | |
a76e022a MS |
100 | global gdb_prompt |
101 | ||
102 | gdb_test_no_output "set follow-fork child" | |
103 | ||
104 | gdb_test "show follow-fork" \ | |
105 | "Debugger response to a program call of fork or vfork is \"child\"." \ | |
106 | "explicit show child follow, no catchpoints" | |
107 | ||
108 | gdb_test "next 2" "Attaching after.* fork to.*" \ | |
109 | "explicit child follow, no catchpoints" | |
110 | ||
111 | # The child has been detached; allow time for any output it might | |
112 | # generate to arrive, so that output doesn't get confused with | |
113 | # any gdb_expected debugger output from a subsequent testpoint. | |
114 | # | |
115 | exec sleep 1 | |
74cf1395 JM |
116 | } |
117 | ||
118 | proc catch_fork_child_follow {} { | |
a76e022a MS |
119 | global gdb_prompt |
120 | global srcfile | |
121 | ||
122 | set bp_after_fork [gdb_get_line_number "set breakpoint here"] | |
123 | ||
2c04da0d | 124 | gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" \ |
a76e022a MS |
125 | "explicit child follow, set catch fork" |
126 | ||
127 | # Verify that the catchpoint is mentioned in an "info breakpoints", | |
128 | # and further that the catchpoint mentions no process id. | |
129 | # | |
130 | set test_name "info shows catchpoint without pid" | |
131 | gdb_test_multiple "info breakpoints" "$test_name" { | |
132 | -re ".*catchpoint.*keep y.*fork\[\r\n\]+$gdb_prompt $" { | |
133 | pass "$test_name" | |
134 | } | |
135 | } | |
136 | ||
137 | gdb_test "continue" \ | |
2c04da0d | 138 | "Catchpoint \[0-9\]* \\(forked process \[0-9\]*\\),.*" \ |
a76e022a MS |
139 | "explicit child follow, catch fork" |
140 | ||
141 | # Verify that the catchpoint is mentioned in an "info breakpoints", | |
142 | # and further that the catchpoint managed to capture a process id. | |
143 | # | |
144 | set test_name "info shows catchpoint without pid" | |
145 | gdb_test_multiple "info breakpoints" "$test_name" { | |
146 | -re ".*catchpoint.*keep y.*fork, process.*$gdb_prompt $" { | |
147 | pass "$test_name" | |
148 | } | |
149 | } | |
150 | ||
151 | gdb_test_no_output "set follow-fork child" | |
152 | ||
153 | gdb_test "tbreak ${srcfile}:$bp_after_fork" \ | |
154 | "Temporary breakpoint.*, line $bp_after_fork.*" \ | |
155 | "set follow-fork child, tbreak" | |
156 | ||
157 | gdb_test "continue" \ | |
158 | "Attaching after.* fork to.* at .*$bp_after_fork.*" \ | |
159 | "set follow-fork child, hit tbreak" | |
160 | ||
161 | # The parent has been detached; allow time for any output it might | |
162 | # generate to arrive, so that output doesn't get confused with | |
163 | # any expected debugger output from a subsequent testpoint. | |
164 | # | |
165 | exec sleep 1 | |
166 | ||
167 | gdb_test "delete breakpoints" \ | |
168 | "" \ | |
169 | "set follow-fork child, cleanup" \ | |
e9101ff5 | 170 | "Delete all breakpoints. \\(y or n\\) $" \ |
a76e022a | 171 | "y" |
74cf1395 JM |
172 | } |
173 | ||
b242c3c2 | 174 | proc catch_fork_unpatch_child {} { |
a76e022a MS |
175 | global gdb_prompt |
176 | global srcfile | |
177 | ||
178 | set bp_exit [gdb_get_line_number "at exit"] | |
179 | ||
180 | gdb_test "break callee" "file .*$srcfile, line .*" \ | |
181 | "unpatch child, break at callee" | |
182 | gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" \ | |
183 | "unpatch child, set catch fork" | |
184 | ||
185 | gdb_test "continue" \ | |
2c04da0d | 186 | "Catchpoint \[0-9\]* \\(forked process \[0-9\]*\\),.*" \ |
a76e022a MS |
187 | "unpatch child, catch fork" |
188 | ||
189 | # Delete all breakpoints and catchpoints. | |
190 | delete_breakpoints | |
191 | ||
192 | # Force $srcfile as the current GDB source can be in glibc sourcetree. | |
193 | gdb_test "break $srcfile:$bp_exit" \ | |
194 | "Breakpoint .*file .*$srcfile, line .*" \ | |
195 | "unpatch child, breakpoint at exit call" | |
196 | ||
27d3a1a2 MS |
197 | gdb_test_no_output "set follow-fork child" \ |
198 | "unpatch child, set follow-fork child" | |
a76e022a MS |
199 | |
200 | set test "unpatch child, unpatched parent breakpoints from child" | |
201 | gdb_test_multiple "continue" $test { | |
202 | -re "at exit.*$gdb_prompt $" { | |
203 | pass "$test" | |
204 | } | |
205 | -re "SIGTRAP.*$gdb_prompt $" { | |
206 | fail "$test" | |
207 | ||
208 | # Explicitly kill this child, so we can continue gracefully | |
209 | # with further testing... | |
210 | send_gdb "kill\n" | |
211 | gdb_expect { | |
212 | -re ".*Kill the program being debugged.*y or n. $" { | |
213 | send_gdb "y\n" | |
214 | gdb_expect -re "$gdb_prompt $" {} | |
215 | } | |
216 | } | |
217 | } | |
218 | } | |
b242c3c2 PA |
219 | } |
220 | ||
74cf1395 | 221 | proc tcatch_fork_parent_follow {} { |
a76e022a MS |
222 | global gdb_prompt |
223 | global srcfile | |
224 | ||
225 | set bp_after_fork [gdb_get_line_number "set breakpoint here"] | |
226 | ||
2c04da0d | 227 | gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" \ |
a76e022a MS |
228 | "explicit parent follow, set tcatch fork" |
229 | ||
74cf1395 JM |
230 | # ??rehrauer: I don't yet know how to get the id of the tcatch |
231 | # via this script, so that I can add a -do list to it. For now, | |
232 | # do the follow stuff after the catch happens. | |
233 | ||
2c04da0d UW |
234 | gdb_test "continue" \ |
235 | "Catchpoint \[0-9\]* \\(forked process \[0-9\]*\\),.*" \ | |
a76e022a MS |
236 | "explicit parent follow, tcatch fork" |
237 | ||
238 | gdb_test_no_output "set follow-fork parent" | |
239 | ||
240 | gdb_test "tbreak ${srcfile}:$bp_after_fork" \ | |
241 | "Temporary breakpoint.*, line $bp_after_fork.*" \ | |
242 | "set follow-fork parent, tbreak" | |
243 | ||
244 | gdb_test "continue" \ | |
245 | "Detaching after fork from.* at .*$bp_after_fork.*" \ | |
246 | "set follow-fork parent, hit tbreak" | |
247 | ||
248 | # The child has been detached; allow time for any output it might | |
249 | # generate to arrive, so that output doesn't get confused with | |
250 | # any expected debugger output from a subsequent testpoint. | |
251 | # | |
252 | exec sleep 1 | |
253 | ||
254 | gdb_test "delete breakpoints" \ | |
255 | "" \ | |
256 | "set follow-fork parent, cleanup" \ | |
e9101ff5 | 257 | "Delete all breakpoints. \\(y or n\\) $" \ |
a76e022a | 258 | "y" |
74cf1395 JM |
259 | } |
260 | ||
261 | proc do_fork_tests {} { | |
a76e022a | 262 | global gdb_prompt |
74cf1395 | 263 | |
a76e022a MS |
264 | # Verify that help is available for "set follow-fork-mode". |
265 | # | |
266 | gdb_test "help set follow-fork-mode" \ | |
267 | "Set debugger response to a program call of fork or vfork..* | |
74cf1395 JM |
268 | A fork or vfork creates a new process. follow-fork-mode can be:.* |
269 | .*parent - the original process is debugged after a fork.* | |
270 | .*child - the new process is debugged after a fork.* | |
ef04f396 | 271 | The unfollowed process will continue to run..* |
a76e022a MS |
272 | By default, the debugger will follow the parent process..*" \ |
273 | "help set follow-fork" | |
274 | ||
275 | # Verify that we can set follow-fork-mode, using an abbreviation | |
276 | # for both the flag and its value. | |
277 | # | |
278 | gdb_test_no_output "set follow-fork ch" | |
279 | ||
280 | gdb_test "show follow-fork" \ | |
281 | "Debugger response to a program call of fork or vfork is \"child\".*" \ | |
282 | "set follow-fork, using abbreviations" | |
283 | ||
284 | # Verify that we cannot set follow-fork-mode to nonsense. | |
285 | # | |
286 | gdb_test "set follow-fork chork" "Undefined item: \"chork\".*" \ | |
287 | "set follow-fork to nonsense is prohibited" | |
288 | ||
289 | gdb_test_no_output "set follow-fork parent" "reset parent" | |
290 | ||
291 | # Check that fork catchpoints are supported, as an indicator for whether | |
292 | # fork-following is supported. | |
293 | if [runto_main] then { check_fork_catchpoints } | |
294 | ||
295 | # Test the default behaviour, which is to follow the parent of a | |
296 | # fork, and detach from the child. Do this without catchpoints. | |
297 | # | |
298 | if [runto_main] then { default_fork_parent_follow } | |
299 | ||
300 | # Test the ability to explicitly follow the parent of a fork, and | |
301 | # detach from the child. Do this without catchpoints. | |
302 | # | |
303 | if [runto_main] then { explicit_fork_parent_follow } | |
304 | ||
305 | # Test the ability to follow the child of a fork, and detach from | |
306 | # the parent. Do this without catchpoints. | |
307 | # | |
308 | if [runto_main] then { explicit_fork_child_follow } | |
309 | ||
310 | # Test the ability to follow both child and parent of a fork. Do | |
311 | # this without catchpoints. | |
312 | # ??rehrauer: NYI. Will add testpoints here when implemented. | |
313 | # | |
314 | ||
315 | # Test the ability to have the debugger ask the user at fork-time | |
316 | # whether to follow the parent, child or both. Do this without | |
317 | # catchpoints. | |
318 | # ??rehrauer: NYI. Will add testpoints here when implemented. | |
319 | # | |
320 | ||
321 | # Test the ability to catch a fork, specify that the child be | |
322 | # followed, and continue. Make the catchpoint permanent. | |
323 | # | |
324 | if [runto_main] then { catch_fork_child_follow } | |
325 | ||
326 | # Test that parent breakpoints are successfully detached from the | |
327 | # child at fork time, even if the user removes them from the | |
328 | # breakpoints list after stopping at a fork catchpoint. | |
329 | if [runto_main] then { catch_fork_unpatch_child } | |
330 | ||
331 | # Test the ability to catch a fork, specify via a -do clause that | |
332 | # the parent be followed, and continue. Make the catchpoint temporary. | |
333 | # | |
334 | if [runto_main] then { tcatch_fork_parent_follow } | |
74cf1395 JM |
335 | } |
336 | ||
337 | # Start with a fresh gdb | |
338 | ||
339 | gdb_exit | |
340 | gdb_start | |
341 | gdb_reinitialize_dir $srcdir/$subdir | |
342 | gdb_load ${binfile} | |
343 | ||
e85a822c DJ |
344 | # The "Detaching..." and "Attaching..." messages may be hidden by |
345 | # default. | |
27d3a1a2 | 346 | gdb_test_no_output "set verbose" |
74cf1395 JM |
347 | |
348 | # This is a test of gdb's ability to follow the parent, child or both | |
349 | # parent and child of a Unix fork() system call. | |
350 | # | |
351 | do_fork_tests | |
352 | ||
353 | return 0 |