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