1 # Copyright 1997, 1999, 2007 Free Software Foundation, Inc.
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.
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.
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. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
24 if { ![isnative] } then {
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.
34 ##if [istarget "hppa2.0w-hp-hpux*"] {
35 ## warning "Don't run gdb.base/foll-vfork.exp until JAGaa43495 kernel problem is fixed."
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}
46 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
47 untested foll-vfork.exp
51 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
52 untested foll-vfork.exp
57 # Until "set follow-fork-mode" and "catch vfork" are implemented on
60 if ![istarget "hppa*-hp-hpux*"] then {
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
68 if [istarget "hppa*-hp-hpux10.20"] then {
72 # A few of these tests require a little more time than the standard
74 set oldtimeout $timeout
75 set timeout [expr "$timeout + 10"]
77 proc vfork_parent_follow_through_step {} {
80 send_gdb "set follow parent\n"
82 -re "$gdb_prompt $" {pass "set follow parent, vfork through step"}
83 timeout {fail "set follow parent, vfork through step"}
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" }
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.
99 proc vfork_parent_follow_to_bp {} {
102 send_gdb "set follow parent\n"
104 -re "$gdb_prompt $" {pass "set follow parent, vfork to bp"}
105 timeout {fail "set follow parent, vfork to bp"}
107 send_gdb "break 18\n"
109 -re "$gdb_prompt $" {pass "break, vfork to bp"}
110 timeout {fail "break, vfork to bp"}
112 send_gdb "continue\n"
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" }
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.
126 proc vfork_and_exec_child_follow_to_main_bp {} {
130 send_gdb "set follow child\n"
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"}
135 send_gdb "continue\n"
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" }
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.
148 # Explicitly kill this child, or a subsequent rerun actually runs
149 # the exec'd child, not the original program...
152 -re ".*Kill the program being debugged.*y or n. $" {
154 send_gdb "file $binfile\n"
156 -re ".*Load new symbol table from.*y or n. $" {
159 -re "Reading symbols from.*$gdb_prompt $" {}
160 timeout { fail "loading symbols (timeout)"; return }
163 -re ".*gdb_prompt $" {}
164 timeout { fail "loading symbols (timeout)"; return }
167 -re ".*$gdb_prompt $" {}
168 timeout { fail "killing inferior (timeout)" ; return }
172 proc vfork_and_exec_child_follow_through_step {} {
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.
183 if { ![istarget "hppa*-*-hpux11.*"] } {
184 verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
188 send_gdb "set follow child\n"
190 -re "$gdb_prompt $" {pass "set follow child, vfork and exec through step"}
191 timeout {fail "set follow child, vfork and exec through step"}
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" }
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.
206 # Explicitly kill this child, or a subsequent rerun actually runs
207 # the exec'd child, not the original program...
210 -re ".*Kill the program being debugged.*y or n. $" {
212 send_gdb "file $binfile\n"
214 -re ".*Load new symbol table from.*y or n. $" {
217 -re "Reading symbols from.*$gdb_prompt $" {}
218 timeout { fail "loading symbols (timeout)"; return }
221 -re ".*gdb_prompt $" {}
222 timeout { fail "loading symbols (timeout)"; return }
225 -re ".*$gdb_prompt $" {}
226 timeout { fail "killing inferior (timeout)" ; return }
230 proc tcatch_vfork_then_parent_follow {} {
234 send_gdb "set follow parent\n"
236 -re "$gdb_prompt $" {pass "set follow parent, tcatch vfork"}
237 timeout {fail "set follow parent, tcatch vfork"}
239 send_gdb "tcatch vfork\n"
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"}
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".
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"}
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" }
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.
271 proc tcatch_vfork_then_child_follow {} {
275 send_gdb "set follow child\n"
277 -re "$gdb_prompt $" {pass "set follow child, tcatch vfork"}
278 timeout {fail "set follow child, tcatch vfork"}
280 send_gdb "tcatch vfork\n"
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"}
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".
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"}
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" }
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.
312 proc do_vfork_and_exec_tests {} {
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 }
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 }
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.
328 if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
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.
337 if [runto_main] then { vfork_and_exec_child_follow_through_step }
339 # Try catching a vfork, and stepping out to the parent.
341 if [runto_main] then { tcatch_vfork_then_parent_follow }
343 # Try catching a vfork, and stepping out to the child.
345 if [runto_main] then { tcatch_vfork_then_child_follow }
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.
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
355 # ??rehrauer: NYI. Will add testpoints here when implemented.
359 # Start with a fresh gdb
363 gdb_reinitialize_dir $srcdir/$subdir
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.)
371 do_vfork_and_exec_tests
373 set timeout $oldtimeout