]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/multi-forks.exp
2006-01-04 Michael Snyder <msnyder@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / multi-forks.exp
1 # Copyright 2005 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 if { ![isnative] } then {
25 continue
26 }
27
28 # Until "set follow-fork-mode" and "catch fork" are implemented on
29 # other targets...
30 #
31 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-*-linux*"]} then {
32 continue
33 }
34
35 set prms_id 0
36 set bug_id 0
37
38 set testfile "multi-forks"
39 set srcfile ${testfile}.c
40 set binfile ${objdir}/${subdir}/${testfile}
41
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
43 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44 }
45
46 # Start with a fresh gdb
47
48 gdb_exit
49 gdb_start
50 gdb_reinitialize_dir $srcdir/$subdir
51 gdb_load ${binfile}
52
53 global gdb_prompt
54
55 # This is a test of gdb's ability to follow the parent, child or both
56 # parent and child of multiple Unix fork() system calls.
57 #
58
59 # Inferior program calls fork 4 times. Since each fork
60 # calls fork 4 times, there will be 16 forks. Each fork
61 # saves the return values of its own 4 fork calls.
62
63 # First set gdb to follow the child.
64 # The result should be that each of the 4 forks returns zero.
65
66 runto_main
67 set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
68 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
69 gdb_test "set follow child" "" ""
70
71 send_gdb "continue\n"
72 gdb_expect {
73 -re ".*Break.* main .*$gdb_prompt $" {}
74 -re ".*$gdb_prompt $" {fail "run to exit 1"}
75 default {fail "run to exit 1 (timeout)"}
76 }
77
78 gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
79
80 # Now set gdb to follow the parent.
81 # Result should be that none of the 4 forks returns zero.
82
83 delete_breakpoints
84 runto_main
85 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" "Break at exit"
86 gdb_test "set follow parent" "" ""
87
88 send_gdb "continue\n"
89 gdb_expect {
90 -re ".*Break.* main .*$gdb_prompt $" {}
91 -re ".*$gdb_prompt $" {fail "run to exit 2"}
92 default {fail "run to exit 2 (timeout)"}
93 }
94
95 gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
96 " = 0" "follow parent, print pids"
97
98 #
99 # Now test with detach-on-fork off.
100 #
101
102 runto_main
103 gdb_test "break $exit_bp_loc" "Breakpoint.* at .*" ""
104
105 gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
106 "help set detach"
107
108 gdb_test "show detach-on-fork" "on." "show detach default on"
109
110 gdb_test "set detach off" "" "set detach off"
111
112 #
113 # We will now run every fork up to the exit bp,
114 # eventually winding up with 16 forks.
115 #
116
117 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 1"
118 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 1"
119 gdb_test "restart 1" "_dl_sysinfo_int80.*" "restart 1"
120
121 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 2"
122 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 2"
123 gdb_test "restart 2" "_dl_sysinfo_int80.*" "restart 2"
124
125 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 3"
126 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 3"
127 gdb_test "restart 3" "_dl_sysinfo_int80.*" "restart 3"
128
129 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 4"
130 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 4"
131 gdb_test "restart 4" "_dl_sysinfo_int80.*" "restart 4"
132
133 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 5"
134 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 5"
135 gdb_test "restart 5" "_dl_sysinfo_int80.*" "restart 5"
136
137 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 6"
138 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 6"
139 gdb_test "restart 6" "_dl_sysinfo_int80.*" "restart 6"
140
141 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 7"
142 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 7"
143 gdb_test "restart 7" "_dl_sysinfo_int80.*" "restart 7"
144
145 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 8"
146 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 8"
147 gdb_test "restart 8" "_dl_sysinfo_int80.*" "restart 8"
148
149 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 9"
150 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 9"
151 gdb_test "restart 9" "_dl_sysinfo_int80.*" "restart 9"
152
153 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 10"
154 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 10"
155 gdb_test "restart 10" "_dl_sysinfo_int80.*" "restart 10"
156
157 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 11"
158 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 11"
159 gdb_test "restart 11" "_dl_sysinfo_int80.*" "restart 11"
160
161 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 12"
162 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 12"
163 gdb_test "restart 12" "_dl_sysinfo_int80.*" "restart 12"
164
165 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 13"
166 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 13"
167 gdb_test "restart 13" "_dl_sysinfo_int80.*" "restart 13"
168
169 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 14"
170 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 14"
171 gdb_test "restart 14" "_dl_sysinfo_int80.*" "restart 14"
172
173 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 15"
174 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 15"
175 gdb_test "restart 15" "_dl_sysinfo_int80.*" "restart 15"
176
177 gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
178 gdb_test "info fork" " 4 .* 3 .* 2 .* 1 .*" "info fork 16"
179 gdb_test "restart 0" " main .*" "restart final"
180
181 #
182 # Now we should examine all the pids.
183 #
184
185 #
186 # Test detach-fork
187 #
188
189 # [assumes we're at #0]
190 gdb_test "detach-fork 1" "Detached .*" "Detach 1"
191 gdb_test "detach-fork 2" "Detached .*" "Detach 2"
192 gdb_test "detach-fork 3" "Detached .*" "Detach 3"
193 gdb_test "detach-fork 4" "Detached .*" "Detach 4"
194
195 #
196 # Test delete-fork
197 #
198
199 gdb_test "delete-fork 5" "" "Delete 5"
200 gdb_test "delete-fork 6" "" "Delete 6"
201 gdb_test "delete-fork 7" "" "Delete 7"
202 gdb_test "delete-fork 8" "" "Delete 8"
203 gdb_test "delete-fork 9" "" "Delete 9"
204 gdb_test "delete-fork 10" "" "Delete 10"
205 gdb_test "delete-fork 11" "" "Delete 11"
206 gdb_test "delete-fork 12" "" "Delete 12"
207 gdb_test "delete-fork 13" "" "Delete 13"
208 gdb_test "delete-fork 14" "" "Delete 14"
209 gdb_test "delete-fork 15" "" "Delete 15"
210
211
212
213 return 0
214