# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>. */
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
-
-if $tracelevel then {
- strace $tracelevel
- }
-
-if { ![isnative] } then {
+if { [is_remote target] || ![isnative] } then {
continue
}
set prms_id 0
set bug_id 0
+global srcfile
set testfile "foll-fork"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
# Until "set follow-fork-mode" and "catch fork" are implemented on
# other targets...
#
-if ![istarget "hppa*-hp-hpux*"] then {
+if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
continue
}
+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
+ }
+}
+
proc default_fork_parent_follow {} {
global gdb_prompt
}
send_gdb "next 2\n"
gdb_expect {
- -re "Detaching from program:.*Attaching after fork to.*$gdb_prompt $"\
+ -re "Attaching after fork to.*$gdb_prompt $"\
{pass "explicit child follow, no catchpoints"}
-re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
timeout {fail "(timeout) explicit child follow, no catchpoints"}
proc catch_fork_child_follow {} {
global gdb_prompt
+ global srcfile
send_gdb "catch fork\n"
gdb_expect {
send_gdb "continue\n"
gdb_expect {
- -re "Catchpoint.*(forked process.*),.*in _fork_sys.*$gdb_prompt $"\
+ -re "Catchpoint.*(forked process.*),.*in .*fork.*$gdb_prompt $"\
{pass "explicit child follow, catch fork"}
-re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
timeout {fail "(timeout) explicit child follow, catch fork"}
-re "$gdb_prompt $" {pass "set follow child"}
timeout {fail "(timeout) set follow child"}
}
- send_gdb "tbreak 24\n"
+ send_gdb "tbreak ${srcfile}:24\n"
gdb_expect {
-re "Breakpoint.*, line 24.*$gdb_prompt $"\
{pass "set follow child, tbreak"}
}
send_gdb "continue\n"
gdb_expect {
- -re ".*Detaching from program:.*Attaching after fork to.* at .*24.*$gdb_prompt $"\
+ -re "Attaching after fork to.* at .*24.*$gdb_prompt $"\
{pass "set follow child, hit tbreak"}
-re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
timeout {fail "(timeout) set follow child, hit tbreak"}
proc tcatch_fork_parent_follow {} {
global gdb_prompt
+ global srcfile
send_gdb "catch fork\n"
gdb_expect {
send_gdb "continue\n"
gdb_expect {
- -re ".*in _fork_sys.*$gdb_prompt $"\
+ -re ".*in .*fork.*$gdb_prompt $"\
{pass "explicit parent follow, tcatch fork"}
-re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
timeout {fail "(timeout) explicit parent follow, tcatch fork"}
-re "$gdb_prompt $" {pass "set follow parent"}
timeout {fail "(timeout) set follow parent"}
}
- send_gdb "tbreak 24\n"
+ send_gdb "tbreak ${srcfile}:24\n"
gdb_expect {
-re "Breakpoint.*, line 24.*$gdb_prompt $"\
{pass "set follow parent, tbreak"}
timeout {fail "set follow to nonsense is prohibited (reset parent)"}
}
+ # Check that fork catchpoints are supported, as an indicator for whether
+ # fork-following is supported.
+ if [runto_main] then { check_fork_catchpoints }
+
# Test the default behaviour, which is to follow the parent of a
# fork, and detach from the child. Do this without catchpoints.
#
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
+# The "Detaching..." and "Attaching..." messages may be hidden by
+# default.
+gdb_test "set verbose" ""
# This is a test of gdb's ability to follow the parent, child or both
# parent and child of a Unix fork() system call.