1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2015-2024 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 require allow_btrace_tests
21 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
22 untested "failed to prepare"
26 save_vars { GDBFLAGS } {
27 append GDBFLAGS " -ex \"set non-stop on\""
28 clean_restart $testfile
36 set bp_1 [gdb_get_line_number "bp.1" $srcfile]
37 set bp_2 [gdb_get_line_number "bp.2" $srcfile]
38 set bp_3 [gdb_get_line_number "bp.3" $srcfile]
43 # get the line number containing most of the trace
44 set loop [gdb_get_line_number "loop" $srcfile]
46 # a stop on the above line as reported by GDB
47 set loop_line "$loop\[^\\\r\\\n\]*/\\\* loop \\\*/"
49 # make sure $line matches the full expected output per thread.
50 # and let's hope that GDB never mixes the output from different threads.
51 proc gdb_cont_to { threads cmd line nthreads } {
53 set full_cmd "thread apply $threads $cmd"
55 # consume the prompt. since we started the command in the background,
56 # the prompt precedes any further output except some errors.
57 gdb_test_multiple "$full_cmd &" "$full_cmd: prompt" {
63 # now check for the expected line - one per thread.
64 for {set i 0} {$i < $nthreads} {incr i} {
65 gdb_test_multiple "" "$full_cmd: thread $i" {
66 -re "$line\[^\\\r\\\n\]*\r\n" {
73 proc gdb_cont_to_bp_line { line threads nthreads } {
74 gdb_cont_to $threads "continue" \
76 "Breakpoint\[^\\\r\\\n\]*$line" \
82 proc gdb_cont_to_no_history_backward { threads cmd nthreads } {
83 gdb_cont_to $threads $cmd \
85 "Reached end of recorded history; stopping\." \
86 "Backward execution from here not possible\." \
93 proc gdb_cont_to_no_history_forward { threads cmd nthreads } {
94 gdb_cont_to $threads $cmd \
96 "Reached end of recorded history; stopping\." \
97 "Following forward execution will be added to history\." \
104 # trace the code between the two breakpoints
105 with_test_prefix "prepare" {
106 gdb_cont_to_bp_line "$srcfile:$bp_1" all 2
108 with_test_prefix "record" {
109 gdb_test_no_output "record btrace"
110 gdb_cont_to_bp_line "$srcfile:$bp_2" all 2
113 # we don't need those breakpoints any longer.
114 # they will only disturb our stepping.
117 # show the threads - this is useful for debugging fails
118 gdb_test "thread apply all info rec" ".*"
119 gdb_test "info threads" ".*"
121 with_test_prefix "navigate" {
122 gdb_test "thread apply 1 record goto 3" "$loop_line"
123 gdb_test "thread apply 2 record goto 4" "$loop_line"
124 gdb_test "thread apply 1 info record" \
125 ".*Replay in progress\. At instruction 3\." "thread 1 at insn 3"
126 gdb_test "thread apply 2 info record" \
127 ".*Replay in progress\. At instruction 4\." "thread 2 at insn 4"
129 gdb_test "thread apply all record goto 5" "$loop_line"
130 gdb_test "thread apply 1 info record" \
131 ".*Replay in progress\. At instruction 5\." "thread 1 at insn 5"
132 gdb_test "thread apply 2 info record" \
133 ".*Replay in progress\. At instruction 5\." "thread 2 at insn 5"
136 with_test_prefix "step" {
137 with_test_prefix "thread 1" {
138 gdb_test "thread apply 1 stepi 2" "$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 5\."
145 with_test_prefix "thread 2" {
146 gdb_test "thread apply 2 stepi 3" "$loop_line"
147 gdb_test "thread apply 1 info record" \
148 ".*Replay in progress\. At instruction 7\."
149 gdb_test "thread apply 2 info record" \
150 ".*Replay in progress\. At instruction 8\."
153 with_test_prefix "all" {
154 gdb_cont_to all "stepi 4" "$loop_line" 2
155 gdb_test "thread apply 1 info record" \
156 ".*Replay in progress\. At instruction 11\."
157 gdb_test "thread apply 2 info record" \
158 ".*Replay in progress\. At instruction 12\."
162 with_test_prefix "reverse-step" {
163 with_test_prefix "thread 1" {
164 gdb_test "thread apply 1 reverse-stepi 2" "$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 12\."
171 with_test_prefix "thread 2" {
172 gdb_test "thread apply 2 reverse-stepi 3" "$loop_line"
173 gdb_test "thread apply 1 info record" \
174 ".*Replay in progress\. At instruction 9\."
175 gdb_test "thread apply 2 info record" \
176 ".*Replay in progress\. At instruction 9\."
179 with_test_prefix "all" {
180 gdb_cont_to all "reverse-stepi 4" "$loop_line" 2
181 gdb_test "thread apply 1 info record" \
182 ".*Replay in progress\. At instruction 5\."
183 gdb_test "thread apply 2 info record" \
184 ".*Replay in progress\. At instruction 5\."
188 with_test_prefix "continue" {
189 with_test_prefix "thread 1" {
190 with_test_prefix "continue" {
191 gdb_cont_to_no_history_forward 1 "continue" 1
192 gdb_test "thread apply 1 info record" \
193 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
194 gdb_test "thread apply 2 info record" \
195 ".*Replay in progress\. At instruction 5\."
197 with_test_prefix "reverse-continue" {
198 gdb_cont_to_no_history_backward 1 "reverse-continue" 1
199 gdb_test "thread apply 1 info record" \
200 ".*Replay in progress\. At instruction 1\."
201 gdb_test "thread apply 2 info record" \
202 ".*Replay in progress\. At instruction 5\."
206 with_test_prefix "thread 2" {
207 with_test_prefix "continue" {
208 gdb_cont_to_no_history_forward 2 "continue" 1
209 gdb_test "thread apply 1 info record" \
210 ".*Replay in progress\. At instruction 1\."
211 gdb_test "thread apply 2 info record" \
212 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
214 with_test_prefix "reverse-continue" {
215 gdb_cont_to_no_history_backward 2 "reverse-continue" 1
216 gdb_test "thread apply 1 info record" \
217 ".*Replay in progress\. At instruction 1\."
218 gdb_test "thread apply 2 info record" \
219 ".*Replay in progress\. At instruction 1\."
224 # a thread may only resume if no thread is still replaying
225 with_test_prefix "no progress" {
226 with_test_prefix "thread 1" {
227 gdb_test "thread apply 1 record goto end" ".*"
228 gdb_test "thread apply 2 record goto begin" ".*"
230 gdb_cont_to_no_history_forward 1 "continue" 1
231 gdb_cont_to_no_history_forward 1 "step" 1
232 gdb_test "thread apply 1 info record" \
233 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
234 gdb_test "thread apply 2 info record" \
235 ".*Replay in progress\. At instruction 1\."
238 with_test_prefix "thread 2" {
239 gdb_test "thread apply 1 record goto begin" ".*"
240 gdb_test "thread apply 2 record goto end" ".*"
242 gdb_cont_to_no_history_forward 2 "continue" 1
243 gdb_cont_to_no_history_forward 2 "step" 1
244 gdb_test "thread apply 1 info record" \
245 ".*Replay in progress\. At instruction 1\."
246 gdb_test "thread apply 2 info record" \
247 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
250 with_test_prefix "all" {
251 gdb_test "thread apply all record goto begin" ".*"
253 gdb_cont_to_no_history_forward all "continue" 2
254 gdb_test "thread apply 1 info record" \
255 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
256 gdb_test "thread apply 2 info record" \
257 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
261 # now that both threads stopped replaying we may resume recording
262 with_test_prefix "cont to end" {
264 gdb_cont_to_bp_line "$srcfile:$bp_3" all 1