2010-06-08 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / tfind.exp
CommitLineData
4c38e0a4 1# Copyright 1998, 2002, 2005, 2007, 2008, 2009, 2010
0fb0cc75 2# Free Software Foundation, Inc.
c906108c
SS
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Michael Snyder (msnyder@cygnus.com)
18
19load_lib "trace-support.exp";
20
21if $tracelevel then {
22 strace $tracelevel
23}
24
c906108c
SS
25
26gdb_exit
27gdb_start
28
f8b7eaf3
DJ
29set testfile "actions"
30set srcfile ${testfile}.c
31set binfile $objdir/$subdir/tfind
32
33if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
34 executable {debug nowarnings}] != "" } {
35 untested tfind.exp
36 return -1
c906108c 37}
f8b7eaf3 38gdb_load $binfile
de7ff789
MS
39gdb_test "tstop" ".*" ""
40gdb_test "tfind none" ".*" ""
f8b7eaf3 41runto_main
c906108c
SS
42gdb_reinitialize_dir $srcdir/$subdir
43
44# We generously give ourselves one "pass" if we successfully
45# detect that this test cannot be run on this target!
46if { ![gdb_target_supports_trace] } then {
0ef2251b 47 pass "Current target does not support trace"
c906108c
SS
48 return 1;
49
50}
51
52# If testing on a remote host, download the source file.
53# remote_download host $srcdir/$subdir/$srcfile
54
55# define relative source line numbers:
56# all subsequent line numbers are relative to this first one (baseline)
57set baseline [gdb_find_recursion_test_baseline $srcfile];
58if { $baseline == -1 } then {
59 fail "Could not find gdb_recursion_test function"
60 return;
61}
62
63set testline1 [expr $baseline + 1]
64set testline2 [expr $baseline + 5]
65set testline3 [expr $baseline + 6]
66set testline4 [expr $baseline + 7]
67set testline5 [expr $baseline + 8]
68
69#
70# test tfind command
71#
72
73gdb_delete_tracepoints
74set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
75set tdp2 [gdb_gettpnum $testline2]
76set tdp3 [gdb_gettpnum $testline3]
77set tdp4 [gdb_gettpnum $testline4]
78set tdp5 [gdb_gettpnum $testline5]
79if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
80 $tdp4 <= 0 || $tdp5 <= 0 } then {
81 fail "setting tracepoints"
82 return;
83}
84
85# 6.1 test tstart command
0ab48859
MS
86
87set return_me 1
88gdb_test_multiple "tstart" "6.1: tstart" {
c906108c
SS
89 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
90 fail "6.1: tstart (not connected to remote?)"
c906108c
SS
91 }
92 -re "Target does not support this command.*$gdb_prompt $" {
93 fail "6.1: tstart (connected to wrong target?)"
c906108c
SS
94 }
95 -re "Target returns error code.*$gdb_prompt $" {
96 fail "6.1: tstart (connected to wrong target?)"
c906108c
SS
97 }
98 -re "$gdb_prompt $" {
99 pass "6.1: tstart"
0ab48859 100 set return_me 0
c906108c
SS
101 }
102}
103
0ab48859
MS
104if { $return_me == 1 } then {
105 return -1;
106}
107
c906108c
SS
108# test tstatus (when trace on)
109gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
110
111# 6.2 test help tstart
112gdb_test "help tstart" "Start trace data collection." "6.2: help tstart"
113
de7ff789 114gdb_test "break end" ".*" ""
f8b7eaf3
DJ
115gdb_test "continue" \
116 "Continuing.*Breakpoint $decimal, end.*" \
117 "run trace experiment"
c906108c
SS
118
119# 7.1 test tstop command
0ab48859
MS
120
121set return_me 1
122gdb_test_multiple "tstop" "7.1: tstop" {
c906108c
SS
123 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
124 fail "7.1: tstop (not connected to remote?)"
c906108c
SS
125 }
126 -re "Target does not support this command.*$gdb_prompt $" {
127 fail "7.1: tstop (connected to wrong target?)"
c906108c
SS
128 }
129 -re "Target returns error code.*$gdb_prompt $" {
130 fail "7.1: tstop (connected to wrong target?)"
c906108c
SS
131 }
132 -re "$gdb_prompt $" {
133 pass "7.1: tstop"
0ab48859 134 set return_me 0
c906108c 135 }
0ab48859
MS
136}
137
138if { $return_me == 1 } then {
139 return -1;
c906108c
SS
140}
141
142# 7.2 test help tstop
143gdb_test "help tstop" "Stop trace data collection." "7.2: help tstop"
144
145# test tstatus (when trace off)
6a8f2671
PA
146gdb_test "tstatus" "Trace stopped by a tstop command.*" \
147 "test tstatus off after tstop"
c906108c
SS
148
149## record starting PC
150set save_pc [gdb_readexpr "(unsigned long) \$pc"];
151if { $save_pc == -1 } then {
152 fail "could not read PC"
153 return;
154}
155
156# 8.7 tfind start
157## check $trace_frame == 0
158gdb_tfind_test "8.7: tfind start command" "start" "0";
159## check $pc != startPC
160gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
161 "x 1 x" \
162 "8.7b: tfind start"
163
164# 8.8 tfind none
165## check $trace_frame == -1
166gdb_tfind_test "8.8: tfind none" "none" "-1";
167## check $pc == startPC
168gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
169 "x 1 x" \
170 "8.8b: tfind none (restores non-trace PC)"
171
172# 8.9 tfind end
173## check $trace_frame == -1
174gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
175## check $pc == startPC
176gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
177 "x 1 x" \
178 "8.9b: tfind end (restores non-tracing PC)"
179
180# 8.1 tfind n
181## check $trace_frame == n
182gdb_tfind_test "8.1: tfind 1" "1" "1"
183## check $trace_line corresponds to tracepoint for frame n
184gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
185
186# 8.28 tfind invalid n (big number)
187## check "not found" error
188## check $trace_frame != n
189gdb_test "tfind 32767" \
190 "failed to find.*" \
191 "8.28: tfind <n> command rejects invalid frame number"
192
193gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
194 "x 0 x" \
195 "8.28: tfind <n> rejected bad input (32767)"
196
197# 8.31 tfind negative n
198## check error
199gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
200## check $trace_frame != -n
201gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
202 "8.31: tfind <n> rejected negative input (-3)"
203
204# 8.10 tfind <no arg>
205## check $trace_frame += 1
206
207gdb_tfind_test "8.10: tfind start" "start" "0";
208gdb_test "print \$trace_line" "$baseline" \
209 "8.10: tfind 0 (correct line $baseline)"
210gdb_tfind_test "8.10: tfind noargument 1" "" "1";
211gdb_test "print \$trace_line" "$testline2" \
212 "8.10: tfind 1 (correct line $testline2)"
213gdb_tfind_test "8.10: tfind noargument 2" "" "2";
214gdb_test "print \$trace_line" "$testline3" \
215 "8.10: tfind 2 (correct line $testline3)"
216gdb_tfind_test "8.10: tfind noargument 3" "" "3";
217gdb_test "print \$trace_line" "$testline4" \
218 "8.10: tfind 3 (correct line $testline4)"
219
220gdb_tfind_test "8.11: tfind 3" "3" "3";
221gdb_test "print \$trace_line" "$testline4" \
222 "8.11: tfind 3 (correct line $testline4)"
223gdb_tfind_test "8.11: tfind backward 2" "-" "2";
224gdb_test "print \$trace_line" "$testline3" \
225 "8.11: tfind 2 (correct line $testline3)"
226gdb_tfind_test "8.11: tfind backward 1" "-" "1";
227gdb_test "print \$trace_line" "$testline2" \
228 "8.11: tfind 1 (correct line $testline2)"
229gdb_tfind_test "8.11: tfind backward 0" "-" "0";
230gdb_test "print \$trace_line" "$baseline" \
231 "8.11: tfind 0 (correct line $baseline)"
232
233gdb_tfind_test "8.12: tfind none" "none" "-1";
234gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
235 "\$tracepoint" "$tdp2";
236gdb_test "print \$trace_line" "$testline2" \
237 "8.12: tfind tracepoint <n> (line $testline2)"
238
239gdb_tfind_test "8.25: tfind none" "none" "-1";
240gdb_test "tfind tracepoint 0" "failed to find.*" \
241 "8.25: tfind tracepoint rejects zero"
242gdb_test "tfind tracepoint 32767" "failed to find.*" \
243 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
244gdb_test "tfind tracepoint -1" "failed to find.*" \
245 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
246
247# 8.37 tfind tracepoint n where n no longer exists (but used to)
35ec993f 248gdb_test_no_output "delete trace $tdp2" ""
c906108c
SS
249gdb_tfind_test "8.37: tfind none" "none" "-1";
250gdb_tfind_test "8.37: tfind deleted tracepoint" \
251 "tracepoint $tdp2" \
252 "\$tracepoint" "$tdp2";
253gdb_test "print \$trace_line" "$testline2" \
254 "8.37: tfind deleted tracepoint (line $testline2)"
255
256# 8.13 tfind tracepoint <no arg>
257## check $tracepoint same before and after, $trace_frame changed
258
259gdb_tfind_test "8.13: tfind none" "none" "-1";
260gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
261 "\$tracepoint" "$tdp1";
262gdb_test "print \$trace_line" "$baseline" \
263 "8.13: tfind tracepoint $tdp1 (line $baseline)"
35ec993f 264gdb_test_no_output "set \$save_frame = \$trace_frame" ""
c906108c
SS
265gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
266 "\$tracepoint" "$tdp1";
267gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
268 "x 0 x" \
5f579bc5 269 "8.13: tracepoint <no arg>, tracepoint number unchanged"
c906108c
SS
270
271# 1.12 set tracepoint in prologue
272#
273# tdp1 was set at *gdb_recursion_test (ie. the hard address of the
274# function, before the prologue). Test to see that it succeeded.
275# Current pc should be equal to the address of the function.
276
277gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
278 "x 1 x" \
279 "1.12: set tracepoint in prologue"
280
281# 8.14 tfind pc x
282## check pc == x, $trace_frame != -1
283gdb_tfind_test "8.14: tfind 3" "3" "3"
284gdb_test "print \$trace_line" "$testline4" \
285 "8.14: tfind 3 (line $testline4)"
286
35ec993f 287gdb_test_no_output "set \$test_pc = \$pc" ""
c906108c
SS
288gdb_tfind_test "8.14: tfind none" "none" "-1"
289gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
290gdb_test "print \$trace_line" "$testline4" \
291 "8.14: tfind pc x (line $testline4)"
292gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
293 "x 1 x" \
294 "8.14: tfind pc x"
295
296# 8.15 tfind pc <no arg>
297## check pc same before and after, $trace_frame changed
298gdb_tfind_test "8.15: tfind 3" "3" "3"
299gdb_test "print \$trace_line" "$testline4" \
300 "8.15: tfind 3 (line $testline4)"
35ec993f 301gdb_test_no_output "set \$test_pc = \$pc" ""
c906108c
SS
302gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
303gdb_test "print \$trace_line" "$testline4" \
304 "8.15: tfind pc (line $testline4)"
305gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
306 "8.15: trace frame didn't change"
307
308# 8.26 tfind pc invalid x
309## check error, pc != x (trace_frame unchanged?)
310gdb_tfind_test "8.26: tfind start" "start" "0"
311gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
312gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
313
314# 8.16 tfind line n
315## check #trace_frame != -1, $trace_line == n
316gdb_tfind_test "8.16: tfind none" "none" "-1"
317gdb_tfind_test "8.16: tfind line $testline3" \
318 "line $testline3" \
319 "\$trace_line == $testline3" "1"
320
321# 8.17 tfind line <no arg> (# 8.19, 8.20)
322## check $trace_line changed, no error, pc changed, frame changed, tdp changed
323gdb_tfind_test "8.17: tfind none" "none" "-1"
324gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
325gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
326
327# 8.36 tfind and disassembly
328gdb_tfind_test "8.36: tfind start" "start" "0"
329set timeout 60
c906108c 330# look for disassembly of function label
0ab48859
MS
331gdb_test "disassemble gdb_c_test" \
332 "<(\.\[0-9\]+|)>:.*End of assembler dump.*" \
333 "8.36: trace disassembly"
c906108c
SS
334
335gdb_test "tfind line 0" \
336 "out of range.*|failed to find.*" \
337 "8.18: tfind line 0";
338gdb_test "tfind line 32767" \
339 "out of range.*|failed to find.*" \
340 "8.27: tfind line 32767";
341gdb_test "tfind line NoSuChFiLe.c:$baseline" \
342 "No source file named.*" \
343 "8.27: tfind line in bad source file";
344
345# 8.32 tfind invalid subcommand (tfind foo)
346## check error
347gdb_test "tfind NoSuChOpTiOn 21" \
348 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
349 "8.32: tfind with bad subcommand"
350
351# 8.38 test help tfind
352gdb_test "help tfind" "Select a trace frame.*" \
353 "8.38: help tfind"
354gdb_test "help tfind pc" "Select a trace frame by PC.*" \
355 "8.38: help tfind PC"
356gdb_test "help tfind end" "Synonym for 'none'.*" \
357 "8.38: help tfind end"
358gdb_test "help tfind none" "De-select any trace frame.*" \
359 "8.38: help tfind none"
360gdb_test "help tfind line" "Select a trace frame by source line.*" \
361 "8.38: help tfind line"
362gdb_test "help tfind start" "Select the first trace frame.*" \
363 "8.38: help tfind start"
364gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
365 "8.38: help tfind range"
366gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
367 "8.38: help tfind tracepoint"
368
369# Finished!
370gdb_tfind_test "8.17: tfind none" "none" "-1"
This page took 2.736635 seconds and 4 git commands to generate.