1 # Copyright 1998, 2002, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Michael Snyder (msnyder@cygnus.com)
19 load_lib "trace-support.exp";
29 set testfile "actions"
30 set srcfile ${testfile}.c
31 set binfile $objdir/$subdir/tfind
33 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
34 executable {debug nowarnings}] != "" } {
39 gdb_test "tstop" ".*" ""
40 gdb_test "tfind none" ".*" ""
42 gdb_reinitialize_dir $srcdir/$subdir
44 # We generously give ourselves one "pass" if we successfully
45 # detect that this test cannot be run on this target!
46 if { ![gdb_target_supports_trace] } then {
47 pass "Current target does not support trace"
52 # If testing on a remote host, download the source file.
53 # remote_download host $srcdir/$subdir/$srcfile
55 # define relative source line numbers:
56 # all subsequent line numbers are relative to this first one (baseline)
57 set baseline [gdb_find_recursion_test_baseline $srcfile];
58 if { $baseline == -1 } then {
59 fail "Could not find gdb_recursion_test function"
63 set testline1 [expr $baseline + 1]
64 set testline2 [expr $baseline + 5]
65 set testline3 [expr $baseline + 6]
66 set testline4 [expr $baseline + 7]
67 set testline5 [expr $baseline + 8]
73 gdb_delete_tracepoints
74 set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
75 set tdp2 [gdb_gettpnum $testline2]
76 set tdp3 [gdb_gettpnum $testline3]
77 set tdp4 [gdb_gettpnum $testline4]
78 set tdp5 [gdb_gettpnum $testline5]
79 if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
80 $tdp4 <= 0 || $tdp5 <= 0 } then {
81 fail "setting tracepoints"
85 # 6.1 test tstart command
88 gdb_test_multiple "tstart" "6.1: tstart" {
89 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
90 fail "6.1: tstart (not connected to remote?)"
92 -re "Target does not support this command.*$gdb_prompt $" {
93 fail "6.1: tstart (connected to wrong target?)"
95 -re "Target returns error code.*$gdb_prompt $" {
96 fail "6.1: tstart (connected to wrong target?)"
104 if { $return_me == 1 } then {
108 # test tstatus (when trace on)
109 gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
111 # 6.2 test help tstart
112 gdb_test "help tstart" "Start trace data collection." "6.2: help tstart"
114 gdb_test "break end" ".*" ""
115 gdb_test "continue" \
116 "Continuing.*Breakpoint $decimal, end.*" \
117 "run trace experiment"
119 # 7.1 test tstop command
122 gdb_test_multiple "tstop" "7.1: tstop" {
123 -re "Trace can only be run on remote targets.*$gdb_prompt $" {
124 fail "7.1: tstop (not connected to remote?)"
126 -re "Target does not support this command.*$gdb_prompt $" {
127 fail "7.1: tstop (connected to wrong target?)"
129 -re "Target returns error code.*$gdb_prompt $" {
130 fail "7.1: tstop (connected to wrong target?)"
132 -re "$gdb_prompt $" {
138 if { $return_me == 1 } then {
142 # 7.2 test help tstop
143 gdb_test "help tstop" "Stop trace data collection." "7.2: help tstop"
145 # test tstatus (when trace off)
146 gdb_test "tstatus" "Trace stopped by a tstop command.*" \
147 "test tstatus off after tstop"
149 ## record starting PC
150 set save_pc [gdb_readexpr "(unsigned long) \$pc"];
151 if { $save_pc == -1 } then {
152 fail "could not read PC"
157 ## check $trace_frame == 0
158 gdb_tfind_test "8.7: tfind start command" "start" "0";
159 ## check $pc != startPC
160 gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
165 ## check $trace_frame == -1
166 gdb_tfind_test "8.8: tfind none" "none" "-1";
167 ## check $pc == startPC
168 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
170 "8.8b: tfind none (restores non-trace PC)"
173 ## check $trace_frame == -1
174 gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
175 ## check $pc == startPC
176 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
178 "8.9b: tfind end (restores non-tracing PC)"
181 ## check $trace_frame == n
182 gdb_tfind_test "8.1: tfind 1" "1" "1"
183 ## check $trace_line corresponds to tracepoint for frame n
184 gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
186 # 8.28 tfind invalid n (big number)
187 ## check "not found" error
188 ## check $trace_frame != n
189 gdb_test "tfind 32767" \
191 "8.28: tfind <n> command rejects invalid frame number"
193 gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
195 "8.28: tfind <n> rejected bad input (32767)"
197 # 8.31 tfind negative n
199 gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
200 ## check $trace_frame != -n
201 gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
202 "8.31: tfind <n> rejected negative input (-3)"
204 # 8.10 tfind <no arg>
205 ## check $trace_frame += 1
207 gdb_tfind_test "8.10: tfind start" "start" "0";
208 gdb_test "print \$trace_line" "$baseline" \
209 "8.10: tfind 0 (correct line $baseline)"
210 gdb_tfind_test "8.10: tfind noargument 1" "" "1";
211 gdb_test "print \$trace_line" "$testline2" \
212 "8.10: tfind 1 (correct line $testline2)"
213 gdb_tfind_test "8.10: tfind noargument 2" "" "2";
214 gdb_test "print \$trace_line" "$testline3" \
215 "8.10: tfind 2 (correct line $testline3)"
216 gdb_tfind_test "8.10: tfind noargument 3" "" "3";
217 gdb_test "print \$trace_line" "$testline4" \
218 "8.10: tfind 3 (correct line $testline4)"
220 gdb_tfind_test "8.11: tfind 3" "3" "3";
221 gdb_test "print \$trace_line" "$testline4" \
222 "8.11: tfind 3 (correct line $testline4)"
223 gdb_tfind_test "8.11: tfind backward 2" "-" "2";
224 gdb_test "print \$trace_line" "$testline3" \
225 "8.11: tfind 2 (correct line $testline3)"
226 gdb_tfind_test "8.11: tfind backward 1" "-" "1";
227 gdb_test "print \$trace_line" "$testline2" \
228 "8.11: tfind 1 (correct line $testline2)"
229 gdb_tfind_test "8.11: tfind backward 0" "-" "0";
230 gdb_test "print \$trace_line" "$baseline" \
231 "8.11: tfind 0 (correct line $baseline)"
233 gdb_tfind_test "8.12: tfind none" "none" "-1";
234 gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
235 "\$tracepoint" "$tdp2";
236 gdb_test "print \$trace_line" "$testline2" \
237 "8.12: tfind tracepoint <n> (line $testline2)"
239 gdb_tfind_test "8.25: tfind none" "none" "-1";
240 gdb_test "tfind tracepoint 0" "failed to find.*" \
241 "8.25: tfind tracepoint rejects zero"
242 gdb_test "tfind tracepoint 32767" "failed to find.*" \
243 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
244 gdb_test "tfind tracepoint -1" "failed to find.*" \
245 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
247 # 8.37 tfind tracepoint n where n no longer exists (but used to)
248 gdb_test_no_output "delete trace $tdp2" ""
249 gdb_tfind_test "8.37: tfind none" "none" "-1";
250 gdb_tfind_test "8.37: tfind deleted tracepoint" \
252 "\$tracepoint" "$tdp2";
253 gdb_test "print \$trace_line" "$testline2" \
254 "8.37: tfind deleted tracepoint (line $testline2)"
256 # 8.13 tfind tracepoint <no arg>
257 ## check $tracepoint same before and after, $trace_frame changed
259 gdb_tfind_test "8.13: tfind none" "none" "-1";
260 gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
261 "\$tracepoint" "$tdp1";
262 gdb_test "print \$trace_line" "$baseline" \
263 "8.13: tfind tracepoint $tdp1 (line $baseline)"
264 gdb_test_no_output "set \$save_frame = \$trace_frame" ""
265 gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
266 "\$tracepoint" "$tdp1";
267 gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
269 "8.13: tracepoint <no arg>, tracepoint number unchanged"
271 # 1.12 set tracepoint in prologue
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.
277 gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
279 "1.12: set tracepoint in prologue"
282 ## check pc == x, $trace_frame != -1
283 gdb_tfind_test "8.14: tfind 3" "3" "3"
284 gdb_test "print \$trace_line" "$testline4" \
285 "8.14: tfind 3 (line $testline4)"
287 gdb_test_no_output "set \$test_pc = \$pc" ""
288 gdb_tfind_test "8.14: tfind none" "none" "-1"
289 gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
290 gdb_test "print \$trace_line" "$testline4" \
291 "8.14: tfind pc x (line $testline4)"
292 gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
296 # 8.15 tfind pc <no arg>
297 ## check pc same before and after, $trace_frame changed
298 gdb_tfind_test "8.15: tfind 3" "3" "3"
299 gdb_test "print \$trace_line" "$testline4" \
300 "8.15: tfind 3 (line $testline4)"
301 gdb_test_no_output "set \$test_pc = \$pc" ""
302 gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
303 gdb_test "print \$trace_line" "$testline4" \
304 "8.15: tfind pc (line $testline4)"
305 gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
306 "8.15: trace frame didn't change"
308 # 8.26 tfind pc invalid x
309 ## check error, pc != x (trace_frame unchanged?)
310 gdb_tfind_test "8.26: tfind start" "start" "0"
311 gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
312 gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
315 ## check #trace_frame != -1, $trace_line == n
316 gdb_tfind_test "8.16: tfind none" "none" "-1"
317 gdb_tfind_test "8.16: tfind line $testline3" \
319 "\$trace_line == $testline3" "1"
321 # 8.17 tfind line <no arg> (# 8.19, 8.20)
322 ## check $trace_line changed, no error, pc changed, frame changed, tdp changed
323 gdb_tfind_test "8.17: tfind none" "none" "-1"
324 gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
325 gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
327 # 8.36 tfind and disassembly
328 gdb_tfind_test "8.36: tfind start" "start" "0"
330 # look for disassembly of function label
331 gdb_test "disassemble gdb_c_test" \
332 "<(\.\[0-9\]+|)>:.*End of assembler dump.*" \
333 "8.36: trace disassembly"
335 gdb_test "tfind line 0" \
336 "out of range.*|failed to find.*" \
337 "8.18: tfind line 0";
338 gdb_test "tfind line 32767" \
339 "out of range.*|failed to find.*" \
340 "8.27: tfind line 32767";
341 gdb_test "tfind line NoSuChFiLe.c:$baseline" \
342 "No source file named.*" \
343 "8.27: tfind line in bad source file";
345 # 8.32 tfind invalid subcommand (tfind foo)
347 gdb_test "tfind NoSuChOpTiOn 21" \
348 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
349 "8.32: tfind with bad subcommand"
351 # 8.38 test help tfind
352 gdb_test "help tfind" "Select a trace frame.*" \
354 gdb_test "help tfind pc" "Select a trace frame by PC.*" \
355 "8.38: help tfind PC"
356 gdb_test "help tfind end" "Synonym for 'none'.*" \
357 "8.38: help tfind end"
358 gdb_test "help tfind none" "De-select any trace frame.*" \
359 "8.38: help tfind none"
360 gdb_test "help tfind line" "Select a trace frame by source line.*" \
361 "8.38: help tfind line"
362 gdb_test "help tfind start" "Select the first trace frame.*" \
363 "8.38: help tfind start"
364 gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
365 "8.38: help tfind range"
366 gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
367 "8.38: help tfind tracepoint"
370 gdb_tfind_test "8.17: tfind none" "none" "-1"