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