Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Deuling <deuling@de.ibm.com>
To: GDB Patches <gdb-patches@sourceware.org>
Cc: Ulrich Weigand <uweigand@de.ibm.com>
Subject: [patch]: Add endianess to valprint routines
Date: Mon, 19 May 2008 15:19:00 -0000	[thread overview]
Message-ID: <48314BC3.4040207@de.ibm.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]

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


[-- Attachment #2: diff-vprint-endian --]
[-- Type: text/plain, Size: 5971 bytes --]

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

             reply	other threads:[~2008-05-19  9:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-19 15:19 Markus Deuling [this message]
2008-05-20 17:48 ` Ulrich Weigand
2008-05-21 16:45   ` Markus Deuling
2008-05-21 18:35     ` Ulrich Weigand
2008-05-23 16:32       ` Markus Deuling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48314BC3.4040207@de.ibm.com \
    --to=deuling@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox