]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # Copyright (C) 1996, 1997 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@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set prms_id 0 | |
27 | set bug_id 0 | |
28 | ||
29 | # This only works with native configurations | |
30 | if ![isnative] then { | |
31 | return | |
32 | } | |
33 | ||
34 | set testfile "pthreads" | |
35 | set srcfile ${testfile}.c | |
36 | set binfile ${objdir}/${subdir}/${testfile} | |
37 | ||
38 | # regexp for "horizontal" text (i.e. doesn't include newline or | |
39 | # carriage return) | |
40 | set horiz "\[^\n\r\]*" | |
41 | ||
42 | set built_binfile 0 | |
43 | if [istarget "*-*-linux"] then { | |
44 | set target_cflags "-D_MIT_POSIX_THREADS" | |
45 | } else { | |
46 | set target_cflags "" | |
47 | } | |
48 | set why_msg "unrecognized error" | |
0d06e24b | 49 | foreach lib {-lpthreads -lpthread -lthread} { |
c906108c SS |
50 | set options "debug" |
51 | lappend options "incdir=${objdir}/${subdir}" | |
52 | lappend options "libs=$lib" | |
53 | set ccout [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $options] | |
54 | switch -regexp -- $ccout { | |
55 | ".*no posix threads support.*" { | |
56 | set why_msg "missing threads include file" | |
57 | break | |
58 | } | |
59 | ".*cannot open -lpthread.*" { | |
60 | set why_msg "missing runtime threads library" | |
61 | } | |
62 | ".*Can't find library for -lpthread.*" { | |
63 | set why_msg "missing runtime threads library" | |
64 | } | |
65 | {^$} { | |
66 | pass "successfully compiled posix threads test case" | |
67 | set built_binfile 1 | |
68 | break | |
69 | } | |
70 | } | |
71 | } | |
72 | if {$built_binfile == "0"} { | |
73 | unsupported "Couldn't compile ${srcfile}, ${why_msg}" | |
74 | return -1 | |
75 | } | |
76 | ||
77 | # Now we can proceed with the real testing. | |
78 | ||
79 | # Start with a fresh gdb. | |
80 | ||
81 | gdb_exit | |
82 | gdb_start | |
83 | gdb_reinitialize_dir $srcdir/$subdir | |
84 | gdb_load ${binfile} | |
85 | ||
86 | gdb_test "set print sevenbit-strings" "" | |
87 | #gdb_test "set print address off" "" | |
88 | gdb_test "set width 0" "" | |
89 | ||
90 | # We'll need this when we send_gdb a ^C to GDB. Need to do it before we | |
91 | # run the program and gdb starts saving and restoring tty states. | |
92 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
93 | # doesn't use vfork). | |
94 | if ![istarget "*-*-ultrix*"] then { | |
95 | gdb_test "shell stty intr '^C'" "" | |
96 | } | |
97 | ||
98 | proc all_threads_running {} { | |
99 | global gdb_prompt | |
100 | global srcfile | |
101 | ||
102 | # Reset all the counters to zero. | |
103 | gdb_test "set var common_routine::hits=0" "" | |
104 | gdb_test "set var common_routine::from_thread1=0" "" | |
105 | gdb_test "set var common_routine::from_thread2=0" "" | |
106 | gdb_test "set var common_routine::from_main=0" "" | |
107 | gdb_test "set var common_routine::full_coverage=0" "" | |
108 | ||
109 | # Disable all breakpoints. | |
110 | gdb_test "disable" "" | |
111 | ||
112 | # Set up a breakpoint that will cause us to stop when we have | |
113 | # been called 15 times. This should be plenty of time to allow | |
114 | # every thread to run at least once, since each thread sleeps for | |
115 | # one second between calls to common_routine. | |
2f09097b | 116 | gdb_test "tbreak common_routine if hits >= 15" "" |
c906108c SS |
117 | |
118 | # Start all the threads running again and wait for the inferior | |
119 | # to stop. Since no other breakpoints are set at this time | |
120 | # we should stop only when we have been previously called 15 times. | |
121 | ||
122 | send_gdb "continue\n" | |
123 | gdb_expect { | |
124 | -re "Continuing.*common_routine.*at.*$srcfile.*$gdb_prompt $" {} | |
125 | default { | |
126 | fail "continue until common routine run 15 times" | |
127 | return 0 | |
128 | } | |
129 | timeout { | |
130 | fail "continue until common routine run 15 times (timeout)" | |
131 | return 0 | |
132 | } | |
133 | } | |
134 | ||
135 | # Check that we stopped when we actually expected to stop, by | |
136 | # verifying that there have been 15 previous hits. | |
137 | ||
2f09097b ND |
138 | # NOTE: Because of synchronization behavior, it is possible for |
139 | # more than one thread to increment "hits" between one breakpoint | |
140 | # trap and the next. So stopping after 16 or 17 hits should be | |
141 | # considered acceptable. | |
142 | ||
c906108c SS |
143 | send_gdb "p common_routine::hits\n" |
144 | gdb_expect { | |
cf74b8ca AC |
145 | -re ".*= 15\r\n$gdb_prompt $" { |
146 | pass "stopped before calling common_routine 15 times" | |
147 | } | |
148 | -re ".*= 16\r\n$gdb_prompt $" { | |
149 | pass "stopped before calling common_routine 15 times (16 times)" | |
150 | } | |
151 | -re ".*= 17\r\n$gdb_prompt $" { | |
152 | pass "stopped before calling common_routine 15 times (17 times)" | |
153 | } | |
c906108c SS |
154 | default { |
155 | fail "stopped before calling common_routine 15 times" | |
156 | return 0 | |
157 | } | |
158 | -re ".*$gdb_prompt $" { | |
159 | fail "stopped before calling common_routine 15 times" | |
160 | return 0 | |
161 | } | |
162 | timeout { | |
163 | fail "stopped before calling common_routine 15 times (timeout)" | |
164 | return 0 | |
165 | } | |
166 | } | |
167 | ||
168 | # Also check that all of the threads have run, which will only be true | |
169 | # if the full_coverage variable is set. | |
170 | ||
171 | send_gdb "p common_routine::full_coverage\n" | |
172 | gdb_expect { | |
0816a3e5 MS |
173 | -re ".* = 1.*$gdb_prompt $" {} |
174 | -re ".* = 0.*$gdb_prompt $" { | |
175 | fail "some threads didn't run" | |
176 | return 0 | |
177 | } | |
c906108c SS |
178 | default { |
179 | fail "some threads didn't run" | |
180 | return 0 | |
181 | } | |
182 | timeout { | |
183 | fail "some threads didn't run (timeout)" | |
184 | return 0 | |
185 | } | |
186 | } | |
187 | ||
188 | # Looks fine, return success. | |
189 | return 1 | |
190 | } | |
191 | ||
192 | proc test_startup {} { | |
193 | global srcdir srcfile gdb_prompt expect_out | |
194 | global horiz | |
195 | global main_id thread1_id thread2_id | |
196 | ||
197 | # We should be able to do an info threads before starting any others. | |
198 | send_gdb "info threads\n" | |
199 | gdb_expect { | |
ae23c492 | 200 | -re ".*Thread.*main.*$gdb_prompt $" { |
c906108c SS |
201 | pass "info threads" |
202 | } | |
203 | -re "\r\n$gdb_prompt $" { | |
ae23c492 | 204 | unsupported "gdb does not support pthreads for this machine" |
c906108c SS |
205 | return 0 |
206 | } | |
207 | } | |
208 | ||
209 | # Extract the thread id number of main thread from "info threads" output. | |
210 | send_gdb "info threads\n" | |
211 | gdb_expect -re "(\[0-9\]+)(${horiz}Thread${horiz}main.*)($gdb_prompt $)" | |
212 | set main_id $expect_out(1,string) | |
213 | ||
214 | # Check that we can continue and create the first thread. | |
215 | gdb_test "break thread1" "Breakpoint .* file .*$srcdir.*" | |
216 | gdb_test "continue" \ | |
217 | "Continuing.*Breakpoint .*, thread1 \\(arg=0xfeedface\\).*at.*$srcfile.*" \ | |
218 | "Continue to creation of first thread" | |
219 | gdb_test "disable" "" | |
220 | ||
221 | # Extract the thread id number of thread 1 from "info threads" output. | |
222 | send_gdb "info threads\n" | |
223 | gdb_expect -re "(\[0-9\]+)(${horiz}Thread${horiz}thread1.*)($gdb_prompt $)" | |
224 | set thread1_id $expect_out(1,string) | |
225 | ||
226 | # Check that we can continue and create the second thread, | |
227 | # ignoring the first thread for the moment. | |
228 | gdb_test "break thread2" "Breakpoint .* file .*$srcdir.*" | |
229 | gdb_test "continue" \ | |
230 | "Continuing.*Breakpoint .*, thread2 \\(arg=0xdeadbeef\\).*at.*$srcfile.*" \ | |
231 | "Continue to creation of second thread" | |
232 | ||
233 | # Extract the thread id number of thread 2 from "info threads" output. | |
234 | send_gdb "info threads\n" | |
235 | gdb_expect -re "(\[0-9\]+)(${horiz}Thread${horiz}thread2.*)($gdb_prompt $)" | |
236 | set thread2_id $expect_out(1,string) | |
237 | ||
238 | return 1 | |
239 | } | |
240 | ||
241 | proc check_control_c {} { | |
242 | global gdb_prompt | |
243 | ||
244 | # Verify that all threads are running. | |
245 | if [all_threads_running] then { | |
246 | pass "All threads running after startup" | |
247 | } | |
248 | ||
249 | # Send a continue followed by ^C to the process to stop it. | |
250 | send_gdb "continue\n" | |
251 | set description "Stopped with a ^C" | |
252 | after 1000 [send_gdb "\003"] | |
253 | gdb_expect { | |
254 | -re "Program received signal SIGINT.*$gdb_prompt $" { | |
255 | pass $description | |
256 | } | |
257 | -re "Quit.*$gdb_prompt $" { | |
258 | pass $description | |
259 | } | |
260 | timeout { | |
261 | fail "$description (timeout)" | |
da55addb | 262 | return 1; |
c906108c SS |
263 | } |
264 | } | |
265 | gdb_test "bt" "" | |
266 | ||
267 | # Verify that all threads can be run again after a ^C stop. | |
268 | if [all_threads_running] then { | |
269 | pass "All threads running after continuing from ^C stop" | |
270 | } | |
da55addb | 271 | return 0; |
c906108c SS |
272 | } |
273 | ||
274 | proc check_backtraces {} { | |
275 | global gdb_prompt main_id thread1_id thread2_id | |
276 | ||
277 | # Check that the "thread apply N backtrace" command works | |
278 | ||
279 | gdb_test "thread apply $main_id backtrace" \ | |
280 | ".* in main \\(argc=.*, argv=.*\\).*" \ | |
281 | "check backtrace from main thread" | |
282 | gdb_test "thread apply $thread1_id backtrace" \ | |
283 | ".* in thread1 \\(arg=0xfeedface\\).*" \ | |
284 | "check backtrace from thread 1" | |
285 | gdb_test "thread apply $thread2_id backtrace" \ | |
286 | ".* in thread2 \\(arg=0xdeadbeef\\).*" \ | |
287 | "check backtrace from thread 2" | |
288 | ||
289 | # Check that we can apply the backtrace command to all | |
290 | # three threads with a single gdb command | |
291 | ||
292 | gdb_test "thread apply $main_id $thread1_id $thread2_id bt" \ | |
293 | ".* in main .* in thread1 .* in thread2.*" \ | |
294 | "apply backtrace command to all three threads" | |
295 | ||
296 | # Check that we can do thread specific backtraces | |
297 | # This also tests that we can do thread specific breakpoints. | |
298 | ||
299 | gdb_test "break common_routine thread $thread2_id" \ | |
300 | "Breakpoint .* at 0x.* file .* line .*" \ | |
301 | "set break at common_routine in thread 2" | |
302 | ||
303 | send_gdb "continue\n" | |
304 | gdb_expect { | |
305 | -re "Breakpoint .* common_routine \\(arg=2\\).*" { | |
cf74b8ca | 306 | pass "continue to bkpt at common_routine in thread 2" |
c906108c SS |
307 | send_gdb "backtrace\n" |
308 | gdb_expect { | |
309 | -re "#0.*common_routine \\(arg=2\\).*#1.*thread2.*" { | |
310 | pass "backtrace from thread 2 bkpt in common_routine" | |
311 | } | |
312 | default { | |
313 | fail "backtrace from thread 2 bkpt in common_routine" | |
314 | } | |
315 | timeout { | |
316 | fail "backtrace from thread 2 bkpt in common_routine (timeout)" | |
317 | } | |
318 | } | |
319 | } | |
320 | -re "Breakpoint .* common_routine \\(arg=0\\).*" { | |
cf74b8ca | 321 | fail "continue to bkpt at common_routine in thread 2 (arg=0)" |
c906108c SS |
322 | } |
323 | -re "Breakpoint .* common_routine \\(arg=1\\).*" { | |
cf74b8ca | 324 | fail "continue to bkpt at common_routine in thread 2 (arg=1)" |
c906108c SS |
325 | } |
326 | -re ".*$gdb_prompt" { | |
327 | fail "continue to bkpt at common_routine in thread 2" | |
328 | } | |
329 | default { | |
cf74b8ca | 330 | fail "continue to bkpt at common_routine in thread 2 (default)" |
c906108c SS |
331 | } |
332 | timeout { | |
333 | fail "continue to bkpt at common_routine in thread 2 (timeout)" | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | setup_xfail "alpha-*-osf*" | |
339 | if [runto_main] then { | |
340 | clear_xfail "alpha-*-osf*" | |
341 | if [test_startup] then { | |
da55addb MS |
342 | if [check_control_c] then { |
343 | warning "Could not stop child with ^C; skipping rest of tests.\n" | |
344 | return; | |
345 | } | |
c906108c SS |
346 | check_backtraces |
347 | } | |
348 | } | |
349 | clear_xfail "alpha-*-osf*" |