public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/testsuite: Fix pretty-print.exp on big-endian platforms
@ 2019-10-01 17:21 Andreas Arnez
  0 siblings, 0 replies; only message in thread
From: Andreas Arnez @ 2019-10-01 17:21 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=53d666ecfbb18f836cd4cb9f1de7013e3d03f4df

commit 53d666ecfbb18f836cd4cb9f1de7013e3d03f4df
Author: Andreas Arnez <arnez@linux.ibm.com>
Date:   Tue Oct 1 19:20:29 2019 +0200

    gdb/testsuite: Fix pretty-print.exp on big-endian platforms
    
    The pretty-print test case fails on s390/s390x because it relies on a
    little-endian representation of bit fields.  Little-endian architectures
    typically allocate bit fields from least to most significant bit, but
    big-endian architectures typically use the reverse order, allocating the
    most significant bit first.  Thus the two bit fields in each of the test
    case's unions overlap either in their lower or in their higher bits,
    depending on the target's endianness:
    
        union {
          int three : 3;
          int four : 4;
        };
    
    Now, when initializing 'three' with 3, 'four' will become 3 on little
    endian targets, but 6 on big-endian targets, making it FAIL there.
    
    Fix this by initializing the longer bit field instead and using an
    all-ones bit pattern.  In this way the result does not depend on
    endianness.  Use 'unsigned' instead of int for one of the bit fields in
    each of the unions, to increase the variety of resulting values.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/pretty-print.c (struct s1_t): Change fields 'three' and
    	'six' to unsigned.
    	(s1): Initialize fields 'four' and 'six' instead of 'three' and
    	'five'.  Use an all-ones bit pattern for each.
    	* gdb.base/pretty-print.exp: Adjust expected output of "print s1"
    	to its changed values.

Diff:
---
 gdb/testsuite/ChangeLog                 | 9 +++++++++
 gdb/testsuite/gdb.base/pretty-print.c   | 8 +++++---
 gdb/testsuite/gdb.base/pretty-print.exp | 8 ++++----
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8420c39..1a20cda 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2019-10-01  Andreas Arnez  <arnez@linux.ibm.com>
+
+	* gdb.base/pretty-print.c (struct s1_t): Change fields 'three' and
+	'six' to unsigned.
+	(s1): Initialize fields 'four' and 'six' instead of 'three' and
+	'five'.  Use an all-ones bit pattern for each.
+	* gdb.base/pretty-print.exp: Adjust expected output of "print s1"
+	to its changed values.
+
 2019-09-30  Tom Tromey  <tromey@adacore.com>
 
 	* gdb.rust/traits.rs: Disable all warnings.
diff --git a/gdb/testsuite/gdb.base/pretty-print.c b/gdb/testsuite/gdb.base/pretty-print.c
index 9e241f8..fe15b85 100644
--- a/gdb/testsuite/gdb.base/pretty-print.c
+++ b/gdb/testsuite/gdb.base/pretty-print.c
@@ -23,16 +23,18 @@ struct s1_t
   struct
   {
     union {
-      int three : 3;
+      unsigned three : 3;
       int four : 4;
     };
 
     union {
       int five : 3;
-      int six : 4;
+      unsigned six : 4;
     };
   } data;
-} s1 = { .one = 1, .two = 2, .data = { .three = 3, .five = 5 } };
+} s1 = { .one = 1, .two = 2,
+	 /* Use all-ones bit patterns for endianness independence.  */
+	 .data = { .four = -1, .six = 15 } };
 
 struct s2_t
 {
diff --git a/gdb/testsuite/gdb.base/pretty-print.exp b/gdb/testsuite/gdb.base/pretty-print.exp
index 91e685e..02400e7 100644
--- a/gdb/testsuite/gdb.base/pretty-print.exp
+++ b/gdb/testsuite/gdb.base/pretty-print.exp
@@ -36,12 +36,12 @@ gdb_test "print s1" \
 	 "  two = 2," \
 	 "  data = {" \
 	 "    {" \
-	 "      three = 3," \
-	 "      four = 3" \
+	 "      three = 7," \
+	 "      four = -1" \
 	 "    }," \
 	 "    {" \
-	 "      five = -3," \
-	 "      six = 5" \
+	 "      five = -1," \
+	 "      six = 15" \
 	 "    }" \
 	 "  }" \
 	 "}" ]


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-10-01 17:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-01 17:21 [binutils-gdb] gdb/testsuite: Fix pretty-print.exp on big-endian platforms Andreas Arnez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).