]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/tfind.exp
Switch the license of all .exp files to GPLv3.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / tfind.exp
CommitLineData
6aba47ca 1# Copyright 1998, 2002, 2005, 2007 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
SS
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This file was written by Michael Snyder (msnyder@cygnus.com)
20
21load_lib "trace-support.exp";
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30gdb_exit
31gdb_start
32
33if [istarget "m68k-*-elf"] then {
34 load_lib "emc-support.exp";
35 set srcfile gdb_c_test.c
36 set binfile [board_info target d490_binfile];
37 gdb_test "set remotetimeout 6" "" ""
38 set timeout 500
39 gdb_target_monitor $binfile
40 # Give a TSTOP and ignore errors, to make sure any previous trace is off
41 gdb_test "tstop" "" ""
42 gdb_test "tfind none" "" ""
43 send_gdb "compare-sections CS\n"
44 gdb_expect {
45 -re "MIS-MATCHED.*$gdb_prompt $" {
b60f0898
JB
46 untested tfind.exp
47 return -1
c906108c
SS
48 all tests in this module will fail.";
49 }
50 -re ".*$gdb_prompt $" { }
51 }
52} else {
53 set testfile "actions"
54 set srcfile ${testfile}.c
55 set binfile $objdir/$subdir/$testfile
f0a847b8 56
f0a847b8 57 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
fc91c6c2 58 executable {debug nowarnings}] != "" } {
b60f0898
JB
59 untested tfind.exp
60 return -1
c906108c
SS
61 }
62 gdb_load $binfile
63 gdb_test "tstop" "" ""
64 gdb_test "tfind none" "" ""
65 runto_main
66}
67gdb_reinitialize_dir $srcdir/$subdir
68
69# We generously give ourselves one "pass" if we successfully
70# detect that this test cannot be run on this target!
71if { ![gdb_target_supports_trace] } then {
72 pass "Current target does not supporst trace"
73 return 1;
74
75}
76
77# If testing on a remote host, download the source file.
78# remote_download host $srcdir/$subdir/$srcfile
79
80# define relative source line numbers:
81# all subsequent line numbers are relative to this first one (baseline)
82set baseline [gdb_find_recursion_test_baseline $srcfile];
83if { $baseline == -1 } then {
84 fail "Could not find gdb_recursion_test function"
85 return;
86}
87
88set testline1 [expr $baseline + 1]
89set testline2 [expr $baseline + 5]
90set testline3 [expr $baseline + 6]
91set testline4 [expr $baseline + 7]
92set testline5 [expr $baseline + 8]
93
94#
95# test tfind command
96#
97
98gdb_delete_tracepoints
99set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
100set tdp2 [gdb_gettpnum $testline2]
101set tdp3 [gdb_gettpnum $testline3]
102set tdp4 [gdb_gettpnum $testline4]
103set tdp5 [gdb_gettpnum $testline5]
104if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
105 $tdp4 <= 0 || $tdp5 <= 0 } then {
106 fail "setting tracepoints"
107 return;
108}
109
110# 6.1 test tstart command
111send_gdb "tstart\n"
112gdb_expect {
113 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
114 fail "6.1: tstart (not connected to remote?)"
115 return;
116 }
117 -re "Target does not support this command.*$gdb_prompt $" {
118 fail "6.1: tstart (connected to wrong target?)"
119 return;
120 }
121 -re "Target returns error code.*$gdb_prompt $" {
122 fail "6.1: tstart (connected to wrong target?)"
123 return;
124 }
125 -re "$gdb_prompt $" {
126 pass "6.1: tstart"
127 }
128 default {
129 fail "6.1: tstart (default)"
130 return;
131 }
132}
133
134# test tstatus (when trace on)
135gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
136
137# 6.2 test help tstart
138gdb_test "help tstart" "Start trace data collection." "6.2: help tstart"
139
140if [istarget "m68k-*-elf"] then {
141 gdb_emclaptop_command "85,1,2,3,4,5,6"
142 sleep 5
143
144 gdb_emclaptop_command "85,7,8,9,A,B,C"
145 sleep 5
146} else {
147 gdb_test "break end" "" ""
148 gdb_test "continue" \
149 "Continuing.*Breakpoint $decimal, end.*" \
150 "run trace experiment"
151}
152
153# 7.1 test tstop command
154send_gdb "tstop\n"
155gdb_expect {
156 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
157 fail "7.1: tstop (not connected to remote?)"
158 return;
159 }
160 -re "Target does not support this command.*$gdb_prompt $" {
161 fail "7.1: tstop (connected to wrong target?)"
162 return;
163 }
164 -re "Target returns error code.*$gdb_prompt $" {
165 fail "7.1: tstop (connected to wrong target?)"
166 return;
167 }
168 -re "$gdb_prompt $" {
169 pass "7.1: tstop"
170 }
171 default {
172 fail "7.1: tstop (default)"
173 return;
174 }
175}
176
177# 7.2 test help tstop
178gdb_test "help tstop" "Stop trace data collection." "7.2: help tstop"
179
180# test tstatus (when trace off)
181gdb_test "tstatus" "\[Tt\]race.* not running.*" "test tstatus off"
182
183## record starting PC
184set save_pc [gdb_readexpr "(unsigned long) \$pc"];
185if { $save_pc == -1 } then {
186 fail "could not read PC"
187 return;
188}
189
190# 8.7 tfind start
191## check $trace_frame == 0
192gdb_tfind_test "8.7: tfind start command" "start" "0";
193## check $pc != startPC
194gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
195 "x 1 x" \
196 "8.7b: tfind start"
197
198# 8.8 tfind none
199## check $trace_frame == -1
200gdb_tfind_test "8.8: tfind none" "none" "-1";
201## check $pc == startPC
202gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
203 "x 1 x" \
204 "8.8b: tfind none (restores non-trace PC)"
205
206# 8.9 tfind end
207## check $trace_frame == -1
208gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
209## check $pc == startPC
210gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
211 "x 1 x" \
212 "8.9b: tfind end (restores non-tracing PC)"
213
214# 8.1 tfind n
215## check $trace_frame == n
216gdb_tfind_test "8.1: tfind 1" "1" "1"
217## check $trace_line corresponds to tracepoint for frame n
218gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
219
220# 8.28 tfind invalid n (big number)
221## check "not found" error
222## check $trace_frame != n
223gdb_test "tfind 32767" \
224 "failed to find.*" \
225 "8.28: tfind <n> command rejects invalid frame number"
226
227gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
228 "x 0 x" \
229 "8.28: tfind <n> rejected bad input (32767)"
230
231# 8.31 tfind negative n
232## check error
233gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
234## check $trace_frame != -n
235gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
236 "8.31: tfind <n> rejected negative input (-3)"
237
238# 8.10 tfind <no arg>
239## check $trace_frame += 1
240
241gdb_tfind_test "8.10: tfind start" "start" "0";
242gdb_test "print \$trace_line" "$baseline" \
243 "8.10: tfind 0 (correct line $baseline)"
244gdb_tfind_test "8.10: tfind noargument 1" "" "1";
245gdb_test "print \$trace_line" "$testline2" \
246 "8.10: tfind 1 (correct line $testline2)"
247gdb_tfind_test "8.10: tfind noargument 2" "" "2";
248gdb_test "print \$trace_line" "$testline3" \
249 "8.10: tfind 2 (correct line $testline3)"
250gdb_tfind_test "8.10: tfind noargument 3" "" "3";
251gdb_test "print \$trace_line" "$testline4" \
252 "8.10: tfind 3 (correct line $testline4)"
253
254gdb_tfind_test "8.11: tfind 3" "3" "3";
255gdb_test "print \$trace_line" "$testline4" \
256 "8.11: tfind 3 (correct line $testline4)"
257gdb_tfind_test "8.11: tfind backward 2" "-" "2";
258gdb_test "print \$trace_line" "$testline3" \
259 "8.11: tfind 2 (correct line $testline3)"
260gdb_tfind_test "8.11: tfind backward 1" "-" "1";
261gdb_test "print \$trace_line" "$testline2" \
262 "8.11: tfind 1 (correct line $testline2)"
263gdb_tfind_test "8.11: tfind backward 0" "-" "0";
264gdb_test "print \$trace_line" "$baseline" \
265 "8.11: tfind 0 (correct line $baseline)"
266
267gdb_tfind_test "8.12: tfind none" "none" "-1";
268gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
269 "\$tracepoint" "$tdp2";
270gdb_test "print \$trace_line" "$testline2" \
271 "8.12: tfind tracepoint <n> (line $testline2)"
272
273gdb_tfind_test "8.25: tfind none" "none" "-1";
274gdb_test "tfind tracepoint 0" "failed to find.*" \
275 "8.25: tfind tracepoint rejects zero"
276gdb_test "tfind tracepoint 32767" "failed to find.*" \
277 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
278gdb_test "tfind tracepoint -1" "failed to find.*" \
279 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
280
281# 8.37 tfind tracepoint n where n no longer exists (but used to)
282gdb_test "delete trace $tdp2" "" ""
283gdb_tfind_test "8.37: tfind none" "none" "-1";
284gdb_tfind_test "8.37: tfind deleted tracepoint" \
285 "tracepoint $tdp2" \
286 "\$tracepoint" "$tdp2";
287gdb_test "print \$trace_line" "$testline2" \
288 "8.37: tfind deleted tracepoint (line $testline2)"
289
290# 8.13 tfind tracepoint <no arg>
291## check $tracepoint same before and after, $trace_frame changed
292
293gdb_tfind_test "8.13: tfind none" "none" "-1";
294gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
295 "\$tracepoint" "$tdp1";
296gdb_test "print \$trace_line" "$baseline" \
297 "8.13: tfind tracepoint $tdp1 (line $baseline)"
298gdb_test "set \$save_frame = \$trace_frame" "" ""
299gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
300 "\$tracepoint" "$tdp1";
301gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
302 "x 0 x" \
5f579bc5 303 "8.13: tracepoint <no arg>, tracepoint number unchanged"
c906108c
SS
304
305# 1.12 set tracepoint in prologue
306#
307# tdp1 was set at *gdb_recursion_test (ie. the hard address of the
308# function, before the prologue). Test to see that it succeeded.
309# Current pc should be equal to the address of the function.
310
311gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
312 "x 1 x" \
313 "1.12: set tracepoint in prologue"
314
315# 8.14 tfind pc x
316## check pc == x, $trace_frame != -1
317gdb_tfind_test "8.14: tfind 3" "3" "3"
318gdb_test "print \$trace_line" "$testline4" \
319 "8.14: tfind 3 (line $testline4)"
320
321gdb_test "set \$test_pc = \$pc" "" ""
322gdb_tfind_test "8.14: tfind none" "none" "-1"
323gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
324gdb_test "print \$trace_line" "$testline4" \
325 "8.14: tfind pc x (line $testline4)"
326gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
327 "x 1 x" \
328 "8.14: tfind pc x"
329
330# 8.15 tfind pc <no arg>
331## check pc same before and after, $trace_frame changed
332gdb_tfind_test "8.15: tfind 3" "3" "3"
333gdb_test "print \$trace_line" "$testline4" \
334 "8.15: tfind 3 (line $testline4)"
335gdb_test "set \$test_pc = \$pc" "" ""
336gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
337gdb_test "print \$trace_line" "$testline4" \
338 "8.15: tfind pc (line $testline4)"
339gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
340 "8.15: trace frame didn't change"
341
342# 8.26 tfind pc invalid x
343## check error, pc != x (trace_frame unchanged?)
344gdb_tfind_test "8.26: tfind start" "start" "0"
345gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
346gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
347
348# 8.16 tfind line n
349## check #trace_frame != -1, $trace_line == n
350gdb_tfind_test "8.16: tfind none" "none" "-1"
351gdb_tfind_test "8.16: tfind line $testline3" \
352 "line $testline3" \
353 "\$trace_line == $testline3" "1"
354
355# 8.17 tfind line <no arg> (# 8.19, 8.20)
356## check $trace_line changed, no error, pc changed, frame changed, tdp changed
357gdb_tfind_test "8.17: tfind none" "none" "-1"
358gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
359gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
360
361# 8.36 tfind and disassembly
362gdb_tfind_test "8.36: tfind start" "start" "0"
363set timeout 60
364send_gdb "disassemble gdb_c_test\n"
365# look for disassembly of function label
366gdb_expect {
367 -re "<gdb_c_test>:.*$gdb_prompt $" { pass "8.36: trace disassembly" }
368 -re ".*$gdb_prompt $" { fail "8.36: trace disassembly" }
369 timeout { fail "8.36: trace disassembly (timeout)" }
370}
371
372gdb_test "tfind line 0" \
373 "out of range.*|failed to find.*" \
374 "8.18: tfind line 0";
375gdb_test "tfind line 32767" \
376 "out of range.*|failed to find.*" \
377 "8.27: tfind line 32767";
378gdb_test "tfind line NoSuChFiLe.c:$baseline" \
379 "No source file named.*" \
380 "8.27: tfind line in bad source file";
381
382# 8.32 tfind invalid subcommand (tfind foo)
383## check error
384gdb_test "tfind NoSuChOpTiOn 21" \
385 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
386 "8.32: tfind with bad subcommand"
387
388# 8.38 test help tfind
389gdb_test "help tfind" "Select a trace frame.*" \
390 "8.38: help tfind"
391gdb_test "help tfind pc" "Select a trace frame by PC.*" \
392 "8.38: help tfind PC"
393gdb_test "help tfind end" "Synonym for 'none'.*" \
394 "8.38: help tfind end"
395gdb_test "help tfind none" "De-select any trace frame.*" \
396 "8.38: help tfind none"
397gdb_test "help tfind line" "Select a trace frame by source line.*" \
398 "8.38: help tfind line"
399gdb_test "help tfind start" "Select the first trace frame.*" \
400 "8.38: help tfind start"
401gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
402 "8.38: help tfind range"
403gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
404 "8.38: help tfind tracepoint"
405
406# Finished!
407gdb_tfind_test "8.17: tfind none" "none" "-1"