1 # Copyright (C) 1997 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
27 # are we on a target board
32 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
37 set testfile "foll-vfork"
38 set testfile2 "vforked-program"
39 set srcfile ${testfile}.c
40 set srcfile2 ${testfile2}.c
41 set binfile ${objdir}/${subdir}/${testfile}
42 set binfile2 ${objdir}/${subdir}/${testfile2}
44 # build the first test case
45 #execute_anywhere "echo set prototypes 1 > ${objdir}/${subdir}/${testfile}.tmp"
46 #if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile2} -o ${binfile2} "] != "" } {
47 # perror "Couldn't compile ${srcfile2}"
51 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
52 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
55 #if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
56 # execute_anywhere "rm -f ${objdir}/${subdir}/${testfile}.tmp"
57 # built the second test case since we can't use prototypes
58 # warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
59 # execute_anywhere "echo set prototypes 0 > ${objdir}/${subdir}/${testfile}.tmp"
60 # if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
61 # perror "Couldn't compile ${testfile}.c"
66 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
67 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
71 # Until "set follow-fork-mode" and "catch vfork" are implemented on
74 if ![istarget "hppa*-hp-hpux*"] then {
79 # A few of these tests require a little more time than the standard
81 set oldtimeout $timeout
82 set timeout [expr "$timeout + 10"]
84 proc vfork_parent_follow_through_step {} {
87 send_gdb "set follow parent\n"
89 -re "$gdb_prompt $" {pass "set follow parent, vfork through step"}
90 timeout {fail "set follow parent, vfork through step"}
94 -re "Detaching after fork from.*8.*$gdb_prompt $"\
95 {pass "vfork parent follow, through step"}
96 -re "$gdb_prompt $" {fail "vfork parent follow, through step"}
97 timeout {fail "(timeout) vfork parent follow, through step" }
99 # The child has been detached; allow time for any output it might
100 # generate to arrive, so that output doesn't get confused with
101 # any gdb_expected debugger output from a subsequent testpoint.
106 proc vfork_parent_follow_to_bp {} {
109 send_gdb "set follow parent\n"
111 -re "$gdb_prompt $" {pass "set follow parent, vfork to bp"}
112 timeout {fail "set follow parent, vfork to bp"}
114 send_gdb "break 13\n"
116 -re "$gdb_prompt $" {pass "break, vfork to bp"}
117 timeout {fail "break, vfork to bp"}
119 send_gdb "continue\n"
121 -re ".*Detaching after fork from process.*Breakpoint.*13.*$gdb_prompt $"\
122 {pass "vfork parent follow, to bp"}
123 -re "$gdb_prompt $" {fail "vfork parent follow, to bp"}
124 timeout {fail "(timeout) vfork parent follow, to bp" }
126 # The child has been detached; allow time for any output it might
127 # generate to arrive, so that output doesn't get confused with
128 # any expected debugger output from a subsequent testpoint.
133 proc vfork_and_exec_child_follow_to_main_bp {} {
137 send_gdb "set follow child\n"
139 -re "$gdb_prompt $" {pass "set follow child, vfork and exec to main bp"}
140 timeout {fail "set follow child, vfork and exec to main bp"}
142 send_gdb "continue\n"
144 -re "Detaching from program.*Attaching after fork to.*Executing new program.*Breakpoint.*vforked-program.c:5.*$gdb_prompt $"\
145 {pass "vfork and exec child follow, to main bp"}
146 -re "$gdb_prompt $" {fail "vfork and exec child follow, to main bp"}
147 timeout {fail "(timeout) vfork and exec child follow, to main bp" }
149 # The parent has been detached; allow time for any output it might
150 # generate to arrive, so that output doesn't get confused with
151 # any gdb_expected debugger output from a subsequent testpoint.
155 # Explicitly kill this child, or a subsequent rerun actually runs
156 # the exec'd child, not the original program...
159 -re ".*Kill the program being debugged.*y or n. $" {
161 send_gdb "file $binfile\n"
163 -re ".*Load new symbol table from.*y or n. $" {
166 -re "Reading symbols from.*$gdb_prompt $" {}
167 timeout { fail "loading symbols (timeout)"; return }
170 -re ".*gdb_prompt $" {}
171 timeout { fail "loading symbols (timeout)"; return }
174 -re ".*$gdb_prompt $" {}
175 timeout { fail "killing inferior (timeout)" ; return }
179 proc vfork_and_exec_child_follow_through_step {} {
183 # This test cannot be performed prior to HP-UX 10.30, because ptrace-based
184 # debugging of a vforking program basically doesn't allow the child to do
185 # things like hit a breakpoint between a vfork and exec. This means that
186 # saying "set follow child; next" at a vfork() call won't work, because
187 # the implementation of "next" sets a "step resume" breakpoint at the
188 # return from the vfork(), which the child will hit on its way to exec'ing.
190 if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } {
191 verbose "vfork child-following next test ignored for non-hppa or pre-HP/UX-10.30 targets."
195 send_gdb "set follow child\n"
197 -re "$gdb_prompt $" {pass "set follow child, vfork and exec through step"}
198 timeout {fail "set follow child, vfork and exec through step"}
202 -re "Detaching from program.*Attaching after fork to.*Executing new program.*Breakpoint.*vforked_program.c:5.*$gdb_prompt $"\
203 {pass "vfork and exec child follow, through step"}
204 -re "$gdb_prompt $" {fail "vfork and exec child follow, through step"}
205 timeout {fail "(timeout) vfork and exec child follow, through step" }
207 # The parent has been detached; allow time for any output it might
208 # generate to arrive, so that output doesn't get confused with
209 # any expected debugger output from a subsequent testpoint.
213 # Explicitly kill this child, or a subsequent rerun actually runs
214 # the exec'd child, not the original program...
217 -re ".*Kill the program being debugged.*y or n. $" {
219 send_gdb "file $binfile\n"
221 -re ".*Load new symbol table from.*y or n. $" {
224 -re "Reading symbols from.*$gdb_prompt $" {}
225 timeout { fail "loading symbols (timeout)"; return }
228 -re ".*gdb_prompt $" {}
229 timeout { fail "loading symbols (timeout)"; return }
232 -re ".*$gdb_prompt $" {}
233 timeout { fail "killing inferior (timeout)" ; return }
237 proc tcatch_vfork_then_parent_follow {} {
241 send_gdb "set follow parent\n"
243 -re "$gdb_prompt $" {pass "set follow parent, tcatch vfork"}
244 timeout {fail "set follow parent, tcatch vfork"}
246 send_gdb "tcatch vfork\n"
248 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
249 {pass "vfork parent follow, set tcatch vfork"}
250 -re "$gdb_prompt $" {fail "vfork parent follow, set tcatch vfork"}
251 timeout {fail "(timeout) vfork parent follow, set tcatch vfork"}
253 send_gdb "continue\n"
254 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
255 # stop you in "_vfork".
257 -re "0x\[0-9a-fA-F\]*.*vfork.*$gdb_prompt $"\
258 {pass "vfork parent follow, tcatch vfork"}
259 -re "0x\[0-9a-fA-F\]*.*_vfork.*$gdb_prompt $"\
260 {pass "vfork parent follow, tcatch vfork"}
261 -re "$gdb_prompt $" {fail "vfork parent follow, tcatch vfork"}
262 timeout {fail "(timeout) vfork parent follow, tcatch vfork"}
266 -re "Run till exit from.*vfork.*0x\[0-9a-fA-F\]* in main .* at .*${srcfile}:7.*$gdb_prompt $"\
267 {pass "vfork parent follow, finish after tcatch vfork"}
268 -re "$gdb_prompt $" {fail "vfork parent follow, finish after tcatch vfork"}
269 timeout {fail "(timeout) vfork parent follow, finish after tcatch vfork" }
271 # The child has been detached; allow time for any output it might
272 # generate to arrive, so that output doesn't get confused with
273 # any expected debugger output from a subsequent testpoint.
278 proc tcatch_vfork_then_child_follow {} {
282 send_gdb "set follow child\n"
284 -re "$gdb_prompt $" {pass "set follow child, tcatch vfork"}
285 timeout {fail "set follow child, tcatch vfork"}
287 send_gdb "tcatch vfork\n"
289 -re "Catchpoint .*(vfork).*$gdb_prompt $"\
290 {pass "vfork child follow, set tcatch vfork"}
291 -re "$gdb_prompt $" {fail "vfork child follow, set tcatch vfork"}
292 timeout {fail "(timeout) vfork child follow, set tcatch vfork"}
294 send_gdb "continue\n"
295 # HP-UX 10.20 seems to stop you in "vfork", while more recent HP-UXs
296 # stop you in "_vfork".
298 -re "0x\[0-9a-fA-F\]*.*vfork.*$gdb_prompt $"\
299 {pass "vfork child follow, tcatch vfork"}
300 -re "0x\[0-9a-fA-F\]*.*_vfork.*$gdb_prompt $"\
301 {pass "vfork child follow, tcatch vfork"}
302 -re "$gdb_prompt $" {fail "vfork child follow, tcatch vfork"}
303 timeout {fail "(timeout) vfork child follow, tcatch vfork"}
307 -re "Run till exit from.*vfork.*${srcfile2}:5.*$gdb_prompt $"\
308 {pass "vfork child follow, finish after tcatch vfork"}
309 -re "$gdb_prompt $" {fail "vfork child follow, finish after tcatch vfork"}
310 timeout {fail "(timeout) vfork child follow, finish after tcatch vfork" }
312 # The parent has been detached; allow time for any output it might
313 # generate to arrive, so that output doesn't get confused with
314 # any expected debugger output from a subsequent testpoint.
319 proc do_vfork_and_exec_tests {} {
322 # Try following the parent process by stepping through a call to
323 # vfork. Do this without catchpoints.
324 if [runto_main] then { vfork_parent_follow_through_step }
326 # Try following the parent process by setting a breakpoint on the
327 # other side of a vfork, and running to that point. Do this
328 # without catchpoints.
329 if [runto_main] then { vfork_parent_follow_to_bp }
331 # Try following the child process by just continuing through the
332 # vfork, and letting the parent's breakpoint on "main" be auto-
333 # magically reset in the child.
335 if [runto_main] then { vfork_and_exec_child_follow_to_main_bp }
337 # Try following the child process by stepping through a call to
338 # vfork. The child also executes an exec. Since the child cannot
339 # be debugged until after it has exec'd, and since there's a bp on
340 # "main" in the parent, and since the bp's for the parent are
341 # recomputed in the exec'd child, the step through a vfork should
342 # land us in the "main" for the exec'd child, too.
344 if [runto_main] then { vfork_and_exec_child_follow_through_step }
346 # Try catching a vfork, and stepping out to the parent.
348 if [runto_main] then { tcatch_vfork_then_parent_follow }
350 # Try catching a vfork, and stepping out to the child.
352 if [runto_main] then { tcatch_vfork_then_child_follow }
354 # Test the ability to follow both child and parent of a vfork. Do
355 # this without catchpoints.
356 # ??rehrauer: NYI. Will add testpoints here when implemented.
359 # Test the ability to have the debugger ask the user at vfork-time
360 # whether to follow the parent, child or both. Do this without
362 # ??rehrauer: NYI. Will add testpoints here when implemented.
366 # Start with a fresh gdb
370 gdb_reinitialize_dir $srcdir/$subdir
374 # This is a test of gdb's ability to follow the parent or child
375 # of a Unix vfork() system call. (The child will subsequently
376 # call a variant of a Unix exec() system call.)
378 do_vfork_and_exec_tests
380 set timeout $oldtimeout