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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.base/] [foll-fork.exp] - Blame information for rev 231

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 227 jeremybenn
#   Copyright 1997, 1999, 2007, 2008, 2009, 2010
2
#   Free Software Foundation, Inc.
3
 
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see .
16
 
17
if { [is_remote target] || ![isnative] } then {
18
    continue
19
}
20
 
21
set prms_id 0
22
set bug_id 0
23
 
24
global srcfile
25
set testfile "foll-fork"
26
set srcfile ${testfile}.c
27
set binfile ${objdir}/${subdir}/${testfile}
28
 
29
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
30
     untested foll-fork.exp
31
     return -1
32
}
33
 
34
 
35
 
36
# Until "set follow-fork-mode" and "catch fork" are implemented on
37
# other targets...
38
#
39
if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
40
    continue
41
}
42
 
43
proc check_fork_catchpoints {} {
44
  global gdb_prompt
45
 
46
  # Verify that the system supports "catch fork".
47
  gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "insert first fork catchpoint"
48
  set has_fork_catchpoints 0
49
  gdb_test_multiple "continue" "continue to first fork catchpoint" {
50
    -re ".*Your system does not support fork catchpoints.*$gdb_prompt $" {
51
      unsupported "continue to first fork catchpoint"
52
    }
53
    -re ".*Catchpoint.*$gdb_prompt $" {
54
      set has_fork_catchpoints 1
55
      pass "continue to first fork catchpoint"
56
    }
57
  }
58
 
59
  if {$has_fork_catchpoints == 0} {
60
    unsupported "fork catchpoints"
61
    return -code return
62
  }
63
}
64
 
65
proc default_fork_parent_follow {} {
66
   global gdb_prompt
67
 
68
   send_gdb "show follow-fork\n"
69
   gdb_expect {
70
      -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
71
                      {pass "default show parent follow, no catchpoints"}
72
      -re "$gdb_prompt $" {fail "default show parent follow, no catchpoints"}
73
      timeout         {fail "(timeout) default show parent follow, no catchpoints"}
74
   }
75
   send_gdb "next 2\n"
76
   gdb_expect {
77
      -re "Detaching after fork from.*$gdb_prompt $"\
78
                      {pass "default parent follow, no catchpoints"}
79
      -re "$gdb_prompt $" {fail "default parent follow, no catchpoints"}
80
      timeout         {fail "(timeout) default parent follow, no catchpoints" }
81
   }
82
   # The child has been detached; allow time for any output it might
83
   # generate to arrive, so that output doesn't get confused with
84
   # any expected debugger output from a subsequent testpoint.
85
   #
86
   exec sleep 1
87
}
88
 
89
proc explicit_fork_parent_follow {} {
90
   global gdb_prompt
91
 
92
   send_gdb "set follow-fork parent\n"
93
   gdb_expect {
94
      -re "$gdb_prompt $" {pass "set follow-fork parent"}
95
      timeout         {fail "(timeout) set follow-fork parent"}
96
   }
97
   send_gdb "show follow-fork\n"
98
   gdb_expect {
99
      -re "Debugger response to a program call of fork or vfork is \"parent\"..*$gdb_prompt $"\
100
                      {pass "explicit show parent follow, no catchpoints"}
101
      -re "$gdb_prompt $" {fail "explicit show parent follow, no catchpoints"}
102
      timeout         {fail "(timeout) explicit show parent follow, no catchpoints"}
103
   }
104
   send_gdb "next 2\n"
105
   gdb_expect {
106
      -re "Detaching after fork from.*$gdb_prompt $"\
107
                      {pass "explicit parent follow, no catchpoints"}
108
      -re "$gdb_prompt $" {fail "explicit parent follow, no catchpoints"}
109
      timeout         {fail "(timeout) explicit parent follow, no catchpoints"}
110
   }
111
   # The child has been detached; allow time for any output it might
112
   # generate to arrive, so that output doesn't get confused with
113
   # any expected debugger output from a subsequent testpoint.
114
   #
115
   exec sleep 1
116
}
117
 
118
proc explicit_fork_child_follow {} {
119
   global gdb_prompt
120
 
121
   send_gdb "set follow-fork child\n"
122
   gdb_expect {
123
      -re "$gdb_prompt $" {pass "set follow-fork child"}
124
      timeout         {fail "(timeout) set follow-fork child"}
125
   }
126
   send_gdb "show follow-fork\n"
127
   gdb_expect {
128
      -re "Debugger response to a program call of fork or vfork is \"child\"..*$gdb_prompt $"\
129
                      {pass "explicit show child follow, no catchpoints"}
130
      -re "$gdb_prompt $" {fail "explicit show child follow, no catchpoints"}
131
      timeout         {fail "(timeout) explicit show child follow, no catchpoints"}
132
   }
133
   send_gdb "next 2\n"
134
   gdb_expect {
135
      -re "Attaching after.* fork to.*$gdb_prompt $"\
136
                      {pass "explicit child follow, no catchpoints"}
137
      -re "$gdb_prompt $" {fail "explicit child follow, no catchpoints"}
138
      timeout         {fail "(timeout) explicit child follow, no catchpoints"}
139
   }
140
   # The child has been detached; allow time for any output it might
141
   # generate to arrive, so that output doesn't get confused with
142
   # any gdb_expected debugger output from a subsequent testpoint.
143
   #
144
   exec sleep 1
145
}
146
 
147
proc catch_fork_child_follow {} {
148
   global gdb_prompt
149
   global srcfile
150
 
151
   set bp_after_fork [gdb_get_line_number "set breakpoint here"]
152
 
153
   send_gdb "catch fork\n"
154
   gdb_expect {
155
      -re "Catchpoint .*(fork).*$gdb_prompt $"\
156
                      {pass "explicit child follow, set catch fork"}
157
      -re "$gdb_prompt $" {fail "explicit child follow, set catch fork"}
158
      timeout         {fail "(timeout) explicit child follow, set catch fork"}
159
   }
160
 
161
   # Verify that the catchpoint is mentioned in an "info breakpoints",
162
   # and further that the catchpoint mentions no process id.
163
   #
164
   set test_name "info shows catchpoint without pid"
165
   gdb_test_multiple "info breakpoints" "$test_name" {
166
     -re ".*catchpoint.*keep y.*fork\[\r\n\]+$gdb_prompt $" {
167
       pass "$test_name"
168
     }
169
   }
170
 
171
   send_gdb "continue\n"
172
   gdb_expect {
173
      -re "Catchpoint.*(forked process.*),.*in .*(fork|__kernel_v?syscall).*$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
   set test_name "info shows catchpoint without pid"
183
   gdb_test_multiple "info breakpoints" "$test_name" {
184
     -re ".*catchpoint.*keep y.*fork, process.*$gdb_prompt $" {
185
       pass "$test_name"
186
     }
187
   }
188
 
189
   send_gdb "set follow-fork child\n"
190
   gdb_expect {
191
      -re "$gdb_prompt $" {pass "set follow-fork child"}
192
      timeout         {fail "(timeout) set follow-fork child"}
193
   }
194
   send_gdb "tbreak ${srcfile}:$bp_after_fork\n"
195
   gdb_expect {
196
      -re "Temporary breakpoint.*, line $bp_after_fork.*$gdb_prompt $"\
197
                      {pass "set follow-fork child, tbreak"}
198
      -re "$gdb_prompt $" {fail "set follow-fork child, tbreak"}
199
      timeout         {fail "(timeout) set follow-fork child, tbreak"}
200
   }
201
   send_gdb "continue\n"
202
   gdb_expect {
203
      -re "Attaching after.* fork to.* at .*$bp_after_fork.*$gdb_prompt $"\
204
                      {pass "set follow-fork child, hit tbreak"}
205
      -re "$gdb_prompt $" {fail "set follow-fork child, hit tbreak"}
206
      timeout         {fail "(timeout) set follow-fork child, hit tbreak"}
207
   }
208
   # The parent has been detached; allow time for any output it might
209
   # generate to arrive, so that output doesn't get confused with
210
   # any expected debugger output from a subsequent testpoint.
211
   #
212
   exec sleep 1
213
   send_gdb "delete breakpoints\n"
214
   gdb_expect {
215
      -re "Delete all breakpoints.*$" {
216
         send_gdb "y\n"
217
         gdb_expect {
218
            -re "$gdb_prompt $"\
219
                    {pass "set follow-fork child, cleanup"}
220
            timeout {fail "(timeout) set follow-fork child, cleanup"}
221
         }
222
      }
223
      -re "$gdb_prompt $" {fail "set follow-fork child, cleanup"}
224
      timeout         {fail "(timeout) set follow-fork child, cleanup"}
225
   }
226
}
227
 
228
proc catch_fork_unpatch_child {} {
229
   global gdb_prompt
230
   global srcfile
231
 
232
   set bp_exit [gdb_get_line_number "at exit"]
233
 
234
   gdb_test "break callee" "file .*$srcfile, line .*" "unpatch child, break at callee"
235
   gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "unpatch child, set catch fork"
236
 
237
   gdb_test "continue" \
238
       "Catchpoint.*\\(forked process.*\\).*,.*in .*(fork|__kernel_v?syscall).*" \
239
       "unpatch child, catch fork"
240
 
241
   # Delete all breakpoints and catchpoints.
242
   delete_breakpoints
243
 
244
   # Force $srcfile as the current GDB source can be in glibc sourcetree.
245
   gdb_test "break $srcfile:$bp_exit" \
246
       "Breakpoint .*file .*$srcfile, line .*" \
247
       "unpatch child, breakpoint at exit call"
248
 
249
   gdb_test "set follow-fork child" "" "unpatch child, set follow-fork child"
250
 
251
   set test "unpatch child, unpatched parent breakpoints from child"
252
   gdb_test_multiple "continue" $test {
253
      -re "at exit.*$gdb_prompt $" {
254
          pass "$test"
255
      }
256
      -re "SIGTRAP.*$gdb_prompt $" {
257
          fail "$test"
258
 
259
          # Explicitly kill this child, so we can continue gracefully
260
          # with further testing...
261
          send_gdb "kill\n"
262
          gdb_expect {
263
              -re ".*Kill the program being debugged.*y or n. $" {
264
                  send_gdb "y\n"
265
                  gdb_expect -re "$gdb_prompt $" {}
266
              }
267
          }
268
      }
269
      -re ".*$gdb_prompt $" {
270
          fail "$test (unknown output)"
271
      }
272
      timeout {
273
          fail "$test (timeout)"
274
      }
275
   }
276
}
277
 
278
proc tcatch_fork_parent_follow {} {
279
   global gdb_prompt
280
   global srcfile
281
 
282
   set bp_after_fork [gdb_get_line_number "set breakpoint here"]
283
 
284
   send_gdb "catch fork\n"
285
   gdb_expect {
286
      -re "Catchpoint .*(fork).*$gdb_prompt $"\
287
                      {pass "explicit parent follow, set tcatch fork"}
288
      -re "$gdb_prompt $" {fail "explicit parent follow, set tcatch fork"}
289
      timeout         {fail "(timeout) explicit parent follow, set tcatch fork"}
290
   }
291
# ??rehrauer: I don't yet know how to get the id of the tcatch
292
# via this script, so that I can add a -do list to it.  For now,
293
# do the follow stuff after the catch happens.
294
 
295
   send_gdb "continue\n"
296
   gdb_expect {
297
      -re ".*in .*(fork|__kernel_v?syscall).*$gdb_prompt $"\
298
                      {pass "explicit parent follow, tcatch fork"}
299
      -re "$gdb_prompt $" {fail "explicit parent follow, tcatch fork"}
300
      timeout         {fail "(timeout) explicit parent follow, tcatch fork"}
301
   }
302
   send_gdb "set follow-fork parent\n"
303
   gdb_expect {
304
      -re "$gdb_prompt $" {pass "set follow-fork parent"}
305
      timeout         {fail "(timeout) set follow-fork parent"}
306
   }
307
   send_gdb "tbreak ${srcfile}:$bp_after_fork\n"
308
   gdb_expect {
309
      -re "Temporary breakpoint.*, line $bp_after_fork.*$gdb_prompt $"\
310
                      {pass "set follow-fork parent, tbreak"}
311
      -re "$gdb_prompt $" {fail "set follow-fork parent, tbreak"}
312
      timeout         {fail "(timeout) set follow-fork child, tbreak"}
313
   }
314
   send_gdb "continue\n"
315
   gdb_expect {
316
      -re ".*Detaching after fork from.* at .*$bp_after_fork.*$gdb_prompt $"\
317
                      {pass "set follow-fork parent, hit tbreak"}
318
      -re "$gdb_prompt $" {fail "set follow-fork parent, hit tbreak"}
319
      timeout         {fail "(timeout) set follow-fork parent, hit tbreak"}
320
   }
321
   # The child has been detached; allow time for any output it might
322
   # generate to arrive, so that output doesn't get confused with
323
   # any expected debugger output from a subsequent testpoint.
324
   #
325
   exec sleep 1
326
   send_gdb "delete breakpoints\n"
327
   gdb_expect {
328
      -re "Delete all breakpoints.*$" {
329
         send_gdb "y\n"
330
         gdb_expect {
331
            -re "$gdb_prompt $"\
332
                    {pass "set follow-fork parent, cleanup"}
333
            timeout {fail "(timeout) set follow-fork parent, cleanup"}
334
         }
335
      }
336
      -re "$gdb_prompt $" {fail "set follow-fork parent, cleanup"}
337
      timeout         {fail "(timeout) set follow-fork parent, cleanup"}
338
   }
339
}
340
 
341
proc do_fork_tests {} {
342
   global gdb_prompt
343
 
344
   # Verify that help is available for "set follow-fork-mode".
345
   #
346
   send_gdb "help set follow-fork-mode\n"
347
   gdb_expect {
348
      -re "Set debugger response to a program call of fork or vfork..*
349
A fork or vfork creates a new process.  follow-fork-mode can be:.*
350
.*parent  - the original process is debugged after a fork.*
351
.*child   - the new process is debugged after a fork.*
352
The unfollowed process will continue to run..*
353
By default, the debugger will follow the parent process..*$gdb_prompt $"\
354
                      { pass "help set follow-fork" }
355
      -re "$gdb_prompt $" { fail "help set follow" }
356
      timeout         { fail "(timeout) help set follow-fork" }
357
   }
358
 
359
   # Verify that we can set follow-fork-mode, using an abbreviation
360
   # for both the flag and its value.
361
   #
362
   send_gdb "set follow-fork ch\n"
363
   send_gdb "show follow-fork\n"
364
   gdb_expect {
365
     -re "Debugger response to a program call of fork or vfork is \"child\".*$gdb_prompt $"\
366
             {pass "set follow-fork, using abbreviations"}
367
     timeout {fail "(timeout) set follow-fork, using abbreviations"}
368
   }
369
 
370
   # Verify that we cannot set follow-fork-mode to nonsense.
371
   #
372
   send_gdb "set follow-fork chork\n"
373
   gdb_expect {
374
     -re "Undefined item: \"chork\".*$gdb_prompt $"\
375
                     {pass "set follow-fork to nonsense is prohibited"}
376
     -re "$gdb_prompt $" {fail "set follow-fork to nonsense is prohibited"}
377
     timeout         {fail "(timeout) set follow-fork to nonsense is prohibited"}
378
   }
379
   send_gdb "set follow-fork parent\n"
380
   gdb_expect {
381
     -re "$gdb_prompt $" {pass "set follow-fork to nonsense is prohibited (reset parent)"}
382
     timeout         {fail "set follow-fork to nonsense is prohibited (reset parent)"}
383
   }
384
 
385
   # Check that fork catchpoints are supported, as an indicator for whether
386
   # fork-following is supported.
387
   if [runto_main] then { check_fork_catchpoints }
388
 
389
   # Test the default behaviour, which is to follow the parent of a
390
   # fork, and detach from the child.  Do this without catchpoints.
391
   #
392
   if [runto_main] then { default_fork_parent_follow }
393
 
394
   # Test the ability to explicitly follow the parent of a fork, and
395
   # detach from the child.  Do this without catchpoints.
396
   #
397
   if [runto_main] then { explicit_fork_parent_follow }
398
 
399
   # Test the ability to follow the child of a fork, and detach from
400
   # the parent.  Do this without catchpoints.
401
   #
402
   if [runto_main] then { explicit_fork_child_follow }
403
 
404
   # Test the ability to follow both child and parent of a fork.  Do
405
   # this without catchpoints.
406
   # ??rehrauer: NYI.  Will add testpoints here when implemented.
407
   #
408
 
409
   # Test the ability to have the debugger ask the user at fork-time
410
   # whether to follow the parent, child or both.  Do this without
411
   # catchpoints.
412
   # ??rehrauer: NYI.  Will add testpoints here when implemented.
413
   #
414
 
415
   # Test the ability to catch a fork, specify that the child be
416
   # followed, and continue.  Make the catchpoint permanent.
417
   #
418
   if [runto_main] then { catch_fork_child_follow }
419
 
420
   # Test that parent breakpoints are successfully detached from the
421
   # child at fork time, even if the user removes them from the
422
   # breakpoints list after stopping at a fork catchpoint.
423
   if [runto_main] then { catch_fork_unpatch_child }
424
 
425
   # Test the ability to catch a fork, specify via a -do clause that
426
   # the parent be followed, and continue.  Make the catchpoint temporary.
427
   #
428
   if [runto_main] then { tcatch_fork_parent_follow }
429
}
430
 
431
# Start with a fresh gdb
432
 
433
gdb_exit
434
gdb_start
435
gdb_reinitialize_dir $srcdir/$subdir
436
gdb_load ${binfile}
437
 
438
# The "Detaching..." and "Attaching..." messages may be hidden by
439
# default.
440
gdb_test "set verbose" ""
441
 
442
# This is a test of gdb's ability to follow the parent, child or both
443
# parent and child of a Unix fork() system call.
444
#
445
do_fork_tests
446
 
447
return 0

powered by: WebSVN 2.1.0

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