2009-01-03 13:58:08 +08:00
|
|
|
# Copyright 1997, 1999, 2007, 2008, 2009 Free Software Foundation, Inc.
|
1999-06-29 07:04:32 +08:00
|
|
|
|
|
|
|
# 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
|
2007-08-24 02:14:19 +08:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
1999-06-29 07:04:32 +08:00
|
|
|
# (at your option) any later version.
|
2007-08-24 02:14:19 +08:00
|
|
|
#
|
1999-06-29 07:04:32 +08:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2007-08-24 02:14:19 +08:00
|
|
|
#
|
1999-06-29 07:04:32 +08:00
|
|
|
# You should have received a copy of the GNU General Public License
|
2008-01-30 06:47:20 +08:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1999-06-29 07:04:32 +08:00
|
|
|
|
2008-01-30 06:47:20 +08:00
|
|
|
if { [is_remote target] || ![isnative] } then {
|
1999-07-27 08:51:29 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
1999-06-29 07:04:32 +08:00
|
|
|
set prms_id 0
|
|
|
|
set bug_id 0
|
|
|
|
|
2008-01-30 06:47:20 +08:00
|
|
|
global srcfile
|
1999-06-29 07:04:32 +08:00
|
|
|
set testfile "foll-fork"
|
|
|
|
set srcfile ${testfile}.c
|
|
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
|
|
|
|
|
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
|
2006-08-10 13:27:22 +08:00
|
|
|
untested foll-fork.exp
|
|
|
|
return -1
|
1999-06-29 07:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Until "set follow-fork-mode" and "catch fork" are implemented on
|
|
|
|
# other targets...
|
|
|
|
#
|
2008-01-30 06:47:20 +08:00
|
|
|
if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
|
1999-06-29 07:04:32 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2008-01-30 06:47:20 +08:00
|
|
|
proc check_fork_catchpoints {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
# Verify that the system supports "catch fork".
|
|
|
|
gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint"
|
|
|
|
set has_fork_catchpoints 0
|
|
|
|
gdb_test_multiple "continue" "continue to first fork catchpoint" {
|
|
|
|
-re ".*Your system does not support fork catchpoints.*$gdb_prompt $" {
|
|
|
|
unsupported "continue to first fork catchpoint"
|
|
|
|
}
|
|
|
|
-re ".*Catchpoint.*$gdb_prompt $" {
|
|
|
|
set has_fork_catchpoints 1
|
|
|
|
pass "continue to first fork catchpoint"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if {$has_fork_catchpoints == 0} {
|
|
|
|
unsupported "fork catchpoints"
|
|
|
|
return -code return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-29 07:04:32 +08:00
|
|
|
proc default_fork_parent_follow {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
send_gdb "show follow\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
|
|
|
|
{pass "default show parent follow, no catchpoints"}
|
|
|
|
-re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
|
|
|
|
timeout {fail "(timeout) default show parent follow, no catchpoints"}
|
|
|
|
}
|
|
|
|
send_gdb "next 2\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Detaching after fork from.*$gdb_prompt $"\
|
|
|
|
{pass "default parent follow, no catchpoints"}
|
|
|
|
-re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
|
|
|
|
timeout {fail "(timeout) default parent follow, no catchpoints" }
|
|
|
|
}
|
|
|
|
# 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 explicit_fork_parent_follow {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
send_gdb "set follow parent\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $" {pass "set follow parent"}
|
|
|
|
timeout {fail "(timeout) set follow parent"}
|
|
|
|
}
|
|
|
|
send_gdb "show follow\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
|
|
|
|
{pass "explicit show parent follow, no catchpoints"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
|
|
|
|
timeout {fail "(timeout) explicit show parent follow, no catchpoints"}
|
|
|
|
}
|
|
|
|
send_gdb "next 2\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Detaching after fork from.*$gdb_prompt $"\
|
|
|
|
{pass "explicit parent follow, no catchpoints"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
|
|
|
|
timeout {fail "(timeout) explicit parent follow, no catchpoints"}
|
|
|
|
}
|
|
|
|
# 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 explicit_fork_child_follow {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
send_gdb "set follow child\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $" {pass "set follow child"}
|
|
|
|
timeout {fail "(timeout) set follow child"}
|
|
|
|
}
|
|
|
|
send_gdb "show follow\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
|
|
|
|
{pass "explicit show child follow, no catchpoints"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
|
|
|
|
timeout {fail "(timeout) explicit show child follow, no catchpoints"}
|
|
|
|
}
|
|
|
|
send_gdb "next 2\n"
|
|
|
|
gdb_expect {
|
2008-01-30 06:47:20 +08:00
|
|
|
-re "Attaching after fork to.*$gdb_prompt $"\
|
1999-06-29 07:04:32 +08:00
|
|
|
{pass "explicit child follow, no catchpoints"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
|
|
|
|
timeout {fail "(timeout) explicit child follow, no catchpoints"}
|
|
|
|
}
|
|
|
|
# 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 catch_fork_child_follow {} {
|
|
|
|
global gdb_prompt
|
2008-01-30 06:47:20 +08:00
|
|
|
global srcfile
|
1999-06-29 07:04:32 +08:00
|
|
|
|
|
|
|
send_gdb "catch fork\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Catchpoint .*(fork).*$gdb_prompt $"\
|
|
|
|
{pass "explicit child follow, set catch fork"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
|
|
|
|
timeout {fail "(timeout) explicit child follow, set catch fork"}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that the catchpoint is mentioned in an "info breakpoints",
|
|
|
|
# and further that the catchpoint mentions no process id.
|
|
|
|
#
|
2008-10-17 00:25:37 +08:00
|
|
|
set test_name "info shows catchpoint without pid"
|
|
|
|
gdb_test_multiple "info breakpoints" "$test_name" {
|
|
|
|
-re ".*catchpoint.*keep y.*fork\[\r\n\]+$gdb_prompt $" {
|
|
|
|
pass "$test_name"
|
|
|
|
}
|
1999-06-29 07:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
send_gdb "continue\n"
|
|
|
|
gdb_expect {
|
2008-11-21 01:17:59 +08:00
|
|
|
-re "Catchpoint.*(forked process.*),.*in .*(fork|__kernel_v?syscall).*$gdb_prompt $"\
|
1999-06-29 07:04:32 +08:00
|
|
|
{pass "explicit child follow, catch fork"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
|
|
|
|
timeout {fail "(timeout) explicit child follow, catch fork"}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that the catchpoint is mentioned in an "info breakpoints",
|
|
|
|
# and further that the catchpoint managed to capture a process id.
|
|
|
|
#
|
2008-10-17 00:25:37 +08:00
|
|
|
set test_name "info shows catchpoint without pid"
|
|
|
|
gdb_test_multiple "info breakpoints" "$test_name" {
|
|
|
|
-re ".*catchpoint.*keep y.*fork, process.*$gdb_prompt $" {
|
|
|
|
pass "$test_name"
|
|
|
|
}
|
1999-06-29 07:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
send_gdb "set follow child\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $" {pass "set follow child"}
|
|
|
|
timeout {fail "(timeout) set follow child"}
|
|
|
|
}
|
2008-01-30 06:47:20 +08:00
|
|
|
send_gdb "tbreak ${srcfile}:24\n"
|
1999-06-29 07:04:32 +08:00
|
|
|
gdb_expect {
|
2008-04-15 22:33:55 +08:00
|
|
|
-re "Temporary breakpoint.*, line 24.*$gdb_prompt $"\
|
1999-06-29 07:04:32 +08:00
|
|
|
{pass "set follow child, tbreak"}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow child, tbreak"}
|
|
|
|
timeout {fail "(timeout) set follow child, tbreak"}
|
|
|
|
}
|
|
|
|
send_gdb "continue\n"
|
|
|
|
gdb_expect {
|
2008-01-30 06:47:20 +08:00
|
|
|
-re "Attaching after fork to.* at .*24.*$gdb_prompt $"\
|
1999-06-29 07:04:32 +08:00
|
|
|
{pass "set follow child, hit tbreak"}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
|
|
|
|
timeout {fail "(timeout) set follow child, hit tbreak"}
|
|
|
|
}
|
|
|
|
# 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
|
|
|
|
send_gdb "delete breakpoints\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Delete all breakpoints.*$" {
|
|
|
|
send_gdb "y\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $"\
|
|
|
|
{pass "set follow child, cleanup"}
|
|
|
|
timeout {fail "(timeout) set follow child, cleanup"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow child, cleanup"}
|
|
|
|
timeout {fail "(timeout) set follow child, cleanup"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc tcatch_fork_parent_follow {} {
|
|
|
|
global gdb_prompt
|
2008-01-30 06:47:20 +08:00
|
|
|
global srcfile
|
1999-06-29 07:04:32 +08:00
|
|
|
|
|
|
|
send_gdb "catch fork\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Catchpoint .*(fork).*$gdb_prompt $"\
|
|
|
|
{pass "explicit parent follow, set tcatch fork"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
|
|
|
|
timeout {fail "(timeout) explicit parent follow, set tcatch fork"}
|
|
|
|
}
|
|
|
|
# ??rehrauer: I don't yet know how to get the id of the tcatch
|
|
|
|
# via this script, so that I can add a -do list to it. For now,
|
|
|
|
# do the follow stuff after the catch happens.
|
|
|
|
|
|
|
|
send_gdb "continue\n"
|
|
|
|
gdb_expect {
|
2008-11-21 01:17:59 +08:00
|
|
|
-re ".*in .*(fork|__kernel_v?syscall).*$gdb_prompt $"\
|
1999-06-29 07:04:32 +08:00
|
|
|
{pass "explicit parent follow, tcatch fork"}
|
|
|
|
-re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
|
|
|
|
timeout {fail "(timeout) explicit parent follow, tcatch fork"}
|
|
|
|
}
|
|
|
|
send_gdb "set follow parent\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $" {pass "set follow parent"}
|
|
|
|
timeout {fail "(timeout) set follow parent"}
|
|
|
|
}
|
2008-01-30 06:47:20 +08:00
|
|
|
send_gdb "tbreak ${srcfile}:24\n"
|
1999-06-29 07:04:32 +08:00
|
|
|
gdb_expect {
|
2008-04-15 22:33:55 +08:00
|
|
|
-re "Temporary breakpoint.*, line 24.*$gdb_prompt $"\
|
1999-06-29 07:04:32 +08:00
|
|
|
{pass "set follow parent, tbreak"}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow parent, tbreak"}
|
|
|
|
timeout {fail "(timeout) set follow child, tbreak"}
|
|
|
|
}
|
|
|
|
send_gdb "continue\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re ".*Detaching after fork from.* at .*24.*$gdb_prompt $"\
|
|
|
|
{pass "set follow parent, hit tbreak"}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow parent, hit tbreak"}
|
|
|
|
timeout {fail "(timeout) set follow parent, hit tbreak"}
|
|
|
|
}
|
|
|
|
# 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
|
|
|
|
send_gdb "delete breakpoints\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Delete all breakpoints.*$" {
|
|
|
|
send_gdb "y\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $"\
|
|
|
|
{pass "set follow parent, cleanup"}
|
|
|
|
timeout {fail "(timeout) set follow parent, cleanup"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow parent, cleanup"}
|
|
|
|
timeout {fail "(timeout) set follow parent, cleanup"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_fork_tests {} {
|
|
|
|
global gdb_prompt
|
|
|
|
|
|
|
|
# Verify that help is available for "set follow-fork-mode".
|
|
|
|
#
|
|
|
|
send_gdb "help set follow-fork-mode\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Set debugger response to a program call of fork or vfork..*
|
|
|
|
A fork or vfork creates a new process. follow-fork-mode can be:.*
|
|
|
|
.*parent - the original process is debugged after a fork.*
|
|
|
|
.*child - the new process is debugged after a fork.*
|
2004-04-05 04:28:21 +08:00
|
|
|
The unfollowed process will continue to run..*
|
1999-06-29 07:04:32 +08:00
|
|
|
By default, the debugger will follow the parent process..*$gdb_prompt $"\
|
|
|
|
{ pass "help set follow" }
|
|
|
|
-re "$gdb_prompt $" { fail "help set follow" }
|
|
|
|
timeout { fail "(timeout) help set follow" }
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we can set follow-fork-mode, using an abbreviation
|
|
|
|
# for both the flag and its value.
|
|
|
|
#
|
|
|
|
send_gdb "set follow ch\n"
|
|
|
|
send_gdb "show fol\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
|
|
|
|
{pass "set follow, using abbreviations"}
|
|
|
|
timeout {fail "(timeout) set follow, using abbreviations"}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify that we cannot set follow-fork-mode to nonsense.
|
|
|
|
#
|
|
|
|
send_gdb "set follow chork\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "Undefined item: \"chork\".*$gdb_prompt $"\
|
|
|
|
{pass "set follow to nonsense is prohibited"}
|
|
|
|
-re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
|
|
|
|
timeout {fail "(timeout) set follow to nonsense is prohibited"}
|
|
|
|
}
|
|
|
|
send_gdb "set follow parent\n"
|
|
|
|
gdb_expect {
|
|
|
|
-re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
|
|
|
|
timeout {fail "set follow to nonsense is prohibited (reset parent)"}
|
|
|
|
}
|
|
|
|
|
2008-01-30 06:47:20 +08:00
|
|
|
# Check that fork catchpoints are supported, as an indicator for whether
|
|
|
|
# fork-following is supported.
|
|
|
|
if [runto_main] then { check_fork_catchpoints }
|
|
|
|
|
1999-06-29 07:04:32 +08:00
|
|
|
# Test the default behaviour, which is to follow the parent of a
|
|
|
|
# fork, and detach from the child. Do this without catchpoints.
|
|
|
|
#
|
|
|
|
if [runto_main] then { default_fork_parent_follow }
|
|
|
|
|
|
|
|
# Test the ability to explicitly follow the parent of a fork, and
|
|
|
|
# detach from the child. Do this without catchpoints.
|
|
|
|
#
|
|
|
|
if [runto_main] then { explicit_fork_parent_follow }
|
|
|
|
|
|
|
|
# Test the ability to follow the child of a fork, and detach from
|
|
|
|
# the parent. Do this without catchpoints.
|
|
|
|
#
|
|
|
|
if [runto_main] then { explicit_fork_child_follow }
|
|
|
|
|
|
|
|
# Test the ability to follow both child and parent of a fork. Do
|
|
|
|
# this without catchpoints.
|
|
|
|
# ??rehrauer: NYI. Will add testpoints here when implemented.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test the ability to have the debugger ask the user at fork-time
|
|
|
|
# whether to follow the parent, child or both. Do this without
|
|
|
|
# catchpoints.
|
|
|
|
# ??rehrauer: NYI. Will add testpoints here when implemented.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test the ability to catch a fork, specify that the child be
|
|
|
|
# followed, and continue. Make the catchpoint permanent.
|
|
|
|
#
|
|
|
|
if [runto_main] then { catch_fork_child_follow }
|
|
|
|
|
|
|
|
# Test the ability to catch a fork, specify via a -do clause that
|
|
|
|
# the parent be followed, and continue. Make the catchpoint temporary.
|
|
|
|
#
|
|
|
|
if [runto_main] then { tcatch_fork_parent_follow }
|
|
|
|
}
|
|
|
|
|
|
|
|
# Start with a fresh gdb
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
gdb_load ${binfile}
|
|
|
|
|
2008-01-30 06:47:20 +08:00
|
|
|
# The "Detaching..." and "Attaching..." messages may be hidden by
|
|
|
|
# default.
|
|
|
|
gdb_test "set verbose" ""
|
1999-06-29 07:04:32 +08:00
|
|
|
|
|
|
|
# This is a test of gdb's ability to follow the parent, child or both
|
|
|
|
# parent and child of a Unix fork() system call.
|
|
|
|
#
|
|
|
|
do_fork_tests
|
|
|
|
|
|
|
|
return 0
|