gdb: handle endbr64 instruction in amd64_analyze_prologue
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / tfind.exp
1 # Copyright 1998-2020 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Michael Snyder (msnyder@cygnus.com)
17
18 load_lib "trace-support.exp"
19
20
21 gdb_exit
22 gdb_start
23
24 standard_testfile actions.c
25
26 if ![gdb_trace_common_supports_arch] {
27 unsupported "no trace-common.h support for arch"
28 return -1
29 }
30
31 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
32 executable {debug nowarnings nopie}] != "" } {
33 untested "failed to compile"
34 return -1
35 }
36 gdb_load $binfile
37 gdb_test "tstop" ".*" ""
38 gdb_test "tfind none" ".*" ""
39
40 # 6.2 test help tstart
41 gdb_test "help tstart" \
42 "Start trace data collection\.\[\r\n\]+Usage: tstart \\\[NOTES\\\]\.\.\.\[\r\n\]+Any arguments supplied are recorded with the trace as a note and\[\r\n\]+reported by tstatus \\(if the target supports trace notes\\)\." \
43 "6.2: help tstart"
44 # 7.2 test help tstop
45 gdb_test "help tstop" \
46 "Stop trace data collection\.\[\r\n\]+Usage: tstop \\\[NOTES\\\]\.\.\.\[\r\n\]+Any arguments supplied are recorded with the trace as a stop reason and\[\r\n\]+reported by tstatus \\(if the target supports trace notes\\)\." \
47 "7.2: help tstop"
48
49 # 8.38 test help tfind
50 gdb_test "help tfind" "Select a trace frame.*" \
51 "8.38: help tfind"
52 gdb_test "help tfind pc" "Select a trace frame by PC.*" \
53 "8.38: help tfind PC"
54 gdb_test "help tfind end" "De-select any trace frame.*" \
55 "8.38: help tfind end"
56 gdb_test "help tfind none" "De-select any trace frame.*" \
57 "8.38: help tfind none"
58 gdb_test "help tfind line" "Select a trace frame by source line.*" \
59 "8.38: help tfind line"
60 gdb_test "help tfind start" "Select the first trace frame.*" \
61 "8.38: help tfind start"
62 gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
63 "8.38: help tfind range"
64 gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
65 "8.38: help tfind tracepoint"
66
67 runto_main
68 gdb_reinitialize_dir $srcdir/$subdir
69
70 if { ![gdb_target_supports_trace] } then {
71 unsupported "current target does not support trace"
72 return 1
73
74 }
75
76 # If testing on a remote host, download the source file.
77 # remote_download host $srcdir/$subdir/$srcfile
78
79 # define relative source line numbers:
80 # all subsequent line numbers are relative to this first one (baseline)
81 set baseline [gdb_find_recursion_test_baseline $srcfile]
82 if { $baseline == -1 } then {
83 fail "could not find gdb_recursion_test function"
84 return
85 }
86
87 set testline1 [expr $baseline + 1]
88 set testline2 [expr $baseline + 5]
89 set testline3 [expr $baseline + 6]
90 set testline4 [expr $baseline + 7]
91 set testline5 [expr $baseline + 8]
92
93 #
94 # test tfind command
95 #
96
97 gdb_delete_tracepoints
98 set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
99 set tdp2 [gdb_gettpnum $testline2]
100 set tdp3 [gdb_gettpnum $testline3]
101 set tdp4 [gdb_gettpnum $testline4]
102 set tdp5 [gdb_gettpnum $testline5]
103 if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
104 $tdp4 <= 0 || $tdp5 <= 0 } then {
105 fail "setting tracepoints"
106 return
107 }
108
109 # 6.1 test tstart command
110
111 set return_me 1
112 gdb_test_multiple "tstart" "6.1: tstart" {
113 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
114 fail "6.1: tstart (not connected to remote?)"
115 }
116 -re "Target does not support this command.*$gdb_prompt $" {
117 fail "6.1: tstart (connected to wrong target?)"
118 }
119 -re "Target returns error code.*$gdb_prompt $" {
120 fail "6.1: tstart (connected to wrong target?)"
121 }
122 -re "$gdb_prompt $" {
123 pass "6.1: tstart"
124 set return_me 0
125 }
126 }
127
128 if { $return_me == 1 } then {
129 return -1
130 }
131
132 # test tstatus (when trace on)
133 gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
134
135 gdb_breakpoint "end" qualified
136 gdb_test "continue" \
137 "Continuing.*Breakpoint $decimal, end.*" \
138 "run trace experiment"
139
140 # 7.1 test tstop command
141
142 set return_me 1
143 gdb_test_multiple "tstop" "7.1: tstop" {
144 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
145 fail "7.1: tstop (not connected to remote?)"
146 }
147 -re "Target does not support this command.*$gdb_prompt $" {
148 fail "7.1: tstop (connected to wrong target?)"
149 }
150 -re "Target returns error code.*$gdb_prompt $" {
151 fail "7.1: tstop (connected to wrong target?)"
152 }
153 -re "$gdb_prompt $" {
154 pass "7.1: tstop"
155 set return_me 0
156 }
157 }
158
159 if { $return_me == 1 } then {
160 return -1
161 }
162
163 # test tstatus (when trace off)
164 gdb_test "tstatus" "Trace stopped by a tstop command.*" \
165 "test tstatus off after tstop"
166
167 ## record starting PC
168 set save_pc [gdb_readexpr "(unsigned long) \$pc"]
169 if { $save_pc == -1 } then {
170 fail "could not read PC"
171 return
172 }
173
174 # 8.7 tfind start
175 ## check $trace_frame == 0
176 gdb_tfind_test "8.7: tfind start command" "start" "0"
177 ## check $pc != startPC
178 gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
179 "x 1 x" \
180 "8.7b: tfind start"
181
182 # 8.8 tfind none
183 ## check $trace_frame == -1
184 gdb_tfind_test "8.8: tfind none" "none" "-1"
185 ## check $pc == startPC
186 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
187 "x 1 x" \
188 "8.8b: tfind none (restores non-trace PC)"
189
190 # 8.9 tfind end
191 ## check $trace_frame == -1
192 gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1"
193 ## check $pc == startPC
194 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
195 "x 1 x" \
196 "8.9b: tfind end (restores non-tracing PC)"
197
198 # 8.1 tfind n
199 ## check $trace_frame == n
200 gdb_tfind_test "8.1: tfind 1" "1" "1"
201 ## check $trace_line corresponds to tracepoint for frame n
202 gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
203
204 # 8.28 tfind invalid n (big number)
205 ## check "not found" error
206 ## check $trace_frame != n
207 gdb_test "tfind 32767" \
208 "failed to find.*" \
209 "8.28: tfind <n> command rejects invalid frame number"
210
211 gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
212 "x 0 x" \
213 "8.28: tfind <n> rejected bad input (32767)"
214
215 # 8.31 tfind negative n
216 ## check error
217 gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
218 ## check $trace_frame != -n
219 gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
220 "8.31: tfind <n> rejected negative input (-3)"
221
222 # 8.10 tfind <no arg>
223 ## check $trace_frame += 1
224
225 gdb_tfind_test "8.10: tfind start" "start" "0"
226 gdb_test "print \$trace_line" "$baseline" \
227 "8.10: tfind 0 (correct line $baseline)"
228 gdb_tfind_test "8.10: tfind noargument 1" "" "1"
229 gdb_test "print \$trace_line" "$testline2" \
230 "8.10: tfind 1 (correct line $testline2)"
231 gdb_tfind_test "8.10: tfind noargument 2" "" "2"
232 gdb_test "print \$trace_line" "$testline3" \
233 "8.10: tfind 2 (correct line $testline3)"
234 gdb_tfind_test "8.10: tfind noargument 3" "" "3"
235 gdb_test "print \$trace_line" "$testline4" \
236 "8.10: tfind 3 (correct line $testline4)"
237
238 gdb_tfind_test "8.11: tfind 3" "3" "3"
239 gdb_test "print \$trace_line" "$testline4" \
240 "8.11: tfind 3 (correct line $testline4)"
241 gdb_tfind_test "8.11: tfind backward 2" "-" "2"
242 gdb_test "print \$trace_line" "$testline3" \
243 "8.11: tfind 2 (correct line $testline3)"
244 gdb_tfind_test "8.11: tfind backward 1" "-" "1"
245 gdb_test "print \$trace_line" "$testline2" \
246 "8.11: tfind 1 (correct line $testline2)"
247 gdb_tfind_test "8.11: tfind backward 0" "-" "0"
248 gdb_test "print \$trace_line" "$baseline" \
249 "8.11: tfind 0 (correct line $baseline)"
250
251 gdb_tfind_test "8.12: tfind none" "none" "-1"
252 gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
253 "\$tracepoint" "$tdp2"
254 gdb_test "print \$trace_line" "$testline2" \
255 "8.12: tfind tracepoint <n> (line $testline2)"
256
257 gdb_tfind_test "8.25: tfind none" "none" "-1"
258 gdb_test "tfind tracepoint 0" "failed to find.*" \
259 "8.25: tfind tracepoint rejects zero"
260 gdb_test "tfind tracepoint 32767" "failed to find.*" \
261 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
262 gdb_test "tfind tracepoint -1" "failed to find.*" \
263 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
264
265 # 8.37 tfind tracepoint n where n no longer exists (but used to)
266 gdb_test_no_output "delete trace $tdp2" ""
267 gdb_tfind_test "8.37: tfind none" "none" "-1"
268 gdb_tfind_test "8.37: tfind deleted tracepoint" \
269 "tracepoint $tdp2" \
270 "\$tracepoint" "$tdp2"
271 gdb_test "print \$trace_line" "$testline2" \
272 "8.37: tfind deleted tracepoint (line $testline2)"
273
274 # 8.13 tfind tracepoint <no arg>
275 ## check $tracepoint same before and after, $trace_frame changed
276
277 gdb_tfind_test "8.13: tfind none" "none" "-1"
278 gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
279 "\$tracepoint" "$tdp1"
280 gdb_test "print \$trace_line" "$baseline" \
281 "8.13: tfind tracepoint $tdp1 (line $baseline)"
282 gdb_test_no_output "set \$save_frame = \$trace_frame" ""
283 gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
284 "\$tracepoint" "$tdp1"
285 gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
286 "x 0 x" \
287 "8.13: tracepoint <no arg>, tracepoint number unchanged"
288
289 # 1.12 set tracepoint in prologue
290 #
291 # tdp1 was set at *gdb_recursion_test (ie. the hard address of the
292 # function, before the prologue). Test to see that it succeeded.
293 # Current pc should be equal to the address of the function.
294
295 gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
296 "x 1 x" \
297 "1.12: set tracepoint in prologue"
298
299 # 8.14 tfind pc x
300 ## check pc == x, $trace_frame != -1
301 gdb_tfind_test "8.14: tfind 3" "3" "3"
302 gdb_test "print \$trace_line" "$testline4" \
303 "8.14: tfind 3 (line $testline4)"
304
305 gdb_test_no_output "set \$test_pc = \$pc" ""
306 gdb_tfind_test "8.14: tfind none" "none" "-1"
307 gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1"
308 gdb_test "print \$trace_line" "$testline4" \
309 "8.14: tfind pc x (line $testline4)"
310 gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
311 "x 1 x" \
312 "8.14: tfind pc x"
313
314 # 8.15 tfind pc <no arg>
315 ## check pc same before and after, $trace_frame changed
316 gdb_tfind_test "8.15: tfind 3" "3" "3"
317 gdb_test "print \$trace_line" "$testline4" \
318 "8.15: tfind 3 (line $testline4)"
319 gdb_test_no_output "set \$test_pc = \$pc" ""
320 gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
321 gdb_test "print \$trace_line" "$testline4" \
322 "8.15: tfind pc (line $testline4)"
323 gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
324 "8.15: trace frame didn't change"
325
326 # 8.26 tfind pc invalid x
327 ## check error, pc != x (trace_frame unchanged?)
328 gdb_tfind_test "8.26: tfind start" "start" "0"
329 gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
330 gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
331
332 # 8.16 tfind line n
333 ## check #trace_frame != -1, $trace_line == n
334 gdb_tfind_test "8.16: tfind none" "none" "-1"
335 gdb_tfind_test "8.16: tfind line $testline3" \
336 "line $testline3" \
337 "\$trace_line == $testline3" "1"
338
339 # 8.17 tfind line <no arg> (# 8.19, 8.20)
340 ## check $trace_line changed, no error, pc changed, frame changed, tdp changed
341 gdb_tfind_test "8.17: tfind none" "none" "-1"
342 gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
343 gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
344
345 # 8.36 tfind and disassembly
346 gdb_tfind_test "8.36: tfind start" "start" "0"
347 set timeout 60
348 # look for disassembly of function label
349 gdb_test "disassemble gdb_c_test" \
350 "<(\.\[0-9\]+|)>:.*End of assembler dump.*" \
351 "8.36: trace disassembly"
352
353 gdb_test "tfind line 0" \
354 "out of range.*|failed to find.*|No line 0 in .*" \
355 "8.18: tfind line 0"
356 gdb_test "tfind line 32767" \
357 "out of range.*|failed to find.*|No line 32767 in .*" \
358 "8.27: tfind line 32767"
359 gdb_test "tfind line NoSuChFiLe.c:$baseline" \
360 "No source file named.*" \
361 "8.27: tfind line in bad source file"
362
363 # 8.32 tfind invalid subcommand (tfind foo)
364 ## check error
365 gdb_test "tfind NoSuChOpTiOn 21" \
366 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
367 "8.32: tfind with bad subcommand"
368
369 # Finished!
370 gdb_tfind_test "8.17: tfind none" "none" "-1"
This page took 0.037369 seconds and 4 git commands to generate.