xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.trace/tsv.exp (revision a8c74629f602faa0ccf8a463757d7baf858bbf3a)
1#   Copyright 2009-2020 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
16load_lib "trace-support.exp"
17
18
19gdb_exit
20gdb_start
21standard_testfile actions.c
22if ![gdb_trace_common_supports_arch] {
23    unsupported "no trace-common.h support for arch"
24    return -1
25}
26if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
27	  executable {debug nowarnings}] != "" } {
28    untested "failed to compile"
29    return -1
30}
31gdb_load $binfile
32
33# PR gdb/21352: Command tsave does not support -r argument
34gdb_test "tsave -r" "Argument required \\\(file in which to save trace data\\\)\." \
35    "tsave command properly supports -r argument"
36
37gdb_test "tvariable \$tvar1" \
38  "Trace state variable \\\$tvar1 created, with initial value 0." \
39  "create a trace state variable"
40
41gdb_test "tvariable \$tvar2 = 45" \
42  "Trace state variable \\\$tvar2 created, with initial value 45." \
43  "create a trace state variable with initial value"
44
45gdb_test "tvariable \$tvar2 = -92" \
46  "Trace state variable \\\$tvar2 now has initial value -92." \
47  "change initial value of a trace state variable"
48
49gdb_test "tvariable \$tvar3 = 2 + 3" \
50  "Trace state variable \\\$tvar3 created, with initial value 5." \
51  "create a trace state variable with expression"
52
53gdb_test "tvariable \$tvar3 = 1234567000000" \
54  "Trace state variable \\\$tvar3 now has initial value 1234567000000." \
55  "init trace state variable to a 64-bit value"
56
57gdb_test "tvariable $" \
58  "Must supply a non-empty variable name" \
59  "tvariable syntax error, not empty variable name"
60
61gdb_test "tvariable main" \
62  "Name of trace variable should start with '\\\$'" \
63  "tvariable syntax error, bad name"
64
65gdb_test "tvariable \$\$" \
66  "Syntax must be \\\$NAME \\\[ = EXPR \\\]" \
67  "tvariable syntax error, bad name 2"
68
69gdb_test "tvariable \$123" \
70  "\\\$123 is not a valid trace state variable name" \
71  "tvariable syntax error, bad name 3"
72
73gdb_test "tvariable \$tvar1 - 93" \
74  "Syntax must be \\\$NAME \\\[ = EXPR \\\]" \
75  "tvariable syntax error, not an assignment"
76
77gdb_test "tvariable \$tvar0 = 1 = 1" \
78  "Left operand of assignment is not an lvalue\." \
79  "tvariable creation fails with invalid expression"
80
81gdb_test "info tvariables" \
82    "Name\[\t \]+Initial\[\t \]+Current.*
83\\\$tvar1\[\t \]+0\[\t \]+<undefined>.*
84\\\$tvar2\[\t \]+-92\[\t \]+<undefined>.*
85\\\$tvar3\[\t \]+1234567000000\[\t \]+.*<undefined>.*" \
86  "List tvariables"
87
88gdb_test "print \$tvar2" " = void" \
89    "Print a trace state variable before run"
90
91gdb_test_no_output "delete tvariable \$tvar2" \
92  "delete trace state variable"
93
94gdb_test "info tvariables" \
95    "Name\[\t \]+Initial\[\t \]+Current.*
96\\\$tvar1\[\t \]+0\[\t \]+<undefined>.*
97\\\$tvar3\[\t \]+1234567000000\[\t \]+.*<undefined>.*" \
98  "List tvariables after deletion"
99
100gdb_test "delete tvariable" \
101    "" \
102    "Delete all trace state variables" \
103    "Delete all trace state variables.*y or n.*$" \
104    "y"
105
106gdb_test "info tvariables" \
107  "No trace state variables.*" \
108  "list tvariables after deleting all"
109
110# Now try running a trace.
111
112runto_main
113gdb_reinitialize_dir $srcdir/$subdir
114
115# The rest of the testing needs actual tracing to work.
116if { ![gdb_target_supports_trace] } then {
117    unsupported "current target does not support trace"
118    return 1
119}
120
121gdb_delete_tracepoints
122set trcpt1 [gdb_gettpnum gdb_c_test]
123
124if { $trcpt1 <= 0 } then {
125    fail "setting tracepoints"
126    return
127}
128
129gdb_test "tvariable \$tvar5 = 15" \
130  "Trace state variable \\\$tvar5 created, with initial value 15." \
131  "create a trace state variable tvar5"
132
133gdb_trace_setactions "collect tsv for first tracepoint" \
134	"$trcpt1" \
135	"collect \$tvar5 += 1" "^$"
136
137gdb_test_no_output "tstart" ""
138
139gdb_test "print \$tvar5" " = 15" \
140    "Print a trace state variable at start of run"
141
142# Be sure not to fall off the end of the program.
143gdb_breakpoint "end" qualified
144gdb_test "continue" \
145    "Continuing.*Breakpoint $decimal, end.*" \
146    "run trace experiment"
147
148gdb_test "print \$tvar5" " = 16" \
149    "Print a trace state variable during run"
150
151gdb_test_no_output "tstop" ""
152
153# Save trace frames to tfile.
154set tracefile [standard_output_file ${testfile}]
155gdb_test "tsave ${tracefile}.tf" \
156    "Trace data saved to file '${tracefile}.tf'.*" \
157    "save tfile trace file"
158# Save trace frames to ctf.
159gdb_test "tsave -ctf ${tracefile}.ctf" \
160    "Trace data saved to directory '${tracefile}.ctf'.*" \
161    "save ctf trace file"
162
163proc check_tsv { data_source } {
164    with_test_prefix "${data_source}" {
165	gdb_test "tfind 0"
166	gdb_test "print \$tvar5" " = 16" \
167	    "Print a trace state variable"
168	gdb_test "tfind" \
169	    "Target failed to find requested trace frame.*"
170    }
171}
172
173# Check the tsv from the live inferior.
174check_tsv "live"
175
176# Change target to tfile.
177set test "change to tfile target"
178gdb_test_multiple "target tfile ${tracefile}.tf" "$test" {
179    -re "A program is being debugged already.  Kill it. .y or n. " {
180	send_gdb "y\n"
181	exp_continue
182    }
183    -re "$gdb_prompt $" {
184	pass "$test"
185    }
186}
187
188# Check the tsv from tfile.
189
190check_tsv "tfile"
191# Try to read ctf data if GDB supports.
192gdb_test_multiple "target ctf ${tracefile}.ctf" "" {
193    -re "Undefined target command: \"ctf ${tracefile}.ctf\"\.  Try \"help target\"\.\r\n$gdb_prompt $" {
194    }
195    -re ".*\r\n$gdb_prompt $" {
196	check_tsv "ctf"
197    }
198}
199
200# Restart.
201clean_restart ${binfile}
202
203if ![runto_main] then {
204    fail "can't run to main"
205    return
206}
207
208# If there are predefined TSVs, test these predefined TSVs are correctly
209# uploaded.
210if [target_info exists gdb,predefined_tsv] {
211    set tsv [target_info gdb,predefined_tsv]
212
213    # Test predefined TSVs are uploaded.
214    gdb_test "info tvariables" ".*${tsv}.*" "predefined tsvs are uploaded"
215} else {
216    # Otherwise (the predefined TSVs are not defined in the board file),
217    # test there is no TSVs in GDB.
218    gdb_test "info tvariables" "No trace state variables\." \
219	"no predefined tsvs"
220}
221