* gdb.trace/tfind.exp: Adjust expected disassembly output.
[binutils-gdb.git] / gdb / testsuite / gdb.trace / tfind.exp
1 # Copyright 1998, 2002, 2005, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
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/>.
16
17 # This file was written by Michael Snyder (msnyder@cygnus.com)
18
19 load_lib "trace-support.exp";
20
21 if $tracelevel then {
22 strace $tracelevel
23 }
24
25 set prms_id 0
26 set bug_id 0
27
28 gdb_exit
29 gdb_start
30
31 set testfile "actions"
32 set srcfile ${testfile}.c
33 set binfile $objdir/$subdir/tfind
34
35 if { [gdb_compile "$srcdir/$subdir/$srcfile" "$binfile" \
36 executable {debug nowarnings}] != "" } {
37 untested tfind.exp
38 return -1
39 }
40 gdb_load $binfile
41 gdb_test "tstop" "" ""
42 gdb_test "tfind none" "" ""
43 runto_main
44 gdb_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!
48 if { ![gdb_target_supports_trace] } then {
49 pass "Current target does not support trace"
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)
59 set baseline [gdb_find_recursion_test_baseline $srcfile];
60 if { $baseline == -1 } then {
61 fail "Could not find gdb_recursion_test function"
62 return;
63 }
64
65 set testline1 [expr $baseline + 1]
66 set testline2 [expr $baseline + 5]
67 set testline3 [expr $baseline + 6]
68 set testline4 [expr $baseline + 7]
69 set testline5 [expr $baseline + 8]
70
71 #
72 # test tfind command
73 #
74
75 gdb_delete_tracepoints
76 set tdp1 [gdb_gettpnum "\*gdb_recursion_test"]
77 set tdp2 [gdb_gettpnum $testline2]
78 set tdp3 [gdb_gettpnum $testline3]
79 set tdp4 [gdb_gettpnum $testline4]
80 set tdp5 [gdb_gettpnum $testline5]
81 if { $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
88 send_gdb "tstart\n"
89 gdb_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)
112 gdb_test "tstatus" "\[Tt\]race is running.*" "test tstatus on"
113
114 # 6.2 test help tstart
115 gdb_test "help tstart" "Start trace data collection." "6.2: help tstart"
116
117 gdb_test "break end" "" ""
118 gdb_test "continue" \
119 "Continuing.*Breakpoint $decimal, end.*" \
120 "run trace experiment"
121
122 # 7.1 test tstop command
123 send_gdb "tstop\n"
124 gdb_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
147 gdb_test "help tstop" "Stop trace data collection." "7.2: help tstop"
148
149 # test tstatus (when trace off)
150 gdb_test "tstatus" "Trace stopped by a tstop command.*" \
151 "test tstatus off after tstop"
152
153 ## record starting PC
154 set save_pc [gdb_readexpr "(unsigned long) \$pc"];
155 if { $save_pc == -1 } then {
156 fail "could not read PC"
157 return;
158 }
159
160 # 8.7 tfind start
161 ## check $trace_frame == 0
162 gdb_tfind_test "8.7: tfind start command" "start" "0";
163 ## check $pc != startPC
164 gdb_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
170 gdb_tfind_test "8.8: tfind none" "none" "-1";
171 ## check $pc == startPC
172 gdb_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
178 gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
179 ## check $pc == startPC
180 gdb_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
186 gdb_tfind_test "8.1: tfind 1" "1" "1"
187 ## check $trace_line corresponds to tracepoint for frame n
188 gdb_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
193 gdb_test "tfind 32767" \
194 "failed to find.*" \
195 "8.28: tfind <n> command rejects invalid frame number"
196
197 gdb_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
203 gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
204 ## check $trace_frame != -n
205 gdb_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
211 gdb_tfind_test "8.10: tfind start" "start" "0";
212 gdb_test "print \$trace_line" "$baseline" \
213 "8.10: tfind 0 (correct line $baseline)"
214 gdb_tfind_test "8.10: tfind noargument 1" "" "1";
215 gdb_test "print \$trace_line" "$testline2" \
216 "8.10: tfind 1 (correct line $testline2)"
217 gdb_tfind_test "8.10: tfind noargument 2" "" "2";
218 gdb_test "print \$trace_line" "$testline3" \
219 "8.10: tfind 2 (correct line $testline3)"
220 gdb_tfind_test "8.10: tfind noargument 3" "" "3";
221 gdb_test "print \$trace_line" "$testline4" \
222 "8.10: tfind 3 (correct line $testline4)"
223
224 gdb_tfind_test "8.11: tfind 3" "3" "3";
225 gdb_test "print \$trace_line" "$testline4" \
226 "8.11: tfind 3 (correct line $testline4)"
227 gdb_tfind_test "8.11: tfind backward 2" "-" "2";
228 gdb_test "print \$trace_line" "$testline3" \
229 "8.11: tfind 2 (correct line $testline3)"
230 gdb_tfind_test "8.11: tfind backward 1" "-" "1";
231 gdb_test "print \$trace_line" "$testline2" \
232 "8.11: tfind 1 (correct line $testline2)"
233 gdb_tfind_test "8.11: tfind backward 0" "-" "0";
234 gdb_test "print \$trace_line" "$baseline" \
235 "8.11: tfind 0 (correct line $baseline)"
236
237 gdb_tfind_test "8.12: tfind none" "none" "-1";
238 gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
239 "\$tracepoint" "$tdp2";
240 gdb_test "print \$trace_line" "$testline2" \
241 "8.12: tfind tracepoint <n> (line $testline2)"
242
243 gdb_tfind_test "8.25: tfind none" "none" "-1";
244 gdb_test "tfind tracepoint 0" "failed to find.*" \
245 "8.25: tfind tracepoint rejects zero"
246 gdb_test "tfind tracepoint 32767" "failed to find.*" \
247 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
248 gdb_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)
252 gdb_test "delete trace $tdp2" "" ""
253 gdb_tfind_test "8.37: tfind none" "none" "-1";
254 gdb_tfind_test "8.37: tfind deleted tracepoint" \
255 "tracepoint $tdp2" \
256 "\$tracepoint" "$tdp2";
257 gdb_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
263 gdb_tfind_test "8.13: tfind none" "none" "-1";
264 gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
265 "\$tracepoint" "$tdp1";
266 gdb_test "print \$trace_line" "$baseline" \
267 "8.13: tfind tracepoint $tdp1 (line $baseline)"
268 gdb_test "set \$save_frame = \$trace_frame" "" ""
269 gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
270 "\$tracepoint" "$tdp1";
271 gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
272 "x 0 x" \
273 "8.13: tracepoint <no arg>, tracepoint number unchanged"
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
281 gdb_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
287 gdb_tfind_test "8.14: tfind 3" "3" "3"
288 gdb_test "print \$trace_line" "$testline4" \
289 "8.14: tfind 3 (line $testline4)"
290
291 gdb_test "set \$test_pc = \$pc" "" ""
292 gdb_tfind_test "8.14: tfind none" "none" "-1"
293 gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
294 gdb_test "print \$trace_line" "$testline4" \
295 "8.14: tfind pc x (line $testline4)"
296 gdb_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
302 gdb_tfind_test "8.15: tfind 3" "3" "3"
303 gdb_test "print \$trace_line" "$testline4" \
304 "8.15: tfind 3 (line $testline4)"
305 gdb_test "set \$test_pc = \$pc" "" ""
306 gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
307 gdb_test "print \$trace_line" "$testline4" \
308 "8.15: tfind pc (line $testline4)"
309 gdb_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?)
314 gdb_tfind_test "8.26: tfind start" "start" "0"
315 gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
316 gdb_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
320 gdb_tfind_test "8.16: tfind none" "none" "-1"
321 gdb_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
327 gdb_tfind_test "8.17: tfind none" "none" "-1"
328 gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
329 gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
330
331 # 8.36 tfind and disassembly
332 gdb_tfind_test "8.36: tfind start" "start" "0"
333 set timeout 60
334 send_gdb "disassemble gdb_c_test\n"
335 # look for disassembly of function label
336 gdb_expect {
337 -re "<(\.\[0-9\]+|)>:.*End of assembler dump.*$gdb_prompt $" { pass "8.36: trace disassembly" }
338 -re ".*$gdb_prompt $" { fail "8.36: trace disassembly" }
339 timeout { fail "8.36: trace disassembly (timeout)" }
340 }
341
342 gdb_test "tfind line 0" \
343 "out of range.*|failed to find.*" \
344 "8.18: tfind line 0";
345 gdb_test "tfind line 32767" \
346 "out of range.*|failed to find.*" \
347 "8.27: tfind line 32767";
348 gdb_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
354 gdb_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
359 gdb_test "help tfind" "Select a trace frame.*" \
360 "8.38: help tfind"
361 gdb_test "help tfind pc" "Select a trace frame by PC.*" \
362 "8.38: help tfind PC"
363 gdb_test "help tfind end" "Synonym for 'none'.*" \
364 "8.38: help tfind end"
365 gdb_test "help tfind none" "De-select any trace frame.*" \
366 "8.38: help tfind none"
367 gdb_test "help tfind line" "Select a trace frame by source line.*" \
368 "8.38: help tfind line"
369 gdb_test "help tfind start" "Select the first trace frame.*" \
370 "8.38: help tfind start"
371 gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
372 "8.38: help tfind range"
373 gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
374 "8.38: help tfind tracepoint"
375
376 # Finished!
377 gdb_tfind_test "8.17: tfind none" "none" "-1"