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