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