1 # Copyright
2005, 2006 Free Software Foundation
, Inc.
3 # This
program is free software
; you can redistribute it and
/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation
; either version
2 of the License
, or
6 #
(at your option
) any later version.
8 # This
program is distributed in the hope that it will be useful
,
9 # but WITHOUT
ANY WARRANTY
; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License
for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this
program; if not
, write to the Free Software
15 # Foundation
, Inc.
, 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA.
21 if { ![isnative
] } then {
25 # Until
"set follow-fork-mode" and "catch fork" are implemented on
28 if {![istarget
"hppa*-hp-hpux*"] && ![istarget "*-*-linux*"]} then {
35 set testfile
"multi-forks"
36 set srcfile $
{testfile
}.c
37 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
39 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
43 # Start with a fresh gdb
47 gdb_reinitialize_dir $srcdir
/$subdir
52 # This is a test of gdb
's ability to follow the parent, child or both
53 # parent and child of multiple Unix fork() system calls.
56 # Inferior program calls fork 4 times. Since each fork
57 # calls fork 4 times, there will be 16 forks. Each fork
58 # saves the return values of its own 4 fork calls.
60 # First set gdb to follow the child.
61 # The result should be that each of the 4 forks returns zero.
64 set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
65 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
66 gdb_test "set follow child" "" ""
70 -re ".*Break.* main .*$gdb_prompt.*$" {}
71 -re ".*$gdb_prompt $" {fail "run to exit 1"}
72 default {fail "run to exit 1 (timeout)"}
75 gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
77 # Now set gdb to follow the parent.
78 # Result should be that none of the 4 forks returns zero.
82 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
83 gdb_test "set follow parent" "" ""
87 -re ".*Break.* main .*$gdb_prompt.*$" {}
88 -re ".*$gdb_prompt $" {fail "run to exit 2"}
89 default {fail "run to exit 2 (timeout)"}
92 gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
93 " = 0" "follow parent, print pids"
96 # Now test with detach-on-fork off.
100 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" ""
102 gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
105 gdb_test "show detach-on-fork" "on." "show detach default on"
107 gdb_test "set detach off" "" "set detach off"
110 # We will now run every fork up to the exit bp,
111 # eventually winding up with 16 forks.
114 for {set i 1} {$i <= 15} {incr i} {
115 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit $i"
116 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork $i"
117 gdb_test "restart $i" "(_dl_sysinfo_int80|fork).*" "restart $i"
120 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
121 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 16"
122 gdb_test "restart 0" " main .*" "restart final"
125 # Now we should examine all the pids.
132 # [assumes we're at #
0]
133 gdb_test
"detach-fork 1" "Detached .*" "Detach 1"
134 gdb_test
"detach-fork 2" "Detached .*" "Detach 2"
135 gdb_test
"detach-fork 3" "Detached .*" "Detach 3"
136 gdb_test
"detach-fork 4" "Detached .*" "Detach 4"
142 gdb_test
"delete fork 5" "" "Delete 5"
143 gdb_test
"info fork 5" "No fork number 5." "Did delete 5"
144 gdb_test
"delete fork 6" "" "Delete 6"
145 gdb_test
"info fork 6" "No fork number 6." "Did delete 6"
146 gdb_test
"delete fork 7" "" "Delete 7"
147 gdb_test
"info fork 7" "No fork number 7." "Did delete 7"
148 gdb_test
"delete fork 8" "" "Delete 8"
149 gdb_test
"info fork 8" "No fork number 8." "Did delete 8"
150 gdb_test
"delete fork 9" "" "Delete 9"
151 gdb_test
"info fork 9" "No fork number 9." "Did delete 9"
152 gdb_test
"delete fork 10" "" "Delete 10"
153 gdb_test
"info fork 10" "No fork number 10." "Did delete 10"
154 gdb_test
"delete fork 11" "" "Delete 11"
155 gdb_test
"info fork 11" "No fork number 11." "Did delete 11"
156 gdb_test
"delete fork 12" "" "Delete 12"
157 gdb_test
"info fork 12" "No fork number 12." "Did delete 12"
158 gdb_test
"delete fork 13" "" "Delete 13"
159 gdb_test
"info fork 13" "No fork number 13." "Did delete 13"
160 gdb_test
"delete fork 14" "" "Delete 14"
161 gdb_test
"info fork 14" "No fork number 14." "Did delete 14"
162 gdb_test
"delete fork 15" "" "Delete 15"
163 gdb_test
"info fork 15" "No fork number 15." "Did delete 15"