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