import gdb-1999-06-28 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-fork.exp
1 # Copyright (C) 1997 Free Software Foundation, Inc.
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
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 set prms_id 0
25 set bug_id 0
26
27 set testfile "foll-fork"
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}
30
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."
33 }
34
35
36
37 # Until "set follow-fork-mode" and "catch fork" are implemented on
38 # other targets...
39 #
40 if ![istarget "hppa*-hp-hpux*"] then {
41 continue
42 }
43
44 proc default_fork_parent_follow {} {
45 global gdb_prompt
46
47 send_gdb "show follow\n"
48 gdb_expect {
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"}
53 }
54 send_gdb "next 2\n"
55 gdb_expect {
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" }
60 }
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.
64 #
65 exec sleep 1
66 }
67
68 proc explicit_fork_parent_follow {} {
69 global gdb_prompt
70
71 send_gdb "set follow parent\n"
72 gdb_expect {
73 -re "$gdb_prompt $" {pass "set follow parent"}
74 timeout {fail "(timeout) set follow parent"}
75 }
76 send_gdb "show follow\n"
77 gdb_expect {
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"}
82 }
83 send_gdb "next 2\n"
84 gdb_expect {
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"}
89 }
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.
93 #
94 exec sleep 1
95 }
96
97 proc explicit_fork_child_follow {} {
98 global gdb_prompt
99
100 send_gdb "set follow child\n"
101 gdb_expect {
102 -re "$gdb_prompt $" {pass "set follow child"}
103 timeout {fail "(timeout) set follow child"}
104 }
105 send_gdb "show follow\n"
106 gdb_expect {
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"}
111 }
112 send_gdb "next 2\n"
113 gdb_expect {
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"}
118 }
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.
122 #
123 exec sleep 1
124 }
125
126 proc catch_fork_child_follow {} {
127 global gdb_prompt
128
129 send_gdb "catch fork\n"
130 gdb_expect {
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"}
135 }
136
137 # Verify that the catchpoint is mentioned in an "info breakpoints",
138 # and further that the catchpoint mentions no process id.
139 #
140 send_gdb "info breakpoints\n"
141 gdb_expect {
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"}
148 }
149
150 send_gdb "continue\n"
151 gdb_expect {
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"}
156 }
157
158 # Verify that the catchpoint is mentioned in an "info breakpoints",
159 # and further that the catchpoint managed to capture a process id.
160 #
161 send_gdb "info breakpoints\n"
162 gdb_expect {
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"}
167 }
168
169 send_gdb "set follow child\n"
170 gdb_expect {
171 -re "$gdb_prompt $" {pass "set follow child"}
172 timeout {fail "(timeout) set follow child"}
173 }
174 send_gdb "tbreak 24\n"
175 gdb_expect {
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"}
180 }
181 send_gdb "continue\n"
182 gdb_expect {
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"}
187 }
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.
191 #
192 exec sleep 1
193 send_gdb "delete breakpoints\n"
194 gdb_expect {
195 -re "Delete all breakpoints.*$" {
196 send_gdb "y\n"
197 gdb_expect {
198 -re "$gdb_prompt $"\
199 {pass "set follow child, cleanup"}
200 timeout {fail "(timeout) set follow child, cleanup"}
201 }
202 }
203 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
204 timeout {fail "(timeout) set follow child, cleanup"}
205 }
206 }
207
208 proc tcatch_fork_parent_follow {} {
209 global gdb_prompt
210
211 send_gdb "catch fork\n"
212 gdb_expect {
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"}
217 }
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.
221
222 send_gdb "continue\n"
223 gdb_expect {
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"}
228 }
229 send_gdb "set follow parent\n"
230 gdb_expect {
231 -re "$gdb_prompt $" {pass "set follow parent"}
232 timeout {fail "(timeout) set follow parent"}
233 }
234 send_gdb "tbreak 24\n"
235 gdb_expect {
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"}
240 }
241 send_gdb "continue\n"
242 gdb_expect {
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"}
247 }
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.
251 #
252 exec sleep 1
253 send_gdb "delete breakpoints\n"
254 gdb_expect {
255 -re "Delete all breakpoints.*$" {
256 send_gdb "y\n"
257 gdb_expect {
258 -re "$gdb_prompt $"\
259 {pass "set follow parent, cleanup"}
260 timeout {fail "(timeout) set follow parent, cleanup"}
261 }
262 }
263 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
264 timeout {fail "(timeout) set follow parent, cleanup"}
265 }
266 }
267
268 proc do_fork_tests {} {
269 global gdb_prompt
270
271 # Verify that help is available for "set follow-fork-mode".
272 #
273 send_gdb "help set follow-fork-mode\n"
274 gdb_expect {
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" }
285 }
286
287 # Verify that we can set follow-fork-mode, using an abbreviation
288 # for both the flag and its value.
289 #
290 send_gdb "set follow ch\n"
291 send_gdb "show fol\n"
292 gdb_expect {
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"}
296 }
297
298 # Verify that we cannot set follow-fork-mode to nonsense.
299 #
300 send_gdb "set follow chork\n"
301 gdb_expect {
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"}
306 }
307 send_gdb "set follow parent\n"
308 gdb_expect {
309 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
310 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
311 }
312
313 # Test the default behaviour, which is to follow the parent of a
314 # fork, and detach from the child. Do this without catchpoints.
315 #
316 if [runto_main] then { default_fork_parent_follow }
317
318 # Test the ability to explicitly follow the parent of a fork, and
319 # detach from the child. Do this without catchpoints.
320 #
321 if [runto_main] then { explicit_fork_parent_follow }
322
323 # Test the ability to follow the child of a fork, and detach from
324 # the parent. Do this without catchpoints.
325 #
326 if [runto_main] then { explicit_fork_child_follow }
327
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.
331 #
332
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
335 # catchpoints.
336 # ??rehrauer: NYI. Will add testpoints here when implemented.
337 #
338
339 # Test the ability to catch a fork, specify that the child be
340 # followed, and continue. Make the catchpoint permanent.
341 #
342 if [runto_main] then { catch_fork_child_follow }
343
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.
346 #
347 if [runto_main] then { tcatch_fork_parent_follow }
348 }
349
350 # Start with a fresh gdb
351
352 gdb_exit
353 gdb_start
354 gdb_reinitialize_dir $srcdir/$subdir
355 gdb_load ${binfile}
356
357
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.
360 #
361 do_fork_tests
362
363 return 0
This page took 0.038268 seconds and 5 git commands to generate.