]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/foll-fork.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-fork.exp
CommitLineData
6aba47ca 1# Copyright 1997, 1999, 2007 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
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
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.
12#
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. */
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20if $tracelevel then {
21 strace $tracelevel
22 }
23
5a2468f5
JM
24if { ![isnative] } then {
25 continue
26}
27
74cf1395
JM
28set prms_id 0
29set bug_id 0
30
31set testfile "foll-fork"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/${testfile}
34
35if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
36 untested foll-fork.exp
37 return -1
74cf1395
JM
38}
39
40
41
42# Until "set follow-fork-mode" and "catch fork" are implemented on
43# other targets...
44#
45if ![istarget "hppa*-hp-hpux*"] then {
46 continue
47}
48
49proc default_fork_parent_follow {} {
50 global gdb_prompt
51
52 send_gdb "show follow\n"
53 gdb_expect {
54 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
55 {pass "default show parent follow, no catchpoints"}
56 -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
57 timeout {fail "(timeout) default show parent follow, no catchpoints"}
58 }
59 send_gdb "next 2\n"
60 gdb_expect {
61 -re "Detaching after fork from.*$gdb_prompt $"\
62 {pass "default parent follow, no catchpoints"}
63 -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
64 timeout {fail "(timeout) default parent follow, no catchpoints" }
65 }
66 # The child has been detached; allow time for any output it might
67 # generate to arrive, so that output doesn't get confused with
68 # any expected debugger output from a subsequent testpoint.
69 #
70 exec sleep 1
71}
72
73proc explicit_fork_parent_follow {} {
74 global gdb_prompt
75
76 send_gdb "set follow parent\n"
77 gdb_expect {
78 -re "$gdb_prompt $" {pass "set follow parent"}
79 timeout {fail "(timeout) set follow parent"}
80 }
81 send_gdb "show follow\n"
82 gdb_expect {
83 -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
84 {pass "explicit show parent follow, no catchpoints"}
85 -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
86 timeout {fail "(timeout) explicit show parent follow, no catchpoints"}
87 }
88 send_gdb "next 2\n"
89 gdb_expect {
90 -re "Detaching after fork from.*$gdb_prompt $"\
91 {pass "explicit parent follow, no catchpoints"}
92 -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
93 timeout {fail "(timeout) explicit parent follow, no catchpoints"}
94 }
95 # The child has been detached; allow time for any output it might
96 # generate to arrive, so that output doesn't get confused with
97 # any expected debugger output from a subsequent testpoint.
98 #
99 exec sleep 1
100}
101
102proc explicit_fork_child_follow {} {
103 global gdb_prompt
104
105 send_gdb "set follow child\n"
106 gdb_expect {
107 -re "$gdb_prompt $" {pass "set follow child"}
108 timeout {fail "(timeout) set follow child"}
109 }
110 send_gdb "show follow\n"
111 gdb_expect {
112 -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
113 {pass "explicit show child follow, no catchpoints"}
114 -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
115 timeout {fail "(timeout) explicit show child follow, no catchpoints"}
116 }
117 send_gdb "next 2\n"
118 gdb_expect {
119 -re "Detaching from program:.*Attaching after fork to.*$gdb_prompt $"\
120 {pass "explicit child follow, no catchpoints"}
121 -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
122 timeout {fail "(timeout) explicit child follow, no catchpoints"}
123 }
124 # The child has been detached; allow time for any output it might
125 # generate to arrive, so that output doesn't get confused with
126 # any gdb_expected debugger output from a subsequent testpoint.
127 #
128 exec sleep 1
129}
130
131proc catch_fork_child_follow {} {
132 global gdb_prompt
133
134 send_gdb "catch fork\n"
135 gdb_expect {
136 -re "Catchpoint .*(fork).*$gdb_prompt $"\
137 {pass "explicit child follow, set catch fork"}
138 -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
139 timeout {fail "(timeout) explicit child follow, set catch fork"}
140 }
141
142 # Verify that the catchpoint is mentioned in an "info breakpoints",
143 # and further that the catchpoint mentions no process id.
144 #
145 send_gdb "info breakpoints\n"
146 gdb_expect {
147 -re ".*catch fork.*keep y.*$gdb_prompt $"\
148 {pass "info shows catchpoint without pid"}
149 -re ".*catch fork.*process .*$gdb_prompt $"\
150 {fail "info shows catchpoint without pid"}
151 -re "$gdb_prompt $" {fail "info shows catchpoint without pid"}
152 timeout {fail "(timeout) info shows catchpoint without pid"}
153 }
154
155 send_gdb "continue\n"
156 gdb_expect {
157 -re "Catchpoint.*(forked process.*),.*in _fork_sys.*$gdb_prompt $"\
158 {pass "explicit child follow, catch fork"}
159 -re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
160 timeout {fail "(timeout) explicit child follow, catch fork"}
161 }
162
163 # Verify that the catchpoint is mentioned in an "info breakpoints",
164 # and further that the catchpoint managed to capture a process id.
165 #
166 send_gdb "info breakpoints\n"
167 gdb_expect {
168 -re ".*catch fork .*process \[0-9\]+.*$gdb_prompt $"\
169 {pass "info shows catchpoint pid"}
170 -re "$gdb_prompt $" {fail "info shows catchpoint pid"}
171 timeout {fail "(timeout) info shows catchpoint pid"}
172 }
173
174 send_gdb "set follow child\n"
175 gdb_expect {
176 -re "$gdb_prompt $" {pass "set follow child"}
177 timeout {fail "(timeout) set follow child"}
178 }
179 send_gdb "tbreak 24\n"
180 gdb_expect {
181 -re "Breakpoint.*, line 24.*$gdb_prompt $"\
182 {pass "set follow child, tbreak"}
183 -re "$gdb_prompt $" {fail "set follow child, tbreak"}
184 timeout {fail "(timeout) set follow child, tbreak"}
185 }
186 send_gdb "continue\n"
187 gdb_expect {
188 -re ".*Detaching from program:.*Attaching after fork to.* at .*24.*$gdb_prompt $"\
189 {pass "set follow child, hit tbreak"}
190 -re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
191 timeout {fail "(timeout) set follow child, hit tbreak"}
192 }
193 # The child has been detached; allow time for any output it might
194 # generate to arrive, so that output doesn't get confused with
195 # any expected debugger output from a subsequent testpoint.
196 #
197 exec sleep 1
198 send_gdb "delete breakpoints\n"
199 gdb_expect {
200 -re "Delete all breakpoints.*$" {
201 send_gdb "y\n"
202 gdb_expect {
203 -re "$gdb_prompt $"\
204 {pass "set follow child, cleanup"}
205 timeout {fail "(timeout) set follow child, cleanup"}
206 }
207 }
208 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
209 timeout {fail "(timeout) set follow child, cleanup"}
210 }
211}
212
213proc tcatch_fork_parent_follow {} {
214 global gdb_prompt
215
216 send_gdb "catch fork\n"
217 gdb_expect {
218 -re "Catchpoint .*(fork).*$gdb_prompt $"\
219 {pass "explicit parent follow, set tcatch fork"}
220 -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
221 timeout {fail "(timeout) explicit parent follow, set tcatch fork"}
222 }
223# ??rehrauer: I don't yet know how to get the id of the tcatch
224# via this script, so that I can add a -do list to it. For now,
225# do the follow stuff after the catch happens.
226
227 send_gdb "continue\n"
228 gdb_expect {
229 -re ".*in _fork_sys.*$gdb_prompt $"\
230 {pass "explicit parent follow, tcatch fork"}
231 -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
232 timeout {fail "(timeout) explicit parent follow, tcatch fork"}
233 }
234 send_gdb "set follow parent\n"
235 gdb_expect {
236 -re "$gdb_prompt $" {pass "set follow parent"}
237 timeout {fail "(timeout) set follow parent"}
238 }
239 send_gdb "tbreak 24\n"
240 gdb_expect {
241 -re "Breakpoint.*, line 24.*$gdb_prompt $"\
242 {pass "set follow parent, tbreak"}
243 -re "$gdb_prompt $" {fail "set follow parent, tbreak"}
244 timeout {fail "(timeout) set follow child, tbreak"}
245 }
246 send_gdb "continue\n"
247 gdb_expect {
248 -re ".*Detaching after fork from.* at .*24.*$gdb_prompt $"\
249 {pass "set follow parent, hit tbreak"}
250 -re "$gdb_prompt $" {fail "set follow parent, hit tbreak"}
251 timeout {fail "(timeout) set follow parent, hit tbreak"}
252 }
253 # The child has been detached; allow time for any output it might
254 # generate to arrive, so that output doesn't get confused with
255 # any expected debugger output from a subsequent testpoint.
256 #
257 exec sleep 1
258 send_gdb "delete breakpoints\n"
259 gdb_expect {
260 -re "Delete all breakpoints.*$" {
261 send_gdb "y\n"
262 gdb_expect {
263 -re "$gdb_prompt $"\
264 {pass "set follow parent, cleanup"}
265 timeout {fail "(timeout) set follow parent, cleanup"}
266 }
267 }
268 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
269 timeout {fail "(timeout) set follow parent, cleanup"}
270 }
271}
272
273proc do_fork_tests {} {
274 global gdb_prompt
275
276 # Verify that help is available for "set follow-fork-mode".
277 #
278 send_gdb "help set follow-fork-mode\n"
279 gdb_expect {
280 -re "Set debugger response to a program call of fork or vfork..*
281A fork or vfork creates a new process. follow-fork-mode can be:.*
282.*parent - the original process is debugged after a fork.*
283.*child - the new process is debugged after a fork.*
ef04f396 284The unfollowed process will continue to run..*
74cf1395
JM
285By default, the debugger will follow the parent process..*$gdb_prompt $"\
286 { pass "help set follow" }
287 -re "$gdb_prompt $" { fail "help set follow" }
288 timeout { fail "(timeout) help set follow" }
289 }
290
291 # Verify that we can set follow-fork-mode, using an abbreviation
292 # for both the flag and its value.
293 #
294 send_gdb "set follow ch\n"
295 send_gdb "show fol\n"
296 gdb_expect {
297 -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
298 {pass "set follow, using abbreviations"}
299 timeout {fail "(timeout) set follow, using abbreviations"}
300 }
301
302 # Verify that we cannot set follow-fork-mode to nonsense.
303 #
304 send_gdb "set follow chork\n"
305 gdb_expect {
306 -re "Undefined item: \"chork\".*$gdb_prompt $"\
307 {pass "set follow to nonsense is prohibited"}
308 -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
309 timeout {fail "(timeout) set follow to nonsense is prohibited"}
310 }
311 send_gdb "set follow parent\n"
312 gdb_expect {
313 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
314 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
315 }
316
317 # Test the default behaviour, which is to follow the parent of a
318 # fork, and detach from the child. Do this without catchpoints.
319 #
320 if [runto_main] then { default_fork_parent_follow }
321
322 # Test the ability to explicitly follow the parent of a fork, and
323 # detach from the child. Do this without catchpoints.
324 #
325 if [runto_main] then { explicit_fork_parent_follow }
326
327 # Test the ability to follow the child of a fork, and detach from
328 # the parent. Do this without catchpoints.
329 #
330 if [runto_main] then { explicit_fork_child_follow }
331
332 # Test the ability to follow both child and parent of a fork. Do
333 # this without catchpoints.
334 # ??rehrauer: NYI. Will add testpoints here when implemented.
335 #
336
337 # Test the ability to have the debugger ask the user at fork-time
338 # whether to follow the parent, child or both. Do this without
339 # catchpoints.
340 # ??rehrauer: NYI. Will add testpoints here when implemented.
341 #
342
343 # Test the ability to catch a fork, specify that the child be
344 # followed, and continue. Make the catchpoint permanent.
345 #
346 if [runto_main] then { catch_fork_child_follow }
347
348 # Test the ability to catch a fork, specify via a -do clause that
349 # the parent be followed, and continue. Make the catchpoint temporary.
350 #
351 if [runto_main] then { tcatch_fork_parent_follow }
352}
353
354# Start with a fresh gdb
355
356gdb_exit
357gdb_start
358gdb_reinitialize_dir $srcdir/$subdir
359gdb_load ${binfile}
360
361
362# This is a test of gdb's ability to follow the parent, child or both
363# parent and child of a Unix fork() system call.
364#
365do_fork_tests
366
367return 0