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 if { [skip_hp_tests] } then { continue }
29 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
34 set testfile "foll-fork"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
38 # build the first test case
39 #if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
40 # execute_anywhere "rm -f ${objdir}/${subdir}/${testfile}.tmp"
41 # built the second test case since we can't use prototypes
42 # warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
43 # execute_anywhere "echo set prototypes 0 > ${objdir}/${subdir}/${testfile}.tmp"
44 # if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
45 # perror "Couldn't compile ${testfile}.c"
50 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
51 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
56 # Until "set follow-fork-mode" and "catch fork" are implemented on
59 if ![istarget "hppa*-hp-hpux*"] then {
63 proc default_fork_parent_follow {} {
66 send_gdb "show follow\n"
68 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
69 {pass "default show parent follow, no catchpoints"}
70 -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
71 timeout {fail "(timeout) default show parent follow, no catchpoints"}
75 -re "Detaching after fork from.*$gdb_prompt $"\
76 {pass "default parent follow, no catchpoints"}
77 -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
78 timeout {fail "(timeout) default parent follow, no catchpoints" }
80 # The child has been detached; allow time for any output it might
81 # generate to arrive, so that output doesn't get confused with
82 # any expected debugger output from a subsequent testpoint.
87 proc explicit_fork_parent_follow {} {
90 send_gdb "set follow parent\n"
92 -re "$gdb_prompt $" {pass "set follow parent"}
93 timeout {fail "(timeout) set follow parent"}
95 send_gdb "show follow\n"
97 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
98 {pass "explicit show parent follow, no catchpoints"}
99 -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
100 timeout {fail "(timeout) explicit show parent follow, no catchpoints"}
104 -re "Detaching after fork from.*$gdb_prompt $"\
105 {pass "explicit parent follow, no catchpoints"}
106 -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
107 timeout {fail "(timeout) explicit parent follow, no catchpoints"}
109 # The child has been detached; allow time for any output it might
110 # generate to arrive, so that output doesn't get confused with
111 # any expected debugger output from a subsequent testpoint.
116 proc explicit_fork_child_follow {} {
119 send_gdb "set follow child\n"
121 -re "$gdb_prompt $" {pass "set follow child"}
122 timeout {fail "(timeout) set follow child"}
124 send_gdb "show follow\n"
126 -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
127 {pass "explicit show child follow, no catchpoints"}
128 -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
129 timeout {fail "(timeout) explicit show child follow, no catchpoints"}
133 -re "Detaching from program:.*Attaching after fork to.*$gdb_prompt $"\
134 {pass "explicit child follow, no catchpoints"}
135 -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
136 timeout {fail "(timeout) explicit child follow, no catchpoints"}
138 # The child has been detached; allow time for any output it might
139 # generate to arrive, so that output doesn't get confused with
140 # any gdb_expected debugger output from a subsequent testpoint.
145 proc catch_fork_child_follow {} {
148 send_gdb "catch fork\n"
150 -re "Catchpoint .*(fork).*$gdb_prompt $"\
151 {pass "explicit child follow, set catch fork"}
152 -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
153 timeout {fail "(timeout) explicit child follow, set catch fork"}
156 # Verify that the catchpoint is mentioned in an "info breakpoints",
157 # and further that the catchpoint mentions no process id.
159 send_gdb "info breakpoints\n"
161 -re ".*catch fork.*keep y.*$gdb_prompt $"\
162 {pass "info shows catchpoint without pid"}
163 -re ".*catch fork.*process .*$gdb_prompt $"\
164 {fail "info shows catchpoint without pid"}
165 -re "$gdb_prompt $" {fail "info shows catchpoint without pid"}
166 timeout {fail "(timeout) info shows catchpoint without pid"}
169 send_gdb "continue\n"
171 -re "Catchpoint.*(forked process.*),.*in _fork_sys.*$gdb_prompt $"\
172 {pass "explicit child follow, catch fork"}
173 -re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
174 timeout {fail "(timeout) explicit child follow, catch fork"}
177 # Verify that the catchpoint is mentioned in an "info breakpoints",
178 # and further that the catchpoint managed to capture a process id.
180 send_gdb "info breakpoints\n"
182 -re ".*catch fork .*process \[0-9\]+.*$gdb_prompt $"\
183 {pass "info shows catchpoint pid"}
184 -re "$gdb_prompt $" {fail "info shows catchpoint pid"}
185 timeout {fail "(timeout) info shows catchpoint pid"}
188 send_gdb "set follow child\n"
190 -re "$gdb_prompt $" {pass "set follow child"}
191 timeout {fail "(timeout) set follow child"}
193 send_gdb "tbreak 15\n"
195 -re "Breakpoint.*, line 15.*$gdb_prompt $"\
196 {pass "set follow child, tbreak"}
197 -re "$gdb_prompt $" {fail "set follow child, tbreak"}
198 timeout {fail "(timeout) set follow child, tbreak"}
200 send_gdb "continue\n"
202 -re ".*Detaching from program:.*Attaching after fork to.* at .*15.*$gdb_prompt $"\
203 {pass "set follow child, hit tbreak"}
204 -re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
205 timeout {fail "(timeout) set follow child, hit tbreak"}
207 # The child 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.
212 send_gdb "delete breakpoints\n"
214 -re "Delete all breakpoints.*$" {
218 {pass "set follow child, cleanup"}
219 timeout {fail "(timeout) set follow child, cleanup"}
222 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
223 timeout {fail "(timeout) set follow child, cleanup"}
227 proc tcatch_fork_parent_follow {} {
230 send_gdb "catch fork\n"
232 -re "Catchpoint .*(fork).*$gdb_prompt $"\
233 {pass "explicit parent follow, set tcatch fork"}
234 -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
235 timeout {fail "(timeout) explicit parent follow, set tcatch fork"}
237 # ??rehrauer: I don't yet know how to get the id of the tcatch
238 # via this script, so that I can add a -do list to it. For now,
239 # do the follow stuff after the catch happens.
241 send_gdb "continue\n"
243 -re ".*in _fork_sys.*$gdb_prompt $"\
244 {pass "explicit parent follow, tcatch fork"}
245 -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
246 timeout {fail "(timeout) explicit parent follow, tcatch fork"}
248 send_gdb "set follow parent\n"
250 -re "$gdb_prompt $" {pass "set follow parent"}
251 timeout {fail "(timeout) set follow parent"}
253 send_gdb "tbreak 15\n"
255 -re "Breakpoint.*, line 15.*$gdb_prompt $"\
256 {pass "set follow parent, tbreak"}
257 -re "$gdb_prompt $" {fail "set follow parent, tbreak"}
258 timeout {fail "(timeout) set follow child, tbreak"}
260 send_gdb "continue\n"
262 -re ".*Detaching after fork from.* at .*15.*$gdb_prompt $"\
263 {pass "set follow parent, hit tbreak"}
264 -re "$gdb_prompt $" {fail "set follow parent, hit tbreak"}
265 timeout {fail "(timeout) set follow parent, hit tbreak"}
267 # The child has been detached; allow time for any output it might
268 # generate to arrive, so that output doesn't get confused with
269 # any expected debugger output from a subsequent testpoint.
272 send_gdb "delete breakpoints\n"
274 -re "Delete all breakpoints.*$" {
278 {pass "set follow parent, cleanup"}
279 timeout {fail "(timeout) set follow parent, cleanup"}
282 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
283 timeout {fail "(timeout) set follow parent, cleanup"}
287 proc do_fork_tests {} {
290 # Verify that help is available for "set follow-fork-mode".
292 send_gdb "help set follow-fork-mode\n"
294 -re "Set debugger response to a program call of fork or vfork..*
295 A fork or vfork creates a new process. follow-fork-mode can be:.*
296 .*parent - the original process is debugged after a fork.*
297 .*child - the new process is debugged after a fork.*
298 .*ask - the debugger will ask for one of the above choices.*
299 For \"parent\" or \"child\", the unfollowed process will run free..*
300 By default, the debugger will follow the parent process..*$gdb_prompt $"\
301 { pass "help set follow" }
302 -re "$gdb_prompt $" { fail "help set follow" }
303 timeout { fail "(timeout) help set follow" }
306 # Verify that we can set follow-fork-mode, using an abbreviation
307 # for both the flag and its value.
309 send_gdb "set follow ch\n"
310 send_gdb "show fol\n"
312 -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
313 {pass "set follow, using abbreviations"}
314 timeout {fail "(timeout) set follow, using abbreviations"}
317 # Verify that we cannot set follow-fork-mode to nonsense.
319 send_gdb "set follow chork\n"
321 -re "Undefined item: \"chork\".*$gdb_prompt $"\
322 {pass "set follow to nonsense is prohibited"}
323 -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
324 timeout {fail "(timeout) set follow to nonsense is prohibited"}
326 send_gdb "set follow parent\n"
328 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
329 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
332 # Test the default behaviour, which is to follow the parent of a
333 # fork, and detach from the child. Do this without catchpoints.
335 if [runto_main] then { default_fork_parent_follow }
337 # Test the ability to explicitly follow the parent of a fork, and
338 # detach from the child. Do this without catchpoints.
340 if [runto_main] then { explicit_fork_parent_follow }
342 # Test the ability to follow the child of a fork, and detach from
343 # the parent. Do this without catchpoints.
345 if [runto_main] then { explicit_fork_child_follow }
347 # Test the ability to follow both child and parent of a fork. Do
348 # this without catchpoints.
349 # ??rehrauer: NYI. Will add testpoints here when implemented.
352 # Test the ability to have the debugger ask the user at fork-time
353 # whether to follow the parent, child or both. Do this without
355 # ??rehrauer: NYI. Will add testpoints here when implemented.
358 # Test the ability to catch a fork, specify that the child be
359 # followed, and continue. Make the catchpoint permanent.
361 if [runto_main] then { catch_fork_child_follow }
363 # Test the ability to catch a fork, specify via a -do clause that
364 # the parent be followed, and continue. Make the catchpoint temporary.
366 if [runto_main] then { tcatch_fork_parent_follow }
369 # Start with a fresh gdb
373 gdb_reinitialize_dir $srcdir/$subdir
377 # This is a test of gdb's ability to follow the parent, child or both
378 # parent and child of a Unix fork() system call.