gdb/testsuite: Fix pretty-print.exp on big-endian platforms

Message ID m3lfu54qin.fsf@oc0404454431.ibm.com
State New, archived
Headers

Commit Message

Andreas Arnez Sept. 30, 2019, 5:56 p.m. UTC
  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.
---
 gdb/testsuite/gdb.base/pretty-print.c   | 8 +++++---
 gdb/testsuite/gdb.base/pretty-print.exp | 8 ++++----
 2 files changed, 9 insertions(+), 7 deletions(-)
  

Comments

Tom Tromey Oct. 1, 2019, 5:07 p.m. UTC | #1
>>>>> "Andreas" == Andreas Arnez <arnez@linux.ibm.com> writes:

Andreas> 	* gdb.base/pretty-print.c (struct s1_t): Change fields 'three' and
Andreas> 	'six' to unsigned.
Andreas> 	(s1): Initialize fields 'four' and 'six' instead of 'three' and
Andreas> 	'five'.  Use an all-ones bit pattern for each.
Andreas> 	* gdb.base/pretty-print.exp: Adjust expected output of "print s1"
Andreas> 	to its changed values.

Thanks, this is ok.

Tom
  
Andreas Arnez Oct. 1, 2019, 5:23 p.m. UTC | #2
On Tue, Oct 01 2019, Tom Tromey wrote:

>>>>>> "Andreas" == Andreas Arnez <arnez@linux.ibm.com> writes:
>
> Andreas> 	* gdb.base/pretty-print.c (struct s1_t): Change fields 'three' and
> Andreas> 	'six' to unsigned.
> Andreas> 	(s1): Initialize fields 'four' and 'six' instead of 'three' and
> Andreas> 	'five'.  Use an all-ones bit pattern for each.
> Andreas> 	* gdb.base/pretty-print.exp: Adjust expected output of "print s1"
> Andreas> 	to its changed values.
>
> Thanks, this is ok.
>
> Tom

Thanks, pushed as commit #53d666ecfbb18f836cd4cb9f1de7013e3d03f4df.

--
Andreas
  

Patch

diff --git a/gdb/testsuite/gdb.base/pretty-print.c b/gdb/testsuite/gdb.base/pretty-print.c
index 9e241f8c67..fe15b85464 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 91e685e17c..02400e7615 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" \
 	 "    }" \
 	 "  }" \
 	 "}" ]