From 60108e47b5b16b32a62eb32c5e6f929ab2cb5cf1 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Sat, 19 Dec 2020 16:43:17 +0100 Subject: [PATCH] [gdb/testsuite] Introduce supports_scalar_storage_order_attribute Introduce support test procs: - supports_scalar_storage_order_attribute, and - supports_gnuc and use them in test-case gdb.base/endianity.exp. Tested on x86_64-linux with gcc-7.5.0, gcc-4.8.5, and clang 10.0.1. gdb/testsuite/ChangeLog: 2020-12-19 Tom de Vries * lib/gdb.exp (supports_scalar_storage_order_attribute) (supports_gnuc): New proc. * gdb.base/endianity.exp: Define TEST_SSO. Eliminate test_compiler_info calls. Add unsupported message. * gdb.base/endianity.c: Use TEST_SSO. --- gdb/testsuite/ChangeLog | 8 +++++ gdb/testsuite/gdb.base/endianity.c | 2 +- gdb/testsuite/gdb.base/endianity.exp | 11 +++++-- gdb/testsuite/lib/gdb.exp | 46 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5b504526560..8bcc735b1ce 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2020-12-19 Tom de Vries + + * lib/gdb.exp (supports_scalar_storage_order_attribute) + (supports_gnuc): New proc. + * gdb.base/endianity.exp: Define TEST_SSO. Eliminate + test_compiler_info calls. Add unsupported message. + * gdb.base/endianity.c: Use TEST_SSO. + 2020-12-19 Hannes Domani PR exp/27070 diff --git a/gdb/testsuite/gdb.base/endianity.c b/gdb/testsuite/gdb.base/endianity.c index ef3b6d4fdb2..15cbdd9a265 100644 --- a/gdb/testsuite/gdb.base/endianity.c +++ b/gdb/testsuite/gdb.base/endianity.c @@ -26,7 +26,7 @@ struct otherendian __complex__ float cplx; double d; } -#if defined __GNUC__ && (__GNUC__ >= 6) +#if TEST_SSO #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ __attribute__( ( scalar_storage_order( "big-endian" ) ) ) #else diff --git a/gdb/testsuite/gdb.base/endianity.exp b/gdb/testsuite/gdb.base/endianity.exp index 4520799d04e..d54c1b6973a 100644 --- a/gdb/testsuite/gdb.base/endianity.exp +++ b/gdb/testsuite/gdb.base/endianity.exp @@ -15,7 +15,12 @@ standard_testfile .c -if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { +set test_sso [expr \ + [supports_scalar_storage_order_attribute] \ + && [supports_gnuc]] + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + [list debug additional_flags=-DTEST_SSO=$test_sso]] } { return -1 } @@ -37,12 +42,12 @@ gdb_test "print o.d = -23.125" "= -23.125" gdb_test "print o" "= {v = 4, w = 3, x = 2, f = 1.5, cplx = 1.25 \\+ 7.25i, d = -23.125}" \ "print o after assignment" -if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } { +if { !$test_sso } { # The rest of the testcase requires Scalar Storage Order support. # This compiler does not support it, so skip the rest. + unsupported "No scalar storage order support" return -1 } gdb_test "x/x &o.v" "0x04000000" gdb_test "x/xh &o.w" "0x0300" - diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index e812237d67a..e91023093e1 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7669,5 +7669,51 @@ gdb_caching_proc have_fuse_ld_gold { return [gdb_simple_compile $me $src executable $flags] } +# Return 1 if compiler supports scalar_storage_order attribute, otherwise +# return 0. +gdb_caching_proc supports_scalar_storage_order_attribute { + set me "supports_scalar_storage_order_attribute" + set src { + #include + struct sle { + int v; + } __attribute__((scalar_storage_order("little-endian"))); + struct sbe { + int v; + } __attribute__((scalar_storage_order("big-endian"))); + struct sle sle; + struct sbe sbe; + int main () { + sle.v = sbe.v = 0x11223344; + int same = memcmp (&sle, &sbe, sizeof (int)) == 0; + int sso = !same; + return sso; + } + } + if { ![gdb_simple_compile $me $src executable ""] } { + return 0 + } + + set result [remote_exec target $obj] + set status [lindex $result 0] + set output [lindex $result 1] + if { $output != "" } { + return 0 + } + + return $status +} + +# Return 1 if compiler supports __GNUC__, otherwise return 0. +gdb_caching_proc supports_gnuc { + set me "supports_gnuc" + set src { + #ifndef __GNUC__ + #error "No gnuc" + #endif + } + return [gdb_simple_compile $me $src object ""] +} + # Always load compatibility stuff. load_lib future.exp -- 2.30.2