This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

[RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header)


  This patch RFC is follow up of the
thread concerning problems with the act that
readelf defines BFD64 under other conditions 
than dwarf.c leading to potential problems.

  The idea is to completely remove bfd_vma and dwarf_signed_vma 
from dwarf.h and dwarf.c sources.

  The patch is pretty mechanical, but there are several 
points that probably needs discussion:

 1) This basically makes use of 8-byte for dwarf_vma and dwarf_signed_vma
for almost all modern machines/compilers.
  It could still impact performance for system where int64
computation is slow, I have no idea if this can really be a problem or not.

2) I also tried to remove (long) and (unsigned long) types
whenever they seemed to me to be used for something that could
be a target address or offset and replaced it by a dwarf_{signed_}vma type.
(This is also related to the Mingw64 target issue for
which 'long' is 4-byte whereas 'void *' is 8-byte).
But I might not have caught all occurrences and might have
misunderstood some other cases.
  An example is the address field of the Machine_State_Registers,
I don't know if this relates really to a target address...

  Another important point is that I have no machine
that can run the testsuite on my patch, so that it might very well
introduce regression that I am unaware of.

  Anyhow, I will be pleased to get comments
on this patch.


Pierre Muller
GDB pascal language maintainer





2011-02-25  Pierre Muller  <muller@ics.u-strasbg.fr>

	Replace bfd_vma type and analog types by dwarf_vma and analogs.
	Use dwarf specific print functions to display these type values.
	* dwarf.h (dwarf_signed_vma): New type;
	(DWARF2_External_LineInfo): Replace bfd_vma by dwarf_vma.
	(DWARF2_External_PubNames): Likewise.
	(DWARF2_External_CompUnit): Likewise.
	(DWARF2_External_ARange): Likewise.
	(read_leb128): Change return type to dwarf_vma.
	* dwarf.c (print_dwarf_vma): Check byte_size values.
	(dwarf_vmatoa): Change parameter type to dwarf_vma.
	(dwarf_svmatoa): New static function.
	(read_leb128): Change return type to dwarf_vma.
	(read_sleb128): New static function.
	(struct State_Machine_Registers): Change address field type to
	dwarf_vma.
	(process_extended_line_op): Adapt to type changes.
	(fetch_indirect_string): Likewise.
	(idisplay_block): Likewise.
	(decode_location_expression): Likewise.
	(read_and_display_attr_value): Likewise.
	(process_debug_info): Likewise.
	(display_debug_lines_raw): Likewise.
	(display_debug_lines_decoded): Likewise.
	(SLEB macro): Use new read_sleb128 function.

Index: binutils/dwarf.c
===================================================================
RCS file: /cvs/src/src/binutils/dwarf.c,v
retrieving revision 1.84
diff -u -p -r1.84 dwarf.c
--- binutils/dwarf.c	23 Feb 2011 08:52:33 -0000	1.84
+++ binutils/dwarf.c	25 Feb 2011 10:12:30 -0000
@@ -106,6 +106,7 @@ static void
 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
 {
   static char buff[18];
+  int offset;
 
   /* Printf does not have a way of specifiying a maximum field width for an
      integer value, so we print the full value into a buffer and then
select
@@ -120,11 +121,29 @@ print_dwarf_vma (dwarf_vma val, unsigned
   snprintf (buff, sizeof (buff), "%16.16lx ", val);
 #endif
 
-  fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
+  if (byte_size == 0)
+    offset = 0;
+  else
+    if (byte_size > 0 && byte_size <=8)
+      offset = 16 - 2 * byte_size;
+    else
+      error("Wrong size in print_dwarf_vma");
+
+  fputs (buff + offset, stdout);
 }
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+#ifndef __MSVCRT__
+#define  DWARF_VMA_FMT "ll"
+#else
+#define  DWARF_VMA_FMT "I64"
+#endif
+#else
+#define  DWARF_VMA_FMT "l"
+#endif
+
 static const char *
-dwarf_vmatoa (const char *fmtch, bfd_vma value)
+dwarf_vmatoa (const char *fmtch, dwarf_vma value)
 {
   /* As dwarf_vmatoa is used more then once in a printf call
      for output, we are cycling through an fixed array of pointers
@@ -136,7 +155,7 @@ dwarf_vmatoa (const char *fmtch, bfd_vma
   char fmt[32];
   char *ret;
 
-  sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
+  sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
 
   ret = buf[buf_pos++].place;
   buf_pos %= ARRAY_SIZE(buf);
@@ -146,10 +165,33 @@ dwarf_vmatoa (const char *fmtch, bfd_vma
   return ret;
 }
 
-bfd_vma
+static char *
+dwarf_svmatoa (const char *fmtch, dwarf_signed_vma value)
+{
+  /* As dwarf_vmatoa is used more then once in a printf call
+     for output, we are cycling through an fixed array of pointers
+     for return address.  */
+  static int buf_pos = 0;
+  static struct dwarf_vmatoa_buf {
+    char place[64];
+  } buf[16];
+  char fmt[32];
+  char *ret;
+
+  sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
+
+  ret = buf[buf_pos++].place;
+  buf_pos %= ARRAY_SIZE(buf);
+
+  snprintf (ret, sizeof (buf[0].place), fmt, value);
+
+  return ret;
+}
+
+dwarf_vma
 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
-  bfd_vma result = 0;
+  dwarf_vma result = 0;
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte;
@@ -159,7 +201,7 @@ read_leb128 (unsigned char *data, unsign
       byte = *data++;
       num_read++;
 
-      result |= ((bfd_vma) (byte & 0x7f)) << shift;
+      result |= ((dwarf_vma) (byte & 0x7f)) << shift;
 
       shift += 7;
 
@@ -175,9 +217,16 @@ read_leb128 (unsigned char *data, unsign
   return result;
 }
 
-typedef struct State_Machine_Registers
+/* Create a signed version to avoid painful typecasts.  */
+static dwarf_signed_vma
+read_sleb128 (unsigned char *data, unsigned int *length_return)
+{
+  return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
+}
+
+ typedef struct State_Machine_Registers
 {
-  unsigned long address;
+  dwarf_vma address;
   unsigned int file;
   unsigned int line;
   unsigned int column;
@@ -216,7 +265,7 @@ process_extended_line_op (unsigned char 
   unsigned int bytes_read;
   unsigned int len;
   unsigned char *name;
-  bfd_vma adr;
+  dwarf_vma adr;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -253,19 +302,17 @@ process_extended_line_op (unsigned char 
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
       name = data;
       data += strlen ((char *) data) + 1;
-      printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read,
0)));
       data += bytes_read;
-      printf ("%" BFD_VMA_FMT "u\t",
-	      read_leb128 (data, & bytes_read, 0));
+      printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read,
0)));
       data += bytes_read;
-      printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read,
0)));
       printf ("%s\n\n", name);
       break;
 
     case DW_LNE_set_discriminator:
       printf (_("set Discriminator to %s\n"),
-	      dwarf_vmatoa ("u",
-			    read_leb128 (data, & bytes_read, 0)));
+	      dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
       break;
 
     /* HP extensions.  */
@@ -316,7 +363,7 @@ process_extended_line_op (unsigned char 
 }
 
 static const char *
-fetch_indirect_string (bfd_vma offset)
+fetch_indirect_string (dwarf_vma offset)
 {
   struct dwarf_section *section = &debug_displays [str].section;
 
@@ -327,7 +374,8 @@ fetch_indirect_string (bfd_vma offset)
   offset -= section->address;
   if (offset > section->size)
     {
-      warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset);
+      warn (_("DW_FORM_strp offset too big: %s\n"),
+	    dwarf_vmatoa ("x", offset));
       return _("<offset is too big>");
     }
 
@@ -615,9 +663,9 @@ get_FORM_name (unsigned long form)
 }
 
 static unsigned char *
-display_block (unsigned char *data, unsigned long length)
+display_block (unsigned char *data, dwarf_vma length)
 {
-  printf (_(" %lu byte block: "), length);
+  printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
 
   while (length --)
     printf ("%lx ", (unsigned long) byte_get (data++, 1));
@@ -630,13 +678,13 @@ decode_location_expression (unsigned cha
 			    unsigned int pointer_size,
 			    unsigned int offset_size,
 			    int dwarf_version,
-			    bfd_vma length,
-			    bfd_vma cu_offset,
+			    dwarf_vma length,
+			    dwarf_vma cu_offset,
 			    struct dwarf_section * section)
 {
   unsigned op;
   unsigned int bytes_read;
-  bfd_vma uvalue;
+  dwarf_vma uvalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
 
@@ -687,13 +735,13 @@ decode_location_expression (unsigned cha
 	  data += 8;
 	  break;
 	case DW_OP_constu:
-	  printf ("DW_OP_constu: %" BFD_VMA_FMT "u",
-		  read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_constu: %s",
+		  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_consts:
-	  printf ("DW_OP_consts: %" BFD_VMA_FMT "d",
-		  read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_consts: %s",
+		  dwarf_svmatoa ("d", read_sleb128 (data, &bytes_read)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_dup:
@@ -748,8 +796,8 @@ decode_location_expression (unsigned cha
 	  printf ("DW_OP_plus");
 	  break;
 	case DW_OP_plus_uconst:
-	  printf ("DW_OP_plus_uconst: %" BFD_VMA_FMT "u",
-		  read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_plus_uconst: %s",
+		  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_shl:
@@ -894,36 +942,37 @@ decode_location_expression (unsigned cha
 	case DW_OP_breg29:
 	case DW_OP_breg30:
 	case DW_OP_breg31:
-	  printf ("DW_OP_breg%d (%s): %" BFD_VMA_FMT "d",
+	  printf ("DW_OP_breg%d (%s): %s",
 		  op - DW_OP_breg0,
 		  regname (op - DW_OP_breg0, 1),
-		  read_leb128 (data, &bytes_read, 1));
+		  dwarf_svmatoa ("d", (dwarf_signed_vma) 
+		    read_leb128 (data, &bytes_read, 1)));
 	  data += bytes_read;
 	  break;
 
 	case DW_OP_regx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_regx: %" BFD_VMA_FMT "u (%s)",
-		  uvalue, regname (uvalue, 1));
+	  printf ("DW_OP_regx: %s (%s)",
+		  dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
 	  break;
 	case DW_OP_fbreg:
 	  need_frame_base = 1;
-	  printf ("DW_OP_fbreg: %" BFD_VMA_FMT "d",
-		  read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_fbreg: %s",
+		  dwarf_svmatoa ("d", read_sleb128 (data, &bytes_read)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_bregx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_bregx: %" BFD_VMA_FMT "u (%s) %" BFD_VMA_FMT "d",
-		  uvalue, regname (uvalue, 1),
-		  read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_bregx: %s (%s) %s",
+		  dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
+		  dwarf_svmatoa ("d", read_sleb128 (data, &bytes_read)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_piece:
-	  printf ("DW_OP_piece: %" BFD_VMA_FMT "u",
-		  read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_piece: %s",
+		  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_deref_size:
@@ -943,15 +992,17 @@ decode_location_expression (unsigned cha
 	case DW_OP_call2:
 	  /* XXX: Strictly speaking for 64-bit DWARF3 files
 	     this ought to be an 8-byte wide computation.  */
-	  printf ("DW_OP_call2: <0x%" BFD_VMA_FMT "x>",
-		  (bfd_signed_vma) byte_get (data, 2) + cu_offset);
+	  printf ("DW_OP_call2: <0x%s>",
+		  dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
+				     + cu_offset));
 	  data += 2;
 	  break;
 	case DW_OP_call4:
 	  /* XXX: Strictly speaking for 64-bit DWARF3 files
 	     this ought to be an 8-byte wide computation.  */
-	  printf ("DW_OP_call4: <0x%" BFD_VMA_FMT "x>",
-		  (bfd_signed_vma) byte_get (data, 4) + cu_offset);
+	  printf ("DW_OP_call4: <0x%s>",
+		  dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
+				     + cu_offset));
 	  data += 4;
 	  break;
 	case DW_OP_call_ref:
@@ -965,14 +1016,14 @@ decode_location_expression (unsigned cha
 	    }
 	  if (dwarf_version == 2)
 	    {
-	      printf ("DW_OP_call_ref: <0x%lx>",
-		      (long) byte_get (data, pointer_size));
+	      printf ("DW_OP_call_ref: <0x%s>",
+		      dwarf_vmatoa ("x", byte_get (data, pointer_size)));
 	      data += pointer_size;
 	    }
 	  else
 	    {
-	      printf ("DW_OP_call_ref: <0x%lx>",
-		      (long) byte_get (data, offset_size));
+	      printf ("DW_OP_call_ref: <0x%s>",
+		      dwarf_vmatoa ("x", byte_get (data, offset_size)));
 	      data += offset_size;
 	    }
 	  break;
@@ -984,11 +1035,11 @@ decode_location_expression (unsigned cha
 	  break;
 	case DW_OP_bit_piece:
 	  printf ("DW_OP_bit_piece: ");
-	  printf ("size: %" BFD_VMA_FMT "u ",
-		  read_leb128 (data, &bytes_read, 0));
+	  printf ("size: %s ",
+		  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
 	  data += bytes_read;
-	  printf ("offset: %" BFD_VMA_FMT "u ",
-		  read_leb128 (data, &bytes_read, 0));
+	  printf ("offset: %s ",
+		  dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
 	  data += bytes_read;
 	  break;
 
@@ -1037,20 +1088,18 @@ decode_location_expression (unsigned cha
 	    }
 	  if (dwarf_version == 2)
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: "
-		      "<0x%" BFD_VMA_FMT "x> %" BFD_VMA_FMT "d",
-		      (bfd_vma) byte_get (data, pointer_size),
-		      (bfd_signed_vma) read_leb128 (data + pointer_size,
-						&bytes_read, 1));
+	      printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
+		      dwarf_vmatoa ("x", byte_get (data, pointer_size)),
+		      dwarf_svmatoa ("d", read_sleb128 (data + pointer_size,
+				     &bytes_read)));
 	      data += pointer_size + bytes_read;
 	    }
 	  else
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: "
-		      "<0x%" BFD_VMA_FMT "x> %" BFD_VMA_FMT "d",
-		      (bfd_vma) byte_get (data, offset_size),
-		      (bfd_signed_vma) read_leb128 (data + offset_size,
-						&bytes_read, 1));
+	      printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
+		      dwarf_vmatoa ("x", byte_get (data, offset_size)),
+		      dwarf_svmatoa ("d", read_sleb128 (data + offset_size,
+				     &bytes_read)));
 	      data += offset_size + bytes_read;
 	    }
 	  break;
@@ -1112,15 +1161,15 @@ static unsigned char *
 read_and_display_attr_value (unsigned long attribute,
 			     unsigned long form,
 			     unsigned char * data,
-			     bfd_vma cu_offset,
-			     bfd_vma pointer_size,
-			     bfd_vma offset_size,
+			     dwarf_vma cu_offset,
+			     dwarf_vma pointer_size,
+			     dwarf_vma offset_size,
 			     int dwarf_version,
 			     debug_info * debug_info_p,
 			     int do_loc,
 			     struct dwarf_section * section)
 {
-  bfd_vma uvalue = 0;
+  dwarf_vma uvalue = 0;
   unsigned char *block_start = NULL;
   unsigned char * orig_data = data;
   unsigned int bytes_read;
@@ -1207,7 +1256,7 @@ read_and_display_attr_value (unsigned lo
     {
     case DW_FORM_ref_addr:
       if (!do_loc)
-	printf (" <0x%" BFD_VMA_FMT "x>", uvalue);
+	printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
       break;
 
     case DW_FORM_ref1:
@@ -1215,14 +1264,14 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_ref4:
     case DW_FORM_ref_udata:
       if (!do_loc)
-	printf (" <0x%" BFD_VMA_FMT "x>", uvalue + cu_offset);
+	printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
       break;
 
     case DW_FORM_data4:
     case DW_FORM_addr:
     case DW_FORM_sec_offset:
       if (!do_loc)
-	printf (" 0x%" BFD_VMA_FMT "x", uvalue);
+	printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
       break;
 
     case DW_FORM_flag_present:
@@ -1232,7 +1281,7 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_sdata:
     case DW_FORM_udata:
       if (!do_loc)
-	printf (" %" BFD_VMA_FMT "d", uvalue);
+	printf (" %s", dwarf_vmatoa ("d", uvalue));
       break;
 
     case DW_FORM_ref8:
@@ -1240,7 +1289,7 @@ read_and_display_attr_value (unsigned lo
       if (!do_loc)
 	{
 	  uvalue = byte_get (data, 4);
-	  printf (" 0x%" BFD_VMA_FMT "x", uvalue);
+	  printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
 	  printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
 	}
       if ((do_loc || do_debug_loc || do_debug_ranges)
@@ -1249,7 +1298,7 @@ read_and_display_attr_value (unsigned lo
 	  if (sizeof (uvalue) == 8)
 	    uvalue = byte_get (data, 8);
 	  else
-	    error (_("DW_FORM_data8 is unsupported when sizeof (bfd_vma) !=
8\n"));
+	    error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma)
!= 8\n"));
 	}
       data += 8;
       break;
@@ -1354,7 +1403,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->loc_offsets = (bfd_vma *)
+		  debug_info_p->loc_offsets = (dwarf_vma *)
                       xcrealloc (debug_info_p->loc_offsets,
 				 lmax, sizeof (*debug_info_p->loc_offsets));
 		  debug_info_p->have_frame_base = (int *)
@@ -1385,7 +1434,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->range_lists = (bfd_vma *)
+		  debug_info_p->range_lists = (dwarf_vma *)
                       xcrealloc (debug_info_p->range_lists,
 				 lmax, sizeof (*debug_info_p->range_lists));
 		  debug_info_p->max_range_lists = lmax;
@@ -1463,9 +1512,10 @@ read_and_display_attr_value (unsigned lo
 	case DW_LANG_Upc:		printf ("(Unified Parallel C)");
break;
 	default:
 	  if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
-	    printf ("(implementation defined: %" BFD_VMA_FMT "x)", uvalue);
+	    printf ("(implementation defined: %s)", 
+		    dwarf_vmatoa ("x", uvalue));
 	  else
-	    printf ("(Unknown: %" BFD_VMA_FMT "x)", uvalue);
+	    printf ("(Unknown: %s)", dwarf_vmatoa("x", uvalue));
 	  break;
 	}
       break;
@@ -1829,9 +1879,9 @@ static unsigned char *
 read_and_display_attr (unsigned long attribute,
 		       unsigned long form,
 		       unsigned char * data,
-		       bfd_vma cu_offset,
-		       bfd_vma pointer_size,
-		       bfd_vma offset_size,
+		       dwarf_vma cu_offset,
+		       dwarf_vma pointer_size,
+		       dwarf_vma offset_size,
 		       int dwarf_version,
 		       debug_info * debug_info_p,
 		       int do_loc,
@@ -1943,7 +1993,7 @@ process_debug_info (struct dwarf_section
       unsigned char *hdrptr;
       unsigned char *tags;
       int level;
-      bfd_vma cu_offset;
+      dwarf_vma cu_offset;
       int offset_size;
       int initial_length_size;
       unsigned char signature[8] = { 0 };
@@ -2378,14 +2428,14 @@ display_debug_lines_raw (struct dwarf_se
 
 	      data += strlen ((char *) data) + 1;
 
-	      printf ("%" BFD_VMA_FMT "u\t",
-		      read_leb128 (data, & bytes_read, 0));
+	      printf ("%s\t",
+		      dwarf_vmatoa ("u", read_leb128 (data, & bytes_read,
0)));
 	      data += bytes_read;
-	      printf ("%" BFD_VMA_FMT "u\t",
-		      read_leb128 (data, & bytes_read, 0));
+	      printf ("%s\t",
+		      dwarf_vmatoa ("u", read_leb128 (data, & bytes_read,
0)));
 	      data += bytes_read;
-	      printf ("%" BFD_VMA_FMT "u\t",
-		      read_leb128 (data, & bytes_read, 0));
+	      printf ("%s\t",
+		      dwarf_vmatoa ("u", read_leb128 (data, & bytes_read,
0)));
 	      data += bytes_read;
 	      printf ("%s\n", name);
 	    }
@@ -2400,8 +2450,8 @@ display_debug_lines_raw (struct dwarf_se
       while (data < end_of_sequence)
 	{
 	  unsigned char op_code;
-	  int adv;
-	  unsigned long int uladv;
+	  dwarf_signed_vma adv;
+	  dwarf_vma uladv;
 	  unsigned int bytes_read;
 
 	  op_code = *data++;
@@ -2414,8 +2464,10 @@ display_debug_lines_raw (struct dwarf_se
 		{
 		  uladv *= linfo.li_min_insn_length;
 		  state_machine_regs.address += uladv;
-		  printf (_("  Special opcode %d: advance Address by %lu to
0x%lx"),
-			  op_code, uladv, state_machine_regs.address);
+		  printf (_("  Special opcode %d: "
+			    "advance Address by %s to 0x%s"),
+			  op_code, dwarf_vmatoa ("u", uladv),
+			  dwarf_vmatoa ("x", state_machine_regs.address));
 		}
 	      else
 		{
@@ -2426,14 +2478,16 @@ display_debug_lines_raw (struct dwarf_se
 		  state_machine_regs.op_index
 		    = (state_machine_regs.op_index + uladv)
 		      % linfo.li_max_ops_per_insn;
-		  printf (_("  Special opcode %d: advance Address by %lu to
0x%lx[%d]"),
-			  op_code, uladv, state_machine_regs.address,
+		  printf (_("  Special opcode %d: "
+			    "advance Address by %s to 0x%s[%d]"),
+			  op_code, dwarf_vmatoa ("u", uladv),
+			  dwarf_vmatoa ("x", state_machine_regs.address),
 			  state_machine_regs.op_index);
 		}
 	      adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
 	      state_machine_regs.line += adv;
-	      printf (_(" and Line by %d to %d\n"),
-		      adv, state_machine_regs.line);
+	      printf (_(" and Line by %s to %d\n"),
+		      dwarf_vmatoa ("d", adv), state_machine_regs.line);
 	    }
 	  else switch (op_code)
 	    {
@@ -2452,8 +2506,9 @@ display_debug_lines_raw (struct dwarf_se
 		{
 		  uladv *= linfo.li_min_insn_length;
 		  state_machine_regs.address += uladv;
-		  printf (_("  Advance PC by %lu to 0x%lx\n"), uladv,
-			  state_machine_regs.address);
+		  printf (_("  Advance PC by %s to 0x%s\n"),
+			  dwarf_vmatoa ("u", uladv),
+			  dwarf_vmatoa ("x", state_machine_regs.address));
 		}
 	      else
 		{
@@ -2464,39 +2519,42 @@ display_debug_lines_raw (struct dwarf_se
 		  state_machine_regs.op_index
 		    = (state_machine_regs.op_index + uladv)
 		      % linfo.li_max_ops_per_insn;
-		  printf (_("  Advance PC by %lu to 0x%lx[%d]\n"), uladv,
-			  state_machine_regs.address,
+		  printf (_("  Advance PC by %s to 0x%s[%d]\n"),
+			  dwarf_vmatoa ("u", uladv),
+			  dwarf_vmatoa ("x", state_machine_regs.address),
 			  state_machine_regs.op_index);
 		}
 	      break;
 
 	    case DW_LNS_advance_line:
-	      adv = read_leb128 (data, & bytes_read, 1);
+	      adv = read_sleb128 (data, & bytes_read);
 	      data += bytes_read;
 	      state_machine_regs.line += adv;
-	      printf (_("  Advance Line by %d to %d\n"), adv,
-		      state_machine_regs.line);
+	      printf (_("  Advance Line by %s to %d\n"),
+		        dwarf_svmatoa ("d", adv),
+			state_machine_regs.line);
 	      break;
 
 	    case DW_LNS_set_file:
 	      adv = read_leb128 (data, & bytes_read, 0);
 	      data += bytes_read;
-	      printf (_("  Set File Name to entry %d in the File Name
Table\n"),
-		      adv);
+	      printf (_("  Set File Name to entry %s in the File Name
Table\n"),
+		      dwarf_svmatoa ("d", adv));
 	      state_machine_regs.file = adv;
 	      break;
 
 	    case DW_LNS_set_column:
 	      uladv = read_leb128 (data, & bytes_read, 0);
 	      data += bytes_read;
-	      printf (_("  Set column to %lu\n"), uladv);
+	      printf (_("  Set column to %s\n"), 
+		      dwarf_vmatoa ("u", uladv));
 	      state_machine_regs.column = uladv;
 	      break;
 
 	    case DW_LNS_negate_stmt:
 	      adv = state_machine_regs.is_stmt;
 	      adv = ! adv;
-	      printf (_("  Set is_stmt to %d\n"), adv);
+	      printf (_("  Set is_stmt to %s\n"), dwarf_svmatoa("d", adv));
 	      state_machine_regs.is_stmt = adv;
 	      break;
 
@@ -2511,8 +2569,9 @@ display_debug_lines_raw (struct dwarf_se
 		{
 		  uladv *= linfo.li_min_insn_length;
 		  state_machine_regs.address += uladv;
-		  printf (_("  Advance PC by constant %lu to 0x%lx\n"),
uladv,
-			  state_machine_regs.address);
+		  printf (_("  Advance PC by constant %s to 0x%s\n"),
+			  dwarf_vmatoa ("u", uladv),
+			  dwarf_vmatoa ("x", state_machine_regs.address));
 		}
 	      else
 		{
@@ -2523,8 +2582,9 @@ display_debug_lines_raw (struct dwarf_se
 		  state_machine_regs.op_index
 		    = (state_machine_regs.op_index + uladv)
 		      % linfo.li_max_ops_per_insn;
-		  printf (_("  Advance PC by constant %lu to 0x%lx[%d]\n"),
-			  uladv, state_machine_regs.address,
+		  printf (_("  Advance PC by constant %s to 0x%s[%d]\n"),
+			  dwarf_vmatoa ("u", uladv), 
+			  dwarf_vmatoa ("x", state_machine_regs.address),
 			  state_machine_regs.op_index);
 		}
 	      break;
@@ -2534,8 +2594,9 @@ display_debug_lines_raw (struct dwarf_se
 	      data += 2;
 	      state_machine_regs.address += uladv;
 	      state_machine_regs.op_index = 0;
-	      printf (_("  Advance PC by fixed size amount %lu to 0x%lx\n"),
-		      uladv, state_machine_regs.address);
+	      printf (_("  Advance PC by fixed size amount %s to 0x%s\n"),
+		      dwarf_vmatoa ("u", uladv), 
+		      dwarf_vmatoa ("x", state_machine_regs.address));
 	      break;
 
 	    case DW_LNS_set_prologue_end:
@@ -2549,7 +2610,7 @@ display_debug_lines_raw (struct dwarf_se
 	    case DW_LNS_set_isa:
 	      uladv = read_leb128 (data, & bytes_read, 0);
 	      data += bytes_read;
-	      printf (_("  Set ISA to %lu\n"), uladv);
+	      printf (_("  Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
 	      break;
 
 	    default:
@@ -2557,8 +2618,8 @@ display_debug_lines_raw (struct dwarf_se
 
 	      for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
 		{
-		  printf ("0x%" BFD_VMA_FMT "x%s",
-			  read_leb128 (data, &bytes_read, 0),
+		  printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
+							 &bytes_read, 0)),
 			  i == 1 ? "" : ", ");
 		  data += bytes_read;
 		}
@@ -2888,7 +2949,7 @@ display_debug_lines_decoded (struct dwar
               break;
 
             case DW_LNS_advance_line:
-              adv = read_leb128 (data, & bytes_read, 1);
+              adv = read_sleb128 (data, & bytes_read);
               data += bytes_read;
               state_machine_regs.line += adv;
               break;
@@ -2971,8 +3032,8 @@ display_debug_lines_decoded (struct dwar
 
               for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                 {
-                  printf ("0x%" BFD_VMA_FMT "x%s",
-			  read_leb128 (data, &bytes_read, 0),
+                  printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
+							 &bytes_read, 0)),
                           i == 1 ? "" : ", ");
                   data += bytes_read;
                 }
@@ -3007,24 +3068,24 @@ display_debug_lines_decoded (struct dwar
               if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
                 {
 		  if (linfo.li_max_ops_per_insn == 1)
-		    printf ("%-35s  %11d  %#18lx\n", newFileName,
-			    state_machine_regs.line,
+		    printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x\n",
+			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address);
 		  else
-		    printf ("%-35s  %11d  %#18lx[%d]\n", newFileName,
-			    state_machine_regs.line,
+		    printf ("%-35s  %11d  %#18" DWARF_VMA_FMT "x[%d]\n",
+			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address,
 			    state_machine_regs.op_index);
                 }
               else
                 {
 		  if (linfo.li_max_ops_per_insn == 1)
-		    printf ("%s  %11d  %#18lx\n", newFileName,
-			    state_machine_regs.line,
+		    printf ("%s  %11d  %#18" DWARF_VMA_FMT "x\n",
+			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address);
 		  else
-		    printf ("%s  %11d  %#18lx[%d]\n", newFileName,
-			    state_machine_regs.line,
+		    printf ("%s  %11d  %#18" DWARF_VMA_FMT "x[%d]\n",
+			    newFileName, state_machine_regs.line,
 			    state_machine_regs.address,
 			    state_machine_regs.op_index);
                 }
@@ -4110,7 +4171,7 @@ frame_display_row (Frame_Chunk *fc, int 
 
 #define GET(N)	byte_get (start, N); start += N
 #define LEB()	read_leb128 (start, & length_return, 0); start +=
length_return
-#define SLEB()	read_leb128 (start, & length_return, 1); start +=
length_return
+#define SLEB()	read_sleb128 (start, & length_return); start +=
length_return
 
 static int
 display_debug_frames (struct dwarf_section *section,
Index: binutils/dwarf.h
===================================================================
RCS file: /cvs/src/src/binutils/dwarf.h,v
retrieving revision 1.21
diff -u -p -r1.21 dwarf.h
--- binutils/dwarf.h	23 Feb 2011 08:52:33 -0000	1.21
+++ binutils/dwarf.h	25 Feb 2011 10:12:30 -0000
@@ -20,6 +20,7 @@
    MA 02110-1301, USA.  */
 
 typedef unsigned HOST_WIDEST_INT dwarf_vma;
+typedef HOST_WIDEST_INT dwarf_signed_vma;
 typedef unsigned HOST_WIDEST_INT dwarf_size_type;
 
 /* Structure found in the .debug_line section.  */
@@ -38,7 +39,7 @@ DWARF2_External_LineInfo;
 
 typedef struct
 {
-  bfd_vma	 li_length;
+  dwarf_vma	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -62,10 +63,10 @@ DWARF2_External_PubNames;
 
 typedef struct
 {
-  bfd_vma	 pn_length;
+  dwarf_vma	 pn_length;
   unsigned short pn_version;
-  bfd_vma	 pn_offset;
-  bfd_vma	 pn_size;
+  dwarf_vma	 pn_offset;
+  dwarf_vma	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -81,9 +82,9 @@ DWARF2_External_CompUnit;
 
 typedef struct
 {
-  bfd_vma	 cu_length;
+  dwarf_vma	 cu_length;
   unsigned short cu_version;
-  bfd_vma	 cu_abbrev_offset;
+  dwarf_vma	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -100,9 +101,9 @@ DWARF2_External_ARange;
 
 typedef struct
 {
-  bfd_vma	 ar_length;
+  dwarf_vma	 ar_length;
   unsigned short ar_version;
-  bfd_vma	 ar_info_offset;
+  dwarf_vma	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }
@@ -165,15 +166,15 @@ typedef struct
   unsigned int   pointer_size;
   unsigned int   offset_size;
   int            dwarf_version;
-  bfd_vma	 cu_offset;
-  bfd_vma	 base_address;
+  dwarf_vma	 cu_offset;
+  dwarf_vma	 base_address;
   /* This is an array of offsets to the location list table.  */
-  bfd_vma	*loc_offsets;
+  dwarf_vma	*loc_offsets;
   int		*have_frame_base;
   unsigned int   num_loc_offsets;
   unsigned int   max_loc_offsets;
   /* List of .debug_ranges offsets seen in this .debug_info.  */
-  bfd_vma	*range_lists;
+  dwarf_vma	*range_lists;
   unsigned int   num_range_lists;
   unsigned int   max_range_lists;
 }
@@ -217,5 +218,5 @@ void *cmalloc (size_t, size_t);
 void *xcmalloc (size_t, size_t);
 void *xcrealloc (void *, size_t, size_t);
 
-bfd_vma read_leb128 (unsigned char *data,
+dwarf_vma read_leb128 (unsigned char *data,
 		     unsigned int *length_return, int sign);

> -----Message d'origine-----
> De?: binutils-owner@sourceware.org [mailto:binutils-
> owner@sourceware.org] De la part de H.J. Lu
> Envoyé?: jeudi 24 février 2011 14:51
> À?: Pierre Muller
> Cc?: Kai Tietz; Binutils
> Objet?: Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h
> header
> 
> On Thu, Feb 24, 2011 at 3:33 AM, Pierre Muller
> <pierre.muller@ics-cnrs.unistra.fr> wrote:
> >> #if __GNUC__ >= 2
> >> /* Define BFD64 here, even if our default architecture is 32 bit ELF
> >> ? ?as this will allow us to read in and parse 64bit and 32bit ELF
> >> files.
> >> ? ?Only do this if we believe that the compiler can support a 64 bit
> >> ? ?data type. ?For now we only rely on GCC being able to do this.
> ?*/
> >> #define BFD64
> >> #endif
> >>
> >> ....
> >> #include "dwarf.h"
> >> ---
> >>
> >> dwarf_vma should be the same inside and outside of readelf.c.
> >
> >
> > ?This means, if I understand this correctly that
> > if I compile a 32 bit readelf executable
> > bfd_vma will be a 64-bit integer inside readelf.c,
> > but a 32-bit integer in dwarf.c.
> >
> > ?dwarf.c still mainly uses bfd_vma
> > and has dwarf_vma only for one function
> > get_encoded_value...
> >
> > ?Should read_leb128 (and maybe other functions within
> > dwarf.c) also be changed to use
> > dwarf_vma rather than bfd_vma in that case?
> >
> 
> Probably since readelf.c has
> 
> static unsigned long
> read_uleb128 (unsigned char *data, unsigned int *length_return)
> {
>   return read_leb128 (data, length_return, 0);
> }
> 
> 
> 
> --
> H.J.



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