]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/multi-forks.exp
* gdb.base/multi-forks.exp: Doc fix.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / multi-forks.exp
1 # Copyright 2005, 2006, 2007 Free Software Foundation, Inc.
2
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 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 if $tracelevel then {
17 strace $tracelevel
18 }
19
20 if { [is_remote target] || ![isnative] } then {
21 continue
22 }
23
24 # Until "set follow-fork-mode" and "catch fork" are implemented on
25 # other targets...
26 #
27 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-*-linux*"]} then {
28 continue
29 }
30
31 set prms_id 0
32 set bug_id 0
33
34 set testfile "multi-forks"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
39 untested multi-forks.exp
40 return -1
41 }
42
43 # Start with a fresh gdb
44
45 gdb_exit
46 gdb_start
47 gdb_reinitialize_dir $srcdir/$subdir
48 gdb_load ${binfile}
49
50 global gdb_prompt
51
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.
54 #
55
56 # The inferior program builds a tree of processes by executing a loop
57 # four times, calling fork at each iteration. Thus, at each
58 # iteration, the total number of processes doubles; after four
59 # iterations, we have 16 processes. Each process saves the results
60 # from its 'fork' calls, so we can tell which leaf a given process is
61 # by looking at which forks returned zero and which returned a pid: a
62 # zero means to take the child's branch; a pid means to take the
63 # parent's branch.
64
65 # First set gdb to follow the child.
66 # The result should be that each of the 4 forks returns zero.
67
68 runto_main
69 set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
70 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
71 gdb_test "set follow child" "" ""
72
73 send_gdb "continue\n"
74 gdb_expect {
75 -re ".*Break.* main .*$gdb_prompt.*$" {}
76 -re ".*$gdb_prompt $" {fail "run to exit 1"}
77 default {fail "run to exit 1 (timeout)"}
78 }
79
80 gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
81
82 # Now set gdb to follow the parent.
83 # Result should be that none of the 4 forks returns zero.
84
85 delete_breakpoints
86 runto_main
87 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
88 gdb_test "set follow parent" "" ""
89
90 send_gdb "continue\n"
91 gdb_expect {
92 -re ".*Break.* main .*$gdb_prompt.*$" {}
93 -re ".*$gdb_prompt $" {fail "run to exit 2"}
94 default {fail "run to exit 2 (timeout)"}
95 }
96
97 gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
98 " = 0" "follow parent, print pids"
99
100 #
101 # Now test with detach-on-fork off.
102 #
103
104 runto_main
105 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" ""
106
107 gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
108 "help set detach"
109
110 gdb_test "show detach-on-fork" "on." "show detach default on"
111
112 gdb_test "set detach off" "" "set detach off"
113
114 #
115 # We will now run every fork up to the exit bp,
116 # eventually winding up with 16 forks.
117 #
118
119 for {set i 1} {$i <= 15} {incr i} {
120 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit $i"
121 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork $i"
122 gdb_test "restart $i" "(_dl_sysinfo_int80|fork|__kernel_(v|)syscall).*" \
123 "restart $i"
124 }
125
126 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
127 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 16"
128 gdb_test "restart 0" " main .*" "restart final"
129
130 #
131 # Now we should examine all the pids.
132 #
133
134 #
135 # Test detach fork
136 #
137
138 # [assumes we're at #0]
139 gdb_test "detach fork 1" "Detached .*" "Detach 1"
140 gdb_test "detach fork 2" "Detached .*" "Detach 2"
141 gdb_test "detach fork 3" "Detached .*" "Detach 3"
142 gdb_test "detach fork 4" "Detached .*" "Detach 4"
143
144 #
145 # Test delete fork
146 #
147
148 gdb_test "delete fork 5" "" "Delete 5"
149 gdb_test "info fork 5" "No fork number 5." "Did delete 5"
150 gdb_test "delete fork 6" "" "Delete 6"
151 gdb_test "info fork 6" "No fork number 6." "Did delete 6"
152 gdb_test "delete fork 7" "" "Delete 7"
153 gdb_test "info fork 7" "No fork number 7." "Did delete 7"
154 gdb_test "delete fork 8" "" "Delete 8"
155 gdb_test "info fork 8" "No fork number 8." "Did delete 8"
156 gdb_test "delete fork 9" "" "Delete 9"
157 gdb_test "info fork 9" "No fork number 9." "Did delete 9"
158 gdb_test "delete fork 10" "" "Delete 10"
159 gdb_test "info fork 10" "No fork number 10." "Did delete 10"
160 gdb_test "delete fork 11" "" "Delete 11"
161 gdb_test "info fork 11" "No fork number 11." "Did delete 11"
162 gdb_test "delete fork 12" "" "Delete 12"
163 gdb_test "info fork 12" "No fork number 12." "Did delete 12"
164 gdb_test "delete fork 13" "" "Delete 13"
165 gdb_test "info fork 13" "No fork number 13." "Did delete 13"
166 gdb_test "delete fork 14" "" "Delete 14"
167 gdb_test "info fork 14" "No fork number 14." "Did delete 14"
168 gdb_test "delete fork 15" "" "Delete 15"
169 gdb_test "info fork 15" "No fork number 15." "Did delete 15"
170
171 return 0
172