import gdb-1999-12-21 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / linux-dp.exp
1 # Copyright (C) 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 <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
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).*$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 proc check_philosopher_stack {thread seen_name} {
150 global gdb_prompt
151 upvar $seen_name seen
152
153 set name "philosopher is distinct: $thread"
154 set interesting 0
155
156 select_thread $thread
157 send_gdb "where\n"
158 gdb_expect {
159 -re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
160 set data $expect_out(1,string)
161 if {[info exists seen($data)]} {
162 fail $name
163 } else {
164 pass $name
165 set seen($data) yep
166 }
167 set interesting 1
168 }
169 -re "pthread_start_thread.*\r\n$gdb_prompt $" {
170 ## Maybe the thread hasn't started yet.
171 pass $name
172 }
173 -re " in \\?\\?.*\r\n$gdb_prompt $" {
174 ## Sometimes we can't get a backtrace. I'm going to call
175 ## this a pass, since we do verify that at least one
176 ## thread was interesting, so we can get more consistent
177 ## test suite totals. But in my heart, I think it should
178 ## be an xfail.
179 pass $name
180 }
181 -re "$gdb_prompt $" {
182 fail $name
183 }
184 timeout {
185 fail "$name (timeout)"
186 }
187 }
188
189 return $interesting
190 }
191
192 set any_interesting 0
193 array set seen {}
194 for {set i 3} {$i <= 7} {incr i} {
195 if [check_philosopher_stack $i seen] {
196 set any_interesting 1
197 }
198 }
199
200 if {$any_interesting} {
201 pass "found an interesting thread"
202 } else {
203 fail "found an interesting thread"
204 }
This page took 0.036909 seconds and 4 git commands to generate.