[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gdb-patches
Subject:    [PATCH] gdb/testsuite: Fix py-format-string.exp on big-endian platforms
From:       arnez () linux ! ibm ! com (Andreas Arnez)
Date:       2019-09-30 18:07:00
Message-ID: m3h84t4q05.fsf () oc0404454431 ! ibm ! com
[Download RAW message or body]

GDB's py-format-string test case depends on endianness.  In particular it
relies on the first byte of the machine representation of 42 (as an int)
to be 42 as well.  While this is indeed the case for little-endian
machines, big-endian machines store a zero in the first byte instead.  The
wrong assumption leads to lots of FAILs on such architectures.

Fix this by using a 'palindrome' integer instead, i.e., one that has the
same machine representation on little- and big-endian architectures.  Use
the value 0x2a00002a, such that the expected character in the first byte
remains the same as before.

gdb/testsuite/ChangeLog:

	* gdb.python/py-format-string.c (main): Initialize
	a_struct_with_union.the_union.an_int with a "palindrome" integer
	instead of just 42, for endianness-independence.
	* gdb.python/py-format-string.exp (default_regexp_dict)
	(test_pretty_structs, test_format): Adjust expected output to the
	changed integer value.
---
 gdb/testsuite/gdb.python/py-format-string.c   | 3 ++-
 gdb/testsuite/gdb.python/py-format-string.exp | 8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-format-string.c \
b/gdb/testsuite/gdb.python/py-format-string.c index 120ecce989..f2cac280af 100644
--- a/gdb/testsuite/gdb.python/py-format-string.c
+++ b/gdb/testsuite/gdb.python/py-format-string.c
@@ -84,7 +84,8 @@ main ()
   struct point another_point = { 123, 456 };
 
   struct_union_t a_struct_with_union;
-  a_struct_with_union.the_union.an_int = 42;
+  /* Choose a value whose first byte (little-/big-endian) is 42.  */
+  a_struct_with_union.the_union.an_int = 0x2a00002a;
 
   enum_t an_enum = ENUM_BAR;
 
diff --git a/gdb/testsuite/gdb.python/py-format-string.exp \
b/gdb/testsuite/gdb.python/py-format-string.exp index ebb2074ce8..5512b54e00 100644
--- a/gdb/testsuite/gdb.python/py-format-string.exp
+++ b/gdb/testsuite/gdb.python/py-format-string.exp
@@ -124,7 +124,7 @@ set default_regexp_dict [dict create \
   "a_point_t_pointer"		$default_pointer_regexp \
   "a_point_t_ref"		"Pretty Point \\(42, 12\\)" \
   "another_point"		"Pretty Point \\(123, 456\\)" \
-  "a_struct_with_union"		"\\{the_union = \\{an_int = 42, a_char = 42 '\\*'\\}\\}" \
+  "a_struct_with_union"		"\\{the_union = \\{an_int = 704643114, a_char = 42 \
'\\*'\\}\\}" \  "an_enum"			"ENUM_BAR" \
   "a_string"			"${default_pointer_regexp} \"hello world\"" \
   "a_binary_string"		"${default_pointer_regexp} \"hello\"" \
@@ -333,7 +333,7 @@ proc test_pretty_structs {} {
   global current_lang
 
   set a_struct_with_union_pretty \
-    "\\{\[\r\n\]+  the_union = \\{\[\r\n\]+    an_int = 42,\[\r\n\]+    a_char = 42 \
'\\*'\[\r\n\]+  \\}\[\r\n\]+\\}" +    "\\{\[\r\n\]+  the_union = \\{\[\r\n\]+    \
an_int = 704643114,\[\r\n\]+    a_char = 42 '\\*'\[\r\n\]+  \\}\[\r\n\]+\\}"  
   check_var_with_bool_opt "pretty_structs" "a_point_t"
   check_var_with_bool_opt "pretty_structs" "a_point_t_pointer"
@@ -814,7 +814,7 @@ proc test_format {} {
     check_format_string "a_point_t_pointer" $opts
     check_format_string "another_point" $opts
     check_format_string "a_struct_with_union" $opts \
-      "\\{the_union = \\{an_int = 0x2a, a_char = 0x2a\\}\\}"
+      "\\{the_union = \\{an_int = 0x2a00002a, a_char = 0x2a\\}\\}"
     check_format_string "an_enum" $opts \
       "0x1"
     check_format_string "a_string" $opts \
@@ -851,7 +851,7 @@ proc test_format {} {
       $decimal_pointer_regexp
     check_format_string "another_point" $opts
     check_format_string "a_struct_with_union" $opts \
-      "\\{the_union = \\{an_int = 42, a_char = 42\\}\\}"
+      "\\{the_union = \\{an_int = 704643114, a_char = 42\\}\\}"
     check_format_string "an_enum" $opts \
       "1"
     check_format_string "a_string" $opts \
-- 
2.22.0


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic