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