This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch]: Add endianess to valprint routines


Hi,

this patch adds a new endianess parameter to valprint routines print_hex_chars, print_octal_chars, print_decimal_chars,
print_binary_chars and print_char_chars. Those routines base upon endianess which they currently get via
gdbarch_byte_order.


I temporarely introduce gdbarch_byte_order in the two callers "print_scalar_formatted" and "val_print_type_code_int".
I'll come up with some more patches to improve printing routines in the near future. Then those current_gdbarch's will
disappear.

Tested on x86_64 without regression. Ok to commit ?

ChangeLog:

	* valprint.c (print_hex_chars, print_octal_chars, print_decimal_chars,
	print_binary_chars, print_char_chars): Add endianess parameter and
	replace gdbarch_byte_order.
	(val_print_type_code_int): Introduce gdbarch_byte_order to get at the
	endianness. Update call to print_hex_chars.
	* valprint.h (print_hex_chars, print_octal_chars, print_decimal_chars,
	print_binary_chars, print_char_chars): Add endianess parameter.
	* printcmd.c (print_scalar_formatted): Introduce gdbarch_byte_order to
	get at the endianness. Update print_*_char calls to use endianness.

Regards,
Markus

--
 Markus Deuling
 GNU Toolchain for Linux on Cell BE
 deuling@de.ibm.com

diff -urpN src/gdb/printcmd.c dev/gdb/printcmd.c
--- src/gdb/printcmd.c	2008-05-09 11:34:55.000000000 +0200
+++ dev/gdb/printcmd.c	2008-05-16 11:32:10.000000000 +0200
@@ -322,6 +322,7 @@ print_scalar_formatted (const void *vala
 {
   LONGEST val_long = 0;
   unsigned int len = TYPE_LENGTH (type);
+  enum bfd_endian endianness = gdbarch_byte_order (current_gdbarch);
 
   /* If we get here with a string format, try again without it.  Go
      all the way back to the language printers, which may call us
@@ -340,20 +341,20 @@ print_scalar_formatted (const void *vala
       switch (format)
 	{
 	case 'o':
-	  print_octal_chars (stream, valaddr, len);
+	  print_octal_chars (stream, valaddr, len, endianness);
 	  return;
 	case 'u':
 	case 'd':
-	  print_decimal_chars (stream, valaddr, len);
+	  print_decimal_chars (stream, valaddr, len, endianness);
 	  return;
 	case 't':
-	  print_binary_chars (stream, valaddr, len);
+	  print_binary_chars (stream, valaddr, len, endianness);
 	  return;
 	case 'x':
-	  print_hex_chars (stream, valaddr, len);
+	  print_hex_chars (stream, valaddr, len, endianness);
 	  return;
 	case 'c':
-	  print_char_chars (stream, valaddr, len);
+	  print_char_chars (stream, valaddr, len, endianness);
 	  return;
 	default:
 	  break;
diff -urpN src/gdb/valprint.c dev/gdb/valprint.c
--- src/gdb/valprint.c	2008-05-09 11:34:57.000000000 +0200
+++ dev/gdb/valprint.c	2008-05-16 11:30:49.000000000 +0200
@@ -313,6 +313,7 @@ void
 val_print_type_code_int (struct type *type, const gdb_byte *valaddr,
 			 struct ui_file *stream)
 {
+  enum bfd_endian endianness = gdbarch_byte_order (current_gdbarch);
   if (TYPE_LENGTH (type) > sizeof (LONGEST))
     {
       LONGEST val;
@@ -330,7 +331,7 @@ val_print_type_code_int (struct type *ty
 	     complement (a reasonable assumption, I think) and do
 	     better than this.  */
 	  print_hex_chars (stream, (unsigned char *) valaddr,
-			   TYPE_LENGTH (type));
+			   TYPE_LENGTH (type), endianness);
 	}
     }
   else
@@ -525,7 +526,7 @@ print_decimal_floating (const gdb_byte *
 
 void
 print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
-		    unsigned len)
+		    unsigned len, enum bfd_endian endianness)
 {
 
 #define BITS_IN_BYTES 8
@@ -541,7 +542,7 @@ print_binary_chars (struct ui_file *stre
 
   /* FIXME: We should be not printing leading zeroes in most cases.  */
 
-  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+  if (endianness == BFD_ENDIAN_BIG)
     {
       for (p = valaddr;
 	   p < valaddr + len;
@@ -585,7 +586,7 @@ print_binary_chars (struct ui_file *stre
  */
 void
 print_octal_chars (struct ui_file *stream, const gdb_byte *valaddr,
-		   unsigned len)
+		   unsigned len, enum bfd_endian endianness)
 {
   const gdb_byte *p;
   unsigned char octa1, octa2, octa3, carry;
@@ -628,7 +629,7 @@ print_octal_chars (struct ui_file *strea
   carry = 0;
 
   fputs_filtered ("0", stream);
-  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+  if (endianness == BFD_ENDIAN_BIG)
     {
       for (p = valaddr;
 	   p < valaddr + len;
@@ -733,7 +734,7 @@ print_octal_chars (struct ui_file *strea
  */
 void
 print_decimal_chars (struct ui_file *stream, const gdb_byte *valaddr,
-		     unsigned len)
+		     unsigned len, enum bfd_endian endianness)
 {
 #define TEN             10
 #define TWO_TO_FOURTH   16
@@ -741,11 +742,11 @@ print_decimal_chars (struct ui_file *str
 #define CARRY_LEFT( x ) ((x) % TEN)
 #define SHIFT( x )      ((x) << 4)
 #define START_P \
-        ((gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1)
+        ((endianness == BFD_ENDIAN_BIG) ? valaddr : valaddr + len - 1)
 #define NOT_END_P \
-        ((gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
+        ((endianness == BFD_ENDIAN_BIG) ? (p < valaddr + len) : (p >= valaddr))
 #define NEXT_P \
-        ((gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG) ? p++ : p-- )
+        ((endianness == BFD_ENDIAN_BIG) ? p++ : p-- )
 #define LOW_NIBBLE(  x ) ( (x) & 0x00F)
 #define HIGH_NIBBLE( x ) (((x) & 0x0F0) >> 4)
 
@@ -868,14 +869,14 @@ print_decimal_chars (struct ui_file *str
 
 void
 print_hex_chars (struct ui_file *stream, const gdb_byte *valaddr,
-		 unsigned len)
+		 unsigned len, enum bfd_endian endianness)
 {
   const gdb_byte *p;
 
   /* FIXME: We should be not printing leading zeroes in most cases.  */
 
   fputs_filtered ("0x", stream);
-  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+  if (endianness == BFD_ENDIAN_BIG)
     {
       for (p = valaddr;
 	   p < valaddr + len;
@@ -900,11 +901,11 @@ print_hex_chars (struct ui_file *stream,
 
 void
 print_char_chars (struct ui_file *stream, const gdb_byte *valaddr,
-		  unsigned len)
+		  unsigned len, enum bfd_endian endianness)
 {
   const gdb_byte *p;
 
-  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+  if (endianness == BFD_ENDIAN_BIG)
     {
       p = valaddr;
       while (p < valaddr + len - 1 && *p == 0)
diff -urpN src/gdb/valprint.h dev/gdb/valprint.h
--- src/gdb/valprint.h	2008-01-01 23:53:13.000000000 +0100
+++ dev/gdb/valprint.h	2008-05-16 11:31:05.000000000 +0200
@@ -69,17 +69,17 @@ extern void val_print_type_code_flags (s
 				       struct ui_file *stream);
 
 extern void print_binary_chars (struct ui_file *, const gdb_byte *,
-				unsigned int);
+				unsigned int, enum bfd_endian);
 
 extern void print_octal_chars (struct ui_file *, const gdb_byte *,
-			       unsigned int);
+			       unsigned int, enum bfd_endian);
 
 extern void print_decimal_chars (struct ui_file *, const gdb_byte *,
-				 unsigned int);
+				 unsigned int, enum bfd_endian);
 
 extern void print_hex_chars (struct ui_file *, const gdb_byte *,
-			     unsigned int);
+			     unsigned int, enum bfd_endian);
 
 extern void print_char_chars (struct ui_file *, const gdb_byte *,
-			      unsigned int);
+			      unsigned int, enum bfd_endian);
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]