1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2015-2021 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"
24 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
25 untested "failed to prepare"
29 save_vars { GDBFLAGS } {
30 append GDBFLAGS " -ex \"set non-stop on\""
31 clean_restart $testfile
35 untested "failed to run to main"
40 set bp_1 [gdb_get_line_number "bp.1" $srcfile]
41 set bp_2 [gdb_get_line_number "bp.2" $srcfile]
42 set bp_3 [gdb_get_line_number "bp.3" $srcfile]
47 # get the line number containing most of the trace
48 set loop [gdb_get_line_number "loop" $srcfile]
50 # a stop on the above line as reported by GDB
51 set loop_line "$loop\[^\\\r\\\n\]*/\\\* loop \\\*/"
53 # make sure $line matches the full expected output per thread.
54 # and let's hope that GDB never mixes the output from different threads.
55 proc gdb_cont_to { threads cmd line nthreads } {
57 set full_cmd "thread apply $threads $cmd"
59 # consume the prompt. since we started the command in the background,
60 # the prompt precedes any further output except some errors.
61 gdb_test_multiple "$full_cmd &" "$full_cmd: prompt" {
67 # now check for the expected line - one per thread.
68 for {set i 0} {$i < $nthreads} {incr i} {
69 gdb_test_multiple "" "$full_cmd: thread $i" {
70 -re "$line\[^\\\r\\\n\]*\r\n" {
77 proc gdb_cont_to_bp_line { line threads nthreads } {
78 gdb_cont_to $threads "continue" \
80 "Breakpoint\[^\\\r\\\n\]*$line" \
86 proc gdb_cont_to_no_history { threads cmd nthreads } {
87 gdb_cont_to $threads $cmd \
89 "No more reverse-execution history\." \
96 # trace the code between the two breakpoints
97 with_test_prefix "prepare" {
98 gdb_cont_to_bp_line "$srcfile:$bp_1" all 2
100 with_test_prefix "record" {
101 gdb_test_no_output "record btrace"
102 gdb_cont_to_bp_line "$srcfile:$bp_2" all 2
105 # we don't need those breakpoints any longer.
106 # they will only disturb our stepping.
109 # show the threads - this is useful for debugging fails
110 gdb_test "thread apply all info rec" ".*"
111 gdb_test "info threads" ".*"
113 with_test_prefix "navigate" {
114 gdb_test "thread apply 1 record goto 2" "$loop_line"
115 gdb_test "thread apply 2 record goto 4" "$loop_line"
116 gdb_test "thread apply 1 info record" \
117 ".*Replay in progress\. At instruction 2\." "thread 1 at insn 2"
118 gdb_test "thread apply 2 info record" \
119 ".*Replay in progress\. At instruction 4\." "thread 2 at insn 4"
121 gdb_test "thread apply all record goto 5" "$loop_line"
122 gdb_test "thread apply 1 info record" \
123 ".*Replay in progress\. At instruction 5\." "thread 1 at insn 5"
124 gdb_test "thread apply 2 info record" \
125 ".*Replay in progress\. At instruction 5\." "thread 2 at insn 5"
128 with_test_prefix "step" {
129 with_test_prefix "thread 1" {
130 gdb_test "thread apply 1 stepi 2" "$loop_line"
131 gdb_test "thread apply 1 info record" \
132 ".*Replay in progress\. At instruction 7\."
133 gdb_test "thread apply 2 info record" \
134 ".*Replay in progress\. At instruction 5\."
137 with_test_prefix "thread 2" {
138 gdb_test "thread apply 2 stepi 3" "$loop_line"
139 gdb_test "thread apply 1 info record" \
140 ".*Replay in progress\. At instruction 7\."
141 gdb_test "thread apply 2 info record" \
142 ".*Replay in progress\. At instruction 8\."
145 with_test_prefix "all" {
146 gdb_cont_to all "stepi 4" "$loop_line" 2
147 gdb_test "thread apply 1 info record" \
148 ".*Replay in progress\. At instruction 11\."
149 gdb_test "thread apply 2 info record" \
150 ".*Replay in progress\. At instruction 12\."
154 with_test_prefix "reverse-step" {
155 with_test_prefix "thread 1" {
156 gdb_test "thread apply 1 reverse-stepi 2" "$loop_line"
157 gdb_test "thread apply 1 info record" \
158 ".*Replay in progress\. At instruction 9\."
159 gdb_test "thread apply 2 info record" \
160 ".*Replay in progress\. At instruction 12\."
163 with_test_prefix "thread 2" {
164 gdb_test "thread apply 2 reverse-stepi 3" "$loop_line"
165 gdb_test "thread apply 1 info record" \
166 ".*Replay in progress\. At instruction 9\."
167 gdb_test "thread apply 2 info record" \
168 ".*Replay in progress\. At instruction 9\."
171 with_test_prefix "all" {
172 gdb_cont_to all "reverse-stepi 4" "$loop_line" 2
173 gdb_test "thread apply 1 info record" \
174 ".*Replay in progress\. At instruction 5\."
175 gdb_test "thread apply 2 info record" \
176 ".*Replay in progress\. At instruction 5\."
180 with_test_prefix "continue" {
181 with_test_prefix "thread 1" {
182 with_test_prefix "continue" {
183 gdb_cont_to_no_history 1 "continue" 1
184 gdb_test "thread apply 1 info record" \
185 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
186 gdb_test "thread apply 2 info record" \
187 ".*Replay in progress\. At instruction 5\."
189 with_test_prefix "reverse-continue" {
190 gdb_cont_to_no_history 1 "reverse-continue" 1
191 gdb_test "thread apply 1 info record" \
192 ".*Replay in progress\. At instruction 1\."
193 gdb_test "thread apply 2 info record" \
194 ".*Replay in progress\. At instruction 5\."
198 with_test_prefix "thread 2" {
199 with_test_prefix "continue" {
200 gdb_cont_to_no_history 2 "continue" 1
201 gdb_test "thread apply 1 info record" \
202 ".*Replay in progress\. At instruction 1\."
203 gdb_test "thread apply 2 info record" \
204 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
206 with_test_prefix "reverse-continue" {
207 gdb_cont_to_no_history 2 "reverse-continue" 1
208 gdb_test "thread apply 1 info record" \
209 ".*Replay in progress\. At instruction 1\."
210 gdb_test "thread apply 2 info record" \
211 ".*Replay in progress\. At instruction 1\."
216 # a thread may only resume if no thread is still replaying
217 with_test_prefix "no progress" {
218 with_test_prefix "thread 1" {
219 gdb_test "thread apply 1 record goto end" ".*"
220 gdb_test "thread apply 2 record goto begin" ".*"
222 gdb_cont_to_no_history 1 "continue" 1
223 gdb_cont_to_no_history 1 "step" 1
224 gdb_test "thread apply 1 info record" \
225 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
226 gdb_test "thread apply 2 info record" \
227 ".*Replay in progress\. At instruction 1\."
230 with_test_prefix "thread 2" {
231 gdb_test "thread apply 1 record goto begin" ".*"
232 gdb_test "thread apply 2 record goto end" ".*"
234 gdb_cont_to_no_history 2 "continue" 1
235 gdb_cont_to_no_history 2 "step" 1
236 gdb_test "thread apply 1 info record" \
237 ".*Replay in progress\. At instruction 1\."
238 gdb_test "thread apply 2 info record" \
239 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
242 with_test_prefix "all" {
243 gdb_test "thread apply all record goto begin" ".*"
245 gdb_cont_to_no_history all "continue" 2
246 gdb_test "thread apply 1 info record" \
247 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
248 gdb_test "thread apply 2 info record" \
249 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
253 # now that both threads stopped replaying we may resume recording
254 with_test_prefix "cont to end" {
256 gdb_cont_to_bp_line "$srcfile:$bp_3" all 1