Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # thread_local_stg.exp -- Expect script to test thread-local storage |
2 | # Copyright (C) 1992 Free Software Foundation, Inc. | |
3 | ||
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
17 | ||
18 | # Please email any bugs, comments, and/or additions to this file to: | |
19 | # bug-gdb@prep.ai.mit.edu | |
20 | ||
21 | # use this to debug: | |
22 | # | |
23 | #log_user 1 | |
24 | ||
25 | # Thread stuff is _slow_; prepare for long waits. | |
26 | # | |
27 | # Further, this test has some "null" lines designed | |
28 | # to consume output from gdb that was too late to be | |
29 | # matched (sequence is "gdb_test" sends; timeout and | |
30 | # on to next send; result finally comes in; mismatch). | |
31 | # | |
32 | # The null command is 'gdb_test "p \$pc" ".*" ""' | |
33 | # NOTE: this command undoes any up/down stuff! | |
34 | # | |
35 | proc pre_timeout {} { | |
36 | global timeout | |
37 | ||
38 | set timeout [expr "$timeout + 100"] | |
39 | } | |
40 | ||
41 | proc post_timeout {} { | |
42 | global timeout | |
43 | global oldtimeout | |
44 | ||
45 | set timeout $oldtimeout | |
46 | gdb_test "p \$pc" ".*" "" | |
47 | } | |
48 | ||
49 | if $tracelevel then { | |
50 | strace $tracelevel | |
51 | } | |
52 | ||
7a292a7a SS |
53 | if { [skip_hp_tests] } then { continue } |
54 | ||
c906108c SS |
55 | if { ![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"] } { |
56 | verbose "HPUX thread test ignored for non-hppa or pre-HP/UX-10.30 targets." | |
57 | return 0 | |
58 | } | |
59 | ||
60 | set testfile start-stop | |
61 | set srcfile ${srcdir}/${subdir}/${testfile}.c | |
62 | set binfile ${objdir}/${subdir}/${testfile} | |
63 | ||
64 | if [get_compiler_info ${binfile}] { | |
65 | return -1 | |
66 | } | |
67 | ||
68 | # To build the executable we need to link against the thread library. | |
69 | # | |
70 | # cc -Ae -g -o start_stop -lpthread start_stop.c | |
71 | # | |
72 | #compile "${srcfile} -Ae -g -lpthread -o ${binfile}" | |
73 | ||
74 | if {$gcc_compiled == 0} { | |
75 | set additional_flags "additional_flags=-Ae" | |
76 | } else { | |
77 | set additional_flags "" | |
78 | } | |
79 | ||
80 | if { [gdb_compile "${srcdir}/${subdir}/${testfile}.c" "${binfile}.o" object [list debug $additional_flags]] != "" } { | |
81 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
82 | } | |
83 | remote_exec build "ld /usr/ccs/lib/crt0.o ${binfile}.o -lcl -lpthread -lc /opt/langtools/lib/end.o -o ${binfile}" | |
84 | ||
85 | gdb_exit | |
86 | gdb_start | |
87 | gdb_reinitialize_dir $srcdir/$subdir | |
88 | ||
89 | gdb_load ${binfile} | |
90 | if ![runto_main] then { | |
91 | fail "Can't run to main" | |
92 | return 0 | |
93 | } | |
94 | ||
95 | set oldtimeout $timeout | |
96 | #set timeout [expr "$timeout + 200"] | |
97 | set oldverbose $verbose | |
98 | #set verbose 40 | |
99 | ||
100 | gdb_test "b do_pass" ".*" "set do_pass bp" | |
101 | gdb_test "c" ".*do_pass.*" "run to do_pass" | |
102 | gdb_test "cle" ".*" "" | |
103 | ||
104 | # Set a breakpoint at the "spin" routine and | |
105 | # collect the thread local's value. | |
106 | # | |
107 | gdb_test "b 67" ".*Breakpoint 3.*67.*" "Set bp" | |
108 | ||
109 | # Can't use "gdb_test", as it uses "$gdb_prompt $" in | |
110 | # testing the result. Our new prompt is ">", with | |
111 | # no trailing space, so we can't do this just by | |
112 | # changing "prompt". | |
113 | # | |
114 | # Anyway, I couldn't get expect to see the ">" prompt, | |
115 | # during the command addition, so I just punted. | |
116 | # _You_ are welcome to try, if you want! | |
117 | # | |
118 | send_gdb "commands 3\n" | |
119 | gdb_expect { | |
120 | -re "(.*Type commands.*\"end\"\.\r\n\>)" { | |
121 | pass "start commands" | |
122 | } | |
123 | -re ".*$gdb_prompt $" { | |
124 | fail "start commands" | |
125 | } | |
126 | } | |
127 | ||
128 | # Assume we're in commands-input mode. | |
129 | # | |
130 | send_gdb "silent\n" | |
131 | send_gdb "set val_debugger_saw\[me\] = a_thread_local\n" | |
132 | send_gdb "continue\n" | |
133 | send_gdb "end\n" | |
134 | ||
135 | gdb_expect { | |
136 | -re ".*set.*cont.*$gdb_prompt $" { | |
137 | pass "add commands" | |
138 | } | |
139 | -re ".*$gdb_prompt $" { | |
140 | fail "add commands" | |
141 | } | |
142 | } | |
143 | ||
144 | # Check out of paranoia. | |
145 | # | |
146 | send_gdb "info break 3\n" | |
147 | gdb_expect { | |
148 | -re ".*breakpoint.*set val_debugger.*continue.*$gdb_prompt $" { | |
149 | pass "Commands added" | |
150 | } | |
151 | -re ".*$gdb_prompt $" { | |
152 | fail "Commands not added." | |
153 | } | |
154 | } | |
155 | ||
156 | # Set a bp to inspect the results | |
157 | # | |
158 | gdb_test "b 134" ".*Breakpoint 4.*" "" | |
159 | ||
160 | # We now expect to run through a whole pass, seeing | |
161 | # specific results as noted below (actual gotten by | |
162 | # running application with debugging print statements | |
163 | # turned on. | |
164 | # | |
165 | # Since this'll run for while, set a generous timeout. | |
166 | # | |
167 | set timeout [expr "$timeout + 30"] | |
168 | send_gdb "c\n" | |
169 | gdb_expect { | |
170 | -re ".*Program exited normally.*$gdb_prompt $" { | |
171 | fail "program runaway" | |
172 | } | |
173 | -re ".*Pass 0 done.*Pass 1 done.*$gdb_prompt $" { | |
174 | fail "program runaway 2" | |
175 | } | |
176 | -re ".*Pass 0 done.*Breakpoint 4.*134.*$gdb_prompt $" { | |
177 | pass "get to end of first pass" | |
178 | } | |
179 | -re ".*$gdb_prompt $" { | |
180 | fail "No progress?" | |
181 | } | |
182 | timeout { fail "timeout" } | |
183 | } | |
184 | ||
185 | gdb_test "p val_debugger_saw" ".*0, 1, 3.*" "first pass" | |
186 | ||
187 | send_gdb "i th\n" | |
188 | gdb_expect { | |
189 | -re ".* 1.*system thread.* 2.*system thread.*$gdb_prompt $" { | |
190 | fail "Too many threads left" | |
191 | } | |
192 | -re ".*\\\* 1 system thread.*$gdb_prompt $" { | |
193 | pass "Expect only base thread" | |
194 | } | |
195 | -re ".*No stack.*$gdb_prompt $" { | |
196 | fail "runaway" | |
197 | } | |
198 | -re ".*$gdb_prompt $" { | |
199 | fail "Hunh?" | |
200 | } | |
201 | timeout { fail "timeout" } | |
202 | } | |
203 | ||
204 | gdb_test "i b" ".*4.*breakpoint.*134.*hit.*1 time.*" "Expect 134 bp to exist" | |
205 | ||
206 | gdb_test "c" ".*Breakpoint 4.*134.*" "get to end of second pass" | |
207 | gdb_test "p val_debugger_saw" ".*6, 10, 15.*" "second pass" | |
208 | ||
209 | gdb_test "c" ".*Breakpoint 4.*134.*" "get to end of third pass" | |
210 | gdb_test "p val_debugger_saw" ".*21, 28, 36.*" "third pass" | |
211 | ||
212 | gdb_test "info bre 3" ".*already hit 9 times.*" "count of silent bp hits" | |
213 | ||
214 | # Start over and do some "info address" stuff | |
215 | # | |
216 | send_gdb "d\n" | |
217 | gdb_expect { | |
218 | -re ".*Delete all breakpoints.*$" { | |
219 | send_gdb "y\n" | |
220 | gdb_expect { | |
221 | -re ".*$gdb_prompt $" { | |
222 | pass "del bps" | |
223 | } | |
224 | } | |
225 | } | |
226 | -re ".*$gdb_prompt $" { fail "no question" } | |
227 | } | |
228 | ||
229 | gdb_test "b spin" ".*Breakpoint 5.*" "" | |
230 | ||
231 | send_gdb "r\n" | |
232 | gdb_expect { | |
233 | -re ".*Start it from the beginning.*$" { | |
234 | send_gdb "y\n" | |
235 | gdb_expect { | |
236 | -re ".*$gdb_prompt $" { pass "restart" } | |
237 | } | |
238 | } | |
239 | -re ".*Starting program.*$gdb_prompt $" { | |
240 | pass "restart after previous fails" | |
241 | } | |
242 | -re ".*$gdb_prompt $" { fail "Can't restart" } | |
243 | } | |
244 | gdb_test "i ad a_global" ".*a_global.*static storage at address.*" "i ad a_global" | |
245 | gdb_test "i add me" ".*me.*local variable at frame offset.*" "i ad me" | |
246 | gdb_test "i ad a_thread_local" ".*a_thread_local.*a thread-local variable at offset.*" "i ad a_thread_local" | |
247 | ||
248 | # Done! | |
249 | # | |
250 | gdb_exit | |
251 | ||
252 | set timeout $oldtimeout | |
253 | set verbose $oldverbose | |
254 | ||
255 | # execute_anywhere "rm -f ${binfile}" | |
256 | # | |
257 | return 0 |