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