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