daily update
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / linux-dp.exp
CommitLineData
7148ab62 1# Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
917317f4
JM
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 <jimb@cygnus.com>
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
37if $tracelevel then {
38 strace $tracelevel
39}
40
41set prms_id 0
42set bug_id 0
43
44# This only works with Linux configurations.
45if ![istarget *-*-linux-gnu] then {
46 return
47}
48
49set testfile "linux-dp"
50set srcfile ${testfile}.c
51set binfile ${objdir}/${subdir}/${testfile}
52if {[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
56gdb_start
57gdb_reinitialize_dir $srcdir/$subdir
58gdb_load ${binfile}
59send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
60runto_main
61
62# There should be no threads initially.
63gdb_test "info threads" "" "info threads 1"
64
65# Try stepping over the thread creation function.
66gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
67for {set i 0} {$i < 5} {incr i} {
68 gdb_continue_to_breakpoint "about to create philosopher: $i"
c2d11a7d
JM
69 send_gdb "next\n"
70 gdb_expect {
ed9a39eb 71 -re "\\\[New .*\\\].*$gdb_prompt $" {
c2d11a7d
JM
72 pass "create philosopher: $i"
73 }
754cbe1c 74 -re "Program received signal.*(Unknown signal|SIGUSR|Real-time event).*$gdb_prompt $" {
c2d11a7d
JM
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 }
917317f4
JM
88}
89
90# Run until there are some threads.
91gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
92gdb_continue_to_breakpoint "main thread's sleep"
ed9a39eb 93gdb_test "info threads" "7 Thread .*6 Thread .*5 Thread .*4 Thread .*3 Thread .*2 Thread .*1 Thread .*" "info threads 2"
917317f4
JM
94
95# Try setting a thread-specific breakpoint.
96gdb_breakpoint "print_philosopher thread 5"
97gdb_continue_to_breakpoint "thread 5's print"
98gdb_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.
103set only_five 1
104for {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
120set name "thread-specific breakpoint is thread-specific"
121if {$only_five == 1} { pass $name }
122if {$only_five == 0} { fail $name }
123if {$only_five == -1} { fail "$name (timeout)" }
124
125
126### Select a particular thread.
127proc 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.
ac55707e
MS
149
150set main_seen 0
151set manager_seen 0
152
917317f4
JM
153proc check_philosopher_stack {thread seen_name} {
154 global gdb_prompt
155 upvar $seen_name seen
ac55707e
MS
156 global main_seen
157 global manager_seen
917317f4
JM
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 }
396cc255
DJ
175 -re ".* in __pthread_manager \\(.*$gdb_prompt $" {
176 if {$manager_seen == 1} {
177 fail "manager thread is distinct: $thread"
178 } else {
179 set manager_seen 1
180 pass "manager thread is distinct: $thread"
181 }
182 set interesting 1
183 }
917317f4
JM
184 -re "pthread_start_thread.*\r\n$gdb_prompt $" {
185 ## Maybe the thread hasn't started yet.
186 pass $name
187 }
ac55707e
MS
188 -re ".* in main \\(.*$gdb_prompt $" {
189 if {$main_seen == 1} {
190 fail "main is distinct: $thread"
191 } else {
192 set main_seen 1
193 pass "main is distinct: $thread"
194 }
195 set interesting 1
196 }
917317f4
JM
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
216set any_interesting 0
6ff9af88
DJ
217array set seen {}
218unset seen
ac55707e 219for {set i 1} {$i <= 7} {incr i} {
917317f4
JM
220 if [check_philosopher_stack $i seen] {
221 set any_interesting 1
222 }
223}
224
225if {$any_interesting} {
226 pass "found an interesting thread"
227} else {
228 fail "found an interesting thread"
229}
This page took 0.306793 seconds and 4 git commands to generate.