Index: gdb/testsuite/gdb.base/foll-vfork.exp |
diff --git a/gdb/testsuite/gdb.base/foll-vfork.exp b/gdb/testsuite/gdb.base/foll-vfork.exp |
index 7a3c04e582b9e37cb1ad1b0439329440cca05660..29d6da01aaa51037e5bce49545a5d129b84b01c3 100644 |
--- a/gdb/testsuite/gdb.base/foll-vfork.exp |
+++ b/gdb/testsuite/gdb.base/foll-vfork.exp |
@@ -1,4 +1,4 @@ |
-# Copyright 1997, 1999, 2007-2012 Free Software Foundation, Inc. |
+# Copyright 1997-2013 Free Software Foundation, Inc. |
# This program is free software; you can redistribute it and/or modify |
# it under the terms of the GNU General Public License as published by |
@@ -13,6 +13,11 @@ |
# You should have received a copy of the GNU General Public License |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
+# Various tests of gdb's ability to follow the parent or child of a |
+# Unix vfork system call. A vfork parent is blocked until the child |
+# either execs or exits --- since those events take somewhat different |
+# code paths in GDB, both variants are exercised. |
+ |
if { [is_remote target] || ![isnative] } then { |
continue |
} |
@@ -40,22 +45,23 @@ if [istarget "hppa*-hp-hpux10.20"] then { |
## return 0 |
##} |
-global srcfile |
-set testfile "foll-vfork" |
-set testfile2 "vforked-prog" |
-set srcfile ${testfile}.c |
-set srcfile2 ${testfile2}.c |
-set binfile ${objdir}/${subdir}/${testfile} |
-set binfile2 ${objdir}/${subdir}/${testfile2} |
+standard_testfile |
+ |
+set compile_options debug |
+set dirname [relative_filename [pwd] [file dirname $binfile]] |
+lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\"" |
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
- untested foll-vfork.exp |
- return -1 |
+if {[build_executable $testfile.exp $testfile $srcfile $compile_options] == -1} { |
+ untested "failed to compile $testfile" |
+ return -1 |
} |
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } { |
- untested foll-vfork.exp |
- return -1 |
+set testfile2 "vforked-prog" |
+set srcfile2 ${testfile2}.c |
+ |
+if {[build_executable $testfile.exp $testfile2 $srcfile2 $compile_options] == -1} { |
+ untested "failed to compile $testfile2" |
+ return -1 |
} |
# A few of these tests require a little more time than the standard |
@@ -63,10 +69,29 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {d |
set oldtimeout $timeout |
set timeout [expr "$timeout + 10"] |
+# Start with a fresh GDB, with verbosity enabled, and run to main. On |
+# error, behave as "return", so we don't try to continue testing with |
+# a borked session. |
+proc setup_gdb {} { |
+ global testfile |
+ |
+ clean_restart $testfile |
+ |
+ # The "Detaching..." and "Attaching..." messages may be hidden by |
+ # default. |
+ gdb_test_no_output "set verbose" |
+ |
+ if ![runto_main] { |
+ return -code return |
+ } |
+} |
+ |
proc check_vfork_catchpoints {} { |
global gdb_prompt |
global has_vfork_catchpoints |
+ setup_gdb |
+ |
# Verify that the system supports "catch vfork". |
gdb_test "catch vfork" "Catchpoint \[0-9\]* \\(vfork\\)" "insert first vfork catchpoint" |
set has_vfork_catchpoints 0 |
@@ -87,273 +112,361 @@ proc check_vfork_catchpoints {} { |
} |
proc vfork_parent_follow_through_step {} { |
+ with_test_prefix "vfork parent follow, through step" { |
global gdb_prompt |
- send_gdb "set follow-fork parent\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "set follow-fork parent, vfork through step"} |
- timeout {fail "set follow-fork parent, vfork through step"} |
- } |
- send_gdb "next\n" |
- gdb_expect { |
- -re "Detaching after fork from.*13.*$gdb_prompt "\ |
- {pass "vfork parent follow, through step"} |
- -re "$gdb_prompt $" {fail "vfork parent follow, through step"} |
- timeout {fail "(timeout) vfork parent follow, through step" } |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork parent" |
+ |
+ set test "step" |
+ gdb_test_multiple "next" $test { |
+ -re "Detaching after fork from.*if \\(pid == 0\\).*$gdb_prompt " { |
+ pass $test |
+ } |
} |
# The child has been detached; allow time for any output it might |
# generate to arrive, so that output doesn't get confused with |
# any gdb_expected debugger output from a subsequent testpoint. |
# |
exec sleep 1 |
-} |
+}} |
proc vfork_parent_follow_to_bp {} { |
+ with_test_prefix "vfork parent follow, to bp" { |
global gdb_prompt |
global srcfile |
- send_gdb "set follow-fork parent\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "set follow-fork parent, vfork to bp"} |
- timeout {fail "set follow-fork parent, vfork to bp"} |
- } |
- send_gdb "break ${srcfile}:18\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "break, vfork to bp"} |
- timeout {fail "break, vfork to bp"} |
- } |
- send_gdb "continue\n" |
- gdb_expect { |
- -re ".*Detaching after fork from child process.*Breakpoint.*18.*$gdb_prompt "\ |
- {pass "vfork parent follow, to bp"} |
- -re "$gdb_prompt $" {fail "vfork parent follow, to bp"} |
- timeout {fail "(timeout) vfork parent follow, to bp" } |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork parent" |
+ |
+ set bp_location [gdb_get_line_number "printf (\"I'm the proud parent of child"] |
+ gdb_test "break ${srcfile}:${bp_location}" ".*" "break, vfork to bp" |
+ |
+ set test "continue to bp" |
+ gdb_test_multiple "continue" $test { |
+ -re ".*Detaching after fork from child process.*Breakpoint.*${bp_location}.*$gdb_prompt " { |
+ pass $test |
+ } |
} |
# The child has been detached; allow time for any output it might |
# generate to arrive, so that output doesn't get confused with |
# any expected debugger output from a subsequent testpoint. |
# |
exec sleep 1 |
-} |
+}} |
-proc vfork_and_exec_child_follow_to_main_bp {} { |
+proc vfork_child_follow_to_exit {} { |
+ with_test_prefix "vfork child follow, to exit" { |
global gdb_prompt |
- global binfile |
- send_gdb "set follow-fork child\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec to main bp"} |
- timeout {fail "set follow-fork child, vfork and exec to main bp"} |
- } |
- send_gdb "continue\n" |
- gdb_expect { |
- -re "Attaching after.* vfork to.*xecuting new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\ |
- {pass "vfork and exec child follow, to main bp"} |
- -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"} |
- timeout {fail "(timeout) vfork and exec child follow, to main bp" } |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork child" |
+ |
+ set test "continue to child exit" |
+ gdb_test_multiple "continue" $test { |
+ -re "Couldn't get registers.*$gdb_prompt " { |
+ # PR gdb/14766 |
+ fail "$test" |
+ } |
+ -re "Attaching after.* vfork to.*Detaching vfork parent .* after child exit.*$gdb_prompt " { |
+ pass $test |
+ } |
} |
# The parent has been detached; allow time for any output it might |
# generate to arrive, so that output doesn't get confused with |
# any gdb_expected debugger output from a subsequent testpoint. |
# |
exec sleep 1 |
+}} |
- # Explicitly kill this child, or a subsequent rerun actually runs |
- # the exec'd child, not the original program... |
- send_gdb "kill\n" |
- gdb_expect { |
- -re ".*Kill the program being debugged.*y or n. $" { |
- gdb_test_no_output "y" "" |
- send_gdb "file $binfile\n" |
- gdb_expect { |
- -re ".*Load new symbol table from.*y or n. $" { |
- send_gdb "y\n" |
- gdb_expect { |
- -re "Reading symbols from.*$gdb_prompt $" {} |
- timeout { fail "loading symbols (timeout)"; return } |
- } |
- } |
- -re ".*gdb_prompt $" {} |
- timeout { fail "loading symbols (timeout)"; return } |
- } |
+proc vfork_and_exec_child_follow_to_main_bp {} { |
+ with_test_prefix "vfork and exec child follow, to main bp" { |
+ global gdb_prompt |
+ global srcfile2 |
+ |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork child" |
+ |
+ set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}] |
+ |
+ set test "continue to bp" |
+ gdb_test_multiple "continue" $test { |
+ -re "Attaching after.* vfork to.*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " { |
+ pass $test |
} |
- -re ".*$gdb_prompt $" {} |
- timeout { fail "killing inferior (timeout)" ; return } |
- } |
-} |
+ } |
+ # The parent has been detached; allow time for any output it might |
+ # generate to arrive, so that output doesn't get confused with |
+ # any gdb_expected debugger output from a subsequent testpoint. |
+ # |
+ exec sleep 1 |
+}} |
proc vfork_and_exec_child_follow_through_step {} { |
+ with_test_prefix "vfork and exec child follow, through step" { |
global gdb_prompt |
- global binfile |
- |
-# This test cannot be performed prior to HP-UX 10.30, because ptrace-based |
-# debugging of a vforking program basically doesn't allow the child to do |
-# things like hit a breakpoint between a vfork and exec. This means that |
-# saying "set follow-fork child; next" at a vfork() call won't work, because |
-# the implementation of "next" sets a "step resume" breakpoint at the |
-# return from the vfork(), which the child will hit on its way to exec'ing. |
-# |
- if { ![istarget "hppa*-*-hpux11.*"] } { |
- verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets." |
+ global srcfile2 |
+ |
+ if { [istarget "hppa*-*-hpux*"] && ![istarget "hppa*-*-hpux11.*"] } { |
+ # This test cannot be performed prior to HP-UX 10.30, because |
+ # ptrace-based debugging of a vforking program basically doesn't |
+ # allow the child to do things like hit a breakpoint between a |
+ # vfork and exec. This means that saying "set follow-fork |
+ # child; next" at a vfork() call won't work, because the |
+ # implementation of "next" sets a "step resume" breakpoint at |
+ # the return from the vfork(), which the child will hit on its |
+ # way to exec'ing. |
+ # |
+ verbose "vfork child-following next test ignored for pre-HP/UX-10.30 targets." |
return 0 |
} |
- send_gdb "set follow-fork child\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "set follow-fork child, vfork and exec through step"} |
- timeout {fail "set follow-fork child, vfork and exec through step"} |
- } |
- send_gdb "next\n" |
- gdb_expect { |
- -re "Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt "\ |
- {pass "vfork and exec child follow, through step"} |
- -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"} |
- timeout {fail "(timeout) vfork and exec child follow, through step" } |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork child" |
+ |
+ set test "step over vfork" |
+ if { [istarget "hppa*-*-hpux*"]} { |
+ # Since the child cannot be debugged until after it has exec'd, |
+ # and since there's a bp on "main" in the parent, and since the |
+ # bp's for the parent are recomputed in the exec'd child, the |
+ # step through a vfork should land us in the "main" for the |
+ # exec'd child, too. |
+ # |
+ set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}] |
+ gdb_test_multiple "next" $test { |
+ -re "Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " { |
+ pass "$test" |
+ } |
+ } |
+ } else { |
+ # The ideal support is to be able to debug the child even |
+ # before it execs. Thus, "next" lands on the next line after |
+ # the vfork. |
+ gdb_test_multiple "next" $test { |
+ -re "Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " { |
+ pass "$test" |
+ } |
+ } |
} |
# The parent has been detached; allow time for any output it might |
# generate to arrive, so that output doesn't get confused with |
# any expected debugger output from a subsequent testpoint. |
# |
exec sleep 1 |
- |
- # Explicitly kill this child, or a subsequent rerun actually runs |
- # the exec'd child, not the original program... |
- send_gdb "kill\n" |
- gdb_expect { |
- -re ".*Kill the program being debugged.*y or n. $" { |
- gdb_test_no_output "y" "" |
- send_gdb "file $binfile\n" |
- gdb_expect { |
- -re ".*Load new symbol table from.*y or n. $" { |
- send_gdb "y\n" |
- gdb_expect { |
- -re "Reading symbols from.*$gdb_prompt $" {} |
- timeout { fail "loading symbols (timeout)"; return } |
- } |
- } |
- -re ".*gdb_prompt $" {} |
- timeout { fail "loading symbols (timeout)"; return } |
- } |
- } |
- -re ".*$gdb_prompt $" {} |
- timeout { fail "killing inferior (timeout)" ; return } |
- } |
-} |
+}} |
proc tcatch_vfork_then_parent_follow {} { |
+ with_test_prefix "vfork parent follow, finish after tcatch vfork" { |
global gdb_prompt |
global srcfile |
- send_gdb "set follow-fork parent\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "set follow-fork parent, tcatch vfork"} |
- timeout {fail "set follow-fork parent, tcatch vfork"} |
- } |
- send_gdb "tcatch vfork\n" |
- gdb_expect { |
- -re "Catchpoint .*(vfork).*$gdb_prompt $"\ |
- {pass "vfork parent follow, set tcatch vfork"} |
- -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"} |
- timeout {fail "(timeout) vfork parent follow, set tcatch vfork"} |
- } |
- send_gdb "continue\n" |
-# HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs |
-# stop you in "_vfork". |
- gdb_expect { |
- -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\ |
- {pass "vfork parent follow, tcatch vfork"} |
- -re "vfork \\(\\) at.*$gdb_prompt "\ |
- {pass "vfork parent follow, tcatch vfork"} |
- -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"} |
- timeout {fail "(timeout) vfork parent follow, tcatch vfork"} |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork parent" |
+ |
+ gdb_test "tcatch vfork" "Catchpoint .*(vfork).*" |
+ |
+ # HP-UX 10.20 seems to stop you in "vfork", while more recent |
+ # HP-UXs stop you in "_vfork". |
+ set test "continue to vfork" |
+ gdb_test_multiple "continue" $test { |
+ -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt " { |
+ pass $test |
+ } |
+ -re "vfork \\(\\) at.*$gdb_prompt " { |
+ pass $test |
+ } |
} |
- send_gdb "finish\n" |
- gdb_expect { |
- -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:12.*$gdb_prompt "\ |
- {pass "vfork parent follow, finish after tcatch vfork"} |
+ |
+ set linenum [gdb_get_line_number "pid = vfork ();"] |
+ set test "finish" |
+ gdb_test_multiple "finish" $test { |
+ -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:${linenum}.*$gdb_prompt " { |
+ pass $test |
+ } |
-re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " { |
send_gdb "finish\n" |
exp_continue |
} |
- -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"} |
- timeout {fail "(timeout) vfork parent follow, finish after tcatch vfork" } |
} |
# The child has been detached; allow time for any output it might |
# generate to arrive, so that output doesn't get confused with |
# any expected debugger output from a subsequent testpoint. |
# |
exec sleep 1 |
-} |
+}} |
-proc tcatch_vfork_then_child_follow {} { |
+proc tcatch_vfork_then_child_follow_exec {} { |
+ with_test_prefix "vfork child follow, finish after tcatch vfork" { |
global gdb_prompt |
global srcfile |
global srcfile2 |
- send_gdb "set follow-fork child\n" |
- gdb_expect { |
- -re "$gdb_prompt $" {pass "set follow-fork child, tcatch vfork"} |
- timeout {fail "set follow-fork child, tcatch vfork"} |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork child" |
+ |
+ gdb_test "tcatch vfork" "Catchpoint .*(vfork).*" |
+ |
+ # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs |
+ # stop you in "_vfork". |
+ set test "continue to vfork" |
+ gdb_test_multiple "continue" $test { |
+ -re "vfork \\(\\) at .*$gdb_prompt $" { |
+ pass $test |
+ } |
+ -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt " { |
+ pass $test |
+ } |
} |
- send_gdb "tcatch vfork\n" |
- gdb_expect { |
- -re "Catchpoint .*(vfork).*$gdb_prompt $"\ |
- {pass "vfork child follow, set tcatch vfork"} |
- -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"} |
- timeout {fail "(timeout) vfork child follow, set tcatch vfork"} |
+ |
+ set linenum1 [gdb_get_line_number "pid = vfork ();"] |
+ set linenum2 [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}] |
+ |
+ set test "finish" |
+ gdb_test_multiple "finish" $test { |
+ -re "Run till exit from.*vfork.*${srcfile}:${linenum1}.*$gdb_prompt " { |
+ pass $test |
+ } |
+ -re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " { |
+ send_gdb "finish\n" |
+ exp_continue |
+ } |
+ -re "Run till exit from.*vfork.*${srcfile2}:${linenum2}.*$gdb_prompt " { |
+ pass "$test (followed exec)" |
+ } |
} |
- send_gdb "continue\n" |
-# HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs |
-# stop you in "_vfork". |
- gdb_expect { |
- -re "vfork \\(\\) at .*$gdb_prompt $"\ |
- {pass "vfork child follow, tcatch vfork"} |
- -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt "\ |
- {pass "vfork child follow, tcatch vfork"} |
- -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"} |
- timeout {fail "(timeout) vfork child follow, tcatch vfork"} |
+ # The parent has been detached; allow time for any output it might |
+ # generate to arrive, so that output doesn't get confused with |
+ # any expected debugger output from a subsequent testpoint. |
+ # |
+ exec sleep 1 |
+}} |
+ |
+proc tcatch_vfork_then_child_follow_exit {} { |
+ with_test_prefix "vfork child follow, finish after tcatch vfork" { |
+ global gdb_prompt |
+ global srcfile |
+ |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork child" |
+ |
+ gdb_test "tcatch vfork" "Catchpoint .*(vfork).*" |
+ |
+ # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs |
+ # stop you in "_vfork". |
+ set test "continue to vfork" |
+ gdb_test_multiple "continue" $test { |
+ -re "vfork \\(\\) at .*$gdb_prompt $" { |
+ pass $test |
+ } |
+ -re "0x\[0-9a-fA-F\]*.*(vfork|__kernel_v?syscall).*$gdb_prompt " { |
+ pass $test |
+ } |
} |
- send_gdb "finish\n" |
- gdb_expect { |
- -re "Run till exit from.*vfork.*${srcfile}:12.*$gdb_prompt "\ |
- {pass "vfork child follow, finish after tcatch vfork"} |
+ |
+ set test "finish" |
+ gdb_test_multiple "finish" $test { |
+ -re "Run till exit from.*vfork.*exited normally.*$gdb_prompt " { |
+ setup_kfail "gdb/14762" *-*-* |
+ fail $test |
+ } |
+ -re "Run till exit from.*vfork.*pid = vfork \\(\\).*$gdb_prompt " { |
+ pass $test |
+ } |
-re "Run till exit from.*__kernel_v?syscall.*0x\[0-9a-fA-F\]* in vfork .*$gdb_prompt " { |
send_gdb "finish\n" |
exp_continue |
} |
- -re "Run till exit from.*vfork.*${srcfile2}:9.*$gdb_prompt "\ |
- {pass "vfork child follow, finish after tcatch vfork (followed exec)"} |
- -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"} |
- timeout {fail "(timeout) vfork child follow, finish after tcatch vfork" } |
} |
# The parent has been detached; allow time for any output it might |
# generate to arrive, so that output doesn't get confused with |
# any expected debugger output from a subsequent testpoint. |
# |
exec sleep 1 |
-} |
+}} |
-proc do_vfork_and_exec_tests {} { |
+proc vfork_relations_in_info_inferiors { variant } { |
+ with_test_prefix "vfork relations in info inferiors" { |
global gdb_prompt |
- # Check that vfork catchpoints are supported, as an indicator for whether |
- # vfork-following is supported. |
- if [runto_main] then { check_vfork_catchpoints } |
+ setup_gdb |
+ |
+ gdb_test_no_output "set follow-fork child" |
+ |
+ set test "step over vfork" |
+ gdb_test_multiple "next" $test { |
+ -re "Attaching after .* vfork to child.*if \\(pid == 0\\).*$gdb_prompt " { |
+ pass "$test" |
+ } |
+ } |
+ |
+ gdb_test "info inferiors" \ |
+ ".*is vfork child of inferior 1.*is vfork parent of inferior 2" \ |
+ "info inferiors shows vfork parent/child relation" |
+ |
+ if { $variant == "exec" } { |
+ global srcfile2 |
+ |
+ set linenum [gdb_get_line_number "printf(\"Hello from vforked-prog" ${srcfile2}] |
+ set test "continue to bp" |
+ gdb_test_multiple "continue" $test { |
+ -re ".*xecuting new program.*Breakpoint.*vforked-prog.c:${linenum}.*$gdb_prompt " { |
+ pass $test |
+ } |
+ } |
+ } else { |
+ set test "continue to child exit" |
+ gdb_test_multiple "continue" $test { |
+ -re "exited normally.*$gdb_prompt " { |
+ pass $test |
+ } |
+ } |
+ } |
+ |
+ set test "vfork relation no longer appears in info inferiors" |
+ gdb_test_multiple "info inferiors" $test { |
+ -re "is vfork child of inferior 1.*$gdb_prompt $" { |
+ fail $test |
+ } |
+ -re "is vfork parent of inferior 2.*$gdb_prompt $" { |
+ fail $test |
+ } |
+ -re "$gdb_prompt $" { |
+ pass $test |
+ } |
+ } |
+}} |
+ |
+proc do_vfork_and_follow_parent_tests {} { |
+ global gdb_prompt |
# Try following the parent process by stepping through a call to |
# vfork. Do this without catchpoints. |
- if [runto_main] then { vfork_parent_follow_through_step } |
+ vfork_parent_follow_through_step |
# Try following the parent process by setting a breakpoint on the |
# other side of a vfork, and running to that point. Do this |
# without catchpoints. |
- if [runto_main] then { vfork_parent_follow_to_bp } |
+ vfork_parent_follow_to_bp |
+ |
+ # Try catching a vfork, and stepping out to the parent. |
+ # |
+ tcatch_vfork_then_parent_follow |
+} |
+proc do_vfork_and_follow_child_tests_exec {} { |
# Try following the child process by just continuing through the |
# vfork, and letting the parent's breakpoint on "main" be auto- |
# magically reset in the child. |
# |
- if [runto_main] then { vfork_and_exec_child_follow_to_main_bp } |
+ vfork_and_exec_child_follow_to_main_bp |
# Try following the child process by stepping through a call to |
# vfork. The child also executes an exec. Since the child cannot |
@@ -362,15 +475,11 @@ proc do_vfork_and_exec_tests {} { |
# recomputed in the exec'd child, the step through a vfork should |
# land us in the "main" for the exec'd child, too. |
# |
- if [runto_main] then { vfork_and_exec_child_follow_through_step } |
- |
- # Try catching a vfork, and stepping out to the parent. |
- # |
- if [runto_main] then { tcatch_vfork_then_parent_follow } |
+ vfork_and_exec_child_follow_through_step |
# Try catching a vfork, and stepping out to the child. |
# |
- if [runto_main] then { tcatch_vfork_then_child_follow } |
+ tcatch_vfork_then_child_follow_exec |
# Test the ability to follow both child and parent of a vfork. Do |
# this without catchpoints. |
@@ -382,24 +491,76 @@ proc do_vfork_and_exec_tests {} { |
# catchpoints. |
# ??rehrauer: NYI. Will add testpoints here when implemented. |
# |
+ |
+ # Step over a vfork in the child, do "info inferiors" and check the |
+ # parent/child relation is displayed. Run the child over the exec, |
+ # and confirm the relation is no longer displayed in "info |
+ # inferiors". |
+ # |
+ vfork_relations_in_info_inferiors "exec" |
+} |
+ |
+proc do_vfork_and_follow_child_tests_exit {} { |
+ # Try following the child process by just continuing through the |
+ # vfork, and letting the child exit. |
+ # |
+ vfork_child_follow_to_exit |
+ |
+ # Try catching a vfork, and stepping out to the child. |
+ # |
+ tcatch_vfork_then_child_follow_exit |
+ |
+ # Step over a vfork in the child, do "info inferiors" and check the |
+ # parent/child relation is displayed. Run the child to completion, |
+ # and confirm the relation is no longer displayed in "info |
+ # inferiors". |
+ # |
+ vfork_relations_in_info_inferiors "exit" |
} |
-# Start with a fresh gdb |
+with_test_prefix "check vfork support" { |
+ # Check that vfork catchpoints are supported, as an indicator for |
+ # whether vfork-following is supported. |
+ check_vfork_catchpoints |
+} |
-gdb_exit |
-gdb_start |
-gdb_reinitialize_dir $srcdir/$subdir |
-gdb_load ${binfile} |
+# Follow parent and follow child vfork tests with a child that execs. |
+with_test_prefix "exec" { |
+ # These are tests of gdb's ability to follow the parent of a Unix |
+ # vfork system call. The child will subsequently call a variant |
+ # of the Unix exec system call. |
+ do_vfork_and_follow_parent_tests |
+ |
+ # These are tests of gdb's ability to follow the child of a Unix |
+ # vfork system call. The child will subsequently call a variant |
+ # of a Unix exec system call. |
+ # |
+ do_vfork_and_follow_child_tests_exec |
+} |
-# The "Detaching..." and "Attaching..." messages may be hidden by |
-# default. |
-gdb_test_no_output "set verbose" |
+# Switch to test the case of the child exiting. We can't use |
+# standard_testfile here because we don't want to overwrite the binary |
+# of the previous tests. |
+set testfile "foll-vfork-exit" |
+set srcfile ${testfile}.c |
+set binfile [standard_output_file ${testfile}] |
-# This is a test of gdb's ability to follow the parent or child |
-# of a Unix vfork() system call. (The child will subsequently |
-# call a variant of a Unix exec() system call.) |
-# |
-do_vfork_and_exec_tests |
+if {[build_executable $testfile.exp $testfile $srcfile] == -1} { |
+ untested "failed to build $testfile" |
+ return |
+} |
+ |
+# Follow parent and follow child vfork tests with a child that exits. |
+with_test_prefix "exit" { |
+ # These are tests of gdb's ability to follow the parent of a Unix |
+ # vfork system call. The child will subsequently exit. |
+ do_vfork_and_follow_parent_tests |
+ |
+ # These are tests of gdb's ability to follow the child of a Unix |
+ # vfork system call. The child will subsequently exit. |
+ # |
+ do_vfork_and_follow_child_tests_exit |
+} |
set timeout $oldtimeout |
return 0 |