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