1 # Copyright 1998, 2002, 2005 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Michael Snyder (msnyder@cygnus.com)
22 load_lib "trace-support.exp";
34 if [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" "" ""
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"
46 -re "MIS-MATCHED.*$gdb_prompt $" {
49 all tests in this module will fail.";
51 -re ".*$gdb_prompt $" { }
54 set testfile "actions"
55 set srcfile ${testfile}.c
56 set binfile $objdir/$subdir/$testfile
58 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
59 executable {debug nowarnings}] != "" } {
64 gdb_test "tstop" "" ""
65 gdb_test "tfind none" "" ""
68 gdb_reinitialize_dir $srcdir/$subdir
70 # We generously give ourselves one "pass" if we successfully
71 # detect that this test cannot be run on this target!
72 if { ![gdb_target_supports_trace] } then {
73 pass "Current target does not supporst trace"
78 # If testing on a remote host, download the source file.
79 # remote_download host $srcdir/$subdir/$srcfile
81 # define relative source line numbers:
82 # all subsequent line numbers are relative to this first one (baseline)
83 set baseline [gdb_find_recursion_test_baseline $srcfile];
84 if { $baseline == -1 } then {
85 fail "Could not find gdb_recursion_test function"
89 set testline1 [expr $baseline + 1]
90 set testline2 [expr $baseline + 5]
91 set testline3 [expr $baseline + 6]
92 set testline4 [expr $baseline + 7]
93 set testline5 [expr $baseline + 8]
99 gdb_delete_tracepoints
100 set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
101 set tdp2 [gdb_gettpnum $testline2]
102 set tdp3 [gdb_gettpnum $testline3]
103 set tdp4 [gdb_gettpnum $testline4]
104 set tdp5 [gdb_gettpnum $testline5]
105 if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
106 $tdp4 <= 0 || $tdp5 <= 0 } then {
107 fail "setting tracepoints"
111 # 6.1 test tstart command
114 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
115 fail "6.1: tstart (not connected to remote?)"
118 -re "Target does not support this command.*$gdb_prompt $" {
119 fail "6.1: tstart (connected to wrong target?)"
122 -re "Target returns error code.*$gdb_prompt $" {
123 fail "6.1: tstart (connected to wrong target?)"
126 -re "$gdb_prompt $" {
130 fail "6.1: tstart (default)"
135 # test tstatus (when trace on)
136 gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
138 # 6.2 test help tstart
139 gdb_test "help tstart" "Start trace data collection." "6.2: help tstart"
141 if [istarget "m68k-*-elf"] then {
142 gdb_emclaptop_command "85,1,2,3,4,5,6"
145 gdb_emclaptop_command "85,7,8,9,A,B,C"
148 gdb_test "break end" "" ""
149 gdb_test "continue" \
150 "Continuing.*Breakpoint $decimal, end.*" \
151 "run trace experiment"
154 # 7.1 test tstop command
157 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
158 fail "7.1: tstop (not connected to remote?)"
161 -re "Target does not support this command.*$gdb_prompt $" {
162 fail "7.1: tstop (connected to wrong target?)"
165 -re "Target returns error code.*$gdb_prompt $" {
166 fail "7.1: tstop (connected to wrong target?)"
169 -re "$gdb_prompt $" {
173 fail "7.1: tstop (default)"
178 # 7.2 test help tstop
179 gdb_test "help tstop" "Stop trace data collection." "7.2: help tstop"
181 # test tstatus (when trace off)
182 gdb_test "tstatus" "\[Tt\]race.* not running.*" "test tstatus off"
184 ## record starting PC
185 set save_pc [gdb_readexpr "(unsigned long) \$pc"];
186 if { $save_pc == -1 } then {
187 fail "could not read PC"
192 ## check $trace_frame == 0
193 gdb_tfind_test "8.7: tfind start command" "start" "0";
194 ## check $pc != startPC
195 gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
200 ## check $trace_frame == -1
201 gdb_tfind_test "8.8: tfind none" "none" "-1";
202 ## check $pc == startPC
203 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
205 "8.8b: tfind none (restores non-trace PC)"
208 ## check $trace_frame == -1
209 gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
210 ## check $pc == startPC
211 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
213 "8.9b: tfind end (restores non-tracing PC)"
216 ## check $trace_frame == n
217 gdb_tfind_test "8.1: tfind 1" "1" "1"
218 ## check $trace_line corresponds to tracepoint for frame n
219 gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
221 # 8.28 tfind invalid n (big number)
222 ## check "not found" error
223 ## check $trace_frame != n
224 gdb_test "tfind 32767" \
226 "8.28: tfind <n> command rejects invalid frame number"
228 gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
230 "8.28: tfind <n> rejected bad input (32767)"
232 # 8.31 tfind negative n
234 gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
235 ## check $trace_frame != -n
236 gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
237 "8.31: tfind <n> rejected negative input (-3)"
239 # 8.10 tfind <no arg>
240 ## check $trace_frame += 1
242 gdb_tfind_test "8.10: tfind start" "start" "0";
243 gdb_test "print \$trace_line" "$baseline" \
244 "8.10: tfind 0 (correct line $baseline)"
245 gdb_tfind_test "8.10: tfind noargument 1" "" "1";
246 gdb_test "print \$trace_line" "$testline2" \
247 "8.10: tfind 1 (correct line $testline2)"
248 gdb_tfind_test "8.10: tfind noargument 2" "" "2";
249 gdb_test "print \$trace_line" "$testline3" \
250 "8.10: tfind 2 (correct line $testline3)"
251 gdb_tfind_test "8.10: tfind noargument 3" "" "3";
252 gdb_test "print \$trace_line" "$testline4" \
253 "8.10: tfind 3 (correct line $testline4)"
255 gdb_tfind_test "8.11: tfind 3" "3" "3";
256 gdb_test "print \$trace_line" "$testline4" \
257 "8.11: tfind 3 (correct line $testline4)"
258 gdb_tfind_test "8.11: tfind backward 2" "-" "2";
259 gdb_test "print \$trace_line" "$testline3" \
260 "8.11: tfind 2 (correct line $testline3)"
261 gdb_tfind_test "8.11: tfind backward 1" "-" "1";
262 gdb_test "print \$trace_line" "$testline2" \
263 "8.11: tfind 1 (correct line $testline2)"
264 gdb_tfind_test "8.11: tfind backward 0" "-" "0";
265 gdb_test "print \$trace_line" "$baseline" \
266 "8.11: tfind 0 (correct line $baseline)"
268 gdb_tfind_test "8.12: tfind none" "none" "-1";
269 gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
270 "\$tracepoint" "$tdp2";
271 gdb_test "print \$trace_line" "$testline2" \
272 "8.12: tfind tracepoint <n> (line $testline2)"
274 gdb_tfind_test "8.25: tfind none" "none" "-1";
275 gdb_test "tfind tracepoint 0" "failed to find.*" \
276 "8.25: tfind tracepoint rejects zero"
277 gdb_test "tfind tracepoint 32767" "failed to find.*" \
278 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
279 gdb_test "tfind tracepoint -1" "failed to find.*" \
280 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
282 # 8.37 tfind tracepoint n where n no longer exists (but used to)
283 gdb_test "delete trace $tdp2" "" ""
284 gdb_tfind_test "8.37: tfind none" "none" "-1";
285 gdb_tfind_test "8.37: tfind deleted tracepoint" \
287 "\$tracepoint" "$tdp2";
288 gdb_test "print \$trace_line" "$testline2" \
289 "8.37: tfind deleted tracepoint (line $testline2)"
291 # 8.13 tfind tracepoint <no arg>
292 ## check $tracepoint same before and after, $trace_frame changed
294 gdb_tfind_test "8.13: tfind none" "none" "-1";
295 gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
296 "\$tracepoint" "$tdp1";
297 gdb_test "print \$trace_line" "$baseline" \
298 "8.13: tfind tracepoint $tdp1 (line $baseline)"
299 gdb_test "set \$save_frame = \$trace_frame" "" ""
300 gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
301 "\$tracepoint" "$tdp1";
302 gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
304 "8.13: tracepoint <no arg>, tracepoint number unchanged"
306 # 1.12 set tracepoint in prologue
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.
312 gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
314 "1.12: set tracepoint in prologue"
317 ## check pc == x, $trace_frame != -1
318 gdb_tfind_test "8.14: tfind 3" "3" "3"
319 gdb_test "print \$trace_line" "$testline4" \
320 "8.14: tfind 3 (line $testline4)"
322 gdb_test "set \$test_pc = \$pc" "" ""
323 gdb_tfind_test "8.14: tfind none" "none" "-1"
324 gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
325 gdb_test "print \$trace_line" "$testline4" \
326 "8.14: tfind pc x (line $testline4)"
327 gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
331 # 8.15 tfind pc <no arg>
332 ## check pc same before and after, $trace_frame changed
333 gdb_tfind_test "8.15: tfind 3" "3" "3"
334 gdb_test "print \$trace_line" "$testline4" \
335 "8.15: tfind 3 (line $testline4)"
336 gdb_test "set \$test_pc = \$pc" "" ""
337 gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
338 gdb_test "print \$trace_line" "$testline4" \
339 "8.15: tfind pc (line $testline4)"
340 gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
341 "8.15: trace frame didn't change"
343 # 8.26 tfind pc invalid x
344 ## check error, pc != x (trace_frame unchanged?)
345 gdb_tfind_test "8.26: tfind start" "start" "0"
346 gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
347 gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
350 ## check #trace_frame != -1, $trace_line == n
351 gdb_tfind_test "8.16: tfind none" "none" "-1"
352 gdb_tfind_test "8.16: tfind line $testline3" \
354 "\$trace_line == $testline3" "1"
356 # 8.17 tfind line <no arg> (# 8.19, 8.20)
357 ## check $trace_line changed, no error, pc changed, frame changed, tdp changed
358 gdb_tfind_test "8.17: tfind none" "none" "-1"
359 gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
360 gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
362 # 8.36 tfind and disassembly
363 gdb_tfind_test "8.36: tfind start" "start" "0"
365 send_gdb "disassemble gdb_c_test\n"
366 # look for disassembly of function label
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)" }
373 gdb_test "tfind line 0" \
374 "out of range.*|failed to find.*" \
375 "8.18: tfind line 0";
376 gdb_test "tfind line 32767" \
377 "out of range.*|failed to find.*" \
378 "8.27: tfind line 32767";
379 gdb_test "tfind line NoSuChFiLe.c:$baseline" \
380 "No source file named.*" \
381 "8.27: tfind line in bad source file";
383 # 8.32 tfind invalid subcommand (tfind foo)
385 gdb_test "tfind NoSuChOpTiOn 21" \
386 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
387 "8.32: tfind with bad subcommand"
389 # 8.38 test help tfind
390 gdb_test "help tfind" "Select a trace frame.*" \
392 gdb_test "help tfind pc" "Select a trace frame by PC.*" \
393 "8.38: help tfind PC"
394 gdb_test "help tfind end" "Synonym for 'none'.*" \
395 "8.38: help tfind end"
396 gdb_test "help tfind none" "De-select any trace frame.*" \
397 "8.38: help tfind none"
398 gdb_test "help tfind line" "Select a trace frame by source line.*" \
399 "8.38: help tfind line"
400 gdb_test "help tfind start" "Select the first trace frame.*" \
401 "8.38: help tfind start"
402 gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
403 "8.38: help tfind range"
404 gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
405 "8.38: help tfind tracepoint"
408 gdb_tfind_test "8.17: tfind none" "none" "-1"