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