Update copyright year range in all GDB files
[binutils-gdb.git] / gdb / testsuite / gdb.btrace / non-stop.exp
blob40cced7a8bb7f48ad2cae8cb4dee7543fbd2765d
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"
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     untested "failed to run to main"
36     return -1
39 # set up breakpoints
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]
44 gdb_breakpoint $bp_1
45 gdb_breakpoint $bp_2
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 } {
56     global gdb_prompt
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" {
62         -re "$gdb_prompt " {
63             pass $gdb_test_name
64         }
65     }
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" {
71                 pass $gdb_test_name
72             }
73         }
74     }
77 proc gdb_cont_to_bp_line { line threads nthreads } {
78     gdb_cont_to $threads "continue" \
79         [multi_line \
80              "Breakpoint\[^\\\r\\\n\]*$line" \
81              "\[^\\\r\\\n\]*" \
82             ] \
83         $nthreads
86 proc gdb_cont_to_no_history { threads cmd nthreads } {
87     gdb_cont_to $threads $cmd \
88         [multi_line \
89              "No more reverse-execution history\." \
90              "\[^\\\r\\\n\]*" \
91              "\[^\\\r\\\n\]*" \
92             ] \
93         $nthreads
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.
107 delete_breakpoints
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\."
135     }
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\."
143     }
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\."
151     }
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\."
161     }
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\."
169     }
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\."
177     }
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\."
188         }
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\."
195         }
196     }
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\]*"
205         }
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\."
212         }
213     }
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\."
228     }
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\]*"
240     }
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\]*"
250     }
253 # now that both threads stopped replaying we may resume recording
254 with_test_prefix "cont to end" {
255     gdb_breakpoint $bp_3
256     gdb_cont_to_bp_line "$srcfile:$bp_3" all 1