diff options
author | Pedro Alves <pedro@palves.net> | 2022-04-27 11:08:03 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2022-04-27 19:29:38 +0100 |
commit | 5b758627a18f0d3b90a0207c9689dcf4ec5b9a4a (patch) | |
tree | 02fe714f646e641dcdaa5baf39117a8b1d0e03b6 /gdb/testsuite/gdb.base/parse_number.exp | |
parent | 801eb70f9aa916650b9ca03a1d54d426a3e99f17 (diff) | |
download | gdb-5b758627a18f0d3b90a0207c9689dcf4ec5b9a4a.zip gdb-5b758627a18f0d3b90a0207c9689dcf4ec5b9a4a.tar.gz gdb-5b758627a18f0d3b90a0207c9689dcf4ec5b9a4a.tar.bz2 |
Make gdb.base/parse_number.exp test all architectures
There are some subtle differences between architectures, like the size
of a "long" type, and this isn't currently accounted for in
gdb.base/parse_number.exp.
For example, on aarch64 a long type is 8 bytes, whereas a long type is
4 bytes for x86_64. This causes the following FAIL's:
FAIL: gdb.base/parse_number.exp: lang=asm: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=auto: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=c: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=c++: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=fortran: p/x 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=fortran: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=go: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=local: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=minimal: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=objective-c: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=opencl: ptype 0xffffffffffffffff
FAIL: gdb.base/parse_number.exp: lang=pascal: ptype 0xffffffffffffffff
There are some fortran-specific divergences as well, where 32-bit
architectures show "unsigned int" for both 32-bit and 64-bit integers
and 64-bit architectures show "unsigned int" and "unsigned long" for
32-bit and 64-bit integers.
There might be a bug that 32-bit fortran truncates 64-bit values to
32-bit, given "p/x 0xffffffffffffffff" returns "0xffffffff".
Here's what we get for aarch64:
(gdb) ptype 0xffffffff
type = unsigned int
(gdb) ptype 0xffffffffffffffff
type = unsigned long
(gdb) p sizeof (0xffffffff)
$1 = 4
(gdb) p sizeof (0xffffffffffffffff)
quit
$2 = 8
(gdb) ptype 0xffffffff
type = unsigned int
(gdb) ptype 0xffffffffffffffff
type = unsigned long
And for arm:
(gdb) ptype 0xffffffff
type = unsigned int
(gdb) ptype 0xffffffffffffffff
quit
type = unsigned long long
(gdb) p sizeof (0xffffffff)
quit
$1 = 4
(gdb) p sizeof (0xffffffffffffffff)
quit
$2 = 8
(gdb) ptype 0xffffffff
type = unsigned int
(gdb) ptype 0xffffffffffffffff
type = unsigned long
This patch...
* Makes the testcase iterate over all architectures, thus covering all
the different combinations of types/sizes every time.
* Adjusts the expected values and types based on the sizes of long
long, long and int.
A particularly curious architecture is s12z, which has 32-bit long
long, and thus no way to represent 64-bit integers in C-like
languages.
Co-Authored-By: Luis Machado <luis.machado@arm.com>
Change-Id: Ifc0ccd33e7fd3c7585112ff6bebe7d266136768b
Diffstat (limited to 'gdb/testsuite/gdb.base/parse_number.exp')
-rw-r--r-- | gdb/testsuite/gdb.base/parse_number.exp | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp index e911cc0..ccef3f0 100644 --- a/gdb/testsuite/gdb.base/parse_number.exp +++ b/gdb/testsuite/gdb.base/parse_number.exp @@ -17,37 +17,89 @@ # around parsing large 64-bit numbers, hitting undefined behavior, and # thus crashing a GDB built with UBSan. This testcase goes over all # languages exercising printing the max 64-bit number, making sure -# that GDB doesn't crash. +# that GDB doesn't crash. ARCH is the architecture to test with. -proc test_parse_numbers {} { - clean_restart +proc test_parse_numbers {arch} { + set arch_re [string_to_regexp $arch] + gdb_test "set architecture $arch" "The target architecture is set to \"$arch_re\"." - set all_languages [get_set_option_choices "set language"] - foreach_with_prefix lang $all_languages { + gdb_test_no_output "set language c" + + # Types have different sizes depending on the architecture. + # Figure out type sizes before matching patterns in the upcoming + # tests. + + set sizeof_long_long [get_sizeof "long long" -1] + set sizeof_long [get_sizeof "long" -1] + set sizeof_int [get_sizeof "int" -1] + + if {$sizeof_long_long == 8 && $sizeof_long == 8} { + set 8B_type "unsigned long" + set fortran_type "unsigned long" + set fortran_value "0xffffffffffffffff" + } elseif {$sizeof_long_long == 8 && $sizeof_long == 4 && $sizeof_int == 4} { + set 8B_type "unsigned long long" + set fortran_type "unsigned int" + set fortran_value "0xffffffff" + } elseif {$sizeof_long == 4 && $sizeof_int == 2} { + set 8B_type "unsigned long long" + set fortran_type "unsigned long" + set fortran_value "0xffffffff" + } else { + error "missing case for long long = $sizeof_long_long, long = $sizeof_long, int = $sizeof_int" + } + + foreach_with_prefix lang $::all_languages { gdb_test_no_output "set language $lang" set val "0xffffffffffffffff" if {$lang == "fortran"} { - gdb_test "p/x $val" " = 0xffffffff" - gdb_test "ptype $val" " = unsigned int" + gdb_test "p/x $val" " = $fortran_value" + gdb_test "ptype $val" " = $fortran_type" } elseif {$lang == "modula-2"} { gdb_test "p/x 0FFFFFFFFFFFFFFFFH" "Overflow on numeric constant\\." } elseif {$lang == "unknown"} { gdb_test "p/x $val" \ "expression parsing not implemented for language \"Unknown\"" } else { - gdb_test "p/x $val" " = $val" + # D and Rust define their own built-in 64-bit types, and + # are thus always able to parse/print 64-bit values. + if {$sizeof_long_long == 4 && $lang != "d" && $lang != "rust"} { + set out "0xffffffff" + } else { + set out $val + } + gdb_test "p/x $val" " = $out" if {$lang == "ada"} { - gdb_test "ptype $val" " = <8-byte integer>" + if {$sizeof_long_long == 4} { + gdb_test "ptype $val" " = <4-byte integer>" + } else { + gdb_test "ptype $val" " = <8-byte integer>" + } } elseif {$lang == "d"} { gdb_test "ptype $val" " = ulong" } elseif {$lang == "rust"} { gdb_test "ptype $val" " = i64" } else { - gdb_test "ptype $val" " = unsigned long long" + gdb_test "ptype $val" " = $8B_type" } } } } -test_parse_numbers +clean_restart + +gdb_test_no_output "set max-completions unlimited" + +set supported_archs [get_set_option_choices "set architecture"] +# There should be at least one more than "auto". +gdb_assert {[llength $supported_archs] > 1} "at least one architecture" + +set all_languages [get_set_option_choices "set language"] + +foreach_with_prefix arch $supported_archs { + if {$arch == "auto"} { + continue + } + test_parse_numbers $arch +} |