]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/mi-trace-unavailable.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / mi-trace-unavailable.exp
1 # Copyright 2013-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 load_lib trace-support.exp
17
18 standard_testfile trace-unavailable.c
19
20 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug nopie}] } {
21 return -1
22 }
23
24 if ![runto_main] {
25 return -1
26 }
27
28 if ![gdb_target_supports_trace] {
29 unsupported "current target does not support trace"
30 return -1
31 }
32
33 gdb_exit
34
35 load_lib mi-support.exp
36 set MIFLAGS "-i=mi"
37
38 mi_clean_restart $binfile
39 mi_runto_main
40
41 mi_gdb_test "-break-insert marker" \
42 "\\^done,bkpt=\{number=\"${decimal}\",type=\"breakpoint\".*\"\}" \
43 "insert tracepoint on marker"
44 mi_gdb_test "-break-insert -a bar" \
45 "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \
46 "insert tracepoint on bar"
47
48 # Define an action.
49 mi_gdb_test "-break-commands 3 \"collect array\" \"collect j\" \"end\" " \
50 {\^done} "set action"
51
52 mi_gdb_test "-break-insert -a foo" \
53 "\\^done,bkpt=\{number=\"${decimal}\",type=\"tracepoint\".*\"\}" \
54 "insert tracepoint on foo"
55
56 # Collect 'main' to make sure no registers are collected except PC.
57 mi_gdb_test "-break-commands 4 \"collect main\" \"end\" " \
58 {\^done} "set action on tracepoint 4"
59
60 mi_gdb_test "-trace-start" {.*\^done} "trace start"
61 mi_send_resuming_command "exec-continue" "continuing to marker"
62 mi_expect_stop \
63 "breakpoint-hit" "marker" ".*" ".*" ".*" {"" "disp=\"keep\""} \
64 "stop at marker"
65 mi_gdb_test "-trace-stop" {.*} "trace stop"
66
67 # Save trace frames to tfile.
68 set tracefile [standard_output_file ${testfile}]
69 mi_gdb_test "-trace-save ${tracefile}.tf" ".*\\^done" \
70 "save tfile trace file"
71 # Save trace frames to ctf.
72 mi_gdb_test "-trace-save -ctf ${tracefile}.ctf" ".*\\^done" \
73 "save ctf trace file"
74
75 proc test_trace_unavailable { data_source } {
76 global decimal
77
78 with_test_prefix "$data_source" {
79
80 # Test MI commands '-stack-list-locals', '-stack-list-arguments',
81 # and '-stack-list-variables'.
82 mi_gdb_test "-trace-find frame-number 0" \
83 ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
84 "-trace-find frame-number 0"
85
86 # The "print entry-values" option shouldn't affect the output of
87 # '-stack-list-locals'.
88 foreach entry_values { no only preferred if-needed both compact default } {
89 mi_gdb_test "-gdb-set print entry-values $entry_values" {\^done} ""
90
91 with_test_prefix "$entry_values" {
92 # Test MI command '-stack-list-locals'.
93 mi_gdb_test "-stack-list-locals --simple-values" \
94 ".*\\^done,locals=\\\[\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\},\{name=\"i\",type=\"int\",value=\"<unavailable>\"\}\\\]" \
95 "-stack-list-locals --simple-values"
96 }
97 }
98
99 mi_gdb_test "-gdb-set print entry-values no" {\^done} \
100 "-gdb-set print entry-values no"
101
102 # Test MI command '-stack-list-locals'.
103 mi_gdb_test "-stack-list-locals --simple-values" \
104 ".*\\^done,locals=\\\[\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\},\{name=\"i\",type=\"int\",value=\"<unavailable>\"\}\\\]" \
105 "-stack-list-locals --simple-values"
106 mi_gdb_test "-stack-list-locals --skip-unavailable --simple-values" \
107 ".*\\^done,locals=\\\[\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\}\\\]" \
108 "-stack-list-locals --skip-unavailable --simple-values"
109
110 # Test MI command '-stack-list-arguments'.
111 mi_gdb_test "-stack-list-arguments --simple-values" \
112 ".*\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"j\",type=\"int\",value=\"4\"\},\{name=\"s\",type=\"char \\\*\",value=\"<unavailable>\"\}\\\]\},.*\}.*" \
113 "-stack-list-arguments --simple-values"
114 mi_gdb_test "-stack-list-arguments --skip-unavailable --simple-values" \
115 ".*\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"j\",type=\"int\",value=\"4\"\}\\\]\},.*\}.*" \
116 "-stack-list-arguments --skip-unavailable --simple-values"
117
118 # Test MI command '-stack-list-variables'.
119 mi_gdb_test "-stack-list-variables --simple-values" \
120 ".*\\^done,variables=\\\[\{name=\"j\",arg=\"1\",type=\"int\",value=\"4\"\},\{name=\"s\",arg=\"1\",type=\"char \\\*\",value=\"<unavailable>\"\},\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\},\{name=\"i\",type=\"int\",value=\"<unavailable>\"\}\\\]" \
121 "-stack-list-variables --simple-values"
122 mi_gdb_test "-stack-list-variables --skip-unavailable --simple-values" \
123 ".*\\^done,variables=\\\[\{name=\"j\",arg=\"1\",type=\"int\",value=\"4\"\},\{name=\"array\",type=\"unsigned char \\\[2\\\]\"\}\\\]" \
124 "-stack-list-variables --skip-unavailable --simple-values"
125
126 mi_gdb_test "-trace-find frame-number 1" \
127 ".*\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"1\",frame=\{.*" \
128 "-trace-find frame-number 1"
129
130 set pcnum -1
131 set gpr0num -1
132 if [is_amd64_regs_target] {
133 set pcnum 16
134 set gpr0num 0
135 } elseif [is_x86_like_target] {
136 set pcnum 8
137 set gpr0num 0
138 } elseif [is_aarch64_target] {
139 set pcnum 32
140 set gpr0num 0
141 } elseif [istarget "powerpc*-*-*"] {
142 set pcnum 64
143 set gpr0num 0
144 } elseif { [istarget "s390*-*-*"] } {
145 # Strictly speaking, this is PSWA, not PC.
146 set pcnum 1
147 set gpr0num 2
148 } else {
149 # Other ports support tracepoint should define the number
150 # of its own pc register.
151 }
152
153 if { $pcnum != -1 } {
154 global hex
155 # Test that register 0 and PC are displayed, and register
156 # 0 is unavailable.
157 mi_gdb_test "-data-list-register-values x ${gpr0num} ${pcnum}" \
158 ".*\\^done,register-values=\\\[\{number=\"${gpr0num}\",value=\"<unavailable>\"\},\{number=\"${pcnum}\",value=\"${hex}\"\}\\\]" \
159 "-data-list-register-values x"
160
161 # Test that only available register PC is displayed.
162 mi_gdb_test "-data-list-register-values --skip-unavailable x ${gpr0num} ${pcnum}" \
163 ".*\\^done,register-values=\\\[\{number=\"${pcnum}\",value=\"${hex}\"\}\\\]" \
164 "-data-list-register-values --skip-unavailable x"
165 }
166
167 # Don't issue command '-trace-find none' to return from
168 # tfind mode (examining trace frames) on purpose, in order
169 # to test that GDB is able to clear its tracing-related local state
170 # in the next -target-select.
171 # mi_gdb_test "-trace-find none" ".*\\^done,found=\"0\".*" "-trace-find none"
172 }
173 }
174
175 test_trace_unavailable "live"
176
177 # Change target to ctf if GDB supports it.
178 set msg "-target-select ctf"
179 send_gdb "-target-select ctf ${tracefile}.ctf\n"
180 gdb_expect {
181 -re ".*\\^connected.*${mi_gdb_prompt}$" {
182 # GDB supports ctf, do the test.
183 test_trace_unavailable "ctf"
184 }
185 -re ".*\\^error,msg=\"Undefined target command.*${mi_gdb_prompt}$" {
186 # GDB doesn't support ctf, skip the test.
187 unsupported "gdb does not support ctf target"
188 }
189 -re ".*$mi_gdb_prompt$" {
190 fail "$msg"
191 }
192 timeout {
193 fail "$msg (timeout)"
194 }
195 }
196
197 # Change target to tfile.
198 mi_gdb_test "-target-select tfile ${tracefile}.tf" ".*\\^connected.*" \
199 "-target-select tfile"
200 test_trace_unavailable "tfile"
201
202 mi_gdb_exit