Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.threads / interrupt-while-step-over.exp
blob89c1d06f5ba16e1c025c57e8fd9652974e7224a0
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.
19 standard_testfile
21 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
22          {debug pthreads}] == -1} {
23     return -1
26 if {![runto_main]} {
27     return -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.
34 incr NUM_THREADS
36 # Run command and wait for the prompt, without end anchor.
38 proc gdb_test_no_anchor {cmd} {
39     global gdb_prompt
41     gdb_test_multiple $cmd $cmd {
42         -re "$gdb_prompt " {
43             pass $cmd
44         }
45         -re "infrun:" {
46             exp_continue
47         }
48     }
51 # Enable/disable debugging.
53 proc enable_debug {enable} {
55     # Comment out to debug problems with the test.
56     return
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 } {
65     if {$result != 0} {
66         return -code return $result
67     }
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 {} {
74     global gdb_prompt
75     global NUM_THREADS
76     global decimal
77     global tdlabel_re
79     set saw_continuing 0
80     set test "continue -a &"
81     return_if_nonzero [gdb_test_multiple $test $test {
82         -re "Continuing.\r\n" {
83             set saw_continuing 1
84             exp_continue
85         }
86         -re "$gdb_prompt " {
87             if ![gdb_assert $saw_continuing $test] {
88                 return 1
89             }
90         }
91         -re "infrun:" {
92             exp_continue
93         }
94     }]
96     set running_count 0
97     set test "all threads are running"
98     return_if_nonzero [gdb_test_multiple "info threads" $test {
99         -re "Thread \[^\r\n\]* \\(running\\)" {
100             incr running_count
101             exp_continue
102         }
103         -re "$gdb_prompt " {
104             if ![gdb_assert {$running_count == $NUM_THREADS} $test] {
105                 return 1
106             }
107         }
108         -re "infrun:" {
109             exp_continue
110         }
111     }]
113     set test "interrupt -a"
114     return_if_nonzero [gdb_test_multiple $test $test {
115         -re "$gdb_prompt " {
116             pass $test
117         }
118         -re "infrun:" {
119             exp_continue
120         }
121     }]
123     set stopped_count 0
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" {
129             incr stopped_count
130             if {$stopped_count != $NUM_THREADS} {
131                 exp_continue
132             }
133         }
134         -re "$gdb_prompt " {
135             gdb_assert {$stopped_count == $NUM_THREADS} $test
136         }
137         -re "infrun:" {
138             exp_continue
139         }
140     }
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
145     # happens to fail.
146     set running_count 0
147     set test "all threads are stopped"
148     return_if_nonzero [gdb_test_multiple "info threads" $test {
149         -re "${tdlabel_re} \[^\r\n\]* \\(running\\)" {
150             incr running_count
151             exp_continue
152         }
153         -re "$gdb_prompt " {
154             if ![gdb_assert {$running_count == 0} $test] {
155                 return 1
156             }
157         }
158     }]
160     return 0
163 # The test driver proper.  If DISPLACED is "on", turn on displaced
164 # stepping.  If "off", turn it off.
166 proc testdriver {displaced} {
167     global binfile
168     global GDBFLAGS
170     save_vars { GDBFLAGS } {
171         append GDBFLAGS " -ex \"set non-stop on\""
172         clean_restart $binfile
173     }
175     gdb_test_no_output "set displaced-stepping $displaced"
177     if ![runto all_started] {
178         return
179     }
180     set break_line [gdb_get_line_number "set breakpoint here"]
182     gdb_test "break $break_line if always_zero" "Breakpoint .*" "set breakpoint"
184     enable_debug 1
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} {
191                 return
192             }
193         }
194     }
197 foreach_with_prefix displaced-stepping {"on" "off"} {
198     if { ${displaced-stepping} != "off" && ![support_displaced_stepping] } {
199         continue
200     }
202     testdriver ${displaced-stepping}