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