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