1 # Copyright (C) 2016-2023 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 sucess,
71 # and non-zero if some test fails.
73 proc test_one_iteration {} {
79 set test "continue -a &"
80 return_if_nonzero [gdb_test_multiple $test $test {
81 -re "Continuing.\r\n" {
86 if ![gdb_assert $saw_continuing $test] {
96 set test "all threads are running"
97 return_if_nonzero [gdb_test_multiple "info threads" $test {
98 -re "Thread \[^\r\n\]* \\(running\\)" {
103 if ![gdb_assert {$running_count == $NUM_THREADS} $test] {
112 set test "interrupt -a"
113 return_if_nonzero [gdb_test_multiple $test $test {
123 set test "wait for stops"
124 # Don't return on failure here, in order to let "info threads" put
125 # useful info in gdb.log.
126 gdb_test_multiple "" $test {
127 -re "Thread $decimal \[^\r\n\]*stopped" {
129 if {$stopped_count != $NUM_THREADS} {
134 gdb_assert {$stopped_count == $NUM_THREADS} $test
141 # Check if all threads are seen as stopped with "info
142 # threads". It's a bit redundant with the test above, but
143 # it's useful to have this in the gdb.log if the above ever
146 set test "all threads are stopped"
147 return_if_nonzero [gdb_test_multiple "info threads" $test {
148 -re "Thread \[^\r\n\]* \\(running\\)" {
153 if ![gdb_assert {$running_count == 0} $test] {
162 # The test driver proper. If DISPLACED is "on", turn on displaced
163 # stepping. If "off", turn it off.
165 proc testdriver {displaced} {
169 save_vars { GDBFLAGS } {
170 append GDBFLAGS " -ex \"set non-stop on\""
171 clean_restart $binfile
174 gdb_test_no_output "set displaced-stepping $displaced"
176 if ![runto all_started] {
179 set break_line [gdb_get_line_number "set breakpoint here"]
181 gdb_test "break $break_line if always_zero" "Breakpoint .*" "set breakpoint"
185 for {set iter 0} {$iter < 20} {incr iter} {
186 with_test_prefix "iter=$iter" {
187 # Return early if some test fails, to avoid cascading
188 # timeouts if something goes wrong.
189 if {[test_one_iteration] != 0} {
196 foreach_with_prefix displaced-stepping {"on" "off"} {
197 if { ${displaced-stepping} != "off" && ![support_displaced_stepping] } {
201 testdriver ${displaced-stepping}