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