]>
Commit | Line | Data |
---|---|---|
d55ea55c DT |
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 | ||
20 | if $tracelevel then { | |
21 | strace $tracelevel | |
22 | } | |
23 | ||
24 | set prms_id 0 | |
25 | set bug_id 0 | |
26 | ||
27 | # are we on a target board | |
28 | if ![isnative] then { | |
29 | return | |
30 | } | |
31 | ||
32 | if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} { | |
33 | #setup_xfail "*-*.*" | |
34 | return 0 | |
35 | } | |
36 | ||
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} | |
43 | ||
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}" | |
48 | # return -1 | |
49 | #} | |
50 | ||
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." | |
53 | } | |
54 | ||
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" | |
62 | # return -1 | |
63 | # } | |
64 | #} | |
65 | ||
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." | |
68 | } | |
69 | ||
70 | ||
71 | # Until "set follow-fork-mode" and "catch vfork" are implemented on | |
72 | # other targets... | |
73 | # | |
74 | if ![istarget "hppa*-hp-hpux*"] then { | |
75 | setup_xfail "*-*-*" | |
76 | } | |
77 | ||
78 | ||
79 | # A few of these tests require a little more time than the standard | |
80 | # timeout allows. | |
81 | set oldtimeout $timeout | |
82 | set timeout [expr "$timeout + 10"] | |
83 | ||
84 | proc vfork_parent_follow_through_step {} { | |
85 | global gdb_prompt | |
86 | ||
87 | send_gdb "set follow parent\n" | |
88 | gdb_expect { | |
89 | -re "$gdb_prompt $" {pass "set follow parent, vfork through step"} | |
90 | timeout {fail "set follow parent, vfork through step"} | |
91 | } | |
92 | send_gdb "next\n" | |
93 | gdb_expect { | |
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" } | |
98 | } | |
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. | |
102 | # | |
103 | exec sleep 1 | |
104 | } | |
105 | ||
106 | proc vfork_parent_follow_to_bp {} { | |
107 | global gdb_prompt | |
108 | ||
109 | send_gdb "set follow parent\n" | |
110 | gdb_expect { | |
111 | -re "$gdb_prompt $" {pass "set follow parent, vfork to bp"} | |
112 | timeout {fail "set follow parent, vfork to bp"} | |
113 | } | |
114 | send_gdb "break 13\n" | |
115 | gdb_expect { | |
116 | -re "$gdb_prompt $" {pass "break, vfork to bp"} | |
117 | timeout {fail "break, vfork to bp"} | |
118 | } | |
119 | send_gdb "continue\n" | |
120 | gdb_expect { | |
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" } | |
125 | } | |
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. | |
129 | # | |
130 | exec sleep 1 | |
131 | } | |
132 | ||
133 | proc vfork_and_exec_child_follow_to_main_bp {} { | |
134 | global gdb_prompt | |
135 | global binfile | |
136 | ||
137 | send_gdb "set follow child\n" | |
138 | gdb_expect { | |
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"} | |
141 | } | |
142 | send_gdb "continue\n" | |
143 | gdb_expect { | |
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" } | |
148 | } | |
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. | |
152 | # | |
153 | exec sleep 1 | |
154 | ||
155 | # Explicitly kill this child, or a subsequent rerun actually runs | |
156 | # the exec'd child, not the original program... | |
157 | send_gdb "kill\n" | |
158 | gdb_expect { | |
159 | -re ".*Kill the program being debugged.*y or n. $" { | |
160 | send_gdb "y\n" | |
161 | send_gdb "file $binfile\n" | |
162 | gdb_expect { | |
163 | -re ".*Load new symbol table from.*y or n. $" { | |
164 | send_gdb "y\n" | |
165 | gdb_expect { | |
166 | -re "Reading symbols from.*$gdb_prompt $" {} | |
167 | timeout { fail "loading symbols (timeout)"; return } | |
168 | } | |
169 | } | |
170 | -re ".*gdb_prompt $" {} | |
171 | timeout { fail "loading symbols (timeout)"; return } | |
172 | } | |
173 | } | |
174 | -re ".*$gdb_prompt $" {} | |
175 | timeout { fail "killing inferior (timeout)" ; return } | |
176 | } | |
177 | } | |
178 | ||
179 | proc vfork_and_exec_child_follow_through_step {} { | |
180 | global gdb_prompt | |
181 | global binfile | |
182 | ||
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. | |
189 | # | |
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." | |
192 | return 0 | |
193 | } | |
194 | ||
195 | send_gdb "set follow child\n" | |
196 | gdb_expect { | |
197 | -re "$gdb_prompt $" {pass "set follow child, vfork and exec through step"} | |
198 | timeout {fail "set follow child, vfork and exec through step"} | |
199 | } | |
200 | send_gdb "next\n" | |
201 | gdb_expect { | |
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" } | |
206 | } | |
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. | |
210 | # | |
211 | exec sleep 1 | |
212 | ||
213 | # Explicitly kill this child, or a subsequent rerun actually runs | |
214 | # the exec'd child, not the original program... | |
215 | send_gdb "kill\n" | |
216 | gdb_expect { | |
217 | -re ".*Kill the program being debugged.*y or n. $" { | |
218 | send_gdb "y\n" | |
219 | send_gdb "file $binfile\n" | |
220 | gdb_expect { | |
221 | -re ".*Load new symbol table from.*y or n. $" { | |
222 | send_gdb "y\n" | |
223 | gdb_expect { | |
224 | -re "Reading symbols from.*$gdb_prompt $" {} | |
225 | timeout { fail "loading symbols (timeout)"; return } | |
226 | } | |
227 | } | |
228 | -re ".*gdb_prompt $" {} | |
229 | timeout { fail "loading symbols (timeout)"; return } | |
230 | } | |
231 | } | |
232 | -re ".*$gdb_prompt $" {} | |
233 | timeout { fail "killing inferior (timeout)" ; return } | |
234 | } | |
235 | } | |
236 | ||
237 | proc tcatch_vfork_then_parent_follow {} { | |
238 | global gdb_prompt | |
239 | global srcfile | |
240 | ||
241 | send_gdb "set follow parent\n" | |
242 | gdb_expect { | |
243 | -re "$gdb_prompt $" {pass "set follow parent, tcatch vfork"} | |
244 | timeout {fail "set follow parent, tcatch vfork"} | |
245 | } | |
246 | send_gdb "tcatch vfork\n" | |
247 | gdb_expect { | |
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"} | |
252 | } | |
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". | |
256 | gdb_expect { | |
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"} | |
263 | } | |
264 | send_gdb "finish\n" | |
265 | gdb_expect { | |
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" } | |
270 | } | |
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. | |
274 | # | |
275 | exec sleep 1 | |
276 | } | |
277 | ||
278 | proc tcatch_vfork_then_child_follow {} { | |
279 | global gdb_prompt | |
280 | global srcfile2 | |
281 | ||
282 | send_gdb "set follow child\n" | |
283 | gdb_expect { | |
284 | -re "$gdb_prompt $" {pass "set follow child, tcatch vfork"} | |
285 | timeout {fail "set follow child, tcatch vfork"} | |
286 | } | |
287 | send_gdb "tcatch vfork\n" | |
288 | gdb_expect { | |
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"} | |
293 | } | |
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". | |
297 | gdb_expect { | |
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"} | |
304 | } | |
305 | send_gdb "finish\n" | |
306 | gdb_expect { | |
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" } | |
311 | } | |
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. | |
315 | # | |
316 | exec sleep 1 | |
317 | } | |
318 | ||
319 | proc do_vfork_and_exec_tests {} { | |
320 | global gdb_prompt | |
321 | ||
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 } | |
325 | ||
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 } | |
330 | ||
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. | |
334 | # | |
335 | if [runto_main] then { vfork_and_exec_child_follow_to_main_bp } | |
336 | ||
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. | |
343 | # | |
344 | if [runto_main] then { vfork_and_exec_child_follow_through_step } | |
345 | ||
346 | # Try catching a vfork, and stepping out to the parent. | |
347 | # | |
348 | if [runto_main] then { tcatch_vfork_then_parent_follow } | |
349 | ||
350 | # Try catching a vfork, and stepping out to the child. | |
351 | # | |
352 | if [runto_main] then { tcatch_vfork_then_child_follow } | |
353 | ||
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. | |
357 | # | |
358 | ||
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 | |
361 | # catchpoints. | |
362 | # ??rehrauer: NYI. Will add testpoints here when implemented. | |
363 | # | |
364 | } | |
365 | ||
366 | # Start with a fresh gdb | |
367 | ||
368 | gdb_exit | |
369 | gdb_start | |
370 | gdb_reinitialize_dir $srcdir/$subdir | |
371 | gdb_load ${binfile} | |
372 | ||
373 | ||
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.) | |
377 | # | |
378 | do_vfork_and_exec_tests | |
379 | ||
380 | set timeout $oldtimeout | |
381 | return 0 |