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