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