1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2015-2016 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 # check for btrace support
19 if { [skip_btrace_tests] } { return -1 }
24 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
27 clean_restart $testfile
29 gdb_test_no_output "set non-stop on"
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" {
59 pass "$full_cmd: prompt"
63 # now check for the expected line - one per thread.
64 for {set i 0} {$i < $nthreads} {incr i} {
65 set test "$full_cmd: thread $i"
67 gdb_test_multiple "" $test {
68 -re "$line\[^\\\r\\\n\]*\r\n" {
75 proc gdb_cont_to_bp_line { line threads nthreads } {
76 gdb_cont_to $threads "continue" \
78 "Breakpoint\[^\\\r\\\n\]*$line" \
84 proc gdb_cont_to_no_history { threads cmd nthreads } {
85 gdb_cont_to $threads $cmd \
87 "No more reverse-execution history\." \
94 # trace the code between the two breakpoints
95 gdb_cont_to_bp_line "$srcfile:$bp_1" all 2
96 gdb_test_no_output "record btrace"
97 gdb_cont_to_bp_line "$srcfile:$bp_2" all 2
99 # we don't need those breakpoints any longer.
100 # they will only disturb our stepping.
103 # show the threads - this is useful for debugging fails
104 gdb_test "thread apply all info rec" ".*"
105 gdb_test "info threads" ".*"
107 with_test_prefix "navigate" {
108 gdb_test "thread apply 1 record goto 2" "$loop_line"
109 gdb_test "thread apply 2 record goto 4" "$loop_line"
110 gdb_test "thread apply 1 info record" \
111 ".*Replay in progress\. At instruction 2\."
112 gdb_test "thread apply 2 info record" \
113 ".*Replay in progress\. At instruction 4\."
115 gdb_test "thread apply all record goto 5" "$loop_line"
116 gdb_test "thread apply 1 info record" \
117 ".*Replay in progress\. At instruction 5\."
118 gdb_test "thread apply 2 info record" \
119 ".*Replay in progress\. At instruction 5\."
122 with_test_prefix "step" {
123 with_test_prefix "thread 1" {
124 gdb_test "thread apply 1 stepi 2" "$loop_line"
125 gdb_test "thread apply 1 info record" \
126 ".*Replay in progress\. At instruction 7\."
127 gdb_test "thread apply 2 info record" \
128 ".*Replay in progress\. At instruction 5\."
131 with_test_prefix "thread 2" {
132 gdb_test "thread apply 2 stepi 3" "$loop_line"
133 gdb_test "thread apply 1 info record" \
134 ".*Replay in progress\. At instruction 7\."
135 gdb_test "thread apply 2 info record" \
136 ".*Replay in progress\. At instruction 8\."
139 with_test_prefix "all" {
140 gdb_cont_to all "stepi 4" "$loop_line" 2
141 gdb_test "thread apply 1 info record" \
142 ".*Replay in progress\. At instruction 11\."
143 gdb_test "thread apply 2 info record" \
144 ".*Replay in progress\. At instruction 12\."
148 with_test_prefix "reverse-step" {
149 with_test_prefix "thread 1" {
150 gdb_test "thread apply 1 reverse-stepi 2" "$loop_line"
151 gdb_test "thread apply 1 info record" \
152 ".*Replay in progress\. At instruction 9\."
153 gdb_test "thread apply 2 info record" \
154 ".*Replay in progress\. At instruction 12\."
157 with_test_prefix "thread 2" {
158 gdb_test "thread apply 2 reverse-stepi 3" "$loop_line"
159 gdb_test "thread apply 1 info record" \
160 ".*Replay in progress\. At instruction 9\."
161 gdb_test "thread apply 2 info record" \
162 ".*Replay in progress\. At instruction 9\."
165 with_test_prefix "all" {
166 gdb_cont_to all "reverse-stepi 4" "$loop_line" 2
167 gdb_test "thread apply 1 info record" \
168 ".*Replay in progress\. At instruction 5\."
169 gdb_test "thread apply 2 info record" \
170 ".*Replay in progress\. At instruction 5\."
174 with_test_prefix "continue" {
175 with_test_prefix "thread 1" {
176 gdb_cont_to_no_history 1 "continue" 1
177 gdb_test "thread apply 1 info record" \
178 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
179 gdb_test "thread apply 2 info record" \
180 ".*Replay in progress\. At instruction 5\."
182 gdb_cont_to_no_history 1 "reverse-continue" 1
183 gdb_test "thread apply 1 info record" \
184 ".*Replay in progress\. At instruction 1\."
185 gdb_test "thread apply 2 info record" \
186 ".*Replay in progress\. At instruction 5\."
189 with_test_prefix "thread 2" {
190 gdb_cont_to_no_history 2 "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 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
196 gdb_cont_to_no_history 2 "reverse-continue" 1
197 gdb_test "thread apply 1 info record" \
198 ".*Replay in progress\. At instruction 1\."
199 gdb_test "thread apply 2 info record" \
200 ".*Replay in progress\. At instruction 1\."
204 # a thread may only resume if no thread is still replaying
205 with_test_prefix "no progress" {
206 with_test_prefix "thread 1" {
207 gdb_test "thread apply 1 record goto end" ".*"
208 gdb_test "thread apply 2 record goto begin" ".*"
210 gdb_cont_to_no_history 1 "continue" 1
211 gdb_cont_to_no_history 1 "step" 1
212 gdb_test "thread apply 1 info record" \
213 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
214 gdb_test "thread apply 2 info record" \
215 ".*Replay in progress\. At instruction 1\."
218 with_test_prefix "thread 2" {
219 gdb_test "thread apply 1 record goto begin" ".*"
220 gdb_test "thread apply 2 record goto end" ".*"
222 gdb_cont_to_no_history 2 "continue" 1
223 gdb_cont_to_no_history 2 "step" 1
224 gdb_test "thread apply 1 info record" \
225 ".*Replay in progress\. At instruction 1\."
226 gdb_test "thread apply 2 info record" \
227 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
230 with_test_prefix "all" {
231 gdb_test "thread apply all record goto begin" ".*"
233 gdb_cont_to_no_history all "continue" 2
234 gdb_test "thread apply 1 info record" \
235 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
236 gdb_test "thread apply 2 info record" \
237 ".*Recorded \[0-9\]+ instructions \[^\\\r\\\n\]*"
241 # now that both threads stopped replaying we may resume recording
242 with_test_prefix "cont to end" {
244 gdb_cont_to_bp_line "$srcfile:$bp_3" all 1