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