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 set testfile "foll-fork"
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
32 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
37 # Until "set follow-fork-mode" and "catch fork" are implemented on
40 if ![istarget "hppa*-hp-hpux*"] then {
44 proc default_fork_parent_follow {} {
47 send_gdb "show follow\n"
49 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
50 {pass "default show parent follow, no catchpoints"}
51 -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
52 timeout {fail "(timeout) default show parent follow, no catchpoints"}
56 -re "Detaching after fork from.*$gdb_prompt $"\
57 {pass "default parent follow, no catchpoints"}
58 -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
59 timeout {fail "(timeout) default parent follow, no catchpoints" }
61 # The child has been detached; allow time for any output it might
62 # generate to arrive, so that output doesn't get confused with
63 # any expected debugger output from a subsequent testpoint.
68 proc explicit_fork_parent_follow {} {
71 send_gdb "set follow parent\n"
73 -re "$gdb_prompt $" {pass "set follow parent"}
74 timeout {fail "(timeout) set follow parent"}
76 send_gdb "show follow\n"
78 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
79 {pass "explicit show parent follow, no catchpoints"}
80 -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
81 timeout {fail "(timeout) explicit show parent follow, no catchpoints"}
85 -re "Detaching after fork from.*$gdb_prompt $"\
86 {pass "explicit parent follow, no catchpoints"}
87 -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
88 timeout {fail "(timeout) explicit parent follow, no catchpoints"}
90 # The child has been detached; allow time for any output it might
91 # generate to arrive, so that output doesn't get confused with
92 # any expected debugger output from a subsequent testpoint.
97 proc explicit_fork_child_follow {} {
100 send_gdb "set follow child\n"
102 -re "$gdb_prompt $" {pass "set follow child"}
103 timeout {fail "(timeout) set follow child"}
105 send_gdb "show follow\n"
107 -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
108 {pass "explicit show child follow, no catchpoints"}
109 -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
110 timeout {fail "(timeout) explicit show child follow, no catchpoints"}
114 -re "Detaching from program:.*Attaching after fork to.*$gdb_prompt $"\
115 {pass "explicit child follow, no catchpoints"}
116 -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
117 timeout {fail "(timeout) explicit child follow, no catchpoints"}
119 # The child has been detached; allow time for any output it might
120 # generate to arrive, so that output doesn't get confused with
121 # any gdb_expected debugger output from a subsequent testpoint.
126 proc catch_fork_child_follow {} {
129 send_gdb "catch fork\n"
131 -re "Catchpoint .*(fork).*$gdb_prompt $"\
132 {pass "explicit child follow, set catch fork"}
133 -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
134 timeout {fail "(timeout) explicit child follow, set catch fork"}
137 # Verify that the catchpoint is mentioned in an "info breakpoints",
138 # and further that the catchpoint mentions no process id.
140 send_gdb "info breakpoints\n"
142 -re ".*catch fork.*keep y.*$gdb_prompt $"\
143 {pass "info shows catchpoint without pid"}
144 -re ".*catch fork.*process .*$gdb_prompt $"\
145 {fail "info shows catchpoint without pid"}
146 -re "$gdb_prompt $" {fail "info shows catchpoint without pid"}
147 timeout {fail "(timeout) info shows catchpoint without pid"}
150 send_gdb "continue\n"
152 -re "Catchpoint.*(forked process.*),.*in _fork_sys.*$gdb_prompt $"\
153 {pass "explicit child follow, catch fork"}
154 -re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
155 timeout {fail "(timeout) explicit child follow, catch fork"}
158 # Verify that the catchpoint is mentioned in an "info breakpoints",
159 # and further that the catchpoint managed to capture a process id.
161 send_gdb "info breakpoints\n"
163 -re ".*catch fork .*process \[0-9\]+.*$gdb_prompt $"\
164 {pass "info shows catchpoint pid"}
165 -re "$gdb_prompt $" {fail "info shows catchpoint pid"}
166 timeout {fail "(timeout) info shows catchpoint pid"}
169 send_gdb "set follow child\n"
171 -re "$gdb_prompt $" {pass "set follow child"}
172 timeout {fail "(timeout) set follow child"}
174 send_gdb "tbreak 24\n"
176 -re "Breakpoint.*, line 24.*$gdb_prompt $"\
177 {pass "set follow child, tbreak"}
178 -re "$gdb_prompt $" {fail "set follow child, tbreak"}
179 timeout {fail "(timeout) set follow child, tbreak"}
181 send_gdb "continue\n"
183 -re ".*Detaching from program:.*Attaching after fork to.* at .*24.*$gdb_prompt $"\
184 {pass "set follow child, hit tbreak"}
185 -re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
186 timeout {fail "(timeout) set follow child, hit tbreak"}
188 # The child has been detached; allow time for any output it might
189 # generate to arrive, so that output doesn't get confused with
190 # any expected debugger output from a subsequent testpoint.
193 send_gdb "delete breakpoints\n"
195 -re "Delete all breakpoints.*$" {
199 {pass "set follow child, cleanup"}
200 timeout {fail "(timeout) set follow child, cleanup"}
203 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
204 timeout {fail "(timeout) set follow child, cleanup"}
208 proc tcatch_fork_parent_follow {} {
211 send_gdb "catch fork\n"
213 -re "Catchpoint .*(fork).*$gdb_prompt $"\
214 {pass "explicit parent follow, set tcatch fork"}
215 -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
216 timeout {fail "(timeout) explicit parent follow, set tcatch fork"}
218 # ??rehrauer: I don't yet know how to get the id of the tcatch
219 # via this script, so that I can add a -do list to it. For now,
220 # do the follow stuff after the catch happens.
222 send_gdb "continue\n"
224 -re ".*in _fork_sys.*$gdb_prompt $"\
225 {pass "explicit parent follow, tcatch fork"}
226 -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
227 timeout {fail "(timeout) explicit parent follow, tcatch fork"}
229 send_gdb "set follow parent\n"
231 -re "$gdb_prompt $" {pass "set follow parent"}
232 timeout {fail "(timeout) set follow parent"}
234 send_gdb "tbreak 24\n"
236 -re "Breakpoint.*, line 24.*$gdb_prompt $"\
237 {pass "set follow parent, tbreak"}
238 -re "$gdb_prompt $" {fail "set follow parent, tbreak"}
239 timeout {fail "(timeout) set follow child, tbreak"}
241 send_gdb "continue\n"
243 -re ".*Detaching after fork from.* at .*24.*$gdb_prompt $"\
244 {pass "set follow parent, hit tbreak"}
245 -re "$gdb_prompt $" {fail "set follow parent, hit tbreak"}
246 timeout {fail "(timeout) set follow parent, hit tbreak"}
248 # The child has been detached; allow time for any output it might
249 # generate to arrive, so that output doesn't get confused with
250 # any expected debugger output from a subsequent testpoint.
253 send_gdb "delete breakpoints\n"
255 -re "Delete all breakpoints.*$" {
259 {pass "set follow parent, cleanup"}
260 timeout {fail "(timeout) set follow parent, cleanup"}
263 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
264 timeout {fail "(timeout) set follow parent, cleanup"}
268 proc do_fork_tests {} {
271 # Verify that help is available for "set follow-fork-mode".
273 send_gdb "help set follow-fork-mode\n"
275 -re "Set debugger response to a program call of fork or vfork..*
276 A fork or vfork creates a new process. follow-fork-mode can be:.*
277 .*parent - the original process is debugged after a fork.*
278 .*child - the new process is debugged after a fork.*
279 .*ask - the debugger will ask for one of the above choices.*
280 For \"parent\" or \"child\", the unfollowed process will run free..*
281 By default, the debugger will follow the parent process..*$gdb_prompt $"\
282 { pass "help set follow" }
283 -re "$gdb_prompt $" { fail "help set follow" }
284 timeout { fail "(timeout) help set follow" }
287 # Verify that we can set follow-fork-mode, using an abbreviation
288 # for both the flag and its value.
290 send_gdb "set follow ch\n"
291 send_gdb "show fol\n"
293 -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
294 {pass "set follow, using abbreviations"}
295 timeout {fail "(timeout) set follow, using abbreviations"}
298 # Verify that we cannot set follow-fork-mode to nonsense.
300 send_gdb "set follow chork\n"
302 -re "Undefined item: \"chork\".*$gdb_prompt $"\
303 {pass "set follow to nonsense is prohibited"}
304 -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
305 timeout {fail "(timeout) set follow to nonsense is prohibited"}
307 send_gdb "set follow parent\n"
309 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
310 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
313 # Test the default behaviour, which is to follow the parent of a
314 # fork, and detach from the child. Do this without catchpoints.
316 if [runto_main] then { default_fork_parent_follow }
318 # Test the ability to explicitly follow the parent of a fork, and
319 # detach from the child. Do this without catchpoints.
321 if [runto_main] then { explicit_fork_parent_follow }
323 # Test the ability to follow the child of a fork, and detach from
324 # the parent. Do this without catchpoints.
326 if [runto_main] then { explicit_fork_child_follow }
328 # Test the ability to follow both child and parent of a fork. Do
329 # this without catchpoints.
330 # ??rehrauer: NYI. Will add testpoints here when implemented.
333 # Test the ability to have the debugger ask the user at fork-time
334 # whether to follow the parent, child or both. Do this without
336 # ??rehrauer: NYI. Will add testpoints here when implemented.
339 # Test the ability to catch a fork, specify that the child be
340 # followed, and continue. Make the catchpoint permanent.
342 if [runto_main] then { catch_fork_child_follow }
344 # Test the ability to catch a fork, specify via a -do clause that
345 # the parent be followed, and continue. Make the catchpoint temporary.
347 if [runto_main] then { tcatch_fork_parent_follow }
350 # Start with a fresh gdb
354 gdb_reinitialize_dir $srcdir/$subdir
358 # This is a test of gdb's ability to follow the parent, child or both
359 # parent and child of a Unix fork() system call.