1 |
578 |
markom |
# Copyright 1999 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@gnu.org
|
19 |
|
|
|
20 |
|
|
#### Dining Philosophers, on LinuxThreads - Jim Blandy
|
21 |
|
|
####
|
22 |
|
|
#### At the moment, GDB's support for LinuxThreads is pretty
|
23 |
|
|
#### idiosyncratic --- GDB's output doesn't look much like the output
|
24 |
|
|
#### it produces for other thread implementations, messages appear at
|
25 |
|
|
#### different times, etc. So these tests are specific to LinuxThreads.
|
26 |
|
|
####
|
27 |
|
|
#### However, if all goes well, Linux will soon have a libthread_db
|
28 |
|
|
#### interface, and GDB will manage it the same way it does other
|
29 |
|
|
#### libthread_db-based systems. Then, we can adjust this file to
|
30 |
|
|
#### work with any such system.
|
31 |
|
|
|
32 |
|
|
### Other things we ought to test:
|
33 |
|
|
### stepping a thread while others are running
|
34 |
|
|
### killing and restarting
|
35 |
|
|
### quitting gracefully
|
36 |
|
|
|
37 |
|
|
if $tracelevel then {
|
38 |
|
|
strace $tracelevel
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
set prms_id 0
|
42 |
|
|
set bug_id 0
|
43 |
|
|
|
44 |
|
|
# This only works with Linux configurations.
|
45 |
|
|
if ![istarget *-*-linux-gnu] then {
|
46 |
|
|
return
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
set testfile "linux-dp"
|
50 |
|
|
set srcfile ${testfile}.c
|
51 |
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
52 |
|
|
if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug libs=-lpthread}] != ""} {
|
53 |
|
|
gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
gdb_start
|
57 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
58 |
|
|
gdb_load ${binfile}
|
59 |
|
|
send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
|
60 |
|
|
runto_main
|
61 |
|
|
|
62 |
|
|
# There should be no threads initially.
|
63 |
|
|
gdb_test "info threads" "" "info threads 1"
|
64 |
|
|
|
65 |
|
|
# Try stepping over the thread creation function.
|
66 |
|
|
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
|
67 |
|
|
for {set i 0} {$i < 5} {incr i} {
|
68 |
|
|
gdb_continue_to_breakpoint "about to create philosopher: $i"
|
69 |
|
|
send_gdb "next\n"
|
70 |
|
|
gdb_expect {
|
71 |
|
|
-re "\\\[New .*\\\].*$gdb_prompt $" {
|
72 |
|
|
pass "create philosopher: $i"
|
73 |
|
|
}
|
74 |
|
|
-re "Program received signal.*(Unknown signal|SIGUSR|Real-time event).*$gdb_prompt $" {
|
75 |
|
|
# It would be nice if we could catch the message that GDB prints
|
76 |
|
|
# when it first notices that the thread library doesn't support
|
77 |
|
|
# debugging, or if we could explicitly ask GDB somehow.
|
78 |
|
|
unsupported "This GDB does not support threads on this system."
|
79 |
|
|
return -1
|
80 |
|
|
}
|
81 |
|
|
-re "$gdb_prompt $" {
|
82 |
|
|
fail "create philosopher: $i"
|
83 |
|
|
}
|
84 |
|
|
timeout {
|
85 |
|
|
fail "(timeout) create philosopher: $i"
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
# Run until there are some threads.
|
91 |
|
|
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
|
92 |
|
|
gdb_continue_to_breakpoint "main thread's sleep"
|
93 |
|
|
gdb_test "info threads" "7 Thread .*6 Thread .*5 Thread .*4 Thread .*3 Thread .*2 Thread .*1 Thread .*" "info threads 2"
|
94 |
|
|
|
95 |
|
|
# Try setting a thread-specific breakpoint.
|
96 |
|
|
gdb_breakpoint "print_philosopher thread 5"
|
97 |
|
|
gdb_continue_to_breakpoint "thread 5's print"
|
98 |
|
|
gdb_test "where" "print_philosopher.*philosopher.*pthread_start_thread.*" \
|
99 |
|
|
"first thread-specific breakpoint hit"
|
100 |
|
|
|
101 |
|
|
# Make sure it's catching the right thread. Try hitting the
|
102 |
|
|
# breakpoint ten times, and make sure we don't get anyone else.
|
103 |
|
|
set only_five 1
|
104 |
|
|
for {set i 0} {$only_five > 0 && $i < 10} {incr i} {
|
105 |
|
|
gdb_continue_to_breakpoint "thread 5's print, pass: $i"
|
106 |
|
|
send_gdb "info threads\n"
|
107 |
|
|
gdb_expect {
|
108 |
|
|
-re "\\* 5 Thread .* print_philosopher .*\r\n$gdb_prompt $" {
|
109 |
|
|
# Okay this time.
|
110 |
|
|
}
|
111 |
|
|
-re ".*$gdb_prompt $" {
|
112 |
|
|
set only_five 0
|
113 |
|
|
}
|
114 |
|
|
timeout {
|
115 |
|
|
set only_five -1
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
set name "thread-specific breakpoint is thread-specific"
|
121 |
|
|
if {$only_five == 1} { pass $name }
|
122 |
|
|
if {$only_five == 0} { fail $name }
|
123 |
|
|
if {$only_five == -1} { fail "$name (timeout)" }
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
### Select a particular thread.
|
127 |
|
|
proc select_thread {thread} {
|
128 |
|
|
global gdb_prompt
|
129 |
|
|
|
130 |
|
|
send_gdb "thread $thread\n"
|
131 |
|
|
gdb_expect {
|
132 |
|
|
-re "\\\[Switching to thread .*\\\].*\r\n$gdb_prompt $" {
|
133 |
|
|
pass "selected thread: $thread"
|
134 |
|
|
}
|
135 |
|
|
-re "$gdb_prompt $" {
|
136 |
|
|
fail "selected thread: $thread"
|
137 |
|
|
}
|
138 |
|
|
timeout {
|
139 |
|
|
fail "selected thread: $thread (timeout)"
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
### Select THREAD, check for a plausible backtrace, and make sure
|
145 |
|
|
### we're actually selecting a different philosopher each time.
|
146 |
|
|
### Return true if the thread had a stack which was not only
|
147 |
|
|
### acceptable, but interesting. SEEN should be an array in which
|
148 |
|
|
### SEEN(N) exists iff we have found philosopher number N before.
|
149 |
|
|
|
150 |
|
|
set main_seen 0
|
151 |
|
|
set manager_seen 0
|
152 |
|
|
|
153 |
|
|
proc check_philosopher_stack {thread seen_name} {
|
154 |
|
|
global gdb_prompt
|
155 |
|
|
upvar $seen_name seen
|
156 |
|
|
global main_seen
|
157 |
|
|
global manager_seen
|
158 |
|
|
|
159 |
|
|
set name "philosopher is distinct: $thread"
|
160 |
|
|
set interesting 0
|
161 |
|
|
|
162 |
|
|
select_thread $thread
|
163 |
|
|
send_gdb "where\n"
|
164 |
|
|
gdb_expect {
|
165 |
|
|
-re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
|
166 |
|
|
set data $expect_out(1,string)
|
167 |
|
|
if {[info exists seen($data)]} {
|
168 |
|
|
fail $name
|
169 |
|
|
} else {
|
170 |
|
|
pass $name
|
171 |
|
|
set seen($data) yep
|
172 |
|
|
}
|
173 |
|
|
set interesting 1
|
174 |
|
|
}
|
175 |
|
|
-re "pthread_start_thread.*\r\n$gdb_prompt $" {
|
176 |
|
|
## Maybe the thread hasn't started yet.
|
177 |
|
|
pass $name
|
178 |
|
|
}
|
179 |
|
|
-re ".* in main \\(.*$gdb_prompt $" {
|
180 |
|
|
if {$main_seen == 1} {
|
181 |
|
|
fail "main is distinct: $thread"
|
182 |
|
|
} else {
|
183 |
|
|
set main_seen 1
|
184 |
|
|
pass "main is distinct: $thread"
|
185 |
|
|
}
|
186 |
|
|
set interesting 1
|
187 |
|
|
}
|
188 |
|
|
-re ".* in __pthread_manager \\(.*$gdb_prompt $" {
|
189 |
|
|
if {$manager_seen == 1} {
|
190 |
|
|
fail "manager thread is distinct: $thread"
|
191 |
|
|
} else {
|
192 |
|
|
set manager_seen 1
|
193 |
|
|
pass "manager thread is distinct: $thread"
|
194 |
|
|
}
|
195 |
|
|
set interesting 1
|
196 |
|
|
}
|
197 |
|
|
-re " in \\?\\?.*\r\n$gdb_prompt $" {
|
198 |
|
|
## Sometimes we can't get a backtrace. I'm going to call
|
199 |
|
|
## this a pass, since we do verify that at least one
|
200 |
|
|
## thread was interesting, so we can get more consistent
|
201 |
|
|
## test suite totals. But in my heart, I think it should
|
202 |
|
|
## be an xfail.
|
203 |
|
|
pass $name
|
204 |
|
|
}
|
205 |
|
|
-re "$gdb_prompt $" {
|
206 |
|
|
fail $name
|
207 |
|
|
}
|
208 |
|
|
timeout {
|
209 |
|
|
fail "$name (timeout)"
|
210 |
|
|
}
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
return $interesting
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
set any_interesting 0
|
217 |
|
|
array set seen {}
|
218 |
|
|
for {set i 1} {$i <= 7} {incr i} {
|
219 |
|
|
if [check_philosopher_stack $i seen] {
|
220 |
|
|
set any_interesting 1
|
221 |
|
|
}
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
if {$any_interesting} {
|
225 |
|
|
pass "found an interesting thread"
|
226 |
|
|
} else {
|
227 |
|
|
fail "found an interesting thread"
|
228 |
|
|
}
|