This commit was generated by cvs2svn to track changes on a CVS vendor
[binutils-gdb.git] / gdb / testsuite / gdb.base / foll-vfork.exp
1 # Copyright (C) 1997 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 [istarget "hppa2.0w-hp-hpux*"] {
25 warning "Don't run gdb.base/foll-vfork.exp until JAGaa43495 kernel problem is fixed."
26 return 0
27 }
28
29 set prms_id 0
30 set bug_id 0
31
32 set testfile "foll-vfork"
33 set testfile2 "vforked-prog"
34 set srcfile ${testfile}.c
35 set srcfile2 ${testfile2}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 set binfile2 ${objdir}/${subdir}/${testfile2}
38
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."
41 }
42
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
44 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 }
46
47
48 # Until "set follow-fork-mode" and "catch vfork" are implemented on
49 # other targets...
50 #
51 if ![istarget "hppa*-hp-hpux*"] then {
52 continue
53 }
54
55 # Test to see if we are on an HP-UX 10.20 and if so,
56 # do not run these tests as catching vfork is disabled for
57 # 10.20.
58
59 if [istarget "hppa*-hp-hpux10.20"] then {
60 return 0
61 }
62
63 # A few of these tests require a little more time than the standard
64 # timeout allows.
65 set oldtimeout $timeout
66 set timeout [expr "$timeout + 10"]
67
68 proc vfork_parent_follow_through_step {} {
69 global gdb_prompt
70
71 send_gdb "set follow parent\n"
72 gdb_expect {
73 -re "$gdb_prompt $" {pass "set follow parent, vfork through step"}
74 timeout {fail "set follow parent, vfork through step"}
75 }
76 send_gdb "next\n"
77 gdb_expect {
78 -re "Detaching after fork from.*13.*$gdb_prompt $"\
79 {pass "vfork parent follow, through step"}
80 -re "$gdb_prompt $" {fail "vfork parent follow, through step"}
81 timeout {fail "(timeout) vfork parent follow, through step" }
82 }
83 # The child has been detached; allow time for any output it might
84 # generate to arrive, so that output doesn't get confused with
85 # any gdb_expected debugger output from a subsequent testpoint.
86 #
87 exec sleep 1
88 }
89
90 proc vfork_parent_follow_to_bp {} {
91 global gdb_prompt
92
93 send_gdb "set follow parent\n"
94 gdb_expect {
95 -re "$gdb_prompt $" {pass "set follow parent, vfork to bp"}
96 timeout {fail "set follow parent, vfork to bp"}
97 }
98 send_gdb "break 18\n"
99 gdb_expect {
100 -re "$gdb_prompt $" {pass "break, vfork to bp"}
101 timeout {fail "break, vfork to bp"}
102 }
103 send_gdb "continue\n"
104 gdb_expect {
105 -re ".*Detaching after fork from process.*Breakpoint.*18.*$gdb_prompt $"\
106 {pass "vfork parent follow, to bp"}
107 -re "$gdb_prompt $" {fail "vfork parent follow, to bp"}
108 timeout {fail "(timeout) vfork parent follow, to bp" }
109 }
110 # The child has been detached; allow time for any output it might
111 # generate to arrive, so that output doesn't get confused with
112 # any expected debugger output from a subsequent testpoint.
113 #
114 exec sleep 1
115 }
116
117 proc vfork_and_exec_child_follow_to_main_bp {} {
118 global gdb_prompt
119 global binfile
120
121 send_gdb "set follow child\n"
122 gdb_expect {
123 -re "$gdb_prompt $" {pass "set follow child, vfork and exec to main bp"}
124 timeout {fail "set follow child, vfork and exec to main bp"}
125 }
126 send_gdb "continue\n"
127 gdb_expect {
128 -re "Detaching from program.*Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt $"\
129 {pass "vfork and exec child follow, to main bp"}
130 -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"}
131 timeout {fail "(timeout) vfork and exec child follow, to main bp" }
132 }
133 # The parent has been detached; allow time for any output it might
134 # generate to arrive, so that output doesn't get confused with
135 # any gdb_expected debugger output from a subsequent testpoint.
136 #
137 exec sleep 1
138
139 # Explicitly kill this child, or a subsequent rerun actually runs
140 # the exec'd child, not the original program...
141 send_gdb "kill\n"
142 gdb_expect {
143 -re ".*Kill the program being debugged.*y or n. $" {
144 send_gdb "y\n"
145 send_gdb "file $binfile\n"
146 gdb_expect {
147 -re ".*Load new symbol table from.*y or n. $" {
148 send_gdb "y\n"
149 gdb_expect {
150 -re "Reading symbols from.*$gdb_prompt $" {}
151 timeout { fail "loading symbols (timeout)"; return }
152 }
153 }
154 -re ".*gdb_prompt $" {}
155 timeout { fail "loading symbols (timeout)"; return }
156 }
157 }
158 -re ".*$gdb_prompt $" {}
159 timeout { fail "killing inferior (timeout)" ; return }
160 }
161 }
162
163 proc vfork_and_exec_child_follow_through_step {} {
164 global gdb_prompt
165 global binfile
166
167 # This test cannot be performed prior to HP-UX 10.30, because ptrace-based
168 # debugging of a vforking program basically doesn't allow the child to do
169 # things like hit a breakpoint between a vfork and exec. This means that
170 # saying "set follow child; next" at a vfork() call won't work, because
171 # the implementation of "next" sets a "step resume" breakpoint at the
172 # return from the vfork(), which the child will hit on its way to exec'ing.
173 #
174 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
175 verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
176 return 0
177 }
178
179 send_gdb "set follow child\n"
180 gdb_expect {
181 -re "$gdb_prompt $" {pass "set follow child, vfork and exec through step"}
182 timeout {fail "set follow child, vfork and exec through step"}
183 }
184 send_gdb "next\n"
185 gdb_expect {
186 -re "Detaching from program.*Attaching after fork to.*Executing new program.*Breakpoint.*vforked-prog.c:9.*$gdb_prompt $"\
187 {pass "vfork and exec child follow, through step"}
188 -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"}
189 timeout {fail "(timeout) vfork and exec child follow, through step" }
190 }
191 # The parent has been detached; allow time for any output it might
192 # generate to arrive, so that output doesn't get confused with
193 # any expected debugger output from a subsequent testpoint.
194 #
195 exec sleep 1
196
197 # Explicitly kill this child, or a subsequent rerun actually runs
198 # the exec'd child, not the original program...
199 send_gdb "kill\n"
200 gdb_expect {
201 -re ".*Kill the program being debugged.*y or n. $" {
202 send_gdb "y\n"
203 send_gdb "file $binfile\n"
204 gdb_expect {
205 -re ".*Load new symbol table from.*y or n. $" {
206 send_gdb "y\n"
207 gdb_expect {
208 -re "Reading symbols from.*$gdb_prompt $" {}
209 timeout { fail "loading symbols (timeout)"; return }
210 }
211 }
212 -re ".*gdb_prompt $" {}
213 timeout { fail "loading symbols (timeout)"; return }
214 }
215 }
216 -re ".*$gdb_prompt $" {}
217 timeout { fail "killing inferior (timeout)" ; return }
218 }
219 }
220
221 proc tcatch_vfork_then_parent_follow {} {
222 global gdb_prompt
223 global srcfile
224
225 send_gdb "set follow parent\n"
226 gdb_expect {
227 -re "$gdb_prompt $" {pass "set follow parent, tcatch vfork"}
228 timeout {fail "set follow parent, tcatch vfork"}
229 }
230 send_gdb "tcatch vfork\n"
231 gdb_expect {
232 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
233 {pass "vfork parent follow, set tcatch vfork"}
234 -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"}
235 timeout {fail "(timeout) vfork parent follow, set tcatch vfork"}
236 }
237 send_gdb "continue\n"
238 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
239 # stop you in "_vfork".
240 gdb_expect {
241 -re "0x\[0-9a-fA-F\]*.*vfork.*$gdb_prompt $"\
242 {pass "vfork parent follow, tcatch vfork"}
243 -re "0x\[0-9a-fA-F\]*.*_vfork.*$gdb_prompt $"\
244 {pass "vfork parent follow, tcatch vfork"}
245 -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"}
246 timeout {fail "(timeout) vfork parent follow, tcatch vfork"}
247 }
248 send_gdb "finish\n"
249 gdb_expect {
250 -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:12.*$gdb_prompt $"\
251 {pass "vfork parent follow, finish after tcatch vfork"}
252 -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"}
253 timeout {fail "(timeout) vfork parent follow, finish after tcatch vfork" }
254 }
255 # The child has been detached; allow time for any output it might
256 # generate to arrive, so that output doesn't get confused with
257 # any expected debugger output from a subsequent testpoint.
258 #
259 exec sleep 1
260 }
261
262 proc tcatch_vfork_then_child_follow {} {
263 global gdb_prompt
264 global srcfile2
265
266 send_gdb "set follow child\n"
267 gdb_expect {
268 -re "$gdb_prompt $" {pass "set follow child, tcatch vfork"}
269 timeout {fail "set follow child, tcatch vfork"}
270 }
271 send_gdb "tcatch vfork\n"
272 gdb_expect {
273 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
274 {pass "vfork child follow, set tcatch vfork"}
275 -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"}
276 timeout {fail "(timeout) vfork child follow, set tcatch vfork"}
277 }
278 send_gdb "continue\n"
279 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
280 # stop you in "_vfork".
281 gdb_expect {
282 -re "0x\[0-9a-fA-F\]*.*vfork.*$gdb_prompt $"\
283 {pass "vfork child follow, tcatch vfork"}
284 -re "0x\[0-9a-fA-F\]*.*_vfork.*$gdb_prompt $"\
285 {pass "vfork child follow, tcatch vfork"}
286 -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"}
287 timeout {fail "(timeout) vfork child follow, tcatch vfork"}
288 }
289 send_gdb "finish\n"
290 gdb_expect {
291 -re "Run till exit from.*vfork.*${srcfile2}:9.*$gdb_prompt $"\
292 {pass "vfork child follow, finish after tcatch vfork"}
293 -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"}
294 timeout {fail "(timeout) vfork child follow, finish after tcatch vfork" }
295 }
296 # The parent has been detached; allow time for any output it might
297 # generate to arrive, so that output doesn't get confused with
298 # any expected debugger output from a subsequent testpoint.
299 #
300 exec sleep 1
301 }
302
303 proc do_vfork_and_exec_tests {} {
304 global gdb_prompt
305
306 # Try following the parent process by stepping through a call to
307 # vfork. Do this without catchpoints.
308 if [runto_main] then { vfork_parent_follow_through_step }
309
310 # Try following the parent process by setting a breakpoint on the
311 # other side of a vfork, and running to that point. Do this
312 # without catchpoints.
313 if [runto_main] then { vfork_parent_follow_to_bp }
314
315 # Try following the child process by just continuing through the
316 # vfork, and letting the parent's breakpoint on "main" be auto-
317 # magically reset in the child.
318 #
319 if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
320
321 # Try following the child process by stepping through a call to
322 # vfork. The child also executes an exec. Since the child cannot
323 # be debugged until after it has exec'd, and since there's a bp on
324 # "main" in the parent, and since the bp's for the parent are
325 # recomputed in the exec'd child, the step through a vfork should
326 # land us in the "main" for the exec'd child, too.
327 #
328 if [runto_main] then { vfork_and_exec_child_follow_through_step }
329
330 # Try catching a vfork, and stepping out to the parent.
331 #
332 if [runto_main] then { tcatch_vfork_then_parent_follow }
333
334 # Try catching a vfork, and stepping out to the child.
335 #
336 if [runto_main] then { tcatch_vfork_then_child_follow }
337
338 # Test the ability to follow both child and parent of a vfork. Do
339 # this without catchpoints.
340 # ??rehrauer: NYI. Will add testpoints here when implemented.
341 #
342
343 # Test the ability to have the debugger ask the user at vfork-time
344 # whether to follow the parent, child or both. Do this without
345 # catchpoints.
346 # ??rehrauer: NYI. Will add testpoints here when implemented.
347 #
348 }
349
350 # Start with a fresh gdb
351
352 gdb_exit
353 gdb_start
354 gdb_reinitialize_dir $srcdir/$subdir
355 gdb_load ${binfile}
356
357
358 # This is a test of gdb's ability to follow the parent or child
359 # of a Unix vfork() system call. (The child will subsequently
360 # call a variant of a Unix exec() system call.)
361 #
362 do_vfork_and_exec_tests
363
364 set timeout $oldtimeout
365 return 0