Remove HP-UX references fom testsuite
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-vfork.exp
1 # Copyright 1997-2015 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Various tests of gdb's ability to follow the parent or child of a
17 # Unix vfork system call. A vfork parent is blocked until the child
18 # either execs or exits --- since those events take somewhat different
19 # code paths in GDB, both variants are exercised.
20
21 # Until "set follow-fork-mode" and "catch vfork" are implemented on
22 # other targets...
23 #
24 if {![istarget "*-linux*"]} then {
25 continue
26 }
27
28 standard_testfile
29
30 set compile_options debug
31 set dirname [relative_filename [pwd] [file dirname $binfile]]
32 lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\""
33
34 if {[build_executable $testfile.exp $testfile $srcfile $compile_options] == -1} {
35 untested "failed to compile $testfile"
36 return -1
37 }
38
39 set testfile2 "vforked-prog"
40 set srcfile2 ${testfile2}.c
41
42 if {[build_executable $testfile.exp $testfile2 $srcfile2 $compile_options] == -1} {
43 untested "failed to compile $testfile2"
44 return -1
45 }
46
47 # A few of these tests require a little more time than the standard
48 # timeout allows.
49 set oldtimeout $timeout
50 set timeout [expr "$timeout + 10"]
51
52 # Start with a fresh GDB, with verbosity enabled, and run to main. On
53 # error, behave as "return", so we don't try to continue testing with
54 # a borked session.
55 proc setup_gdb {} {
56 global testfile
57
58 clean_restart $testfile
59
60 # The "Detaching..." and "Attaching..." messages may be hidden by
61 # default.
62 gdb_test_no_output "set verbose"
63
64 if ![runto_main] {
65 return -code return
66 }
67 }
68
69 proc check_vfork_catchpoints {} {
70 global gdb_prompt
71 global has_vfork_catchpoints
72
73 setup_gdb
74
75 # Verify that the system supports "catch vfork".
76 gdb_test "catch vfork" "Catchpoint \[0-9\]* \\(vfork\\)" "insert first vfork catchpoint"
77 set has_vfork_catchpoints 0
78 gdb_test_multiple "continue" "continue to first vfork catchpoint" {
79 -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
80 unsupported "continue to first vfork catchpoint"
81 }
82 -re ".*Catchpoint.*$gdb_prompt $" {
83 set has_vfork_catchpoints 1
84 pass "continue to first vfork catchpoint"
85 }
86 }
87
88 if {$has_vfork_catchpoints == 0} {
89 unsupported "vfork catchpoints"
90 return -code return
91 }
92 }
93
94 proc vfork_parent_follow_through_step {} {
95 with_test_prefix "vfork parent follow, through step" {
96 global gdb_prompt
97
98 setup_gdb
99
100 gdb_test_no_output "set follow-fork parent"
101
102 set test "step"
103 gdb_test_multiple "next" $test {
104 -re "Detaching after vfork from.*if \\(pid == 0\\).*$gdb_prompt " {
105 pass $test
106 }
107 }
108 # The child has been detached; allow time for any output it might
109 # generate to arrive, so that output doesn't get confused with
110 # any gdb_expected debugger output from a subsequent testpoint.
111 #
112 exec sleep 1
113 }}
114
115 proc vfork_parent_follow_to_bp {} {
116 with_test_prefix "vfork parent follow, to bp" {
117 global gdb_prompt
118 global srcfile
119
120 setup_gdb
121
122 gdb_test_no_output "set follow-fork parent"
123
124 set bp_location [gdb_get_line_number "printf (\"I'm the proud parent of child"]
125 gdb_test "break ${srcfile}:${bp_location}" ".*" "break, vfork to bp"
126
127 set test "continue to bp"
128 gdb_test_multiple "continue" $test {
129 -re ".*Detaching after vfork from child process.*Breakpoint.*${bp_location}.*$gdb_prompt " {
130 pass $test
131 }
132 }
133 # The child has been detached; allow time for any output it might
134 # generate to arrive, so that output doesn't get confused with
135 # any expected debugger output from a subsequent testpoint.
136 #
137 exec sleep 1
138 }}
139
140 proc vfork_child_follow_to_exit {} {
141 with_test_prefix "vfork child follow, to exit" {
142 global gdb_prompt
143
144 setup_gdb
145
146 gdb_test_no_output "set follow-fork child"
147
148 set test "continue to child exit"
149 gdb_test_multiple "continue" $test {
150 -re "Couldn't get registers.*$gdb_prompt " {
151 # PR gdb/14766
152 fail "$test"
153 }
154 -re "Attaching after.* vfork to.*Detaching vfork parent .* after child exit.*$gdb_prompt " {
155 pass $test
156 }
157 }
158 # The parent has been detached; allow time for any output it might
159 # generate to arrive, so that output doesn't get confused with
160 # any gdb_expected debugger output from a subsequent testpoint.
161 #
162 exec sleep 1
163 }}
164
165 proc vfork_and_exec_child_follow_to_main_bp {} {
166 with_test_prefix "vfork and exec child follow, to main bp" {
167 global gdb_prompt
168 global srcfile2
169
170 setup_gdb
171
172 gdb_test_no_output "set follow-fork child"
173
174 set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
175
176 set test "continue to bp"
177 gdb_test_multiple "continue" $test {
178 -re "Attaching after.* vfork to.*Detaching vfork parent.*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
179 pass $test
180 }
181 }
182 # The parent has been detached; allow time for any output it might
183 # generate to arrive, so that output doesn't get confused with
184 # any gdb_expected debugger output from a subsequent testpoint.
185 #
186 exec sleep 1
187 }}
188
189 proc vfork_and_exec_child_follow_through_step {} {
190 with_test_prefix "vfork and exec child follow, through step" {
191 global gdb_prompt
192 global srcfile2
193
194 setup_gdb
195
196 gdb_test_no_output "set follow-fork child"
197
198 set test "step over vfork"
199
200 # The ideal support is to be able to debug the child even
201 # before it execs. Thus, "next" lands on the next line after
202 # the vfork.
203 gdb_test_multiple "next" $test {
204 -re "Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " {
205 pass "$test"
206 }
207 }
208 # The parent has been detached; allow time for any output it might
209 # generate to arrive, so that output doesn't get confused with
210 # any expected debugger output from a subsequent testpoint.
211 #
212 exec sleep 1
213 }}
214
215 proc tcatch_vfork_then_parent_follow {} {
216 with_test_prefix "vfork parent follow, finish after tcatch vfork" {
217 global gdb_prompt
218 global srcfile
219
220 setup_gdb
221
222 gdb_test_no_output "set follow-fork parent"
223
224 gdb_test "tcatch vfork" "Catchpoint .*(vfork).*"
225
226 # HP-UX 10.20 seems to stop you in "vfork", while more recent
227 # HP-UXs stop you in "_vfork".
228 set test "continue to vfork"
229 gdb_test_multiple "continue" $test {
230 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt " {
231 pass $test
232 }
233 -re "vfork \\(\\) at.*$gdb_prompt " {
234 pass $test
235 }
236 }
237
238 set linenum [gdb_get_line_number "pid = vfork ();"]
239 set test "finish"
240 gdb_test_multiple "finish" $test {
241 -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:${linenum}.*$gdb_prompt " {
242 pass $test
243 }
244 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
245 send_gdb "finish\n"
246 exp_continue
247 }
248 }
249 # The child has been detached; allow time for any output it might
250 # generate to arrive, so that output doesn't get confused with
251 # any expected debugger output from a subsequent testpoint.
252 #
253 exec sleep 1
254 }}
255
256 proc tcatch_vfork_then_child_follow_exec {} {
257 with_test_prefix "vfork child follow, finish after tcatch vfork" {
258 global gdb_prompt
259 global srcfile
260 global srcfile2
261
262 setup_gdb
263
264 gdb_test_no_output "set follow-fork child"
265
266 gdb_test "tcatch vfork" "Catchpoint .*(vfork).*"
267
268 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
269 # stop you in "_vfork".
270 set test "continue to vfork"
271 gdb_test_multiple "continue" $test {
272 -re "vfork \\(\\) at .*$gdb_prompt $" {
273 pass $test
274 }
275 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt " {
276 pass $test
277 }
278 }
279
280 set linenum1 [gdb_get_line_number "pid = vfork ();"]
281 set linenum2 [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
282
283 set test "finish"
284 gdb_test_multiple "finish" $test {
285 -re "Run till exit from.*vfork.*${srcfile}:${linenum1}.*$gdb_prompt " {
286 pass $test
287 }
288 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
289 send_gdb "finish\n"
290 exp_continue
291 }
292 -re "Run till exit from.*vfork.*${srcfile2}:${linenum2}.*$gdb_prompt " {
293 pass "$test (followed exec)"
294 }
295 }
296 # The parent has been detached; allow time for any output it might
297 # generate to arrive, so that output doesn't get confused with
298 # any expected debugger output from a subsequent testpoint.
299 #
300 exec sleep 1
301 }}
302
303 proc tcatch_vfork_then_child_follow_exit {} {
304 with_test_prefix "vfork child follow, finish after tcatch vfork" {
305 global gdb_prompt
306 global srcfile
307
308 setup_gdb
309
310 gdb_test_no_output "set follow-fork child"
311
312 gdb_test "tcatch vfork" "Catchpoint .*(vfork).*"
313
314 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
315 # stop you in "_vfork".
316 set test "continue to vfork"
317 gdb_test_multiple "continue" $test {
318 -re "vfork \\(\\) at .*$gdb_prompt $" {
319 pass $test
320 }
321 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt " {
322 pass $test
323 }
324 }
325
326 set test "finish"
327 gdb_test_multiple "finish" $test {
328 -re "Run till exit from.*vfork.*exited normally.*$gdb_prompt " {
329 setup_kfail "gdb/14762" *-*-*
330 fail $test
331 }
332 -re "Run till exit from.*vfork.*pid = vfork \\(\\).*$gdb_prompt " {
333 pass $test
334 }
335 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
336 send_gdb "finish\n"
337 exp_continue
338 }
339 }
340 # The parent has been detached; allow time for any output it might
341 # generate to arrive, so that output doesn't get confused with
342 # any expected debugger output from a subsequent testpoint.
343 #
344 exec sleep 1
345 }}
346
347 proc vfork_relations_in_info_inferiors { variant } {
348 with_test_prefix "vfork relations in info inferiors" {
349 global gdb_prompt
350
351 setup_gdb
352
353 gdb_test_no_output "set follow-fork child"
354
355 set test "step over vfork"
356 gdb_test_multiple "next" $test {
357 -re "Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " {
358 pass "$test"
359 }
360 }
361
362 gdb_test "info inferiors" \
363 ".*is vfork parent of inferior 2.*is vfork child of inferior 1" \
364 "info inferiors shows vfork parent/child relation"
365
366 if { $variant == "exec" } {
367 global srcfile2
368
369 set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}]
370 set test "continue to bp"
371 gdb_test_multiple "continue" $test {
372 -re ".*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " {
373 pass $test
374 }
375 }
376 } else {
377 set test "continue to child exit"
378 gdb_test_multiple "continue" $test {
379 -re "exited normally.*$gdb_prompt " {
380 pass $test
381 }
382 }
383 }
384
385 set test "vfork relation no longer appears in info inferiors"
386 gdb_test_multiple "info inferiors" $test {
387 -re "is vfork child of inferior 1.*$gdb_prompt $" {
388 fail $test
389 }
390 -re "is vfork parent of inferior 2.*$gdb_prompt $" {
391 fail $test
392 }
393 -re "$gdb_prompt $" {
394 pass $test
395 }
396 }
397 }}
398
399 proc do_vfork_and_follow_parent_tests {} {
400 global gdb_prompt
401
402 # Try following the parent process by stepping through a call to
403 # vfork. Do this without catchpoints.
404 vfork_parent_follow_through_step
405
406 # Try following the parent process by setting a breakpoint on the
407 # other side of a vfork, and running to that point. Do this
408 # without catchpoints.
409 vfork_parent_follow_to_bp
410
411 # Try catching a vfork, and stepping out to the parent.
412 #
413 tcatch_vfork_then_parent_follow
414 }
415
416 proc do_vfork_and_follow_child_tests_exec {} {
417 # Try following the child process by just continuing through the
418 # vfork, and letting the parent's breakpoint on "main" be auto-
419 # magically reset in the child.
420 #
421 vfork_and_exec_child_follow_to_main_bp
422
423 # Try following the child process by stepping through a call to
424 # vfork. The child also executes an exec. Since the child cannot
425 # be debugged until after it has exec'd, and since there's a bp on
426 # "main" in the parent, and since the bp's for the parent are
427 # recomputed in the exec'd child, the step through a vfork should
428 # land us in the "main" for the exec'd child, too.
429 #
430 vfork_and_exec_child_follow_through_step
431
432 # Try catching a vfork, and stepping out to the child.
433 #
434 tcatch_vfork_then_child_follow_exec
435
436 # Test the ability to follow both child and parent of a vfork. Do
437 # this without catchpoints.
438 # ??rehrauer: NYI. Will add testpoints here when implemented.
439 #
440
441 # Test the ability to have the debugger ask the user at vfork-time
442 # whether to follow the parent, child or both. Do this without
443 # catchpoints.
444 # ??rehrauer: NYI. Will add testpoints here when implemented.
445 #
446
447 # Step over a vfork in the child, do "info inferiors" and check the
448 # parent/child relation is displayed. Run the child over the exec,
449 # and confirm the relation is no longer displayed in "info
450 # inferiors".
451 #
452 vfork_relations_in_info_inferiors "exec"
453 }
454
455 proc do_vfork_and_follow_child_tests_exit {} {
456 # Try following the child process by just continuing through the
457 # vfork, and letting the child exit.
458 #
459 vfork_child_follow_to_exit
460
461 # Try catching a vfork, and stepping out to the child.
462 #
463 tcatch_vfork_then_child_follow_exit
464
465 # Step over a vfork in the child, do "info inferiors" and check the
466 # parent/child relation is displayed. Run the child to completion,
467 # and confirm the relation is no longer displayed in "info
468 # inferiors".
469 #
470 vfork_relations_in_info_inferiors "exit"
471 }
472
473 with_test_prefix "check vfork support" {
474 # Check that vfork catchpoints are supported, as an indicator for
475 # whether vfork-following is supported.
476 check_vfork_catchpoints
477 }
478
479 # Follow parent and follow child vfork tests with a child that execs.
480 with_test_prefix "exec" {
481 # These are tests of gdb's ability to follow the parent of a Unix
482 # vfork system call. The child will subsequently call a variant
483 # of the Unix exec system call.
484 do_vfork_and_follow_parent_tests
485
486 # These are tests of gdb's ability to follow the child of a Unix
487 # vfork system call. The child will subsequently call a variant
488 # of a Unix exec system call.
489 #
490 do_vfork_and_follow_child_tests_exec
491 }
492
493 # Switch to test the case of the child exiting. We can't use
494 # standard_testfile here because we don't want to overwrite the binary
495 # of the previous tests.
496 set testfile "foll-vfork-exit"
497 set srcfile ${testfile}.c
498 set binfile [standard_output_file ${testfile}]
499
500 if {[build_executable $testfile.exp $testfile $srcfile] == -1} {
501 untested "failed to build $testfile"
502 return
503 }
504
505 # Follow parent and follow child vfork tests with a child that exits.
506 with_test_prefix "exit" {
507 # These are tests of gdb's ability to follow the parent of a Unix
508 # vfork system call. The child will subsequently exit.
509 do_vfork_and_follow_parent_tests
510
511 # These are tests of gdb's ability to follow the child of a Unix
512 # vfork system call. The child will subsequently exit.
513 #
514 do_vfork_and_follow_child_tests_exit
515 }
516
517 set timeout $oldtimeout
518 return 0
This page took 0.04145 seconds and 5 git commands to generate.