1 # Copyright
(C
) 1996, 1997, 2002, 2003 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
:
18 # bug
-gdb@prep.ai.mit.edu
20 # This file was written by Daniel Jacobowitz
<drow@mvista.com
>
21 #
(parts based
on pthreads.exp by Fred Fish
(fnf@cygnus.com
).
23 # This test covers the various forms of
"set scheduler-locking".
32 set testfile
"schedlock"
33 set srcfile $
{testfile
}.c
34 set binfile $
{objdir
}/$
{subdir
}/$
{testfile
}
36 if {[gdb_compile_pthreads
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
40 # Now we can proceed with the real testing.
46 send_gdb
"print args\n"
48 -re
"\\\$\[0-9\]+ = {(\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+), (\[0-9\]+)}.*$gdb_prompt"
50 set list_count
[expr $list_count
+ 1]
51 pass
"listed args ($list_count)"
52 return [list $expect_out
(1,string
) $expect_out
(2,string
) $expect_out
(3,string
) $expect_out
(4,string
) $expect_out
(5,string
) $expect_out
(6,string
)]
56 fail
"listed args ($list_count) (unknown output)"
60 fail
"listed args ($list_count) (timeout)"
65 proc stop_process
{ description
} {
68 #
For this to work we must be sure to consume the
"Continuing."
69 # message first
, or GDB
's signal handler may not be in place.
70 after 1000 {send_gdb "\003"}
72 -re "Program received signal SIGINT.*$gdb_prompt $"
78 fail "$description (timeout)"
83 proc get_current_thread { description } {
88 -re "thread_function \\(arg=0x(\[0-9\])\\).*$gdb_prompt $"
91 return $expect_out(1,string)
95 fail "$description (unknown output)"
99 fail "$description (timeout)"
104 proc my_continue { msg } {
105 send_gdb "continue\n"
108 { pass "continue ($msg)" }
110 { fail "continue ($msg) (timeout)" }
113 stop_process "stop all threads ($msg)"
115 # Make sure we're in one of the non
-main looping threads.
116 gdb_breakpoint
[concat
[gdb_get_line_number
"schedlock.exp: main loop"] " if arg != 5"]
117 gdb_continue_to_breakpoint
"return to loop ($msg)"
121 proc step_ten_loops
{ msg
} {
124 for {set i
0} {[expr $i
< 10]} {set i
[expr $i
+ 1]} {
128 -re
".*myp\\) \\+\\+;\[\r\n\]+$gdb_prompt $" {
129 pass
"step to increment ($msg $i)"
131 -re
"$gdb_prompt $" {
132 if {$other_step
== 0} {
137 fail
"step to increment ($msg $i)"
142 fail
"step to increment ($msg $i) (timeout)"
148 # Start with a fresh gdb.
152 gdb_reinitialize_dir $srcdir
/$subdir
154 # We
'll need this when we send_gdb a ^C to GDB. Need to do it before we
155 # run the program and gdb starts saving and restoring tty states.
156 # On Ultrix, we don't need it and it is really slow
(because shell_escape
157 # doesn
't use vfork).
158 if ![istarget "*-*-ultrix*"] then {
159 gdb_test "shell stty intr '^C
'" ""
164 gdb_test "set print sevenbit-strings" ""
165 gdb_test "set width 0" ""
169 # See if scheduler locking is available on this target.
170 send_gdb "set scheduler-locking off\n"
173 -re "Target .* cannot support this command"
175 unsupported "target does not support scheduler locking"
180 pass "scheduler locking set to none"
184 unsupported "target does not support scheduler locking (timeout)"
189 gdb_breakpoint [gdb_get_line_number "schedlock.exp: last thread start"]
190 gdb_continue_to_breakpoint "all threads started"
195 set start_args [get_args]
197 # First make sure that all threads are alive.
198 my_continue "initial"
200 set cont_args [get_args]
202 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
203 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
204 fail "thread $i ran (didn't run
)"
210 # We can
't change threads, unfortunately, in current GDB. Use
211 # whichever we stopped in.
212 set curthread [get_current_thread "find current thread (1)"]
217 # Test stepping without scheduler locking.
218 gdb_test "set scheduler-locking off" ""
220 step_ten_loops "unlocked"
222 # Make sure we're still in the same thread.
223 set newthread
[get_current_thread
"find current thread (2)"]
224 if {$curthread
== $newthread
} {
225 pass
"step without lock does not change thread"
227 fail
"step without lock does not change thread (switched to thread $newthread)"
230 set start_args $cont_args
231 set cont_args
[get_args
]
233 set num_other_threads
0
234 for {set i
0} {[expr $i
< 6]} {set i
[expr $i
+ 1]} {
235 if {[lindex $start_args $i
] == [lindex $cont_args $i
]} {
236 if {$i
== $curthread
} {
237 fail
"current thread stepped (didn't run)"
240 if {$i
== $curthread
} {
241 if {[lindex $start_args $i
] == [expr
[lindex $cont_args $i
] - 10]} {
242 pass
"current thread stepped"
244 fail
"current thread stepped (wrong amount)"
247 set num_other_threads
[expr $num_other_threads
+ 1]
251 if {$num_other_threads
> 0} {
252 pass
"other threads ran (1)"
254 fail
"other threads ran (no other threads ran) (1)"
257 # Test
continue with scheduler locking
258 gdb_test
"set scheduler-locking on" ""
260 my_continue
"with lock"
262 # Make sure we
're still in the same thread.
263 set newthread [get_current_thread "find current thread (3)"]
264 if {$curthread == $newthread} {
265 pass "continue with lock does not change thread"
267 fail "continue with lock does not change thread (switched to thread $newthread)"
270 set start_args $cont_args
271 set cont_args [get_args]
273 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
274 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
275 if {$i == $curthread} {
276 fail "current thread ran (didn't run
)"
278 pass
"other thread $i didn't run"
281 if {$i
== $curthread
} {
282 pass
"current thread ran"
284 fail
"other thread $i didn't run (ran)"
289 # Test stepping with scheduler locking
290 step_ten_loops
"locked"
292 # Make sure we
're still in the same thread.
293 set newthread [get_current_thread "find current thread (2)"]
294 if {$curthread == $newthread} {
295 pass "step with lock does not change thread"
297 fail "step with lock does not change thread (switched to thread $newthread)"
300 set start_args $cont_args
301 set cont_args [get_args]
303 for {set i 0} {[expr $i < 6]} {set i [expr $i + 1]} {
304 if {[lindex $start_args $i] == [lindex $cont_args $i]} {
305 if {$i == $curthread} {
306 fail "current thread stepped locked (didn't run
)"
308 pass
"other thread $i didn't run (stepping)"
311 if {$i
== $curthread
} {
312 if {[lindex $start_args $i
] == [expr
[lindex $cont_args $i
] - 10]} {
313 pass
"current thread stepped locked"
315 fail
"current thread stepped locked (wrong amount)"
318 fail
"other thread $i didn't run (stepping) (ran)"