]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/all-architectures.exp.tcl
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / all-architectures.exp.tcl
1 # Copyright (C) 2016-2024 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 is part of the gdb testsuite.
17
18 # Test manually setting _all_ combinations of all supported bfd
19 # architectures and OS ABIs. This ensures that gdbarch initialization
20 # routines handle unusual combinations gracefully, at least without
21 # crashing.
22
23 # While at it, because the number of possible combinations is quite
24 # large, embed other checks that might be useful to do with all
25 # supported archs.
26
27 # One such test is ensuring that printing float, double and long
28 # double types works in cross/bi-arch scenarios. Some of GDB's float
29 # format conversion routines used to fail to consider that even if
30 # host and target floating formats match, their sizes may still
31 # differ. E.g., on x86, long double is 80-bit extended precision on
32 # both 32-bit vs 64-bit, but it's stored as 96 bit on 32-bit, and 128
33 # bit on 64-bit. This resulted in GDB accessing memory out of bounds.
34 # This test catches the issue when run against gdb linked with
35 # libmcheck, or run under Valgrind.
36
37 # Note: this test is actually split in several driver .exp files, in
38 # order to be able to parallelize the work. Each driver .exp file
39 # exercises a different slice of the supported architectures. See
40 # all-architectures-*.exp and the TEST_SLICE variable.
41
42 clean_restart
43
44 # By default, preparation steps don't output a PASS message. This is
45 # because the testcase has several thousand such steps.
46 set want_tests_messages 0
47
48 # Call this when an "internal" preparation-like step test passed.
49 # Logs the pass in gdb.log, but not in gdb.sum.
50
51 proc internal_pass {message} {
52 global want_tests_messages
53
54 if {$want_tests_messages} {
55 pass $message
56 } else {
57 # Skip the sum file, but still log an internal pass in the log
58 # file.
59 global pf_prefix
60
61 verbose -log "IPASS: $pf_prefix $message"
62 }
63 }
64
65 # The number of times gdb_test_internal was called, and the number of
66 # time that resulted in an internal pass. If these don't match, then
67 # some test failed.
68 set test_count 0
69 set internal_pass_count 0
70
71 # Like gdb_test, but calls internal_pass instead of pass, on success.
72
73 proc gdb_test_internal {cmd pattern {message ""}} {
74 global test_count internal_pass_count
75 global gdb_prompt
76
77 incr test_count
78
79 if {$message == ""} {
80 set message $cmd
81 }
82
83 gdb_test_multiple $cmd $message {
84 -re "$pattern\r\n$gdb_prompt $" {
85 internal_pass $message
86 incr internal_pass_count
87 }
88 }
89 }
90
91 gdb_test_internal "set max-completions unlimited" \
92 "^set max-completions unlimited"
93
94 set supported_archs [get_set_option_choices "set architecture"]
95 # There should be at least one more than "auto".
96 gdb_assert {[llength $supported_archs] > 1} "at least one architecture"
97
98 set supported_osabis [get_set_option_choices "set osabi"]
99 # There should be at least one more than "auto" and "default".
100 gdb_assert {[llength $supported_osabis] > 2} "at least one osabi"
101
102 if {[lsearch $supported_archs "mips"] >= 0} {
103 set supported_mipsfpu [get_set_option_choices "set mipsfpu"]
104 set supported_mips_abi [get_set_option_choices "set mips abi"]
105
106 gdb_assert {[llength $supported_mipsfpu] != 0} "at least one mipsfpu"
107 gdb_assert {[llength $supported_mips_abi] != 0} "at least one mips abi"
108 }
109
110 if {[lsearch $supported_archs "arm"] >= 0} {
111 set supported_arm_fpu [get_set_option_choices "set arm fpu"]
112 set supported_arm_abi [get_set_option_choices "set arm abi"]
113
114 gdb_assert {[llength $supported_arm_fpu] != 0} "at least one arm fpu"
115 gdb_assert {[llength $supported_arm_abi] != 0} "at least one arm abi"
116 }
117
118 set default_architecture "i386"
119
120 # Exercise printing float, double and long double.
121
122 proc print_floats {} {
123 gdb_test_internal "ptype 1.0L" "type = long double" "ptype, long double"
124 gdb_test_internal "print 1.0L" " = 1" "print, long double"
125
126 gdb_test_internal "ptype 1.0" "type = double" "ptype, double"
127 gdb_test_internal "print 1.0" " = 1" "print, double"
128
129 gdb_test_internal "ptype 1.0f" "type = float" "ptype, float"
130 gdb_test_internal "print 1.0f" " = 1" "print, float"
131 }
132
133 # Run tests on the current architecture ARCH.
134
135 proc do_arch_tests {arch} {
136 print_floats
137
138 # When we disassemble using the default architecture then we
139 # expect that the only error we should get from the disassembler
140 # is a memory error.
141 #
142 # When we force the architecture to something other than the
143 # default then we might get the message about unknown errors, this
144 # happens if the libopcodes disassembler returns -1 without first
145 # registering a memory error.
146 set pattern "Cannot access memory at address 0x100"
147 if { $arch != $::default_architecture } {
148 set pattern "(($pattern)|(unknown disassembler error \\(error = -1\\)))"
149 }
150
151 # GDB can't access memory because there is no loaded executable
152 # nor live inferior.
153 gdb_test_internal "disassemble 0x100,+4" "${pattern}"
154 }
155
156 # Given we can't change arch, osabi, endianness, etc. atomically, we
157 # need to silently ignore the case of the current OS ABI (not the one
158 # we'll switch to) not having a handler for the arch.
159 set osabi_warning \
160 [multi_line \
161 "warning: A handler for the OS ABI .* is not built into this configuration" \
162 "of GDB. Attempting to continue with the default .* settings." \
163 "" \
164 "" \
165 ]
166
167 set endian_warning "(Little|Big) endian target not supported by GDB\r\n"
168
169 # Like gdb_test_no_output, but use internal_pass instead of pass, and
170 # ignore "no handler for OS ABI" warnings.
171
172 proc gdb_test_no_output_osabi {cmd test} {
173 global osabi_warning
174 global gdb_prompt
175
176 gdb_test_multiple "$cmd" $test {
177 -re "^${cmd}\r\n(${osabi_warning})?$gdb_prompt $" {
178 internal_pass $test
179 }
180 }
181 }
182
183 # It'd be nicer/safer to restart GDB on each iteration, but, that
184 # increases the testcase's run time several times fold. At the time
185 # of writing, it'd jump from 20s to 4min on x86-64 GNU/Linux with
186 # --enable-targets=all.
187
188 set num_slices 8
189 set num_archs [llength $supported_archs]
190 set archs_per_slice [expr (($num_archs + $num_slices - 1) / $num_slices)]
191
192 with_test_prefix "tests" {
193 foreach_with_prefix osabi $supported_osabis {
194
195 gdb_test_no_output_osabi "set osabi $osabi" \
196 "set osabi"
197
198 set arch_count 0
199 foreach_with_prefix arch $supported_archs {
200
201 incr arch_count
202
203 # Skip architectures outside our slice.
204 if {$arch_count < [expr $test_slice * $archs_per_slice]} {
205 continue
206 }
207 if {$arch_count >= [expr ($test_slice + 1) * $archs_per_slice]} {
208 continue
209 }
210
211 if {$arch == "auto"} {
212 continue
213 }
214 set default_endian ""
215 foreach_with_prefix endian {"auto" "big" "little"} {
216
217 set test "set endian"
218 if {$endian == $default_endian} {
219 continue
220 } elseif {$endian == "auto"} {
221 gdb_test_multiple "set endian $endian" $test {
222 -re "^set endian $endian\r\n(${osabi_warning})?The target endianness is set automatically \\(currently .* endian\\)\\.\r\n$gdb_prompt $" {
223 internal_pass $test
224 }
225 }
226 } else {
227 gdb_test_multiple "set endian $endian" $test {
228 -re "^set endian $endian\r\n${endian_warning}.*\r\n$gdb_prompt $" {
229 internal_pass $test
230 continue
231 }
232 -re "^set endian $endian\r\n(${osabi_warning})?The target is set to $endian endian\\.\r\n$gdb_prompt $" {
233 internal_pass $test
234 }
235 }
236 }
237
238 # Skip setting the same architecture again.
239 if {$endian == "auto"} {
240 set arch_re [string_to_regexp $arch]
241 set test "set architecture $arch"
242 gdb_test_multiple $test $test {
243 -re "^set architecture $arch_re\r\n(${osabi_warning})?The target architecture is set to \"$arch_re\"\\.\r\n$gdb_prompt $" {
244 internal_pass $test
245 }
246 -re "Architecture .* not recognized.*$gdb_prompt $" {
247 # GDB is missing support for a few
248 # machines that bfd supports.
249 if {$arch == "powerpc:EC603e"
250 || $arch == "powerpc:e500mc"
251 || $arch == "powerpc:e500mc64"
252 || $arch == "powerpc:vle"
253 || $arch == "powerpc:titan"
254 || $arch == "powerpc:e5500"
255 || $arch == "powerpc:e6500"} {
256 if {$want_tests_messages} {
257 kfail $test "gdb/19797"
258 }
259 } else {
260 fail "$test (arch not recognized)"
261 }
262 continue
263 }
264 }
265
266 # Record what is the default endianess. As an
267 # optimization, we'll skip testing the manual "set
268 # endian DEFAULT" case.
269 set test "show endian"
270 gdb_test_multiple "show endian" $test {
271 -re "currently little endian.*$gdb_prompt $" {
272 set default_endian "little"
273 internal_pass $test
274 }
275 -re "currently big endian.*$gdb_prompt $" {
276 set default_endian "big"
277 internal_pass $test
278 }
279 }
280 }
281
282 # Some architectures have extra settings that affect
283 # the ABI. Specify the extra testing axes in a
284 # declarative form.
285 #
286 # A list of {COMMAND, VAR, OPTIONS-LIST} elements.
287 set all_axes {}
288
289 if {$arch == "mips"} {
290 lappend all_axes [list "set mips abi" mips_abi $supported_mips_abi]
291 lappend all_axes [list "set mipsfpu" mipsfpu $supported_mipsfpu]
292 } elseif {$arch == "arm"} {
293 lappend all_axes [list "set arm abi" arm_abi $supported_arm_abi]
294 lappend all_axes [list "set arm fpu" arm_fpu $supported_arm_fpu]
295 }
296
297 # Run testing axis CUR_AXIS. This is a recursive
298 # procedure that tries all combinations of options of
299 # all the testing axes.
300 proc run_axis {all_axes cur_axis arch} {
301 if {$cur_axis == [llength $all_axes]} {
302 do_arch_tests $arch
303 return
304 }
305
306 # Unpack the axis.
307 set axis [lindex $all_axes $cur_axis]
308 set cmd [lindex $axis 0]
309 set var [lindex $axis 1]
310 set options [lindex $axis 2]
311
312 foreach v $options {
313 with_test_prefix "$var=$v" {
314 gdb_test_no_output_osabi "$cmd $v" "$cmd"
315 run_axis $all_axes [expr $cur_axis + 1] $arch
316 }
317 }
318 }
319
320 run_axis $all_axes 0 $arch
321 }
322 }
323 }
324 }
325
326 # A test that:
327 #
328 # - ensures there's a PASS if all internal tests actually passed
329 #
330 # - ensures there's at least one test that is interpreted as a
331 # regression (a matching PASS->FAIL) if some of the internal tests
332 # failed, instead of looking like it could be a new FAIL that could
333 # be ignored.
334 #
335 gdb_assert {$internal_pass_count == $test_count} "all passed"