]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/tfind.exp
* config/m68k-emc.exp, lib/emc-support.exp,
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / tfind.exp
1 # Copyright 1998, 2002, 2005, 2007, 2008, 2009
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" "\[Tt\]race.* not running.*" "test tstatus off"
151
152 ## record starting PC
153 set save_pc [gdb_readexpr "(unsigned long) \$pc"];
154 if { $save_pc == -1 } then {
155 fail "could not read PC"
156 return;
157 }
158
159 # 8.7 tfind start
160 ## check $trace_frame == 0
161 gdb_tfind_test "8.7: tfind start command" "start" "0";
162 ## check $pc != startPC
163 gdb_test "printf \"x \%d x\\n\", \$pc != $save_pc" \
164 "x 1 x" \
165 "8.7b: tfind start"
166
167 # 8.8 tfind none
168 ## check $trace_frame == -1
169 gdb_tfind_test "8.8: tfind none" "none" "-1";
170 ## check $pc == startPC
171 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
172 "x 1 x" \
173 "8.8b: tfind none (restores non-trace PC)"
174
175 # 8.9 tfind end
176 ## check $trace_frame == -1
177 gdb_tfind_test "8.9: tfind end, selects no frame" "end" "-1";
178 ## check $pc == startPC
179 gdb_test "printf \"x \%d x\\n\", \$pc == $save_pc" \
180 "x 1 x" \
181 "8.9b: tfind end (restores non-tracing PC)"
182
183 # 8.1 tfind n
184 ## check $trace_frame == n
185 gdb_tfind_test "8.1: tfind 1" "1" "1"
186 ## check $trace_line corresponds to tracepoint for frame n
187 gdb_test "print \$trace_line" "$testline2" "8.1b: tfind 1 (correct line)"
188
189 # 8.28 tfind invalid n (big number)
190 ## check "not found" error
191 ## check $trace_frame != n
192 gdb_test "tfind 32767" \
193 "failed to find.*" \
194 "8.28: tfind <n> command rejects invalid frame number"
195
196 gdb_test "printf \"x \%d x\\n\", \$trace_frame == 32767" \
197 "x 0 x" \
198 "8.28: tfind <n> rejected bad input (32767)"
199
200 # 8.31 tfind negative n
201 ## check error
202 gdb_test "tfind -3" "invalid input.*" "8.31: tfind <n> rejects negative input"
203 ## check $trace_frame != -n
204 gdb_test "printf \"x \%d x\\n\", \$trace_frame == -3" "x 0 x" \
205 "8.31: tfind <n> rejected negative input (-3)"
206
207 # 8.10 tfind <no arg>
208 ## check $trace_frame += 1
209
210 gdb_tfind_test "8.10: tfind start" "start" "0";
211 gdb_test "print \$trace_line" "$baseline" \
212 "8.10: tfind 0 (correct line $baseline)"
213 gdb_tfind_test "8.10: tfind noargument 1" "" "1";
214 gdb_test "print \$trace_line" "$testline2" \
215 "8.10: tfind 1 (correct line $testline2)"
216 gdb_tfind_test "8.10: tfind noargument 2" "" "2";
217 gdb_test "print \$trace_line" "$testline3" \
218 "8.10: tfind 2 (correct line $testline3)"
219 gdb_tfind_test "8.10: tfind noargument 3" "" "3";
220 gdb_test "print \$trace_line" "$testline4" \
221 "8.10: tfind 3 (correct line $testline4)"
222
223 gdb_tfind_test "8.11: tfind 3" "3" "3";
224 gdb_test "print \$trace_line" "$testline4" \
225 "8.11: tfind 3 (correct line $testline4)"
226 gdb_tfind_test "8.11: tfind backward 2" "-" "2";
227 gdb_test "print \$trace_line" "$testline3" \
228 "8.11: tfind 2 (correct line $testline3)"
229 gdb_tfind_test "8.11: tfind backward 1" "-" "1";
230 gdb_test "print \$trace_line" "$testline2" \
231 "8.11: tfind 1 (correct line $testline2)"
232 gdb_tfind_test "8.11: tfind backward 0" "-" "0";
233 gdb_test "print \$trace_line" "$baseline" \
234 "8.11: tfind 0 (correct line $baseline)"
235
236 gdb_tfind_test "8.12: tfind none" "none" "-1";
237 gdb_tfind_test "8.12: tfind tracepoint <n>" "tracepoint $tdp2" \
238 "\$tracepoint" "$tdp2";
239 gdb_test "print \$trace_line" "$testline2" \
240 "8.12: tfind tracepoint <n> (line $testline2)"
241
242 gdb_tfind_test "8.25: tfind none" "none" "-1";
243 gdb_test "tfind tracepoint 0" "failed to find.*" \
244 "8.25: tfind tracepoint rejects zero"
245 gdb_test "tfind tracepoint 32767" "failed to find.*" \
246 "8.25: tfind tracepoint rejects nonexistant tracepoint (32767)"
247 gdb_test "tfind tracepoint -1" "failed to find.*" \
248 "8.25: tfind tracepoint rejects nonexistant tracepoint (-1)"
249
250 # 8.37 tfind tracepoint n where n no longer exists (but used to)
251 gdb_test "delete trace $tdp2" "" ""
252 gdb_tfind_test "8.37: tfind none" "none" "-1";
253 gdb_tfind_test "8.37: tfind deleted tracepoint" \
254 "tracepoint $tdp2" \
255 "\$tracepoint" "$tdp2";
256 gdb_test "print \$trace_line" "$testline2" \
257 "8.37: tfind deleted tracepoint (line $testline2)"
258
259 # 8.13 tfind tracepoint <no arg>
260 ## check $tracepoint same before and after, $trace_frame changed
261
262 gdb_tfind_test "8.13: tfind none" "none" "-1";
263 gdb_tfind_test "8.13: tracepoint $tdp1" "tracepoint $tdp1" \
264 "\$tracepoint" "$tdp1";
265 gdb_test "print \$trace_line" "$baseline" \
266 "8.13: tfind tracepoint $tdp1 (line $baseline)"
267 gdb_test "set \$save_frame = \$trace_frame" "" ""
268 gdb_tfind_test "8.13: tracepoint <no arg>" "tracepoint" \
269 "\$tracepoint" "$tdp1";
270 gdb_test "printf \"x \%d x\\n\", \$trace_frame == \$save_frame" \
271 "x 0 x" \
272 "8.13: tracepoint <no arg>, tracepoint number unchanged"
273
274 # 1.12 set tracepoint in prologue
275 #
276 # tdp1 was set at *gdb_recursion_test (ie. the hard address of the
277 # function, before the prologue). Test to see that it succeeded.
278 # Current pc should be equal to the address of the function.
279
280 gdb_test "printf \"x \%d x\\n\", \$pc == gdb_recursion_test" \
281 "x 1 x" \
282 "1.12: set tracepoint in prologue"
283
284 # 8.14 tfind pc x
285 ## check pc == x, $trace_frame != -1
286 gdb_tfind_test "8.14: tfind 3" "3" "3"
287 gdb_test "print \$trace_line" "$testline4" \
288 "8.14: tfind 3 (line $testline4)"
289
290 gdb_test "set \$test_pc = \$pc" "" ""
291 gdb_tfind_test "8.14: tfind none" "none" "-1"
292 gdb_tfind_test "8.14: tfind pc" "pc \$test_pc" "\$trace_frame != -1" "1";
293 gdb_test "print \$trace_line" "$testline4" \
294 "8.14: tfind pc x (line $testline4)"
295 gdb_test "printf \"x \%d x\\n\", \$pc == \$test_pc" \
296 "x 1 x" \
297 "8.14: tfind pc x"
298
299 # 8.15 tfind pc <no arg>
300 ## check pc same before and after, $trace_frame changed
301 gdb_tfind_test "8.15: tfind 3" "3" "3"
302 gdb_test "print \$trace_line" "$testline4" \
303 "8.15: tfind 3 (line $testline4)"
304 gdb_test "set \$test_pc = \$pc" "" ""
305 gdb_tfind_test "8.15: tfind pc" "pc" "\$pc == \$test_pc" "1"
306 gdb_test "print \$trace_line" "$testline4" \
307 "8.15: tfind pc (line $testline4)"
308 gdb_test "printf \"x \%d x\\n\", \$trace_frame != 3" "x 1 x" \
309 "8.15: trace frame didn't change"
310
311 # 8.26 tfind pc invalid x
312 ## check error, pc != x (trace_frame unchanged?)
313 gdb_tfind_test "8.26: tfind start" "start" "0"
314 gdb_test "tfind pc 0" "failed to find.*" "8.26: tfind pc zero"
315 gdb_test "tfind pc -1" "failed to find.*" "8.26: tfind pc -1"
316
317 # 8.16 tfind line n
318 ## check #trace_frame != -1, $trace_line == n
319 gdb_tfind_test "8.16: tfind none" "none" "-1"
320 gdb_tfind_test "8.16: tfind line $testline3" \
321 "line $testline3" \
322 "\$trace_line == $testline3" "1"
323
324 # 8.17 tfind line <no arg> (# 8.19, 8.20)
325 ## check $trace_line changed, no error, pc changed, frame changed, tdp changed
326 gdb_tfind_test "8.17: tfind none" "none" "-1"
327 gdb_tfind_test "8.17: tfind line $testline3" "line $testline3" "\$trace_line == $testline3" "1"
328 gdb_tfind_test "8.17: tfind line <no arg>" "line" "\$trace_line != $testline3" "1"
329
330 # 8.36 tfind and disassembly
331 gdb_tfind_test "8.36: tfind start" "start" "0"
332 set timeout 60
333 send_gdb "disassemble gdb_c_test\n"
334 # look for disassembly of function label
335 gdb_expect {
336 -re "<gdb_c_test>:.*$gdb_prompt $" { pass "8.36: trace disassembly" }
337 -re ".*$gdb_prompt $" { fail "8.36: trace disassembly" }
338 timeout { fail "8.36: trace disassembly (timeout)" }
339 }
340
341 gdb_test "tfind line 0" \
342 "out of range.*|failed to find.*" \
343 "8.18: tfind line 0";
344 gdb_test "tfind line 32767" \
345 "out of range.*|failed to find.*" \
346 "8.27: tfind line 32767";
347 gdb_test "tfind line NoSuChFiLe.c:$baseline" \
348 "No source file named.*" \
349 "8.27: tfind line in bad source file";
350
351 # 8.32 tfind invalid subcommand (tfind foo)
352 ## check error
353 gdb_test "tfind NoSuChOpTiOn 21" \
354 "No symbol.*|\[Ww\]arning.*|\[Ee\]rror.*" \
355 "8.32: tfind with bad subcommand"
356
357 # 8.38 test help tfind
358 gdb_test "help tfind" "Select a trace frame.*" \
359 "8.38: help tfind"
360 gdb_test "help tfind pc" "Select a trace frame by PC.*" \
361 "8.38: help tfind PC"
362 gdb_test "help tfind end" "Synonym for 'none'.*" \
363 "8.38: help tfind end"
364 gdb_test "help tfind none" "De-select any trace frame.*" \
365 "8.38: help tfind none"
366 gdb_test "help tfind line" "Select a trace frame by source line.*" \
367 "8.38: help tfind line"
368 gdb_test "help tfind start" "Select the first trace frame.*" \
369 "8.38: help tfind start"
370 gdb_test "help tfind range" "Select a trace frame whose PC is in.*" \
371 "8.38: help tfind range"
372 gdb_test "help tfind trace" "Select a trace frame by tracepoint number.*" \
373 "8.38: help tfind tracepoint"
374
375 # Finished!
376 gdb_tfind_test "8.17: tfind none" "none" "-1"