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