1 # Copyright (C) 2014-2015 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 3 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, see <http://www.gnu.org/licenses/>.
16 # Test that GDB in non-stop mode gives roughly equal priority to
17 # events of all threads.
20 set executable ${testfile}
22 if [target_info exists gdb,nosignals] {
23 verbose "Skipping ${testfile}.exp because of nosignals."
27 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] == -1} {
31 gdb_test_no_output "set non-stop on"
37 # We want "handle print", to make sure the target backend reports the
38 # signal to the run control core.
39 gdb_test "handle SIGUSR1 print nostop pass" ""
41 # Get current value of VAR from the inferior. TEST is used as test
44 proc get_value {var test} {
50 gdb_test_multiple "print $var" "$test" {
51 -re ".*= ($decimal).*\r\n$gdb_prompt $" {
52 set value $expect_out(1,string)
59 set NUM_THREADS [get_value "num_threads" "get num_threads"]
61 # Account for the main thread.
64 # Run threads to their start positions. This prepares for a new test
73 gdb_test "print got_sig = 0" " = 0"
75 gdb_breakpoint [gdb_get_line_number "set thread breakpoint here"]
76 gdb_breakpoint [gdb_get_line_number "set kill breakpoint here"]
78 set test "continue -a&"
79 gdb_test_multiple $test $test {
80 -re "Continuing.\r\n$gdb_prompt " {
85 for {set i 1} { $i <= $NUM_THREADS } { incr i } {
86 set test "thread $i restarted"
87 gdb_test_multiple "" $test {
88 -re "breakpoint here" {
89 # The prompt was already matched in the "continue &"
90 # test above. We're now consuming asynchronous output
91 # that comes after the prompt.
100 # The test proper. SIGNAL_THREAD is the thread that has been elected
101 # to receive the SIGUSR1 signal.
103 proc test {signal_thread} {
107 with_test_prefix "signal_thread=$signal_thread" {
110 # Set all threads stepping the infinite loop line in parallel.
111 for {set i 2} { $i <= $NUM_THREADS } { incr i } {
112 gdb_test "thread $i" \
113 "child_function.*set thread breakpoint here.*" \
114 "switch to thread $i to step it"
116 if {$i == $signal_thread} {
117 gdb_test "print signal_thread = self" " = .*"
120 gdb_test "step&" "" "set $i thread stepping"
123 gdb_test "thread 1" "Switching to .*" \
124 "switch to the main thread to queue signal"
126 # Let the main thread queue the signal.
127 gdb_breakpoint "loop_broke"
128 set test "continue &"
129 gdb_test_multiple $test $test {
130 -re "Continuing.\r\n$gdb_prompt " {
135 # Wait for all threads to finish their steps, and for the main
136 # thread to hit the breakpoint.
137 for {set i 1} { $i <= $NUM_THREADS } { incr i } {
138 set test "thread $i broke out of loop"
139 gdb_test_multiple "" $test {
141 # The prompt was already matched in the "continue
142 # &" test above. We're now consuming asynchronous
143 # output that comes after the prompt.
149 # It's helpful to have this in the log if the test ever
151 gdb_test "info threads"
155 # The kernel/debug API may always walk its thread list looking for the
156 # first with an event, resulting in giving priority to e.g. the thread
157 # with lowest kernel thread ID. So test once with the signal pending
158 # in each thread, except the main thread.
159 for {set i 2} { $i <= $NUM_THREADS } { incr i } {