]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/tfind.exp
Update copyright year range in all GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / tfind.exp
CommitLineData
b811d2c2 1# Copyright 1998-2020 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Michael Snyder (msnyder@cygnus.com)
17
4ec70201 18load_lib "trace-support.exp"
c906108c 19
c906108c
SS
20
21gdb_exit
22gdb_start
23
497a5eb0 24standard_testfile actions.c
f8b7eaf3 25
8bca2978
SL
26if ![gdb_trace_common_supports_arch] {
27 unsupported "no trace-common.h support for arch"
28 return -1
29}
30
f8b7eaf3 31if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
ba22ff86 32 executable {debug nowarnings nopie}] != "" } {
84c93cd5 33 untested "failed to compile"
f8b7eaf3 34 return -1
c906108c 35}
f8b7eaf3 36gdb_load $binfile
de7ff789
MS
37gdb_test "tstop" ".*" ""
38gdb_test "tfind none" ".*" ""
15a7e7bc
YQ
39
40# 6.2 test help tstart
41gdb_test "help tstart" \
02d016b7 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\\)\." \
15a7e7bc
YQ
43 "6.2: help tstart"
44# 7.2 test help tstop
45gdb_test "help tstop" \
02d016b7 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\\)\." \
15a7e7bc
YQ
47 "7.2: help tstop"
48
49# 8.38 test help tfind
50gdb_test "help tfind" "Select a trace frame.*" \
51 "8.38: help tfind"
52gdb_test "help tfind pc" "Select a trace frame by PC.*" \
53 "8.38: help tfind PC"
54gdb_test "help tfind end" "De-select any trace frame.*" \
55 "8.38: help tfind end"
56gdb_test "help tfind none" "De-select any trace frame.*" \
57 "8.38: help tfind none"
58gdb_test "help tfind line" "Select a trace frame by source line.*" \
59 "8.38: help tfind line"
60gdb_test "help tfind start" "Select the first trace frame.*" \
61 "8.38: help tfind start"
62gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
63 "8.38: help tfind range"
64gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
65 "8.38: help tfind tracepoint"
66
f8b7eaf3 67runto_main
c906108c
SS
68gdb_reinitialize_dir $srcdir/$subdir
69
c906108c 70if { ![gdb_target_supports_trace] } then {
bc6c7af4 71 unsupported "current target does not support trace"
ae59b1da 72 return 1
c906108c
SS
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)
4ec70201 81set baseline [gdb_find_recursion_test_baseline $srcfile]
c906108c 82if { $baseline == -1 } then {
bc6c7af4 83 fail "could not find gdb_recursion_test function"
4ec70201 84 return
c906108c
SS
85}
86
87set testline1 [expr $baseline + 1]
88set testline2 [expr $baseline + 5]
89set testline3 [expr $baseline + 6]
90set testline4 [expr $baseline + 7]
91set testline5 [expr $baseline + 8]
92
93#
94# test tfind command
95#
96
97gdb_delete_tracepoints
98set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
99set tdp2 [gdb_gettpnum $testline2]
100set tdp3 [gdb_gettpnum $testline3]
101set tdp4 [gdb_gettpnum $testline4]
102set tdp5 [gdb_gettpnum $testline5]
103if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
104 $tdp4 <= 0 || $tdp5 <= 0 } then {
105 fail "setting tracepoints"
4ec70201 106 return
c906108c
SS
107}
108
109# 6.1 test tstart command
0ab48859
MS
110
111set return_me 1
112gdb_test_multiple "tstart" "6.1: tstart" {
c906108c
SS
113 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
114 fail "6.1: tstart (not connected to remote?)"
c906108c
SS
115 }
116 -re "Target does not support this command.*$gdb_prompt $" {
117 fail "6.1: tstart (connected to wrong target?)"
c906108c
SS
118 }
119 -re "Target returns error code.*$gdb_prompt $" {
120 fail "6.1: tstart (connected to wrong target?)"
c906108c
SS
121 }
122 -re "$gdb_prompt $" {
123 pass "6.1: tstart"
0ab48859 124 set return_me 0
c906108c
SS
125 }
126}
127
0ab48859 128if { $return_me == 1 } then {
ae59b1da 129 return -1
0ab48859
MS
130}
131
c906108c
SS
132# test tstatus (when trace on)
133gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
134
194ed413 135gdb_breakpoint "end" qualified
f8b7eaf3
DJ
136gdb_test "continue" \
137 "Continuing.*Breakpoint $decimal, end.*" \
138 "run trace experiment"
c906108c
SS
139
140# 7.1 test tstop command
0ab48859
MS
141
142set return_me 1
143gdb_test_multiple "tstop" "7.1: tstop" {
c906108c
SS
144 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
145 fail "7.1: tstop (not connected to remote?)"
c906108c
SS
146 }
147 -re "Target does not support this command.*$gdb_prompt $" {
148 fail "7.1: tstop (connected to wrong target?)"
c906108c
SS
149 }
150 -re "Target returns error code.*$gdb_prompt $" {
151 fail "7.1: tstop (connected to wrong target?)"
c906108c
SS
152 }
153 -re "$gdb_prompt $" {
154 pass "7.1: tstop"
0ab48859 155 set return_me 0
c906108c 156 }
0ab48859
MS
157}
158
159if { $return_me == 1 } then {
ae59b1da 160 return -1
c906108c
SS
161}
162
c906108c 163# test tstatus (when trace off)
6a8f2671
PA
164gdb_test "tstatus" "Trace stopped by a tstop command.*" \
165 "test tstatus off after tstop"
c906108c
SS
166
167## record starting PC
4ec70201 168set save_pc [gdb_readexpr "(unsigned long) \$pc"]
c906108c
SS
169if { $save_pc == -1 } then {
170 fail "could not read PC"
4ec70201 171 return
c906108c
SS
172}
173
174# 8.7 tfind start
175## check $trace_frame == 0
4ec70201 176gdb_tfind_test "8.7: tfind start command" "start" "0"
c906108c
SS
177## check $pc != startPC
178gdb_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
4ec70201 184gdb_tfind_test "8.8: tfind none" "none" "-1"
c906108c
SS
185## check $pc == startPC
186gdb_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
4ec70201 192gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1"
c906108c
SS
193## check $pc == startPC
194gdb_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
200gdb_tfind_test "8.1: tfind 1" "1" "1"
201## check $trace_line corresponds to tracepoint for frame n
202gdb_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
207gdb_test "tfind 32767" \
208 "failed to find.*" \
209 "8.28: tfind <n> command rejects invalid frame number"
210
211gdb_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
217gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
218## check $trace_frame != -n
219gdb_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
4ec70201 225gdb_tfind_test "8.10: tfind start" "start" "0"
c906108c
SS
226gdb_test "print \$trace_line" "$baseline" \
227 "8.10: tfind 0 (correct line $baseline)"
4ec70201 228gdb_tfind_test "8.10: tfind noargument 1" "" "1"
c906108c
SS
229gdb_test "print \$trace_line" "$testline2" \
230 "8.10: tfind 1 (correct line $testline2)"
4ec70201 231gdb_tfind_test "8.10: tfind noargument 2" "" "2"
c906108c
SS
232gdb_test "print \$trace_line" "$testline3" \
233 "8.10: tfind 2 (correct line $testline3)"
4ec70201 234gdb_tfind_test "8.10: tfind noargument 3" "" "3"
c906108c
SS
235gdb_test "print \$trace_line" "$testline4" \
236 "8.10: tfind 3 (correct line $testline4)"
237
4ec70201 238gdb_tfind_test "8.11: tfind 3" "3" "3"
c906108c
SS
239gdb_test "print \$trace_line" "$testline4" \
240 "8.11: tfind 3 (correct line $testline4)"
4ec70201 241gdb_tfind_test "8.11: tfind backward 2" "-" "2"
c906108c
SS
242gdb_test "print \$trace_line" "$testline3" \
243 "8.11: tfind 2 (correct line $testline3)"
4ec70201 244gdb_tfind_test "8.11: tfind backward 1" "-" "1"
c906108c
SS
245gdb_test "print \$trace_line" "$testline2" \
246 "8.11: tfind 1 (correct line $testline2)"
4ec70201 247gdb_tfind_test "8.11: tfind backward 0" "-" "0"
c906108c
SS
248gdb_test "print \$trace_line" "$baseline" \
249 "8.11: tfind 0 (correct line $baseline)"
250
4ec70201 251gdb_tfind_test "8.12: tfind none" "none" "-1"
c906108c 252gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
4ec70201 253 "\$tracepoint" "$tdp2"
c906108c
SS
254gdb_test "print \$trace_line" "$testline2" \
255 "8.12: tfind tracepoint <n> (line $testline2)"
256
4ec70201 257gdb_tfind_test "8.25: tfind none" "none" "-1"
c906108c
SS
258gdb_test "tfind tracepoint 0" "failed to find.*" \
259 "8.25: tfind tracepoint rejects zero"
260gdb_test "tfind tracepoint 32767" "failed to find.*" \
261 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
262gdb_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)
35ec993f 266gdb_test_no_output "delete trace $tdp2" ""
4ec70201 267gdb_tfind_test "8.37: tfind none" "none" "-1"
c906108c
SS
268gdb_tfind_test "8.37: tfind deleted tracepoint" \
269 "tracepoint $tdp2" \
4ec70201 270 "\$tracepoint" "$tdp2"
c906108c
SS
271gdb_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
4ec70201 277gdb_tfind_test "8.13: tfind none" "none" "-1"
c906108c 278gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
4ec70201 279 "\$tracepoint" "$tdp1"
c906108c
SS
280gdb_test "print \$trace_line" "$baseline" \
281 "8.13: tfind tracepoint $tdp1 (line $baseline)"
35ec993f 282gdb_test_no_output "set \$save_frame = \$trace_frame" ""
c906108c 283gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
4ec70201 284 "\$tracepoint" "$tdp1"
c906108c
SS
285gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
286 "x 0 x" \
5f579bc5 287 "8.13: tracepoint <no arg>, tracepoint number unchanged"
c906108c
SS
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
295gdb_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
301gdb_tfind_test "8.14: tfind 3" "3" "3"
302gdb_test "print \$trace_line" "$testline4" \
303 "8.14: tfind 3 (line $testline4)"
304
35ec993f 305gdb_test_no_output "set \$test_pc = \$pc" ""
c906108c 306gdb_tfind_test "8.14: tfind none" "none" "-1"
4ec70201 307gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1"
c906108c
SS
308gdb_test "print \$trace_line" "$testline4" \
309 "8.14: tfind pc x (line $testline4)"
310gdb_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
316gdb_tfind_test "8.15: tfind 3" "3" "3"
317gdb_test "print \$trace_line" "$testline4" \
318 "8.15: tfind 3 (line $testline4)"
35ec993f 319gdb_test_no_output "set \$test_pc = \$pc" ""
c906108c
SS
320gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
321gdb_test "print \$trace_line" "$testline4" \
322 "8.15: tfind pc (line $testline4)"
323gdb_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?)
328gdb_tfind_test "8.26: tfind start" "start" "0"
329gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
330gdb_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
334gdb_tfind_test "8.16: tfind none" "none" "-1"
335gdb_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
341gdb_tfind_test "8.17: tfind none" "none" "-1"
342gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
343gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
344
345# 8.36 tfind and disassembly
346gdb_tfind_test "8.36: tfind start" "start" "0"
347set timeout 60
c906108c 348# look for disassembly of function label
0ab48859
MS
349gdb_test "disassemble gdb_c_test" \
350 "<(\.\[0-9\]+|)>:.*End of assembler dump.*" \
351 "8.36: trace disassembly"
c906108c
SS
352
353gdb_test "tfind line 0" \
1cc310d2 354 "out of range.*|failed to find.*|No line 0 in .*" \
4ec70201 355 "8.18: tfind line 0"
c906108c 356gdb_test "tfind line 32767" \
1cc310d2 357 "out of range.*|failed to find.*|No line 32767 in .*" \
4ec70201 358 "8.27: tfind line 32767"
c906108c
SS
359gdb_test "tfind line NoSuChFiLe.c:$baseline" \
360 "No source file named.*" \
4ec70201 361 "8.27: tfind line in bad source file"
c906108c
SS
362
363# 8.32 tfind invalid subcommand (tfind foo)
364## check error
365gdb_test "tfind NoSuChOpTiOn 21" \
366 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
367 "8.32: tfind with bad subcommand"
368
c906108c
SS
369# Finished!
370gdb_tfind_test "8.17: tfind none" "none" "-1"