1 # Copyright 1997, 1999, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 if { [is_remote target] || ![isnative] } then {
24 # NOTE drow/2002-12-06: I don't know what the referenced kernel problem
25 # is, but it appears to be fixed in recent HP/UX versions.
27 ##if [istarget "hppa2.0w-hp-hpux*"] {
28 ## warning "Don't run gdb.base/foll-vfork.exp until JAGaa43495 kernel problem is fixed."
33 set testfile "foll-vfork"
34 set testfile2 "vforked-prog"
35 set srcfile ${testfile}.c
36 set srcfile2 ${testfile2}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38 set binfile2 ${objdir}/${subdir}/${testfile2}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
41 untested foll-vfork.exp
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
46 untested foll-vfork.exp
51 # Until "set follow-fork-mode" and "catch vfork" are implemented on
54 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
58 # Test to see if we are on an HP-UX 10.20 and if so,
59 # do not run these tests as catching vfork is disabled for
62 if [istarget "hppa*-hp-hpux10.20"] then {
66 # A few of these tests require a little more time than the standard
68 set oldtimeout $timeout
69 set timeout [expr "$timeout + 10"]
71 proc check_vfork_catchpoints {} {
73 global has_vfork_catchpoints
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 vfork catchpoints.*$gdb_prompt $" {
80 unsupported "continue to first vfork catchpoint"
82 -re ".*Catchpoint.*$gdb_prompt $" {
83 set has_vfork_catchpoints 1
84 pass "continue to first vfork catchpoint"
88 if {$has_vfork_catchpoints == 0} {
89 unsupported "vfork catchpoints"
94 proc vfork_parent_follow_through_step {} {
97 send_gdb "set follow-fork parent\n"
99 -re "$gdb_prompt $" {pass "set follow-fork parent, vfork through step"}
100 timeout {fail "set follow-fork parent, vfork through step"}
104 -re "Detaching after fork from.*13.*$gdb_prompt "\
105 {pass "vfork parent follow, through step"}
106 -re "$gdb_prompt $" {fail "vfork parent follow, through step"}
107 timeout {fail "(timeout) vfork parent follow, through step" }
109 # The child has been detached; allow time for any output it might
110 # generate to arrive, so that output doesn't get confused with
111 # any gdb_expected debugger output from a subsequent testpoint.
116 proc vfork_parent_follow_to_bp {} {
120 send_gdb "set follow-fork parent\n"
122 -re "$gdb_prompt $" {pass "set follow-fork parent, vfork to bp"}
123 timeout {fail "set follow-fork parent, vfork to bp"}
125 send_gdb "break ${srcfile}:18\n"
127 -re "$gdb_prompt $" {pass "break, vfork to bp"}
128 timeout {fail "break, vfork to bp"}
130 send_gdb "continue\n"
132 -re ".*Detaching after fork from child process.*Breakpoint.*18.*$gdb_prompt "\
133 {pass "vfork parent follow, to bp"}
134 -re "$gdb_prompt $" {fail "vfork parent follow, to bp"}
135 timeout {fail "(timeout) vfork parent follow, to bp" }
137 # The child has been detached; allow time for any output it might
138 # generate to arrive, so that output doesn't get confused with
139 # any expected debugger output from a subsequent testpoint.
144 proc vfork_and_exec_child_follow_to_main_bp {} {
148 send_gdb "set follow-fork child\n"
150 -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec to main bp"}
151 timeout {fail "set follow-fork child, vfork and exec to main bp"}
153 send_gdb "continue\n"
155 -re "Attaching after.* vfork to.*xecuting new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\
156 {pass "vfork and exec child follow, to main bp"}
157 -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"}
158 timeout {fail "(timeout) vfork and exec child follow, to main bp" }
160 # The parent has been detached; allow time for any output it might
161 # generate to arrive, so that output doesn't get confused with
162 # any gdb_expected debugger output from a subsequent testpoint.
166 # Explicitly kill this child, or a subsequent rerun actually runs
167 # the exec'd child, not the original program...
170 -re ".*Kill the program being debugged.*y or n. $" {
172 send_gdb "file $binfile\n"
174 -re ".*Load new symbol table from.*y or n. $" {
177 -re "Reading symbols from.*$gdb_prompt $" {}
178 timeout { fail "loading symbols (timeout)"; return }
181 -re ".*gdb_prompt $" {}
182 timeout { fail "loading symbols (timeout)"; return }
185 -re ".*$gdb_prompt $" {}
186 timeout { fail "killing inferior (timeout)" ; return }
190 proc vfork_and_exec_child_follow_through_step {} {
194 # This test cannot be performed prior to HP-UX 10.30, because ptrace-based
195 # debugging of a vforking program basically doesn't allow the child to do
196 # things like hit a breakpoint between a vfork and exec. This means that
197 # saying "set follow-fork child; next" at a vfork() call won't work, because
198 # the implementation of "next" sets a "step resume" breakpoint at the
199 # return from the vfork(), which the child will hit on its way to exec'ing.
201 if { ![istarget "hppa*-*-hpux11.*"] } {
202 verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
206 send_gdb "set follow-fork child\n"
208 -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec through step"}
209 timeout {fail "set follow-fork child, vfork and exec through step"}
213 -re "Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\
214 {pass "vfork and exec child follow, through step"}
215 -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"}
216 timeout {fail "(timeout) vfork and exec child follow, through step" }
218 # The parent has been detached; allow time for any output it might
219 # generate to arrive, so that output doesn't get confused with
220 # any expected debugger output from a subsequent testpoint.
224 # Explicitly kill this child, or a subsequent rerun actually runs
225 # the exec'd child, not the original program...
228 -re ".*Kill the program being debugged.*y or n. $" {
230 send_gdb "file $binfile\n"
232 -re ".*Load new symbol table from.*y or n. $" {
235 -re "Reading symbols from.*$gdb_prompt $" {}
236 timeout { fail "loading symbols (timeout)"; return }
239 -re ".*gdb_prompt $" {}
240 timeout { fail "loading symbols (timeout)"; return }
243 -re ".*$gdb_prompt $" {}
244 timeout { fail "killing inferior (timeout)" ; return }
248 proc tcatch_vfork_then_parent_follow {} {
252 send_gdb "set follow-fork parent\n"
254 -re "$gdb_prompt $" {pass "set follow-fork parent, tcatch vfork"}
255 timeout {fail "set follow-fork parent, tcatch vfork"}
257 send_gdb "tcatch vfork\n"
259 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
260 {pass "vfork parent follow, set tcatch vfork"}
261 -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"}
262 timeout {fail "(timeout) vfork parent follow, set tcatch vfork"}
264 send_gdb "continue\n"
265 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
266 # stop you in "_vfork".
268 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\
269 {pass "vfork parent follow, tcatch vfork"}
270 -re "vfork \\(\\) at.*$gdb_prompt "\
271 {pass "vfork parent follow, tcatch vfork"}
272 -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"}
273 timeout {fail "(timeout) vfork parent follow, tcatch vfork"}
277 -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:12.*$gdb_prompt "\
278 {pass "vfork parent follow, finish after tcatch vfork"}
279 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
283 -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"}
284 timeout {fail "(timeout) vfork parent follow, finish after tcatch vfork" }
286 # The child has been detached; allow time for any output it might
287 # generate to arrive, so that output doesn't get confused with
288 # any expected debugger output from a subsequent testpoint.
293 proc tcatch_vfork_then_child_follow {} {
298 send_gdb "set follow-fork child\n"
300 -re "$gdb_prompt $" {pass "set follow-fork child, tcatch vfork"}
301 timeout {fail "set follow-fork child, tcatch vfork"}
303 send_gdb "tcatch vfork\n"
305 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
306 {pass "vfork child follow, set tcatch vfork"}
307 -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"}
308 timeout {fail "(timeout) vfork child follow, set tcatch vfork"}
310 send_gdb "continue\n"
311 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
312 # stop you in "_vfork".
314 -re "vfork \\(\\) at .*$gdb_prompt $"\
315 {pass "vfork child follow, tcatch vfork"}
316 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\
317 {pass "vfork child follow, tcatch vfork"}
318 -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"}
319 timeout {fail "(timeout) vfork child follow, tcatch vfork"}
323 -re "Run till exit from.*vfork.*${srcfile}:12.*$gdb_prompt "\
324 {pass "vfork child follow, finish after tcatch vfork"}
325 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
329 -re "Run till exit from.*vfork.*${srcfile2}:9.*$gdb_prompt "\
330 {pass "vfork child follow, finish after tcatch vfork (followed exec)"}
331 -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"}
332 timeout {fail "(timeout) vfork child follow, finish after tcatch vfork" }
334 # The parent has been detached; allow time for any output it might
335 # generate to arrive, so that output doesn't get confused with
336 # any expected debugger output from a subsequent testpoint.
341 proc do_vfork_and_exec_tests {} {
344 # Check that vfork catchpoints are supported, as an indicator for whether
345 # vfork-following is supported.
346 if [runto_main] then { check_vfork_catchpoints }
348 # Try following the parent process by stepping through a call to
349 # vfork. Do this without catchpoints.
350 if [runto_main] then { vfork_parent_follow_through_step }
352 # Try following the parent process by setting a breakpoint on the
353 # other side of a vfork, and running to that point. Do this
354 # without catchpoints.
355 if [runto_main] then { vfork_parent_follow_to_bp }
357 # Try following the child process by just continuing through the
358 # vfork, and letting the parent's breakpoint on "main" be auto-
359 # magically reset in the child.
361 if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
363 # Try following the child process by stepping through a call to
364 # vfork. The child also executes an exec. Since the child cannot
365 # be debugged until after it has exec'd, and since there's a bp on
366 # "main" in the parent, and since the bp's for the parent are
367 # recomputed in the exec'd child, the step through a vfork should
368 # land us in the "main" for the exec'd child, too.
370 if [runto_main] then { vfork_and_exec_child_follow_through_step }
372 # Try catching a vfork, and stepping out to the parent.
374 if [runto_main] then { tcatch_vfork_then_parent_follow }
376 # Try catching a vfork, and stepping out to the child.
378 if [runto_main] then { tcatch_vfork_then_child_follow }
380 # Test the ability to follow both child and parent of a vfork. Do
381 # this without catchpoints.
382 # ??rehrauer: NYI. Will add testpoints here when implemented.
385 # Test the ability to have the debugger ask the user at vfork-time
386 # whether to follow the parent, child or both. Do this without
388 # ??rehrauer: NYI. Will add testpoints here when implemented.
392 # Start with a fresh gdb
396 gdb_reinitialize_dir $srcdir/$subdir
399 # The "Detaching..." and "Attaching..." messages may be hidden by
401 gdb_test "set verbose" ""
403 # This is a test of gdb's ability to follow the parent or child
404 # of a Unix vfork() system call. (The child will subsequently
405 # call a variant of a Unix exec() system call.)
407 do_vfork_and_exec_tests
409 set timeout $oldtimeout