GDB copyright headers update after running GDB's copyright.py script.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.btrace / non-stop.exp
1 # This testcase is part of GDB, the GNU debugger.
2 #
3 # Copyright 2015-2016 Free Software Foundation, Inc.
4 #
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.
9 #
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.
14 #
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/>.
17
18 # check for btrace support
19 if { [skip_btrace_tests] } { return -1 }
20
21
22 # start inferior
23 standard_testfile
24 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" "$binfile" executable {debug}] != "" } {
25 return -1
26 }
27 clean_restart $testfile
28
29 gdb_test_no_output "set non-stop on"
30
31 if ![runto_main] {
32 return -1
33 }
34
35 # set up breakpoints
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]
39
40 gdb_breakpoint $bp_1
41 gdb_breakpoint $bp_2
42
43 # get the line number containing most of the trace
44 set loop [gdb_get_line_number "loop" $srcfile]
45
46 # a stop on the above line as reported by GDB
47 set loop_line "$loop\[^\\\r\\\n\]*/\\\* loop \\\*/"
48
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 } {
52 global gdb_prompt
53 set full_cmd "thread apply $threads $cmd"
54
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" {
58 -re "$gdb_prompt " {
59 pass "$full_cmd: prompt"
60 }
61 }
62
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"
66
67 gdb_test_multiple "" $test {
68 -re "$line\[^\\\r\\\n\]*\r\n" {
69 pass $test
70 }
71 }
72 }
73 }
74
75 proc gdb_cont_to_bp_line { line threads nthreads } {
76 gdb_cont_to $threads "continue" \
77 [multi_line \
78 "Breakpoint\[^\\\r\\\n\]*$line" \
79 "\[^\\\r\\\n\]*" \
80 ] \
81 $nthreads
82 }
83
84 proc gdb_cont_to_no_history { threads cmd nthreads } {
85 gdb_cont_to $threads $cmd \
86 [multi_line \
87 "No more reverse-execution history\." \
88 "\[^\\\r\\\n\]*" \
89 "\[^\\\r\\\n\]*" \
90 ] \
91 $nthreads
92 }
93
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
98
99 # we don't need those breakpoints any longer.
100 # they will only disturb our stepping.
101 delete_breakpoints
102
103 # show the threads - this is useful for debugging fails
104 gdb_test "thread apply all info rec" ".*"
105 gdb_test "info threads" ".*"
106
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\."
114
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\."
120 }
121
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\."
129 }
130
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\."
137 }
138
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\."
145 }
146 }
147
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\."
155 }
156
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\."
163 }
164
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\."
171 }
172 }
173
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\."
181
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\."
187 }
188
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\]*"
195
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\."
201 }
202 }
203
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" ".*"
209
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\."
216 }
217
218 with_test_prefix "thread 2" {
219 gdb_test "thread apply 1 record goto begin" ".*"
220 gdb_test "thread apply 2 record goto end" ".*"
221
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\]*"
228 }
229
230 with_test_prefix "all" {
231 gdb_test "thread apply all record goto begin" ".*"
232
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\]*"
238 }
239 }
240
241 # now that both threads stopped replaying we may resume recording
242 with_test_prefix "cont to end" {
243 gdb_breakpoint $bp_3
244 gdb_cont_to_bp_line "$srcfile:$bp_3" all 1
245 }
This page took 0.049578 seconds and 4 git commands to generate.