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