Commit | Line | Data |
---|---|---|
0fb0cc75 | 1 | # Copyright 1997, 1999, 2007, 2008, 2009 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 JM |
20 | set prms_id 0 |
21 | set bug_id 0 | |
22 | ||
e85a822c | 23 | global srcfile |
74cf1395 JM |
24 | set testfile "foll-fork" |
25 | set srcfile ${testfile}.c | |
26 | set binfile ${objdir}/${subdir}/${testfile} | |
27 | ||
28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
29 | untested foll-fork.exp |
30 | return -1 | |
74cf1395 JM |
31 | } |
32 | ||
33 | ||
34 | ||
35 | # Until "set follow-fork-mode" and "catch fork" are implemented on | |
36 | # other targets... | |
37 | # | |
e85a822c | 38 | if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then { |
74cf1395 JM |
39 | continue |
40 | } | |
41 | ||
e85a822c DJ |
42 | proc check_fork_catchpoints {} { |
43 | global gdb_prompt | |
44 | ||
45 | # Verify that the system supports "catch fork". | |
46 | gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint" | |
47 | set has_fork_catchpoints 0 | |
48 | gdb_test_multiple "continue" "continue to first fork catchpoint" { | |
49 | -re ".*Your system does not support fork catchpoints.*$gdb_prompt $" { | |
50 | unsupported "continue to first fork catchpoint" | |
51 | } | |
52 | -re ".*Catchpoint.*$gdb_prompt $" { | |
53 | set has_fork_catchpoints 1 | |
54 | pass "continue to first fork catchpoint" | |
55 | } | |
56 | } | |
57 | ||
58 | if {$has_fork_catchpoints == 0} { | |
59 | unsupported "fork catchpoints" | |
60 | return -code return | |
61 | } | |
62 | } | |
63 | ||
74cf1395 JM |
64 | proc default_fork_parent_follow {} { |
65 | global gdb_prompt | |
66 | ||
67 | send_gdb "show follow\n" | |
68 | gdb_expect { | |
69 | -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\ | |
70 | {pass "default show parent follow, no catchpoints"} | |
71 | -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"} | |
72 | timeout {fail "(timeout) default show parent follow, no catchpoints"} | |
73 | } | |
74 | send_gdb "next 2\n" | |
75 | gdb_expect { | |
76 | -re "Detaching after fork from.*$gdb_prompt $"\ | |
77 | {pass "default parent follow, no catchpoints"} | |
78 | -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"} | |
79 | timeout {fail "(timeout) default parent follow, no catchpoints" } | |
80 | } | |
81 | # The child has been detached; allow time for any output it might | |
82 | # generate to arrive, so that output doesn't get confused with | |
83 | # any expected debugger output from a subsequent testpoint. | |
84 | # | |
85 | exec sleep 1 | |
86 | } | |
87 | ||
88 | proc explicit_fork_parent_follow {} { | |
89 | global gdb_prompt | |
90 | ||
91 | send_gdb "set follow parent\n" | |
92 | gdb_expect { | |
93 | -re "$gdb_prompt $" {pass "set follow parent"} | |
94 | timeout {fail "(timeout) set follow parent"} | |
95 | } | |
96 | send_gdb "show follow\n" | |
97 | gdb_expect { | |
98 | -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\ | |
99 | {pass "explicit show parent follow, no catchpoints"} | |
100 | -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"} | |
101 | timeout {fail "(timeout) explicit show parent follow, no catchpoints"} | |
102 | } | |
103 | send_gdb "next 2\n" | |
104 | gdb_expect { | |
105 | -re "Detaching after fork from.*$gdb_prompt $"\ | |
106 | {pass "explicit parent follow, no catchpoints"} | |
107 | -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"} | |
108 | timeout {fail "(timeout) explicit parent follow, no catchpoints"} | |
109 | } | |
110 | # The child has been detached; allow time for any output it might | |
111 | # generate to arrive, so that output doesn't get confused with | |
112 | # any expected debugger output from a subsequent testpoint. | |
113 | # | |
114 | exec sleep 1 | |
115 | } | |
116 | ||
117 | proc explicit_fork_child_follow {} { | |
118 | global gdb_prompt | |
119 | ||
120 | send_gdb "set follow child\n" | |
121 | gdb_expect { | |
122 | -re "$gdb_prompt $" {pass "set follow child"} | |
123 | timeout {fail "(timeout) set follow child"} | |
124 | } | |
125 | send_gdb "show follow\n" | |
126 | gdb_expect { | |
127 | -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\ | |
128 | {pass "explicit show child follow, no catchpoints"} | |
129 | -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"} | |
130 | timeout {fail "(timeout) explicit show child follow, no catchpoints"} | |
131 | } | |
132 | send_gdb "next 2\n" | |
133 | gdb_expect { | |
e85a822c | 134 | -re "Attaching after fork to.*$gdb_prompt $"\ |
74cf1395 JM |
135 | {pass "explicit child follow, no catchpoints"} |
136 | -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"} | |
137 | timeout {fail "(timeout) explicit child follow, no catchpoints"} | |
138 | } | |
139 | # The child has been detached; allow time for any output it might | |
140 | # generate to arrive, so that output doesn't get confused with | |
141 | # any gdb_expected debugger output from a subsequent testpoint. | |
142 | # | |
143 | exec sleep 1 | |
144 | } | |
145 | ||
146 | proc catch_fork_child_follow {} { | |
147 | global gdb_prompt | |
e85a822c | 148 | global srcfile |
74cf1395 JM |
149 | |
150 | send_gdb "catch fork\n" | |
151 | gdb_expect { | |
152 | -re "Catchpoint .*(fork).*$gdb_prompt $"\ | |
153 | {pass "explicit child follow, set catch fork"} | |
154 | -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"} | |
155 | timeout {fail "(timeout) explicit child follow, set catch fork"} | |
156 | } | |
157 | ||
158 | # Verify that the catchpoint is mentioned in an "info breakpoints", | |
159 | # and further that the catchpoint mentions no process id. | |
160 | # | |
cce89356 JB |
161 | set test_name "info shows catchpoint without pid" |
162 | gdb_test_multiple "info breakpoints" "$test_name" { | |
163 | -re ".*catchpoint.*keep y.*fork\[\r\n\]+$gdb_prompt $" { | |
164 | pass "$test_name" | |
165 | } | |
74cf1395 JM |
166 | } |
167 | ||
168 | send_gdb "continue\n" | |
169 | gdb_expect { | |
a9c64011 | 170 | -re "Catchpoint.*(forked process.*),.*in .*(fork|__kernel_v?syscall).*$gdb_prompt $"\ |
74cf1395 JM |
171 | {pass "explicit child follow, catch fork"} |
172 | -re "$gdb_prompt $" {fail "explicit child follow, catch fork"} | |
173 | timeout {fail "(timeout) explicit child follow, catch fork"} | |
174 | } | |
175 | ||
176 | # Verify that the catchpoint is mentioned in an "info breakpoints", | |
177 | # and further that the catchpoint managed to capture a process id. | |
178 | # | |
cce89356 JB |
179 | set test_name "info shows catchpoint without pid" |
180 | gdb_test_multiple "info breakpoints" "$test_name" { | |
181 | -re ".*catchpoint.*keep y.*fork, process.*$gdb_prompt $" { | |
182 | pass "$test_name" | |
183 | } | |
74cf1395 JM |
184 | } |
185 | ||
186 | send_gdb "set follow child\n" | |
187 | gdb_expect { | |
188 | -re "$gdb_prompt $" {pass "set follow child"} | |
189 | timeout {fail "(timeout) set follow child"} | |
190 | } | |
e85a822c | 191 | send_gdb "tbreak ${srcfile}:24\n" |
74cf1395 | 192 | gdb_expect { |
18ac113b | 193 | -re "Temporary breakpoint.*, line 24.*$gdb_prompt $"\ |
74cf1395 JM |
194 | {pass "set follow child, tbreak"} |
195 | -re "$gdb_prompt $" {fail "set follow child, tbreak"} | |
196 | timeout {fail "(timeout) set follow child, tbreak"} | |
197 | } | |
198 | send_gdb "continue\n" | |
199 | gdb_expect { | |
e85a822c | 200 | -re "Attaching after fork to.* at .*24.*$gdb_prompt $"\ |
74cf1395 JM |
201 | {pass "set follow child, hit tbreak"} |
202 | -re "$gdb_prompt $" {fail "set follow child, hit tbreak"} | |
203 | timeout {fail "(timeout) set follow child, hit tbreak"} | |
204 | } | |
205 | # The child has been detached; allow time for any output it might | |
206 | # generate to arrive, so that output doesn't get confused with | |
207 | # any expected debugger output from a subsequent testpoint. | |
208 | # | |
209 | exec sleep 1 | |
210 | send_gdb "delete breakpoints\n" | |
211 | gdb_expect { | |
212 | -re "Delete all breakpoints.*$" { | |
213 | send_gdb "y\n" | |
214 | gdb_expect { | |
215 | -re "$gdb_prompt $"\ | |
216 | {pass "set follow child, cleanup"} | |
217 | timeout {fail "(timeout) set follow child, cleanup"} | |
218 | } | |
219 | } | |
220 | -re "$gdb_prompt $" {fail "set follow child, cleanup"} | |
221 | timeout {fail "(timeout) set follow child, cleanup"} | |
222 | } | |
223 | } | |
224 | ||
225 | proc tcatch_fork_parent_follow {} { | |
226 | global gdb_prompt | |
e85a822c | 227 | global srcfile |
74cf1395 JM |
228 | |
229 | send_gdb "catch fork\n" | |
230 | gdb_expect { | |
231 | -re "Catchpoint .*(fork).*$gdb_prompt $"\ | |
232 | {pass "explicit parent follow, set tcatch fork"} | |
233 | -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"} | |
234 | timeout {fail "(timeout) explicit parent follow, set tcatch fork"} | |
235 | } | |
236 | # ??rehrauer: I don't yet know how to get the id of the tcatch | |
237 | # via this script, so that I can add a -do list to it. For now, | |
238 | # do the follow stuff after the catch happens. | |
239 | ||
240 | send_gdb "continue\n" | |
241 | gdb_expect { | |
a9c64011 | 242 | -re ".*in .*(fork|__kernel_v?syscall).*$gdb_prompt $"\ |
74cf1395 JM |
243 | {pass "explicit parent follow, tcatch fork"} |
244 | -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"} | |
245 | timeout {fail "(timeout) explicit parent follow, tcatch fork"} | |
246 | } | |
247 | send_gdb "set follow parent\n" | |
248 | gdb_expect { | |
249 | -re "$gdb_prompt $" {pass "set follow parent"} | |
250 | timeout {fail "(timeout) set follow parent"} | |
251 | } | |
e85a822c | 252 | send_gdb "tbreak ${srcfile}:24\n" |
74cf1395 | 253 | gdb_expect { |
18ac113b | 254 | -re "Temporary breakpoint.*, line 24.*$gdb_prompt $"\ |
74cf1395 JM |
255 | {pass "set follow parent, tbreak"} |
256 | -re "$gdb_prompt $" {fail "set follow parent, tbreak"} | |
257 | timeout {fail "(timeout) set follow child, tbreak"} | |
258 | } | |
259 | send_gdb "continue\n" | |
260 | gdb_expect { | |
261 | -re ".*Detaching after fork from.* at .*24.*$gdb_prompt $"\ | |
262 | {pass "set follow parent, hit tbreak"} | |
263 | -re "$gdb_prompt $" {fail "set follow parent, hit tbreak"} | |
264 | timeout {fail "(timeout) set follow parent, hit tbreak"} | |
265 | } | |
266 | # The child has been detached; allow time for any output it might | |
267 | # generate to arrive, so that output doesn't get confused with | |
268 | # any expected debugger output from a subsequent testpoint. | |
269 | # | |
270 | exec sleep 1 | |
271 | send_gdb "delete breakpoints\n" | |
272 | gdb_expect { | |
273 | -re "Delete all breakpoints.*$" { | |
274 | send_gdb "y\n" | |
275 | gdb_expect { | |
276 | -re "$gdb_prompt $"\ | |
277 | {pass "set follow parent, cleanup"} | |
278 | timeout {fail "(timeout) set follow parent, cleanup"} | |
279 | } | |
280 | } | |
281 | -re "$gdb_prompt $" {fail "set follow parent, cleanup"} | |
282 | timeout {fail "(timeout) set follow parent, cleanup"} | |
283 | } | |
284 | } | |
285 | ||
286 | proc do_fork_tests {} { | |
287 | global gdb_prompt | |
288 | ||
289 | # Verify that help is available for "set follow-fork-mode". | |
290 | # | |
291 | send_gdb "help set follow-fork-mode\n" | |
292 | gdb_expect { | |
293 | -re "Set debugger response to a program call of fork or vfork..* | |
294 | A fork or vfork creates a new process. follow-fork-mode can be:.* | |
295 | .*parent - the original process is debugged after a fork.* | |
296 | .*child - the new process is debugged after a fork.* | |
ef04f396 | 297 | The unfollowed process will continue to run..* |
74cf1395 JM |
298 | By default, the debugger will follow the parent process..*$gdb_prompt $"\ |
299 | { pass "help set follow" } | |
300 | -re "$gdb_prompt $" { fail "help set follow" } | |
301 | timeout { fail "(timeout) help set follow" } | |
302 | } | |
303 | ||
304 | # Verify that we can set follow-fork-mode, using an abbreviation | |
305 | # for both the flag and its value. | |
306 | # | |
307 | send_gdb "set follow ch\n" | |
308 | send_gdb "show fol\n" | |
309 | gdb_expect { | |
310 | -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\ | |
311 | {pass "set follow, using abbreviations"} | |
312 | timeout {fail "(timeout) set follow, using abbreviations"} | |
313 | } | |
314 | ||
315 | # Verify that we cannot set follow-fork-mode to nonsense. | |
316 | # | |
317 | send_gdb "set follow chork\n" | |
318 | gdb_expect { | |
319 | -re "Undefined item: \"chork\".*$gdb_prompt $"\ | |
320 | {pass "set follow to nonsense is prohibited"} | |
321 | -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"} | |
322 | timeout {fail "(timeout) set follow to nonsense is prohibited"} | |
323 | } | |
324 | send_gdb "set follow parent\n" | |
325 | gdb_expect { | |
326 | -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"} | |
327 | timeout {fail "set follow to nonsense is prohibited (reset parent)"} | |
328 | } | |
329 | ||
e85a822c DJ |
330 | # Check that fork catchpoints are supported, as an indicator for whether |
331 | # fork-following is supported. | |
332 | if [runto_main] then { check_fork_catchpoints } | |
333 | ||
74cf1395 JM |
334 | # Test the default behaviour, which is to follow the parent of a |
335 | # fork, and detach from the child. Do this without catchpoints. | |
336 | # | |
337 | if [runto_main] then { default_fork_parent_follow } | |
338 | ||
339 | # Test the ability to explicitly follow the parent of a fork, and | |
340 | # detach from the child. Do this without catchpoints. | |
341 | # | |
342 | if [runto_main] then { explicit_fork_parent_follow } | |
343 | ||
344 | # Test the ability to follow the child of a fork, and detach from | |
345 | # the parent. Do this without catchpoints. | |
346 | # | |
347 | if [runto_main] then { explicit_fork_child_follow } | |
348 | ||
349 | # Test the ability to follow both child and parent of a fork. Do | |
350 | # this without catchpoints. | |
351 | # ??rehrauer: NYI. Will add testpoints here when implemented. | |
352 | # | |
353 | ||
354 | # Test the ability to have the debugger ask the user at fork-time | |
355 | # whether to follow the parent, child or both. Do this without | |
356 | # catchpoints. | |
357 | # ??rehrauer: NYI. Will add testpoints here when implemented. | |
358 | # | |
359 | ||
360 | # Test the ability to catch a fork, specify that the child be | |
361 | # followed, and continue. Make the catchpoint permanent. | |
362 | # | |
363 | if [runto_main] then { catch_fork_child_follow } | |
364 | ||
365 | # Test the ability to catch a fork, specify via a -do clause that | |
366 | # the parent be followed, and continue. Make the catchpoint temporary. | |
367 | # | |
368 | if [runto_main] then { tcatch_fork_parent_follow } | |
369 | } | |
370 | ||
371 | # Start with a fresh gdb | |
372 | ||
373 | gdb_exit | |
374 | gdb_start | |
375 | gdb_reinitialize_dir $srcdir/$subdir | |
376 | gdb_load ${binfile} | |
377 | ||
e85a822c DJ |
378 | # The "Detaching..." and "Attaching..." messages may be hidden by |
379 | # default. | |
380 | gdb_test "set verbose" "" | |
74cf1395 JM |
381 | |
382 | # This is a test of gdb's ability to follow the parent, child or both | |
383 | # parent and child of a Unix fork() system call. | |
384 | # | |
385 | do_fork_tests | |
386 | ||
387 | return 0 |