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 # are we on a target board
32 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
37 set testfile "foll-fork"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
41 # build the first test case
42 #if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
43 # execute_anywhere "rm -f ${objdir}/${subdir}/${testfile}.tmp"
44 # built the second test case since we can't use prototypes
45 # warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
46 # execute_anywhere "echo set prototypes 0 > ${objdir}/${subdir}/${testfile}.tmp"
47 # if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
48 # perror "Couldn't compile ${testfile}.c"
53 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
54 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
59 # Until "set follow-fork-mode" and "catch fork" are implemented on
62 if ![istarget "hppa*-hp-hpux*"] then {
66 proc default_fork_parent_follow {} {
69 send_gdb "show follow\n"
71 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
72 {pass "default show parent follow, no catchpoints"}
73 -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
74 timeout {fail "(timeout) default show parent follow, no catchpoints"}
78 -re "Detaching after fork from.*$gdb_prompt $"\
79 {pass "default parent follow, no catchpoints"}
80 -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
81 timeout {fail "(timeout) default parent follow, no catchpoints" }
83 # The child has been detached; allow time for any output it might
84 # generate to arrive, so that output doesn't get confused with
85 # any expected debugger output from a subsequent testpoint.
90 proc explicit_fork_parent_follow {} {
93 send_gdb "set follow parent\n"
95 -re "$gdb_prompt $" {pass "set follow parent"}
96 timeout {fail "(timeout) set follow parent"}
98 send_gdb "show follow\n"
100 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
101 {pass "explicit show parent follow, no catchpoints"}
102 -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
103 timeout {fail "(timeout) explicit show parent follow, no catchpoints"}
107 -re "Detaching after fork from.*$gdb_prompt $"\
108 {pass "explicit parent follow, no catchpoints"}
109 -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
110 timeout {fail "(timeout) explicit parent follow, no catchpoints"}
112 # The child has been detached; allow time for any output it might
113 # generate to arrive, so that output doesn't get confused with
114 # any expected debugger output from a subsequent testpoint.
119 proc explicit_fork_child_follow {} {
122 send_gdb "set follow child\n"
124 -re "$gdb_prompt $" {pass "set follow child"}
125 timeout {fail "(timeout) set follow child"}
127 send_gdb "show follow\n"
129 -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
130 {pass "explicit show child follow, no catchpoints"}
131 -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
132 timeout {fail "(timeout) explicit show child follow, no catchpoints"}
136 -re "Detaching from program:.*Attaching after fork to.*$gdb_prompt $"\
137 {pass "explicit child follow, no catchpoints"}
138 -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
139 timeout {fail "(timeout) explicit child follow, no catchpoints"}
141 # The child has been detached; allow time for any output it might
142 # generate to arrive, so that output doesn't get confused with
143 # any gdb_expected debugger output from a subsequent testpoint.
148 proc catch_fork_child_follow {} {
151 send_gdb "catch fork\n"
153 -re "Catchpoint .*(fork).*$gdb_prompt $"\
154 {pass "explicit child follow, set catch fork"}
155 -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
156 timeout {fail "(timeout) explicit child follow, set catch fork"}
159 # Verify that the catchpoint is mentioned in an "info breakpoints",
160 # and further that the catchpoint mentions no process id.
162 send_gdb "info breakpoints\n"
164 -re ".*catch fork.*keep y.*$gdb_prompt $"\
165 {pass "info shows catchpoint without pid"}
166 -re ".*catch fork.*process .*$gdb_prompt $"\
167 {fail "info shows catchpoint without pid"}
168 -re "$gdb_prompt $" {fail "info shows catchpoint without pid"}
169 timeout {fail "(timeout) info shows catchpoint without pid"}
172 send_gdb "continue\n"
174 -re "Catchpoint.*(forked process.*),.*in _fork_sys.*$gdb_prompt $"\
175 {pass "explicit child follow, catch fork"}
176 -re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
177 timeout {fail "(timeout) explicit child follow, catch fork"}
180 # Verify that the catchpoint is mentioned in an "info breakpoints",
181 # and further that the catchpoint managed to capture a process id.
183 send_gdb "info breakpoints\n"
185 -re ".*catch fork .*process \[0-9\]+.*$gdb_prompt $"\
186 {pass "info shows catchpoint pid"}
187 -re "$gdb_prompt $" {fail "info shows catchpoint pid"}
188 timeout {fail "(timeout) info shows catchpoint pid"}
191 send_gdb "set follow child\n"
193 -re "$gdb_prompt $" {pass "set follow child"}
194 timeout {fail "(timeout) set follow child"}
196 send_gdb "tbreak 15\n"
198 -re "Breakpoint.*, line 15.*$gdb_prompt $"\
199 {pass "set follow child, tbreak"}
200 -re "$gdb_prompt $" {fail "set follow child, tbreak"}
201 timeout {fail "(timeout) set follow child, tbreak"}
203 send_gdb "continue\n"
205 -re ".*Detaching from program:.*Attaching after fork to.* at .*15.*$gdb_prompt $"\
206 {pass "set follow child, hit tbreak"}
207 -re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
208 timeout {fail "(timeout) set follow child, hit tbreak"}
210 # The child has been detached; allow time for any output it might
211 # generate to arrive, so that output doesn't get confused with
212 # any expected debugger output from a subsequent testpoint.
215 send_gdb "delete breakpoints\n"
217 -re "Delete all breakpoints.*$" {
221 {pass "set follow child, cleanup"}
222 timeout {fail "(timeout) set follow child, cleanup"}
225 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
226 timeout {fail "(timeout) set follow child, cleanup"}
230 proc tcatch_fork_parent_follow {} {
233 send_gdb "catch fork\n"
235 -re "Catchpoint .*(fork).*$gdb_prompt $"\
236 {pass "explicit parent follow, set tcatch fork"}
237 -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
238 timeout {fail "(timeout) explicit parent follow, set tcatch fork"}
240 # ??rehrauer: I don't yet know how to get the id of the tcatch
241 # via this script, so that I can add a -do list to it. For now,
242 # do the follow stuff after the catch happens.
244 send_gdb "continue\n"
246 -re ".*in _fork_sys.*$gdb_prompt $"\
247 {pass "explicit parent follow, tcatch fork"}
248 -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
249 timeout {fail "(timeout) explicit parent follow, tcatch fork"}
251 send_gdb "set follow parent\n"
253 -re "$gdb_prompt $" {pass "set follow parent"}
254 timeout {fail "(timeout) set follow parent"}
256 send_gdb "tbreak 15\n"
258 -re "Breakpoint.*, line 15.*$gdb_prompt $"\
259 {pass "set follow parent, tbreak"}
260 -re "$gdb_prompt $" {fail "set follow parent, tbreak"}
261 timeout {fail "(timeout) set follow child, tbreak"}
263 send_gdb "continue\n"
265 -re ".*Detaching after fork from.* at .*15.*$gdb_prompt $"\
266 {pass "set follow parent, hit tbreak"}
267 -re "$gdb_prompt $" {fail "set follow parent, hit tbreak"}
268 timeout {fail "(timeout) set follow parent, hit tbreak"}
270 # The child has been detached; allow time for any output it might
271 # generate to arrive, so that output doesn't get confused with
272 # any expected debugger output from a subsequent testpoint.
275 send_gdb "delete breakpoints\n"
277 -re "Delete all breakpoints.*$" {
281 {pass "set follow parent, cleanup"}
282 timeout {fail "(timeout) set follow parent, cleanup"}
285 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
286 timeout {fail "(timeout) set follow parent, cleanup"}
290 proc do_fork_tests {} {
293 # Verify that help is available for "set follow-fork-mode".
295 send_gdb "help set follow-fork-mode\n"
297 -re "Set debugger response to a program call of fork or vfork..*
298 A fork or vfork creates a new process. follow-fork-mode can be:.*
299 .*parent - the original process is debugged after a fork.*
300 .*child - the new process is debugged after a fork.*
301 .*ask - the debugger will ask for one of the above choices.*
302 For \"parent\" or \"child\", the unfollowed process will run free..*
303 By default, the debugger will follow the parent process..*$gdb_prompt $"\
304 { pass "help set follow" }
305 -re "$gdb_prompt $" { fail "help set follow" }
306 timeout { fail "(timeout) help set follow" }
309 # Verify that we can set follow-fork-mode, using an abbreviation
310 # for both the flag and its value.
312 send_gdb "set follow ch\n"
313 send_gdb "show fol\n"
315 -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
316 {pass "set follow, using abbreviations"}
317 timeout {fail "(timeout) set follow, using abbreviations"}
320 # Verify that we cannot set follow-fork-mode to nonsense.
322 send_gdb "set follow chork\n"
324 -re "Undefined item: \"chork\".*$gdb_prompt $"\
325 {pass "set follow to nonsense is prohibited"}
326 -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
327 timeout {fail "(timeout) set follow to nonsense is prohibited"}
329 send_gdb "set follow parent\n"
331 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
332 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
335 # Test the default behaviour, which is to follow the parent of a
336 # fork, and detach from the child. Do this without catchpoints.
338 if [runto_main] then { default_fork_parent_follow }
340 # Test the ability to explicitly follow the parent of a fork, and
341 # detach from the child. Do this without catchpoints.
343 if [runto_main] then { explicit_fork_parent_follow }
345 # Test the ability to follow the child of a fork, and detach from
346 # the parent. Do this without catchpoints.
348 if [runto_main] then { explicit_fork_child_follow }
350 # Test the ability to follow both child and parent of a fork. Do
351 # this without catchpoints.
352 # ??rehrauer: NYI. Will add testpoints here when implemented.
355 # Test the ability to have the debugger ask the user at fork-time
356 # whether to follow the parent, child or both. Do this without
358 # ??rehrauer: NYI. Will add testpoints here when implemented.
361 # Test the ability to catch a fork, specify that the child be
362 # followed, and continue. Make the catchpoint permanent.
364 if [runto_main] then { catch_fork_child_follow }
366 # Test the ability to catch a fork, specify via a -do clause that
367 # the parent be followed, and continue. Make the catchpoint temporary.
369 if [runto_main] then { tcatch_fork_parent_follow }
372 # Start with a fresh gdb
376 gdb_reinitialize_dir $srcdir/$subdir
380 # This is a test of gdb's ability to follow the parent, child or both
381 # parent and child of a Unix fork() system call.