From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id D04EE3857C50; Wed, 27 Apr 2022 18:32:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D04EE3857C50 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Make gdb.base/parse_number.exp test all architectures X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 801eb70f9aa916650b9ca03a1d54d426a3e99f17 X-Git-Newrev: 5b758627a18f0d3b90a0207c9689dcf4ec5b9a4a Message-Id: <20220427183255.D04EE3857C50@sourceware.org> Date: Wed, 27 Apr 2022 18:32:55 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2022 18:32:55 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5b758627a18f= 0d3b90a0207c9689dcf4ec5b9a4a commit 5b758627a18f0d3b90a0207c9689dcf4ec5b9a4a Author: Pedro Alves Date: Wed Apr 27 11:08:03 2022 +0100 Make gdb.base/parse_number.exp test all architectures =20 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. =20 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: =20 FAIL: gdb.base/parse_number.exp: lang=3Dasm: ptype 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dauto: ptype 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dc: ptype 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dc++: ptype 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dfortran: p/x 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dfortran: ptype 0xfffffffffffff= fff FAIL: gdb.base/parse_number.exp: lang=3Dgo: ptype 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dlocal: ptype 0xffffffffffffffff FAIL: gdb.base/parse_number.exp: lang=3Dminimal: ptype 0xfffffffffffff= fff FAIL: gdb.base/parse_number.exp: lang=3Dobjective-c: ptype 0xfffffffff= fffffff FAIL: gdb.base/parse_number.exp: lang=3Dopencl: ptype 0xffffffffffffff= ff FAIL: gdb.base/parse_number.exp: lang=3Dpascal: ptype 0xffffffffffffff= ff =20 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. =20 There might be a bug that 32-bit fortran truncates 64-bit values to 32-bit, given "p/x 0xffffffffffffffff" returns "0xffffffff". =20 Here's what we get for aarch64: =20 (gdb) ptype 0xffffffff type =3D unsigned int (gdb) ptype 0xffffffffffffffff type =3D unsigned long (gdb) p sizeof (0xffffffff) $1 =3D 4 (gdb) p sizeof (0xffffffffffffffff) quit $2 =3D 8 (gdb) ptype 0xffffffff type =3D unsigned int (gdb) ptype 0xffffffffffffffff type =3D unsigned long =20 And for arm: =20 (gdb) ptype 0xffffffff type =3D unsigned int (gdb) ptype 0xffffffffffffffff quit type =3D unsigned long long (gdb) p sizeof (0xffffffff) quit $1 =3D 4 (gdb) p sizeof (0xffffffffffffffff) quit $2 =3D 8 (gdb) ptype 0xffffffff type =3D unsigned int (gdb) ptype 0xffffffffffffffff type =3D unsigned long =20 This patch... =20 * Makes the testcase iterate over all architectures, thus covering all the different combinations of types/sizes every time. =20 * Adjusts the expected values and types based on the sizes of long long, long and int. =20 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. =20 Co-Authored-By: Luis Machado Change-Id: Ifc0ccd33e7fd3c7585112ff6bebe7d266136768b Diff: --- gdb/testsuite/gdb.base/parse_number.exp | 74 ++++++++++++++++++++++++++++-= ---- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.ba= se/parse_number.exp index e911cc0fdfb..ccef3f09655 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. =20 -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\"." =20 - 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 =3D=3D 8 && $sizeof_long =3D=3D 8} { + set 8B_type "unsigned long" + set fortran_type "unsigned long" + set fortran_value "0xffffffffffffffff" + } elseif {$sizeof_long_long =3D=3D 8 && $sizeof_long =3D=3D 4 && $size= of_int =3D=3D 4} { + set 8B_type "unsigned long long" + set fortran_type "unsigned int" + set fortran_value "0xffffffff" + } elseif {$sizeof_long =3D=3D 4 && $sizeof_int =3D=3D 2} { + set 8B_type "unsigned long long" + set fortran_type "unsigned long" + set fortran_value "0xffffffff" + } else { + error "missing case for long long =3D $sizeof_long_long, long =3D $sizeof= _long, int =3D $sizeof_int" + } + + foreach_with_prefix lang $::all_languages { gdb_test_no_output "set language $lang" =20 set val "0xffffffffffffffff" if {$lang =3D=3D "fortran"} { - gdb_test "p/x $val" " =3D 0xffffffff" - gdb_test "ptype $val" " =3D unsigned int" + gdb_test "p/x $val" " =3D $fortran_value" + gdb_test "ptype $val" " =3D $fortran_type" } elseif {$lang =3D=3D "modula-2"} { gdb_test "p/x 0FFFFFFFFFFFFFFFFH" "Overflow on numeric constant\\." } elseif {$lang =3D=3D "unknown"} { gdb_test "p/x $val" \ "expression parsing not implemented for language \"Unknown\"" } else { - gdb_test "p/x $val" " =3D $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 =3D=3D 4 && $lang !=3D "d" && $lang !=3D "rust"= } { + set out "0xffffffff" + } else { + set out $val + } + gdb_test "p/x $val" " =3D $out" if {$lang =3D=3D "ada"} { - gdb_test "ptype $val" " =3D <8-byte integer>" + if {$sizeof_long_long =3D=3D 4} { + gdb_test "ptype $val" " =3D <4-byte integer>" + } else { + gdb_test "ptype $val" " =3D <8-byte integer>" + } } elseif {$lang =3D=3D "d"} { gdb_test "ptype $val" " =3D ulong" } elseif {$lang =3D=3D "rust"} { gdb_test "ptype $val" " =3D i64" } else { - gdb_test "ptype $val" " =3D unsigned long long" + gdb_test "ptype $val" " =3D $8B_type" } } } } =20 -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 =3D=3D "auto"} { + continue + } + test_parse_numbers $arch +}