1 # Copyright 1999, 2001, 2002 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
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.
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.
32 ### Other things we ought to test:
33 ### stepping a thread while others are running
34 ### killing and restarting
35 ### quitting gracefully
44 # This only works with Linux configurations.
45 if ![istarget *-*-linux-gnu] then {
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."
57 gdb_reinitialize_dir $srcdir/$subdir
59 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
62 # There should be no threads initially.
63 gdb_test "info threads" "" "info threads 1"
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"
71 -re "\\\[New .*\\\].*$gdb_prompt $" {
72 pass "create philosopher: $i"
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."
82 fail "create philosopher: $i"
85 fail "(timeout) create philosopher: $i"
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"
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"
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.
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"
108 -re "\\* 5 Thread .* print_philosopher .*\r\n$gdb_prompt $" {
111 -re ".*$gdb_prompt $" {
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)" }
126 ### Select a particular thread.
127 proc select_thread {thread} {
130 send_gdb "thread $thread\n"
132 -re "\\\[Switching to thread .*\\\].*\r\n$gdb_prompt $" {
133 pass "selected thread: $thread"
135 -re "$gdb_prompt $" {
136 fail "selected thread: $thread"
139 fail "selected thread: $thread (timeout)"
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.
153 proc check_philosopher_stack {thread seen_name} {
155 upvar $seen_name seen
159 set name "philosopher is distinct: $thread"
162 select_thread $thread
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)]} {
175 -re ".* in __pthread_manager \\(.*$gdb_prompt $" {
176 if {$manager_seen == 1} {
177 fail "manager thread is distinct: $thread"
180 pass "manager thread is distinct: $thread"
184 -re "pthread_start_thread.*\r\n$gdb_prompt $" {
185 ## Maybe the thread hasn't started yet.
188 -re ".* in main \\(.*$gdb_prompt $" {
189 if {$main_seen == 1} {
190 fail "main is distinct: $thread"
193 pass "main is distinct: $thread"
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
205 -re "$gdb_prompt $" {
209 fail "$name (timeout)"
216 set any_interesting 0
218 for {set i 1} {$i <= 7} {incr i} {
219 if [check_philosopher_stack $i seen] {
220 set any_interesting 1
224 if {$any_interesting} {
225 pass "found an interesting thread"
227 fail "found an interesting thread"