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