]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/foll-fork.exp
This commit was generated by cvs2svn to track changes on a CVS vendor
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / 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 if { [skip_hp_tests] } then { continue }
28
29 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
30 #setup_xfail "*-*.*"
31 return 0
32 }
33
34 set testfile "foll-fork"
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37
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"
46 # return -1
47 # }
48 #}
49
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."
52 }
53
54
55
56 # Until "set follow-fork-mode" and "catch fork" are implemented on
57 # other targets...
58 #
59 if ![istarget "hppa*-hp-hpux*"] then {
60 setup_xfail "*-*-*"
61 }
62
63 proc default_fork_parent_follow {} {
64 global gdb_prompt
65
66 send_gdb "show follow\n"
67 gdb_expect {
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"}
72 }
73 send_gdb "next 2\n"
74 gdb_expect {
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" }
79 }
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.
83 #
84 exec sleep 1
85 }
86
87 proc explicit_fork_parent_follow {} {
88 global gdb_prompt
89
90 send_gdb "set follow parent\n"
91 gdb_expect {
92 -re "$gdb_prompt $" {pass "set follow parent"}
93 timeout {fail "(timeout) set follow parent"}
94 }
95 send_gdb "show follow\n"
96 gdb_expect {
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"}
101 }
102 send_gdb "next 2\n"
103 gdb_expect {
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"}
108 }
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.
112 #
113 exec sleep 1
114 }
115
116 proc explicit_fork_child_follow {} {
117 global gdb_prompt
118
119 send_gdb "set follow child\n"
120 gdb_expect {
121 -re "$gdb_prompt $" {pass "set follow child"}
122 timeout {fail "(timeout) set follow child"}
123 }
124 send_gdb "show follow\n"
125 gdb_expect {
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"}
130 }
131 send_gdb "next 2\n"
132 gdb_expect {
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"}
137 }
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.
141 #
142 exec sleep 1
143 }
144
145 proc catch_fork_child_follow {} {
146 global gdb_prompt
147
148 send_gdb "catch fork\n"
149 gdb_expect {
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"}
154 }
155
156 # Verify that the catchpoint is mentioned in an "info breakpoints",
157 # and further that the catchpoint mentions no process id.
158 #
159 send_gdb "info breakpoints\n"
160 gdb_expect {
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"}
167 }
168
169 send_gdb "continue\n"
170 gdb_expect {
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"}
175 }
176
177 # Verify that the catchpoint is mentioned in an "info breakpoints",
178 # and further that the catchpoint managed to capture a process id.
179 #
180 send_gdb "info breakpoints\n"
181 gdb_expect {
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"}
186 }
187
188 send_gdb "set follow child\n"
189 gdb_expect {
190 -re "$gdb_prompt $" {pass "set follow child"}
191 timeout {fail "(timeout) set follow child"}
192 }
193 send_gdb "tbreak 15\n"
194 gdb_expect {
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"}
199 }
200 send_gdb "continue\n"
201 gdb_expect {
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"}
206 }
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.
210 #
211 exec sleep 1
212 send_gdb "delete breakpoints\n"
213 gdb_expect {
214 -re "Delete all breakpoints.*$" {
215 send_gdb "y\n"
216 gdb_expect {
217 -re "$gdb_prompt $"\
218 {pass "set follow child, cleanup"}
219 timeout {fail "(timeout) set follow child, cleanup"}
220 }
221 }
222 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
223 timeout {fail "(timeout) set follow child, cleanup"}
224 }
225 }
226
227 proc tcatch_fork_parent_follow {} {
228 global gdb_prompt
229
230 send_gdb "catch fork\n"
231 gdb_expect {
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"}
236 }
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.
240
241 send_gdb "continue\n"
242 gdb_expect {
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"}
247 }
248 send_gdb "set follow parent\n"
249 gdb_expect {
250 -re "$gdb_prompt $" {pass "set follow parent"}
251 timeout {fail "(timeout) set follow parent"}
252 }
253 send_gdb "tbreak 15\n"
254 gdb_expect {
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"}
259 }
260 send_gdb "continue\n"
261 gdb_expect {
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"}
266 }
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.
270 #
271 exec sleep 1
272 send_gdb "delete breakpoints\n"
273 gdb_expect {
274 -re "Delete all breakpoints.*$" {
275 send_gdb "y\n"
276 gdb_expect {
277 -re "$gdb_prompt $"\
278 {pass "set follow parent, cleanup"}
279 timeout {fail "(timeout) set follow parent, cleanup"}
280 }
281 }
282 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
283 timeout {fail "(timeout) set follow parent, cleanup"}
284 }
285 }
286
287 proc do_fork_tests {} {
288 global gdb_prompt
289
290 # Verify that help is available for "set follow-fork-mode".
291 #
292 send_gdb "help set follow-fork-mode\n"
293 gdb_expect {
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" }
304 }
305
306 # Verify that we can set follow-fork-mode, using an abbreviation
307 # for both the flag and its value.
308 #
309 send_gdb "set follow ch\n"
310 send_gdb "show fol\n"
311 gdb_expect {
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"}
315 }
316
317 # Verify that we cannot set follow-fork-mode to nonsense.
318 #
319 send_gdb "set follow chork\n"
320 gdb_expect {
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"}
325 }
326 send_gdb "set follow parent\n"
327 gdb_expect {
328 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
329 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
330 }
331
332 # Test the default behaviour, which is to follow the parent of a
333 # fork, and detach from the child. Do this without catchpoints.
334 #
335 if [runto_main] then { default_fork_parent_follow }
336
337 # Test the ability to explicitly follow the parent of a fork, and
338 # detach from the child. Do this without catchpoints.
339 #
340 if [runto_main] then { explicit_fork_parent_follow }
341
342 # Test the ability to follow the child of a fork, and detach from
343 # the parent. Do this without catchpoints.
344 #
345 if [runto_main] then { explicit_fork_child_follow }
346
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.
350 #
351
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
354 # catchpoints.
355 # ??rehrauer: NYI. Will add testpoints here when implemented.
356 #
357
358 # Test the ability to catch a fork, specify that the child be
359 # followed, and continue. Make the catchpoint permanent.
360 #
361 if [runto_main] then { catch_fork_child_follow }
362
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.
365 #
366 if [runto_main] then { tcatch_fork_parent_follow }
367 }
368
369 # Start with a fresh gdb
370
371 gdb_exit
372 gdb_start
373 gdb_reinitialize_dir $srcdir/$subdir
374 gdb_load ${binfile}
375
376
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.
379 #
380 do_fork_tests
381
382 return 0