1 # Copyright 1998, 2002, 2005, 2007, 2008 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Michael Snyder (msnyder@cygnus.com)
18 load_lib "trace-support.exp";
30 if [istarget "m68k-*-elf"] then {
31 load_lib "emc-support.exp";
32 set srcfile gdb_c_test.c
33 set binfile [board_info target d490_binfile];
34 gdb_test "set remotetimeout 6" "" ""
36 gdb_target_monitor $binfile
37 # Give a TSTOP and ignore errors, to make sure any previous trace is off
38 gdb_test "tstop" "" ""
39 gdb_test "tfind none" "" ""
40 send_gdb "compare-sections CS\n"
42 -re "MIS-MATCHED.*$gdb_prompt $" {
45 all tests in this module will fail.";
47 -re ".*$gdb_prompt $" { }
50 set testfile "actions"
51 set srcfile ${testfile}.c
52 set binfile $objdir/$subdir/$testfile
54 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
55 executable {debug nowarnings}] != "" } {
60 gdb_test "tstop" "" ""
61 gdb_test "tfind none" "" ""
64 gdb_reinitialize_dir $srcdir/$subdir
66 # We generously give ourselves one "pass" if we successfully
67 # detect that this test cannot be run on this target!
68 if { ![gdb_target_supports_trace] } then {
69 pass "Current target does not support trace"
74 # If testing on a remote host, download the source file.
75 # remote_download host $srcdir/$subdir/$srcfile
77 # define relative source line numbers:
78 # all subsequent line numbers are relative to this first one (baseline)
79 set baseline [gdb_find_recursion_test_baseline $srcfile];
80 if { $baseline == -1 } then {
81 fail "Could not find gdb_recursion_test function"
85 set testline1 [expr $baseline + 1]
86 set testline2 [expr $baseline + 5]
87 set testline3 [expr $baseline + 6]
88 set testline4 [expr $baseline + 7]
89 set testline5 [expr $baseline + 8]
95 gdb_delete_tracepoints
96 set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
97 set tdp2 [gdb_gettpnum $testline2]
98 set tdp3 [gdb_gettpnum $testline3]
99 set tdp4 [gdb_gettpnum $testline4]
100 set tdp5 [gdb_gettpnum $testline5]
101 if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
102 $tdp4 <= 0 || $tdp5 <= 0 } then {
103 fail "setting tracepoints"
107 # 6.1 test tstart command
110 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
111 fail "6.1: tstart (not connected to remote?)"
114 -re "Target does not support this command.*$gdb_prompt $" {
115 fail "6.1: tstart (connected to wrong target?)"
118 -re "Target returns error code.*$gdb_prompt $" {
119 fail "6.1: tstart (connected to wrong target?)"
122 -re "$gdb_prompt $" {
126 fail "6.1: tstart (default)"
131 # test tstatus (when trace on)
132 gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
134 # 6.2 test help tstart
135 gdb_test "help tstart" "Start trace data collection." "6.2: help tstart"
137 if [istarget "m68k-*-elf"] then {
138 gdb_emclaptop_command "85,1,2,3,4,5,6"
141 gdb_emclaptop_command "85,7,8,9,A,B,C"
144 gdb_test "break end" "" ""
145 gdb_test "continue" \
146 "Continuing.*Breakpoint $decimal, end.*" \
147 "run trace experiment"
150 # 7.1 test tstop command
153 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
154 fail "7.1: tstop (not connected to remote?)"
157 -re "Target does not support this command.*$gdb_prompt $" {
158 fail "7.1: tstop (connected to wrong target?)"
161 -re "Target returns error code.*$gdb_prompt $" {
162 fail "7.1: tstop (connected to wrong target?)"
165 -re "$gdb_prompt $" {
169 fail "7.1: tstop (default)"
174 # 7.2 test help tstop
175 gdb_test "help tstop" "Stop trace data collection." "7.2: help tstop"
177 # test tstatus (when trace off)
178 gdb_test "tstatus" "\[Tt\]race.* not running.*" "test tstatus off"
180 ## record starting PC
181 set save_pc [gdb_readexpr "(unsigned long) \$pc"];
182 if { $save_pc == -1 } then {
183 fail "could not read PC"
188 ## check $trace_frame == 0
189 gdb_tfind_test "8.7: tfind start command" "start" "0";
190 ## check $pc != startPC
191 gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
196 ## check $trace_frame == -1
197 gdb_tfind_test "8.8: tfind none" "none" "-1";
198 ## check $pc == startPC
199 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
201 "8.8b: tfind none (restores non-trace PC)"
204 ## check $trace_frame == -1
205 gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
206 ## check $pc == startPC
207 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
209 "8.9b: tfind end (restores non-tracing PC)"
212 ## check $trace_frame == n
213 gdb_tfind_test "8.1: tfind 1" "1" "1"
214 ## check $trace_line corresponds to tracepoint for frame n
215 gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
217 # 8.28 tfind invalid n (big number)
218 ## check "not found" error
219 ## check $trace_frame != n
220 gdb_test "tfind 32767" \
222 "8.28: tfind <n> command rejects invalid frame number"
224 gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
226 "8.28: tfind <n> rejected bad input (32767)"
228 # 8.31 tfind negative n
230 gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
231 ## check $trace_frame != -n
232 gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
233 "8.31: tfind <n> rejected negative input (-3)"
235 # 8.10 tfind <no arg>
236 ## check $trace_frame += 1
238 gdb_tfind_test "8.10: tfind start" "start" "0";
239 gdb_test "print \$trace_line" "$baseline" \
240 "8.10: tfind 0 (correct line $baseline)"
241 gdb_tfind_test "8.10: tfind noargument 1" "" "1";
242 gdb_test "print \$trace_line" "$testline2" \
243 "8.10: tfind 1 (correct line $testline2)"
244 gdb_tfind_test "8.10: tfind noargument 2" "" "2";
245 gdb_test "print \$trace_line" "$testline3" \
246 "8.10: tfind 2 (correct line $testline3)"
247 gdb_tfind_test "8.10: tfind noargument 3" "" "3";
248 gdb_test "print \$trace_line" "$testline4" \
249 "8.10: tfind 3 (correct line $testline4)"
251 gdb_tfind_test "8.11: tfind 3" "3" "3";
252 gdb_test "print \$trace_line" "$testline4" \
253 "8.11: tfind 3 (correct line $testline4)"
254 gdb_tfind_test "8.11: tfind backward 2" "-" "2";
255 gdb_test "print \$trace_line" "$testline3" \
256 "8.11: tfind 2 (correct line $testline3)"
257 gdb_tfind_test "8.11: tfind backward 1" "-" "1";
258 gdb_test "print \$trace_line" "$testline2" \
259 "8.11: tfind 1 (correct line $testline2)"
260 gdb_tfind_test "8.11: tfind backward 0" "-" "0";
261 gdb_test "print \$trace_line" "$baseline" \
262 "8.11: tfind 0 (correct line $baseline)"
264 gdb_tfind_test "8.12: tfind none" "none" "-1";
265 gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
266 "\$tracepoint" "$tdp2";
267 gdb_test "print \$trace_line" "$testline2" \
268 "8.12: tfind tracepoint <n> (line $testline2)"
270 gdb_tfind_test "8.25: tfind none" "none" "-1";
271 gdb_test "tfind tracepoint 0" "failed to find.*" \
272 "8.25: tfind tracepoint rejects zero"
273 gdb_test "tfind tracepoint 32767" "failed to find.*" \
274 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
275 gdb_test "tfind tracepoint -1" "failed to find.*" \
276 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
278 # 8.37 tfind tracepoint n where n no longer exists (but used to)
279 gdb_test "delete trace $tdp2" "" ""
280 gdb_tfind_test "8.37: tfind none" "none" "-1";
281 gdb_tfind_test "8.37: tfind deleted tracepoint" \
283 "\$tracepoint" "$tdp2";
284 gdb_test "print \$trace_line" "$testline2" \
285 "8.37: tfind deleted tracepoint (line $testline2)"
287 # 8.13 tfind tracepoint <no arg>
288 ## check $tracepoint same before and after, $trace_frame changed
290 gdb_tfind_test "8.13: tfind none" "none" "-1";
291 gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
292 "\$tracepoint" "$tdp1";
293 gdb_test "print \$trace_line" "$baseline" \
294 "8.13: tfind tracepoint $tdp1 (line $baseline)"
295 gdb_test "set \$save_frame = \$trace_frame" "" ""
296 gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
297 "\$tracepoint" "$tdp1";
298 gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
300 "8.13: tracepoint <no arg>, tracepoint number unchanged"
302 # 1.12 set tracepoint in prologue
304 # tdp1 was set at *gdb_recursion_test (ie. the hard address of the
305 # function, before the prologue). Test to see that it succeeded.
306 # Current pc should be equal to the address of the function.
308 gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
310 "1.12: set tracepoint in prologue"
313 ## check pc == x, $trace_frame != -1
314 gdb_tfind_test "8.14: tfind 3" "3" "3"
315 gdb_test "print \$trace_line" "$testline4" \
316 "8.14: tfind 3 (line $testline4)"
318 gdb_test "set \$test_pc = \$pc" "" ""
319 gdb_tfind_test "8.14: tfind none" "none" "-1"
320 gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
321 gdb_test "print \$trace_line" "$testline4" \
322 "8.14: tfind pc x (line $testline4)"
323 gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
327 # 8.15 tfind pc <no arg>
328 ## check pc same before and after, $trace_frame changed
329 gdb_tfind_test "8.15: tfind 3" "3" "3"
330 gdb_test "print \$trace_line" "$testline4" \
331 "8.15: tfind 3 (line $testline4)"
332 gdb_test "set \$test_pc = \$pc" "" ""
333 gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
334 gdb_test "print \$trace_line" "$testline4" \
335 "8.15: tfind pc (line $testline4)"
336 gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
337 "8.15: trace frame didn't change"
339 # 8.26 tfind pc invalid x
340 ## check error, pc != x (trace_frame unchanged?)
341 gdb_tfind_test "8.26: tfind start" "start" "0"
342 gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
343 gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
346 ## check #trace_frame != -1, $trace_line == n
347 gdb_tfind_test "8.16: tfind none" "none" "-1"
348 gdb_tfind_test "8.16: tfind line $testline3" \
350 "\$trace_line == $testline3" "1"
352 # 8.17 tfind line <no arg> (# 8.19, 8.20)
353 ## check $trace_line changed, no error, pc changed, frame changed, tdp changed
354 gdb_tfind_test "8.17: tfind none" "none" "-1"
355 gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
356 gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
358 # 8.36 tfind and disassembly
359 gdb_tfind_test "8.36: tfind start" "start" "0"
361 send_gdb "disassemble gdb_c_test\n"
362 # look for disassembly of function label
364 -re "<gdb_c_test>:.*$gdb_prompt $" { pass "8.36: trace disassembly" }
365 -re ".*$gdb_prompt $" { fail "8.36: trace disassembly" }
366 timeout { fail "8.36: trace disassembly (timeout)" }
369 gdb_test "tfind line 0" \
370 "out of range.*|failed to find.*" \
371 "8.18: tfind line 0";
372 gdb_test "tfind line 32767" \
373 "out of range.*|failed to find.*" \
374 "8.27: tfind line 32767";
375 gdb_test "tfind line NoSuChFiLe.c:$baseline" \
376 "No source file named.*" \
377 "8.27: tfind line in bad source file";
379 # 8.32 tfind invalid subcommand (tfind foo)
381 gdb_test "tfind NoSuChOpTiOn 21" \
382 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
383 "8.32: tfind with bad subcommand"
385 # 8.38 test help tfind
386 gdb_test "help tfind" "Select a trace frame.*" \
388 gdb_test "help tfind pc" "Select a trace frame by PC.*" \
389 "8.38: help tfind PC"
390 gdb_test "help tfind end" "Synonym for 'none'.*" \
391 "8.38: help tfind end"
392 gdb_test "help tfind none" "De-select any trace frame.*" \
393 "8.38: help tfind none"
394 gdb_test "help tfind line" "Select a trace frame by source line.*" \
395 "8.38: help tfind line"
396 gdb_test "help tfind start" "Select the first trace frame.*" \
397 "8.38: help tfind start"
398 gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
399 "8.38: help tfind range"
400 gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
401 "8.38: help tfind tracepoint"
404 gdb_tfind_test "8.17: tfind none" "none" "-1"