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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [gdb/] [testsuite/] [gdb.base/] [multi-forks.exp] - Blame information for rev 816

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

Line No. Rev Author Line
1 227 jeremybenn
#   Copyright 2005, 2006, 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 $tracelevel then {
18
        strace $tracelevel
19
        }
20
 
21
if { [is_remote target] || ![isnative] } then {
22
    continue
23
}
24
 
25
# Until "set follow-fork-mode" and "catch fork" are implemented on
26
# other targets...
27
#
28
if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-*-linux*"]} then {
29
    continue
30
}
31
 
32
set prms_id 0
33
set bug_id 0
34
 
35
set testfile "multi-forks"
36
set srcfile ${testfile}.c
37
set binfile ${objdir}/${subdir}/${testfile}
38
 
39
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40
     untested multi-forks.exp
41
     return -1
42
}
43
 
44
# Start with a fresh gdb
45
 
46
gdb_exit
47
gdb_start
48
gdb_reinitialize_dir $srcdir/$subdir
49
gdb_load ${binfile}
50
 
51
global gdb_prompt
52
 
53
# This is a test of gdb's ability to follow the parent, child or both
54
# parent and child of multiple Unix fork() system calls.
55
 
56
set exit_bp_loc [gdb_get_line_number "Set exit breakpoint here."]
57
 
58
# Insert a breakpoint at the location provided by the exit_bp_loc global
59
# and resume the execution until hitting that breakpoint.  We also make
60
# sure to consume all the expected output from all processes as well,
61
# to make sure it doesn't cause trouble during a subsequent test.
62
 
63
proc continue_to_exit_bp_loc {} {
64
    global exit_bp_loc decimal gdb_prompt
65
 
66
    gdb_breakpoint $exit_bp_loc
67
 
68
    send_gdb "continue\n"
69
 
70
    # The output from the child processes can be interleaved arbitrarily
71
    # with the output from GDB and the parent process.  If we don't
72
    # consume it all now, it can confuse later interactions.
73
    set seen_done 0
74
    set seen_break 0
75
    set seen_prompt 0
76
    set seen_timeout 0
77
    while { ($seen_done < 16 || ! $seen_prompt) && ! $seen_timeout } {
78
        # We don't know what order the interesting things will arrive in.
79
        # Using a pattern of the form 'x|y|z' instead of -re x ... -re y
80
        # ... -re z ensures that expect always chooses the match that
81
        # occurs leftmost in the input, and not the pattern appearing
82
        # first in the script that occurs anywhere in the input, so that
83
        # we don't skip anything.
84
        gdb_expect {
85
            -re "($decimal done)|(Breakpoint)|($gdb_prompt)" {
86
                if {[info exists expect_out(1,string)]} {
87
                    incr seen_done
88
                } elseif {[info exists expect_out(2,string)]} {
89
                    set seen_break 1
90
                } elseif {[info exists expect_out(3,string)]} {
91
                    set seen_prompt 1
92
                }
93
                array unset expect_out
94
            }
95
            timeout { set seen_timeout 1 }
96
        }
97
    }
98
 
99
    if { $seen_timeout } {
100
        fail "run to exit 2 (timeout)"
101
    } elseif { ! $seen_prompt } {
102
        fail "run to exit 2 (no prompt)"
103
    } elseif { ! $seen_break } {
104
        fail "run to exit 2 (no breakpoint hit)"
105
    } elseif { $seen_done != 16 } {
106
        fail "run to exit 2 (missing done messages)"
107
    } else {
108
        pass "run to exit 2"
109
    }
110
}
111
 
112
# The inferior program builds a tree of processes by executing a loop
113
# four times, calling fork at each iteration.  Thus, at each
114
# iteration, the total number of processes doubles; after four
115
# iterations, we have 16 processes.  Each process saves the results
116
# from its 'fork' calls, so we can tell which leaf a given process is
117
# by looking at which forks returned zero and which returned a pid: a
118
# zero means to take the child's branch; a pid means to take the
119
# parent's branch.
120
 
121
# First set gdb to follow the child.
122
# The result should be that each of the 4 forks returns zero.
123
 
124
runto_main
125
gdb_test "set follow-fork child"
126
continue_to_exit_bp_loc
127
 
128
gdb_test "print pids" "\\$.* = \\{0, 0, 0, 0\\}.*" "follow child, print pids"
129
 
130
# Now set gdb to follow the parent.
131
# Result should be that none of the 4 forks returns zero.
132
 
133
runto_main
134
gdb_test "set follow-fork parent" "" ""
135
continue_to_exit_bp_loc
136
 
137
gdb_test "print pids\[0\]==0 || pids\[1\]==0 || pids\[2\]==0 || pids\[3\]==0" \
138
    " = 0" "follow parent, print pids"
139
 
140
#
141
# Now test with detach-on-fork off.
142
#
143
 
144
# detach-on-fork isn't implemented on hpux.
145
#
146
if {![istarget "*-*-linux*"]} then {
147
    continue
148
}
149
 
150
# Start with a fresh gdb
151
 
152
gdb_exit
153
gdb_start
154
gdb_reinitialize_dir $srcdir/$subdir
155
gdb_load ${binfile}
156
 
157
runto_main
158
gdb_breakpoint $exit_bp_loc
159
 
160
gdb_test "help set detach-on-fork" "whether gdb will detach the child.*" \
161
    "help set detach"
162
 
163
gdb_test "show detach-on-fork" "on." "show detach default on"
164
 
165
gdb_test "set detach off" "" "set detach off"
166
 
167
#
168
# We will now run every fork up to the exit bp,
169
# eventually winding up with 16 inferiors.
170
#
171
 
172
for {set i 1} {$i <= 15} {incr i} {
173
  gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit $i"
174
  gdb_test "info inferior" " 5 .* 4 .* 3 .* 2 .*" "info inferior $i"
175
  gdb_test "inferior $i + 1" "(_dl_sysinfo_int80|fork|__kernel_(v|)syscall).*" \
176
      "inferior $i"
177
}
178
 
179
gdb_test "continue" "Breakpoint .* main .*exit.*" "Run to exit 16"
180
gdb_test "info inferiors" " 5 .* 4 .* 3 .* 2 .*" "info inferior 16"
181
gdb_test "inferior 2" " main .*" "restart final"
182
 
183
#
184
# Now we should examine all the pids.
185
#
186
 
187
#
188
# Test detach inferior
189
#
190
 
191
# [assumes we're at #1]
192
gdb_test "detach inferior 2" "Detaching .*" "Detach 2"
193
gdb_test "detach inferior 3" "Detaching .*" "Detach 3"
194
gdb_test "detach inferior 4" "Detaching .*" "Detach 4"
195
gdb_test "detach inferior 5" "Detaching .*" "Detach 5"
196
 
197
#
198
# Test kill inferior
199
#
200
 
201
gdb_test "kill inferior 6" "" "Kill 6"
202
gdb_test "info inferior 6" ".*" "Did kill 6"
203
gdb_test "kill inferior 7" "" "Kill 7"
204
gdb_test "info inferior 7" ".*" "Did kill 7"
205
gdb_test "kill inferior 8" "" "Kill 8"
206
gdb_test "info inferior 8" ".*" "Did kill 8"
207
gdb_test "kill inferior 9" "" "Kill 9"
208
gdb_test "info inferior 9" ".*" "Did kill 9"
209
gdb_test "kill inferior 10" "" "Kill 10"
210
gdb_test "info inferior 10" ".*" "Did kill 10"
211
gdb_test "kill inferior 11" "" "Kill 11"
212
gdb_test "info inferior 11" ".*" "Did kill 11"
213
gdb_test "kill inferior 12" "" "Kill 12"
214
gdb_test "info inferior 12" ".*" "Did kill 12"
215
gdb_test "kill inferior 13" "" "Kill 13"
216
gdb_test "info inferior 13" ".*" "Did kill 13"
217
gdb_test "kill inferior 14" "" "Kill 14"
218
gdb_test "info inferior 14" ".*" "Did kill 14"
219
gdb_test "kill inferior 15" "" "Kill 15"
220
gdb_test "info inferior 15" ".*" "Did kill 15"
221
gdb_test "kill inferior 16" "" "Kill 16"
222
gdb_test "info inferior 16" ".*" "Did kill 16"
223
 
224
return 0

powered by: WebSVN 2.1.0

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