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