From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OULaE/E+0l/GQgAAWB0awg (envelope-from ) for ; Thu, 10 Dec 2020 10:29:53 -0500 Received: by simark.ca (Postfix, from userid 112) id 4322C1F0A9; Thu, 10 Dec 2020 10:29:53 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C9F891E552 for ; Thu, 10 Dec 2020 10:29:52 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F8883836C08; Thu, 10 Dec 2020 15:29:52 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 512CD3836C08 for ; Thu, 10 Dec 2020 15:29:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 512CD3836C08 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6E020AC6A for ; Thu, 10 Dec 2020 15:29:48 +0000 (UTC) Date: Thu, 10 Dec 2020 16:29:46 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/testsuite] Fix gdb.base/endianity.exp with gcc-4.8 Message-ID: <20201210152945.GA16462@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, When running test-case gdb.base/endianity.exp using gcc-4.8, we get: ... (gdb) x/x &o.v^M 0x7fffffffd120: 0x00000004^M (gdb) XFAIL: gdb.base/endianity.exp: x/x &o.v x/xh &o.w^M 0x7fffffffd124: 0x0003^M (gdb) FAIL: gdb.base/endianity.exp: x/xh &o.w ... The gcc 4.8 compiler does not support the scalar_storage_order attribute, so the testcase is compiled without that attribute, and the expected results are different. This is why there's the first XFAIL, and we could xfail the second FAIL for the same reason. Instead, fix this by adapting the expected values based on whether the attribute has been used in endianity.c. Also, remove hard-coding of the byte order in the expected memory printing. Tested on x86_64-linux, with gcc-4.8, gcc-7, and clang-10. Any comments? Thanks, - Tom [gdb/testsuite] Fix gdb.base/endianity.exp with gcc-4.8 gdb/testsuite/ChangeLog: 2020-12-10 Tom de Vries PR testsuite/26953 * gdb.base/endianity.c (ORDER_ATTR): New macro. (reverse): New variable. (struct otherendian): Use ORDER_ATTR. * gdb.base/endianity.exp: Use reverse variable to see if scalar_storage_order attribute was used. Remove hard-coding of byte order in expected memory printing. --- gdb/testsuite/gdb.base/endianity.c | 34 ++++++++++++++++------ gdb/testsuite/gdb.base/endianity.exp | 56 ++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 14 deletions(-) diff --git a/gdb/testsuite/gdb.base/endianity.c b/gdb/testsuite/gdb.base/endianity.c index ef3b6d4fdb..2bc3d09502 100644 --- a/gdb/testsuite/gdb.base/endianity.c +++ b/gdb/testsuite/gdb.base/endianity.c @@ -17,6 +17,27 @@ /* This tests the handling of dwarf attributes: DW_AT_endianity, DW_END_big, and DW_END_little. */ + + +#if defined __GNUC__ && (__GNUC__ >= 6) +/* Scalar_storage_order attribute supported. */ +int reverse = 1; + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define ORDER_ATTR \ + __attribute__( ( scalar_storage_order( "big-endian" ) ) ) +#else +#define ORDER_ATTR \ + __attribute__( ( scalar_storage_order( "little-endian" ) ) ) +#endif + +#else + +#define ORDER_ATTR +int reverse = 0; + +#endif + struct otherendian { int v; @@ -25,21 +46,16 @@ struct otherendian float f; __complex__ float cplx; double d; -} -#if defined __GNUC__ && (__GNUC__ >= 6) -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -__attribute__( ( scalar_storage_order( "big-endian" ) ) ) -#else -__attribute__( ( scalar_storage_order( "little-endian" ) ) ) -#endif -#endif -; +} ORDER_ATTR; void do_nothing (struct otherendian *c) { } +int v = 4; +short w = 3; + int main (void) { diff --git a/gdb/testsuite/gdb.base/endianity.exp b/gdb/testsuite/gdb.base/endianity.exp index 2fa9ed3bf1..3f39be9239 100644 --- a/gdb/testsuite/gdb.base/endianity.exp +++ b/gdb/testsuite/gdb.base/endianity.exp @@ -34,12 +34,58 @@ gdb_test "print o.x = 2" "= 2" gdb_test "print o.f = 1.5" "= 1.5" gdb_test "print o.d = -23.125" "= -23.125" -# scalar_storage_order requires gcc >= 6 -if { ([test_compiler_info {gcc-[0-5]-*}] || ![test_compiler_info gcc*]) } { - setup_xfail "*-*-*" +proc reverse_hex { val } { + set r {} + foreach {a b} [split $val {}] { + set two "$a$b" + if { "$two" == "0x" } { + continue + } + lappend r "$two" + } + set r [lreverse $r] + set r [join $r ""] + return "0x$r" +} + +set reverse -1 +gdb_test_multiple "p reverse" "" { + -re -wrap "= 1" { + set reverse 1 + } + -re -wrap "= 0" { + set reverse 0 + } +} + +if { $reverse != -1 } { + + gdb_test_multiple "x/x &v" "" { + -wrap -re "$hex :.*($hex)" { + set v $expect_out(1,string) + pass $gdb_test_name + if { $reverse } { + set o_v [reverse_hex $v] + } else { + set o_v $v + } + gdb_test "x/x &o.v" $o_v + } + } + + gdb_test_multiple "x/xh &w" "" { + -wrap -re "$hex :.*($hex)" { + set w $expect_out(1,string) + pass $gdb_test_name + if { $reverse } { + set o_w [reverse_hex $w] + } else { + set o_w $w + } + gdb_test "x/xh &o.w" $o_w + } + } } -gdb_test "x/x &o.v" "0x04000000" -gdb_test "x/xh &o.w" "0x0300" 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"