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