1 # Copyright (C) 2016-2024 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 # Regression test for PR gdb/18360. Test that "interrupt -a" while
17 # some thread is stepping over a breakpoint behaves as expected.
21 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
22 {debug pthreads}] == -1} {
30 # Read the number of threads out of the inferior.
31 set NUM_THREADS [get_integer_valueof "num_threads" -1]
33 # Account for the main thread.
36 # Run command and wait for the prompt, without end anchor.
38 proc gdb_test_no_anchor {cmd} {
41 gdb_test_multiple $cmd $cmd {
51 # Enable/disable debugging.
53 proc enable_debug {enable} {
55 # Comment out to debug problems with the test.
58 gdb_test_no_anchor "set debug infrun $enable"
59 gdb_test_no_anchor "set debug displaced $enable"
62 # If RESULT is not zero, make the caller return RESULT.
64 proc return_if_nonzero { result } {
66 return -code return $result
70 # Do one iteration of "c -a& -> interrupt -a". Return zero on success,
71 # and non-zero if some test fails.
73 proc test_one_iteration {} {
80 set test "continue -a &"
81 return_if_nonzero [gdb_test_multiple $test $test {
82 -re "Continuing.\r\n" {
87 if ![gdb_assert $saw_continuing $test] {
97 set test "all threads are running"
98 return_if_nonzero [gdb_test_multiple "info threads" $test {
99 -re "Thread \[^\r\n\]* \\(running\\)" {
104 if ![gdb_assert {$running_count == $NUM_THREADS} $test] {
113 set test "interrupt -a"
114 return_if_nonzero [gdb_test_multiple $test $test {
124 set test "wait for stops"
125 # Don't return on failure here, in order to let "info threads" put
126 # useful info in gdb.log.
127 gdb_test_multiple "" $test {
128 -re "Thread $decimal \[^\r\n\]*stopped" {
130 if {$stopped_count != $NUM_THREADS} {
135 gdb_assert {$stopped_count == $NUM_THREADS} $test
142 # Check if all threads are seen as stopped with "info
143 # threads". It's a bit redundant with the test above, but
144 # it's useful to have this in the gdb.log if the above ever
147 set test "all threads are stopped"
148 return_if_nonzero [gdb_test_multiple "info threads" $test {
149 -re "${tdlabel_re} \[^\r\n\]* \\(running\\)" {
154 if ![gdb_assert {$running_count == 0} $test] {
163 # The test driver proper. If DISPLACED is "on", turn on displaced
164 # stepping. If "off", turn it off.
166 proc testdriver {displaced} {
170 save_vars { GDBFLAGS } {
171 append GDBFLAGS " -ex \"set non-stop on\""
172 clean_restart $binfile
175 gdb_test_no_output "set displaced-stepping $displaced"
177 if ![runto all_started] {
180 set break_line [gdb_get_line_number "set breakpoint here"]
182 gdb_test "break $break_line if always_zero" "Breakpoint .*" "set breakpoint"
186 for {set iter 0} {$iter < 20} {incr iter} {
187 with_test_prefix "iter=$iter" {
188 # Return early if some test fails, to avoid cascading
189 # timeouts if something goes wrong.
190 if {[test_one_iteration] != 0} {
197 foreach_with_prefix displaced-stepping {"on" "off"} {
198 if { ${displaced-stepping} != "off" && ![support_displaced_stepping] } {
202 testdriver ${displaced-stepping}