1 # Copyright 1997, 1999, 2007, 2008, 2009, 2010, 2011
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 {
22 # NOTE drow/2002-12-06: I don't know what the referenced kernel problem
23 # is, but it appears to be fixed in recent HP/UX versions.
25 ##if [istarget "hppa2.0w-hp-hpux*"] {
26 ## warning "Don't run gdb.base/foll-vfork.exp until JAGaa43495 kernel problem is fixed."
31 set testfile "foll-vfork"
32 set testfile2 "vforked-prog"
33 set srcfile ${testfile}.c
34 set srcfile2 ${testfile2}.c
35 set binfile ${objdir}/${subdir}/${testfile}
36 set binfile2 ${objdir}/${subdir}/${testfile2}
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
39 untested foll-vfork.exp
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
44 untested foll-vfork.exp
49 # Until "set follow-fork-mode" and "catch vfork" are implemented on
52 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
56 # Test to see if we are on an HP-UX 10.20 and if so,
57 # do not run these tests as catching vfork is disabled for
60 if [istarget "hppa*-hp-hpux10.20"] then {
64 # A few of these tests require a little more time than the standard
66 set oldtimeout $timeout
67 set timeout [expr "$timeout + 10"]
69 proc check_vfork_catchpoints {} {
71 global has_vfork_catchpoints
73 # Verify that the system supports "catch vfork".
74 gdb_test "catch vfork" "Catchpoint \[0-9\]* \\(vfork\\)" "insert first vfork catchpoint"
75 set has_vfork_catchpoints 0
76 gdb_test_multiple "continue" "continue to first vfork catchpoint" {
77 -re ".*Your system does not support vfork catchpoints.*$gdb_prompt $" {
78 unsupported "continue to first vfork catchpoint"
80 -re ".*Catchpoint.*$gdb_prompt $" {
81 set has_vfork_catchpoints 1
82 pass "continue to first vfork catchpoint"
86 if {$has_vfork_catchpoints == 0} {
87 unsupported "vfork catchpoints"
92 proc vfork_parent_follow_through_step {} {
95 send_gdb "set follow-fork parent\n"
97 -re "$gdb_prompt $" {pass "set follow-fork parent, vfork through step"}
98 timeout {fail "set follow-fork parent, vfork through step"}
102 -re "Detaching after fork from.*13.*$gdb_prompt "\
103 {pass "vfork parent follow, through step"}
104 -re "$gdb_prompt $" {fail "vfork parent follow, through step"}
105 timeout {fail "(timeout) vfork parent follow, through step" }
107 # The child has been detached; allow time for any output it might
108 # generate to arrive, so that output doesn't get confused with
109 # any gdb_expected debugger output from a subsequent testpoint.
114 proc vfork_parent_follow_to_bp {} {
118 send_gdb "set follow-fork parent\n"
120 -re "$gdb_prompt $" {pass "set follow-fork parent, vfork to bp"}
121 timeout {fail "set follow-fork parent, vfork to bp"}
123 send_gdb "break ${srcfile}:18\n"
125 -re "$gdb_prompt $" {pass "break, vfork to bp"}
126 timeout {fail "break, vfork to bp"}
128 send_gdb "continue\n"
130 -re ".*Detaching after fork from child process.*Breakpoint.*18.*$gdb_prompt "\
131 {pass "vfork parent follow, to bp"}
132 -re "$gdb_prompt $" {fail "vfork parent follow, to bp"}
133 timeout {fail "(timeout) vfork parent follow, to bp" }
135 # The child has been detached; allow time for any output it might
136 # generate to arrive, so that output doesn't get confused with
137 # any expected debugger output from a subsequent testpoint.
142 proc vfork_and_exec_child_follow_to_main_bp {} {
146 send_gdb "set follow-fork child\n"
148 -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec to main bp"}
149 timeout {fail "set follow-fork child, vfork and exec to main bp"}
151 send_gdb "continue\n"
153 -re "Attaching after.* vfork to.*xecuting new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\
154 {pass "vfork and exec child follow, to main bp"}
155 -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"}
156 timeout {fail "(timeout) vfork and exec child follow, to main bp" }
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.
164 # Explicitly kill this child, or a subsequent rerun actually runs
165 # the exec'd child, not the original program...
168 -re ".*Kill the program being debugged.*y or n. $" {
170 send_gdb "file $binfile\n"
172 -re ".*Load new symbol table from.*y or n. $" {
175 -re "Reading symbols from.*$gdb_prompt $" {}
176 timeout { fail "loading symbols (timeout)"; return }
179 -re ".*gdb_prompt $" {}
180 timeout { fail "loading symbols (timeout)"; return }
183 -re ".*$gdb_prompt $" {}
184 timeout { fail "killing inferior (timeout)" ; return }
188 proc vfork_and_exec_child_follow_through_step {} {
192 # This test cannot be performed prior to HP-UX 10.30, because ptrace-based
193 # debugging of a vforking program basically doesn't allow the child to do
194 # things like hit a breakpoint between a vfork and exec. This means that
195 # saying "set follow-fork child; next" at a vfork() call won't work, because
196 # the implementation of "next" sets a "step resume" breakpoint at the
197 # return from the vfork(), which the child will hit on its way to exec'ing.
199 if { ![istarget "hppa*-*-hpux11.*"] } {
200 verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
204 send_gdb "set follow-fork child\n"
206 -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec through step"}
207 timeout {fail "set follow-fork child, vfork and exec through step"}
211 -re "Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\
212 {pass "vfork and exec child follow, through step"}
213 -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"}
214 timeout {fail "(timeout) vfork and exec child follow, through step" }
216 # The parent has been detached; allow time for any output it might
217 # generate to arrive, so that output doesn't get confused with
218 # any expected debugger output from a subsequent testpoint.
222 # Explicitly kill this child, or a subsequent rerun actually runs
223 # the exec'd child, not the original program...
226 -re ".*Kill the program being debugged.*y or n. $" {
228 send_gdb "file $binfile\n"
230 -re ".*Load new symbol table from.*y or n. $" {
233 -re "Reading symbols from.*$gdb_prompt $" {}
234 timeout { fail "loading symbols (timeout)"; return }
237 -re ".*gdb_prompt $" {}
238 timeout { fail "loading symbols (timeout)"; return }
241 -re ".*$gdb_prompt $" {}
242 timeout { fail "killing inferior (timeout)" ; return }
246 proc tcatch_vfork_then_parent_follow {} {
250 send_gdb "set follow-fork parent\n"
252 -re "$gdb_prompt $" {pass "set follow-fork parent, tcatch vfork"}
253 timeout {fail "set follow-fork parent, tcatch vfork"}
255 send_gdb "tcatch vfork\n"
257 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
258 {pass "vfork parent follow, set tcatch vfork"}
259 -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"}
260 timeout {fail "(timeout) vfork parent follow, set tcatch vfork"}
262 send_gdb "continue\n"
263 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
264 # stop you in "_vfork".
266 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\
267 {pass "vfork parent follow, tcatch vfork"}
268 -re "vfork \\(\\) at.*$gdb_prompt "\
269 {pass "vfork parent follow, tcatch vfork"}
270 -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"}
271 timeout {fail "(timeout) vfork parent follow, tcatch vfork"}
275 -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:12.*$gdb_prompt "\
276 {pass "vfork parent follow, finish after tcatch vfork"}
277 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
281 -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"}
282 timeout {fail "(timeout) vfork parent follow, finish after tcatch vfork" }
284 # The child has been detached; allow time for any output it might
285 # generate to arrive, so that output doesn't get confused with
286 # any expected debugger output from a subsequent testpoint.
291 proc tcatch_vfork_then_child_follow {} {
296 send_gdb "set follow-fork child\n"
298 -re "$gdb_prompt $" {pass "set follow-fork child, tcatch vfork"}
299 timeout {fail "set follow-fork child, tcatch vfork"}
301 send_gdb "tcatch vfork\n"
303 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
304 {pass "vfork child follow, set tcatch vfork"}
305 -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"}
306 timeout {fail "(timeout) vfork child follow, set tcatch vfork"}
308 send_gdb "continue\n"
309 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
310 # stop you in "_vfork".
312 -re "vfork \\(\\) at .*$gdb_prompt $"\
313 {pass "vfork child follow, tcatch vfork"}
314 -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\
315 {pass "vfork child follow, tcatch vfork"}
316 -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"}
317 timeout {fail "(timeout) vfork child follow, tcatch vfork"}
321 -re "Run till exit from.*vfork.*${srcfile}:12.*$gdb_prompt "\
322 {pass "vfork child follow, finish after tcatch vfork"}
323 -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " {
327 -re "Run till exit from.*vfork.*${srcfile2}:9.*$gdb_prompt "\
328 {pass "vfork child follow, finish after tcatch vfork (followed exec)"}
329 -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"}
330 timeout {fail "(timeout) vfork child follow, finish after tcatch vfork" }
332 # The parent has been detached; allow time for any output it might
333 # generate to arrive, so that output doesn't get confused with
334 # any expected debugger output from a subsequent testpoint.
339 proc do_vfork_and_exec_tests {} {
342 # Check that vfork catchpoints are supported, as an indicator for whether
343 # vfork-following is supported.
344 if [runto_main] then { check_vfork_catchpoints }
346 # Try following the parent process by stepping through a call to
347 # vfork. Do this without catchpoints.
348 if [runto_main] then { vfork_parent_follow_through_step }
350 # Try following the parent process by setting a breakpoint on the
351 # other side of a vfork, and running to that point. Do this
352 # without catchpoints.
353 if [runto_main] then { vfork_parent_follow_to_bp }
355 # Try following the child process by just continuing through the
356 # vfork, and letting the parent's breakpoint on "main" be auto-
357 # magically reset in the child.
359 if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
361 # Try following the child process by stepping through a call to
362 # vfork. The child also executes an exec. Since the child cannot
363 # be debugged until after it has exec'd, and since there's a bp on
364 # "main" in the parent, and since the bp's for the parent are
365 # recomputed in the exec'd child, the step through a vfork should
366 # land us in the "main" for the exec'd child, too.
368 if [runto_main] then { vfork_and_exec_child_follow_through_step }
370 # Try catching a vfork, and stepping out to the parent.
372 if [runto_main] then { tcatch_vfork_then_parent_follow }
374 # Try catching a vfork, and stepping out to the child.
376 if [runto_main] then { tcatch_vfork_then_child_follow }
378 # Test the ability to follow both child and parent of a vfork. Do
379 # this without catchpoints.
380 # ??rehrauer: NYI. Will add testpoints here when implemented.
383 # Test the ability to have the debugger ask the user at vfork-time
384 # whether to follow the parent, child or both. Do this without
386 # ??rehrauer: NYI. Will add testpoints here when implemented.
390 # Start with a fresh gdb
394 gdb_reinitialize_dir $srcdir/$subdir
397 # The "Detaching..." and "Attaching..." messages may be hidden by
399 gdb_test_no_output "set verbose"
401 # This is a test of gdb's ability to follow the parent or child
402 # of a Unix vfork() system call. (The child will subsequently
403 # call a variant of a Unix exec() system call.)
405 do_vfork_and_exec_tests
407 set timeout $oldtimeout