]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/foll-fork.exp
Initial creation of sourceware repository
[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 # are we on a target board
28 if ![isnative] then {
29 return
30 }
31
32 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
33 #setup_xfail "*-*.*"
34 return 0
35 }
36
37 set testfile "foll-fork"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
40
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"
49 # return -1
50 # }
51 #}
52
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."
55 }
56
57
58
59 # Until "set follow-fork-mode" and "catch fork" are implemented on
60 # other targets...
61 #
62 if ![istarget "hppa*-hp-hpux*"] then {
63 setup_xfail "*-*-*"
64 }
65
66 proc default_fork_parent_follow {} {
67 global gdb_prompt
68
69 send_gdb "show follow\n"
70 gdb_expect {
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"}
75 }
76 send_gdb "next 2\n"
77 gdb_expect {
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" }
82 }
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.
86 #
87 exec sleep 1
88 }
89
90 proc explicit_fork_parent_follow {} {
91 global gdb_prompt
92
93 send_gdb "set follow parent\n"
94 gdb_expect {
95 -re "$gdb_prompt $" {pass "set follow parent"}
96 timeout {fail "(timeout) set follow parent"}
97 }
98 send_gdb "show follow\n"
99 gdb_expect {
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"}
104 }
105 send_gdb "next 2\n"
106 gdb_expect {
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"}
111 }
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.
115 #
116 exec sleep 1
117 }
118
119 proc explicit_fork_child_follow {} {
120 global gdb_prompt
121
122 send_gdb "set follow child\n"
123 gdb_expect {
124 -re "$gdb_prompt $" {pass "set follow child"}
125 timeout {fail "(timeout) set follow child"}
126 }
127 send_gdb "show follow\n"
128 gdb_expect {
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"}
133 }
134 send_gdb "next 2\n"
135 gdb_expect {
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"}
140 }
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.
144 #
145 exec sleep 1
146 }
147
148 proc catch_fork_child_follow {} {
149 global gdb_prompt
150
151 send_gdb "catch fork\n"
152 gdb_expect {
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"}
157 }
158
159 # Verify that the catchpoint is mentioned in an "info breakpoints",
160 # and further that the catchpoint mentions no process id.
161 #
162 send_gdb "info breakpoints\n"
163 gdb_expect {
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"}
170 }
171
172 send_gdb "continue\n"
173 gdb_expect {
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"}
178 }
179
180 # Verify that the catchpoint is mentioned in an "info breakpoints",
181 # and further that the catchpoint managed to capture a process id.
182 #
183 send_gdb "info breakpoints\n"
184 gdb_expect {
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"}
189 }
190
191 send_gdb "set follow child\n"
192 gdb_expect {
193 -re "$gdb_prompt $" {pass "set follow child"}
194 timeout {fail "(timeout) set follow child"}
195 }
196 send_gdb "tbreak 15\n"
197 gdb_expect {
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"}
202 }
203 send_gdb "continue\n"
204 gdb_expect {
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"}
209 }
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.
213 #
214 exec sleep 1
215 send_gdb "delete breakpoints\n"
216 gdb_expect {
217 -re "Delete all breakpoints.*$" {
218 send_gdb "y\n"
219 gdb_expect {
220 -re "$gdb_prompt $"\
221 {pass "set follow child, cleanup"}
222 timeout {fail "(timeout) set follow child, cleanup"}
223 }
224 }
225 -re "$gdb_prompt $" {fail "set follow child, cleanup"}
226 timeout {fail "(timeout) set follow child, cleanup"}
227 }
228 }
229
230 proc tcatch_fork_parent_follow {} {
231 global gdb_prompt
232
233 send_gdb "catch fork\n"
234 gdb_expect {
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"}
239 }
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.
243
244 send_gdb "continue\n"
245 gdb_expect {
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"}
250 }
251 send_gdb "set follow parent\n"
252 gdb_expect {
253 -re "$gdb_prompt $" {pass "set follow parent"}
254 timeout {fail "(timeout) set follow parent"}
255 }
256 send_gdb "tbreak 15\n"
257 gdb_expect {
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"}
262 }
263 send_gdb "continue\n"
264 gdb_expect {
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"}
269 }
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.
273 #
274 exec sleep 1
275 send_gdb "delete breakpoints\n"
276 gdb_expect {
277 -re "Delete all breakpoints.*$" {
278 send_gdb "y\n"
279 gdb_expect {
280 -re "$gdb_prompt $"\
281 {pass "set follow parent, cleanup"}
282 timeout {fail "(timeout) set follow parent, cleanup"}
283 }
284 }
285 -re "$gdb_prompt $" {fail "set follow parent, cleanup"}
286 timeout {fail "(timeout) set follow parent, cleanup"}
287 }
288 }
289
290 proc do_fork_tests {} {
291 global gdb_prompt
292
293 # Verify that help is available for "set follow-fork-mode".
294 #
295 send_gdb "help set follow-fork-mode\n"
296 gdb_expect {
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" }
307 }
308
309 # Verify that we can set follow-fork-mode, using an abbreviation
310 # for both the flag and its value.
311 #
312 send_gdb "set follow ch\n"
313 send_gdb "show fol\n"
314 gdb_expect {
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"}
318 }
319
320 # Verify that we cannot set follow-fork-mode to nonsense.
321 #
322 send_gdb "set follow chork\n"
323 gdb_expect {
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"}
328 }
329 send_gdb "set follow parent\n"
330 gdb_expect {
331 -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
332 timeout {fail "set follow to nonsense is prohibited (reset parent)"}
333 }
334
335 # Test the default behaviour, which is to follow the parent of a
336 # fork, and detach from the child. Do this without catchpoints.
337 #
338 if [runto_main] then { default_fork_parent_follow }
339
340 # Test the ability to explicitly follow the parent of a fork, and
341 # detach from the child. Do this without catchpoints.
342 #
343 if [runto_main] then { explicit_fork_parent_follow }
344
345 # Test the ability to follow the child of a fork, and detach from
346 # the parent. Do this without catchpoints.
347 #
348 if [runto_main] then { explicit_fork_child_follow }
349
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.
353 #
354
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
357 # catchpoints.
358 # ??rehrauer: NYI. Will add testpoints here when implemented.
359 #
360
361 # Test the ability to catch a fork, specify that the child be
362 # followed, and continue. Make the catchpoint permanent.
363 #
364 if [runto_main] then { catch_fork_child_follow }
365
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.
368 #
369 if [runto_main] then { tcatch_fork_parent_follow }
370 }
371
372 # Start with a fresh gdb
373
374 gdb_exit
375 gdb_start
376 gdb_reinitialize_dir $srcdir/$subdir
377 gdb_load ${binfile}
378
379
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.
382 #
383 do_fork_tests
384
385 return 0