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