OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.base/] [foll-fork.exp] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
#   Copyright 1997, 1999, 2007, 2008 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 3 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, see .
15
 
16
if { [is_remote target] || ![isnative] } then {
17
    continue
18
}
19
 
20
set prms_id 0
21
set bug_id 0
22
 
23
global srcfile
24
set testfile "foll-fork"
25
set srcfile ${testfile}.c
26
set binfile ${objdir}/${subdir}/${testfile}
27
 
28
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
29
     untested foll-fork.exp
30
     return -1
31
}
32
 
33
 
34
 
35
# Until "set follow-fork-mode" and "catch fork" are implemented on
36
# other targets...
37
#
38
if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
39
    continue
40
}
41
 
42
proc check_fork_catchpoints {} {
43
  global gdb_prompt
44
 
45
  # Verify that the system supports "catch fork".
46
  gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint"
47
  set has_fork_catchpoints 0
48
  gdb_test_multiple "continue" "continue to first fork catchpoint" {
49
    -re ".*Your system does not support fork catchpoints.*$gdb_prompt $" {
50
      unsupported "continue to first fork catchpoint"
51
    }
52
    -re ".*Catchpoint.*$gdb_prompt $" {
53
      set has_fork_catchpoints 1
54
      pass "continue to first fork catchpoint"
55
    }
56
  }
57
 
58
  if {$has_fork_catchpoints == 0} {
59
    unsupported "fork catchpoints"
60
    return -code return
61
  }
62
}
63
 
64
proc default_fork_parent_follow {} {
65
   global gdb_prompt
66
 
67
   send_gdb "show follow\n"
68
   gdb_expect {
69
      -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
70
                      {pass "default show parent follow, no catchpoints"}
71
      -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
72
      timeout         {fail "(timeout) default show parent follow, no catchpoints"}
73
   }
74
   send_gdb "next 2\n"
75
   gdb_expect {
76
      -re "Detaching after fork from.*$gdb_prompt $"\
77
                      {pass "default parent follow, no catchpoints"}
78
      -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
79
      timeout         {fail "(timeout) default parent follow, no catchpoints" }
80
   }
81
   # The child has been detached; allow time for any output it might
82
   # generate to arrive, so that output doesn't get confused with
83
   # any expected debugger output from a subsequent testpoint.
84
   #
85
   exec sleep 1
86
}
87
 
88
proc explicit_fork_parent_follow {} {
89
   global gdb_prompt
90
 
91
   send_gdb "set follow parent\n"
92
   gdb_expect {
93
      -re "$gdb_prompt $" {pass "set follow parent"}
94
      timeout         {fail "(timeout) set follow parent"}
95
   }
96
   send_gdb "show follow\n"
97
   gdb_expect {
98
      -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
99
                      {pass "explicit show parent follow, no catchpoints"}
100
      -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
101
      timeout         {fail "(timeout) explicit show parent follow, no catchpoints"}
102
   }
103
   send_gdb "next 2\n"
104
   gdb_expect {
105
      -re "Detaching after fork from.*$gdb_prompt $"\
106
                      {pass "explicit parent follow, no catchpoints"}
107
      -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
108
      timeout         {fail "(timeout) explicit parent follow, no catchpoints"}
109
   }
110
   # The child has been detached; allow time for any output it might
111
   # generate to arrive, so that output doesn't get confused with
112
   # any expected debugger output from a subsequent testpoint.
113
   #
114
   exec sleep 1
115
}
116
 
117
proc explicit_fork_child_follow {} {
118
   global gdb_prompt
119
 
120
   send_gdb "set follow child\n"
121
   gdb_expect {
122
      -re "$gdb_prompt $" {pass "set follow child"}
123
      timeout         {fail "(timeout) set follow child"}
124
   }
125
   send_gdb "show follow\n"
126
   gdb_expect {
127
      -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
128
                      {pass "explicit show child follow, no catchpoints"}
129
      -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
130
      timeout         {fail "(timeout) explicit show child follow, no catchpoints"}
131
   }
132
   send_gdb "next 2\n"
133
   gdb_expect {
134
      -re "Attaching after fork to.*$gdb_prompt $"\
135
                      {pass "explicit child follow, no catchpoints"}
136
      -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
137
      timeout         {fail "(timeout) explicit child follow, no catchpoints"}
138
   }
139
   # The child has been detached; allow time for any output it might
140
   # generate to arrive, so that output doesn't get confused with
141
   # any gdb_expected debugger output from a subsequent testpoint.
142
   #
143
   exec sleep 1
144
}
145
 
146
proc catch_fork_child_follow {} {
147
   global gdb_prompt
148
   global srcfile
149
 
150
   send_gdb "catch fork\n"
151
   gdb_expect {
152
      -re "Catchpoint .*(fork).*$gdb_prompt $"\
153
                      {pass "explicit child follow, set catch fork"}
154
      -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
155
      timeout         {fail "(timeout) explicit child follow, set catch fork"}
156
   }
157
 
158
   # Verify that the catchpoint is mentioned in an "info breakpoints",
159
   # and further that the catchpoint mentions no process id.
160
   #
161
   send_gdb "info breakpoints\n"
162
   gdb_expect {
163
     -re ".*catch fork.*keep y.*$gdb_prompt $"\
164
                     {pass "info shows catchpoint without pid"}
165
     -re ".*catch fork.*process .*$gdb_prompt $"\
166
                     {fail "info shows catchpoint without pid"}
167
     -re "$gdb_prompt $" {fail "info shows catchpoint without pid"}
168
     timeout         {fail "(timeout) info shows catchpoint without pid"}
169
   }
170
 
171
   send_gdb "continue\n"
172
   gdb_expect {
173
      -re "Catchpoint.*(forked process.*),.*in .*fork.*$gdb_prompt $"\
174
                      {pass "explicit child follow, catch fork"}
175
      -re "$gdb_prompt $" {fail "explicit child follow, catch fork"}
176
      timeout         {fail "(timeout) explicit child follow, catch fork"}
177
   }
178
 
179
   # Verify that the catchpoint is mentioned in an "info breakpoints",
180
   # and further that the catchpoint managed to capture a process id.
181
   #
182
   send_gdb "info breakpoints\n"
183
   gdb_expect {
184
     -re ".*catch fork .*process \[0-9\]+.*$gdb_prompt $"\
185
                     {pass "info shows catchpoint pid"}
186
     -re "$gdb_prompt $" {fail "info shows catchpoint pid"}
187
     timeout         {fail "(timeout) info shows catchpoint pid"}
188
   }
189
 
190
   send_gdb "set follow child\n"
191
   gdb_expect {
192
      -re "$gdb_prompt $" {pass "set follow child"}
193
      timeout         {fail "(timeout) set follow child"}
194
   }
195
   send_gdb "tbreak ${srcfile}:24\n"
196
   gdb_expect {
197
      -re "Breakpoint.*, line 24.*$gdb_prompt $"\
198
                      {pass "set follow child, tbreak"}
199
      -re "$gdb_prompt $" {fail "set follow child, tbreak"}
200
      timeout         {fail "(timeout) set follow child, tbreak"}
201
   }
202
   send_gdb "continue\n"
203
   gdb_expect {
204
      -re "Attaching after fork to.* at .*24.*$gdb_prompt $"\
205
                      {pass "set follow child, hit tbreak"}
206
      -re "$gdb_prompt $" {fail "set follow child, hit tbreak"}
207
      timeout         {fail "(timeout) set follow child, hit tbreak"}
208
   }
209
   # The child has been detached; allow time for any output it might
210
   # generate to arrive, so that output doesn't get confused with
211
   # any expected debugger output from a subsequent testpoint.
212
   #
213
   exec sleep 1
214
   send_gdb "delete breakpoints\n"
215
   gdb_expect {
216
      -re "Delete all breakpoints.*$" {
217
         send_gdb "y\n"
218
         gdb_expect {
219
            -re "$gdb_prompt $"\
220
                    {pass "set follow child, cleanup"}
221
            timeout {fail "(timeout) set follow child, cleanup"}
222
         }
223
      }
224
      -re "$gdb_prompt $" {fail "set follow child, cleanup"}
225
      timeout         {fail "(timeout) set follow child, cleanup"}
226
   }
227
}
228
 
229
proc tcatch_fork_parent_follow {} {
230
   global gdb_prompt
231
   global srcfile
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.*$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 ${srcfile}:24\n"
257
   gdb_expect {
258
      -re "Breakpoint.*, line 24.*$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 .*24.*$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
The unfollowed process will continue to run..*
302
By default, the debugger will follow the parent process..*$gdb_prompt $"\
303
                      { pass "help set follow" }
304
      -re "$gdb_prompt $" { fail "help set follow" }
305
      timeout         { fail "(timeout) help set follow" }
306
   }
307
 
308
   # Verify that we can set follow-fork-mode, using an abbreviation
309
   # for both the flag and its value.
310
   #
311
   send_gdb "set follow ch\n"
312
   send_gdb "show fol\n"
313
   gdb_expect {
314
     -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
315
             {pass "set follow, using abbreviations"}
316
     timeout {fail "(timeout) set follow, using abbreviations"}
317
   }
318
 
319
   # Verify that we cannot set follow-fork-mode to nonsense.
320
   #
321
   send_gdb "set follow chork\n"
322
   gdb_expect {
323
     -re "Undefined item: \"chork\".*$gdb_prompt $"\
324
                     {pass "set follow to nonsense is prohibited"}
325
     -re "$gdb_prompt $" {fail "set follow to nonsense is prohibited"}
326
     timeout         {fail "(timeout) set follow to nonsense is prohibited"}
327
   }
328
   send_gdb "set follow parent\n"
329
   gdb_expect {
330
     -re "$gdb_prompt $" {pass "set follow to nonsense is prohibited (reset parent)"}
331
     timeout         {fail "set follow to nonsense is prohibited (reset parent)"}
332
   }
333
 
334
   # Check that fork catchpoints are supported, as an indicator for whether
335
   # fork-following is supported.
336
   if [runto_main] then { check_fork_catchpoints }
337
 
338
   # Test the default behaviour, which is to follow the parent of a
339
   # fork, and detach from the child.  Do this without catchpoints.
340
   #
341
   if [runto_main] then { default_fork_parent_follow }
342
 
343
   # Test the ability to explicitly follow the parent of a fork, and
344
   # detach from the child.  Do this without catchpoints.
345
   #
346
   if [runto_main] then { explicit_fork_parent_follow }
347
 
348
   # Test the ability to follow the child of a fork, and detach from
349
   # the parent.  Do this without catchpoints.
350
   #
351
   if [runto_main] then { explicit_fork_child_follow }
352
 
353
   # Test the ability to follow both child and parent of a fork.  Do
354
   # this without catchpoints.
355
   # ??rehrauer: NYI.  Will add testpoints here when implemented.
356
   #
357
 
358
   # Test the ability to have the debugger ask the user at fork-time
359
   # whether to follow the parent, child or both.  Do this without
360
   # catchpoints.
361
   # ??rehrauer: NYI.  Will add testpoints here when implemented.
362
   #
363
 
364
   # Test the ability to catch a fork, specify that the child be
365
   # followed, and continue.  Make the catchpoint permanent.
366
   #
367
   if [runto_main] then { catch_fork_child_follow }
368
 
369
   # Test the ability to catch a fork, specify via a -do clause that
370
   # the parent be followed, and continue.  Make the catchpoint temporary.
371
   #
372
   if [runto_main] then { tcatch_fork_parent_follow }
373
}
374
 
375
# Start with a fresh gdb
376
 
377
gdb_exit
378
gdb_start
379
gdb_reinitialize_dir $srcdir/$subdir
380
gdb_load ${binfile}
381
 
382
# The "Detaching..." and "Attaching..." messages may be hidden by
383
# default.
384
gdb_test "set verbose" ""
385
 
386
# This is a test of gdb's ability to follow the parent, child or both
387
# parent and child of a Unix fork() system call.
388
#
389
do_fork_tests
390
 
391
return 0

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.