1 # Copyright (C) 2016-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite.
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
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
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.
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.
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
48 # Call this when an "internal" preparation-like step test passed.
49 # Logs the pass in gdb.log, but not in gdb.sum.
51 proc internal_pass
{message} {
52 global want_tests_messages
54 if {$want_tests_messages} {
57 # Skip the sum file, but still log an internal pass in the log
61 verbose
-log "IPASS: $pf_prefix $message"
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
69 set internal_pass_count
0
71 # Like gdb_test, but calls internal_pass instead of pass, on success.
73 proc gdb_test_internal
{cmd pattern
{message ""}} {
74 global test_count internal_pass_count
83 gdb_test_multiple
$cmd $message {
84 -re "$pattern\r\n$gdb_prompt $" {
85 internal_pass
$message
86 incr internal_pass_count
91 gdb_test_internal
"set max-completions unlimited" \
92 "^set max-completions unlimited"
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"
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"
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"]
106 gdb_assert
{[llength $supported_mipsfpu] != 0} "at least one mipsfpu"
107 gdb_assert
{[llength $supported_mips_abi] != 0} "at least one mips abi"
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"]
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"
118 set default_architecture
"i386"
120 # Exercise printing float, double and long double.
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"
126 gdb_test_internal
"ptype 1.0" "type = double" "ptype, double"
127 gdb_test_internal
"print 1.0" " = 1" "print, double"
129 gdb_test_internal
"ptype 1.0f" "type = float" "ptype, float"
130 gdb_test_internal
"print 1.0f" " = 1" "print, float"
133 # Run tests on the current architecture ARCH.
135 proc do_arch_tests
{arch
} {
138 # When we disassemble using the default architecture then we
139 # expect that the only error we should get from the disassembler
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\\)))"
151 # GDB can't access memory because there is no loaded executable
153 gdb_test_internal
"disassemble 0x100,+4" "${pattern}"
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.
161 "warning: A handler for the OS ABI .* is not built into this configuration" \
162 "of GDB. Attempting to continue with the default .* settings." \
167 set endian_warning
"(Little|Big) endian target not supported by GDB\r\n"
169 # Like gdb_test_no_output, but use internal_pass instead of pass, and
170 # ignore "no handler for OS ABI" warnings.
172 proc gdb_test_no_output_osabi
{cmd test
} {
176 gdb_test_multiple
"$cmd" $test {
177 -re "^${cmd}\r\n(${osabi_warning})?$gdb_prompt $" {
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.
189 set num_archs
[llength $supported_archs]
190 set archs_per_slice
[expr (($num_archs + $num_slices - 1) / $num_slices)]
192 with_test_prefix
"tests" {
193 foreach_with_prefix osabi
$supported_osabis {
195 gdb_test_no_output_osabi
"set osabi $osabi" \
199 foreach_with_prefix arch
$supported_archs {
203 # Skip architectures outside our slice.
204 if {$arch_count < [expr $test_slice * $archs_per_slice]} {
207 if {$arch_count >= [expr ($test_slice + 1) * $archs_per_slice]} {
211 if {$arch == "auto"} {
214 set default_endian
""
215 foreach_with_prefix endian
{"auto" "big" "little"} {
217 set test
"set endian"
218 if {$endian == $default_endian} {
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 $" {
227 gdb_test_multiple
"set endian $endian" $test {
228 -re "^set endian $endian\r\n${endian_warning}.*\r\n$gdb_prompt $" {
232 -re "^set endian $endian\r\n(${osabi_warning})?The target is set to $endian endian\\.\r\n$gdb_prompt $" {
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 $" {
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"
260 fail
"$test (arch not recognized)"
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"
275 -re "currently big endian.*$gdb_prompt $" {
276 set default_endian
"big"
282 # Some architectures have extra settings that affect
283 # the ABI. Specify the extra testing axes in a
286 # A list of {COMMAND, VAR, OPTIONS-LIST} elements.
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]
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]} {
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]
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
320 run_axis
$all_axes 0 $arch
328 # - ensures there's a PASS if all internal tests actually passed
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
335 gdb_assert
{$internal_pass_count == $test_count} "all passed"