Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.btrace / non-stop.exp
blob0cc78e97f1676544164c0f616359407664a31700
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2015-2023 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 if { [skip_btrace_tests] } {
19     unsupported "target does not support record-btrace"
20     return -1
23 standard_testfile
24 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
25     untested "failed to prepare"
26     return -1
29 save_vars { GDBFLAGS } {
30     append GDBFLAGS " -ex \"set non-stop on\""
31     clean_restart $testfile
34 if ![runto_main] {
35     return -1
38 # set up breakpoints
39 set bp_1 [gdb_get_line_number "bp.1" $srcfile]
40 set bp_2 [gdb_get_line_number "bp.2" $srcfile]
41 set bp_3 [gdb_get_line_number "bp.3" $srcfile]
43 gdb_breakpoint $bp_1
44 gdb_breakpoint $bp_2
46 # get the line number containing most of the trace
47 set loop [gdb_get_line_number "loop" $srcfile]
49 # a stop on the above line as reported by GDB
50 set loop_line "$loop\[^\\\r\\\n\]*/\\\* loop \\\*/"
52 # make sure $line matches the full expected output per thread.
53 # and let's hope that GDB never mixes the output from different threads.
54 proc gdb_cont_to { threads cmd line nthreads } {
55     global gdb_prompt
56     set full_cmd "thread apply $threads $cmd"
58     # consume the prompt.  since we started the command in the background,
59     # the prompt precedes any further output except some errors.
60     gdb_test_multiple "$full_cmd &" "$full_cmd: prompt" {
61         -re "$gdb_prompt " {
62             pass $gdb_test_name
63         }
64     }
66     # now check for the expected line - one per thread.
67     for {set i 0} {$i < $nthreads} {incr i} {
68         gdb_test_multiple "" "$full_cmd: thread $i" {
69             -re "$line\[^\\\r\\\n\]*\r\n" {
70                 pass $gdb_test_name
71             }
72         }
73     }
76 proc gdb_cont_to_bp_line { line threads nthreads } {
77     gdb_cont_to $threads "continue" \
78         [multi_line \
79              "Breakpoint\[^\\\r\\\n\]*$line" \
80              "\[^\\\r\\\n\]*" \
81             ] \
82         $nthreads
85 proc gdb_cont_to_no_history { threads cmd nthreads } {
86     gdb_cont_to $threads $cmd \
87         [multi_line \
88              "No more reverse-execution history\." \
89              "\[^\\\r\\\n\]*" \
90              "\[^\\\r\\\n\]*" \
91             ] \
92         $nthreads
95 # trace the code between the two breakpoints
96 with_test_prefix "prepare" {
97     gdb_cont_to_bp_line "$srcfile:$bp_1" all 2
99 with_test_prefix "record" {
100     gdb_test_no_output "record btrace"
101     gdb_cont_to_bp_line "$srcfile:$bp_2" all 2
104 # we don't need those breakpoints any longer.
105 # they will only disturb our stepping.
106 delete_breakpoints
108 # show the threads - this is useful for debugging fails
109 gdb_test "thread apply all info rec" ".*"
110 gdb_test "info threads" ".*"
112 with_test_prefix "navigate" {
113     gdb_test "thread apply 1 record goto 3" "$loop_line"
114     gdb_test "thread apply 2 record goto 4" "$loop_line"
115     gdb_test "thread apply 1 info record" \
116         ".*Replay in progress\.  At instruction 3\." "thread 1 at insn 3"
117     gdb_test "thread apply 2 info record" \
118         ".*Replay in progress\.  At instruction 4\." "thread 2 at insn 4"
120     gdb_test "thread apply all record goto 5" "$loop_line"
121     gdb_test "thread apply 1 info record" \
122         ".*Replay in progress\.  At instruction 5\." "thread 1 at insn 5"
123     gdb_test "thread apply 2 info record" \
124         ".*Replay in progress\.  At instruction 5\." "thread 2 at insn 5"
127 with_test_prefix "step" {
128     with_test_prefix "thread 1" {
129         gdb_test "thread apply 1 stepi 2" "$loop_line"
130         gdb_test "thread apply 1 info record" \
131             ".*Replay in progress\.  At instruction 7\."
132         gdb_test "thread apply 2 info record" \
133             ".*Replay in progress\.  At instruction 5\."
134     }
136     with_test_prefix "thread 2" {
137         gdb_test "thread apply 2 stepi 3" "$loop_line"
138         gdb_test "thread apply 1 info record" \
139             ".*Replay in progress\.  At instruction 7\."
140         gdb_test "thread apply 2 info record" \
141             ".*Replay in progress\.  At instruction 8\."
142     }
144     with_test_prefix "all" {
145         gdb_cont_to all "stepi 4" "$loop_line" 2
146         gdb_test "thread apply 1 info record" \
147             ".*Replay in progress\.  At instruction 11\."
148         gdb_test "thread apply 2 info record" \
149             ".*Replay in progress\.  At instruction 12\."
150     }
153 with_test_prefix "reverse-step" {
154     with_test_prefix "thread 1" {
155         gdb_test "thread apply 1 reverse-stepi 2" "$loop_line"
156         gdb_test "thread apply 1 info record" \
157             ".*Replay in progress\.  At instruction 9\."
158         gdb_test "thread apply 2 info record" \
159             ".*Replay in progress\.  At instruction 12\."
160     }
162     with_test_prefix "thread 2" {
163         gdb_test "thread apply 2 reverse-stepi 3" "$loop_line"
164         gdb_test "thread apply 1 info record" \
165             ".*Replay in progress\.  At instruction 9\."
166         gdb_test "thread apply 2 info record" \
167             ".*Replay in progress\.  At instruction 9\."
168     }
170     with_test_prefix "all" {
171         gdb_cont_to all "reverse-stepi 4" "$loop_line" 2
172         gdb_test "thread apply 1 info record" \
173             ".*Replay in progress\.  At instruction 5\."
174         gdb_test "thread apply 2 info record" \
175             ".*Replay in progress\.  At instruction 5\."
176     }
179 with_test_prefix "continue" {
180     with_test_prefix "thread 1" {
181         with_test_prefix "continue" {
182             gdb_cont_to_no_history 1 "continue" 1
183             gdb_test "thread apply 1 info record" \
184                 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
185             gdb_test "thread apply 2 info record" \
186                 ".*Replay in progress\.  At instruction 5\."
187         }
188         with_test_prefix "reverse-continue" {
189             gdb_cont_to_no_history 1 "reverse-continue" 1
190             gdb_test "thread apply 1 info record" \
191                 ".*Replay in progress\.  At instruction 1\."
192             gdb_test "thread apply 2 info record" \
193                 ".*Replay in progress\.  At instruction 5\."
194         }
195     }
197     with_test_prefix "thread 2" {
198         with_test_prefix "continue" {
199             gdb_cont_to_no_history 2 "continue" 1
200             gdb_test "thread apply 1 info record" \
201                 ".*Replay in progress\.  At instruction 1\."
202             gdb_test "thread apply 2 info record" \
203                 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
204         }
205         with_test_prefix "reverse-continue" {
206             gdb_cont_to_no_history 2 "reverse-continue" 1
207             gdb_test "thread apply 1 info record" \
208                 ".*Replay in progress\.  At instruction 1\."
209             gdb_test "thread apply 2 info record" \
210                 ".*Replay in progress\.  At instruction 1\."
211         }
212     }
215 # a thread may only resume if no thread is still replaying
216 with_test_prefix "no progress" {
217     with_test_prefix "thread 1" {
218         gdb_test "thread apply 1 record goto end" ".*"
219         gdb_test "thread apply 2 record goto begin" ".*"
221         gdb_cont_to_no_history 1 "continue" 1
222         gdb_cont_to_no_history 1 "step" 1
223         gdb_test "thread apply 1 info record" \
224             ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
225         gdb_test "thread apply 2 info record" \
226             ".*Replay in progress\.  At instruction 1\."
227     }
229     with_test_prefix "thread 2" {
230         gdb_test "thread apply 1 record goto begin" ".*"
231         gdb_test "thread apply 2 record goto end" ".*"
233         gdb_cont_to_no_history 2 "continue" 1
234         gdb_cont_to_no_history 2 "step" 1
235         gdb_test "thread apply 1 info record" \
236             ".*Replay in progress\.  At instruction 1\."
237         gdb_test "thread apply 2 info record" \
238             ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
239     }
241     with_test_prefix "all" {
242         gdb_test "thread apply all record goto begin" ".*"
244         gdb_cont_to_no_history all "continue" 2
245         gdb_test "thread apply 1 info record" \
246             ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
247         gdb_test "thread apply 2 info record" \
248             ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
249     }
252 # now that both threads stopped replaying we may resume recording
253 with_test_prefix "cont to end" {
254     gdb_breakpoint $bp_3
255     gdb_cont_to_bp_line "$srcfile:$bp_3" all 1