public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
@ 2011-02-17 14:21 Kai Tietz
  2011-02-17 18:59 ` Kai Tietz
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-17 14:21 UTC (permalink / raw)
  To: GCC Patches, Binutils, gdb; +Cc: Jakub Jelinek, Joel Brobecker

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

Hello,

This patch addresses issues I've seen in binutils about
cross-compilers and dwarf2 display via objdump -W on hosts, which have
sizeof (long) < target's sizeof(void *). Additionally same issue of
course can be seen on LLP64 targets, too.
Those issues are caused by the fact that the dwarf2.h header in
include/ is using unconditionally the type 'unsigned long' for
vma-scalars.

This patch address additionally the binutils' dwarf.(c|h) files and
make them host bitness independent for gcc base toolchains supporting
the 'long long' type.

I've tested the attached patches for gdb, binutils, and gcc on
i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
cygwin. And I didn't found until now regressions. Later this day I
want to do a regression test for linux64, too.


binutils, gdb, gcc

ChangeLog include/

2011-02-17  Kai Tietz

	* dwarf2.h (dw2_vma_t): New type.
	(dw2_svma_t): New type.
	(DW2_VMA_FMT): New macro specifying
	to be used width-sepecifier for printing
	new types.


ChangeLog binutils/

2011-02-17  Kai Tietz

	* dwarf.c (read_leb128): Use dw2_vma_t instead of
	long type.
	(process_extended_line_op): Use for adr new type
	and print dw2 values via DW2_VMA_FMT.
	(fetch_indirect_string): Adjust offset's type.
	(decode_location_expression): Adjust argument types
	and uvalue type.
	(read_and_display_attr_value): Likewise.
	(read_and_display_attr): Likewise.
	(decode_location_expression): Adjust printf format.
	(process_debug_info): Likewise.
	(display_debug_lines_raw): Likewise.
	(display_debug_lines_decoded): Likewise.
	(display_debug_pubnames): Likewise.
	(display_debug_loc): Likewise.
	(display_debug_aranges): Likewise.
	* dwarf.h: Add include of dwarf2.h header and
	use of dw2_vma_t instead of long types.
	(read_leb128): Adjust return type.
	
	
Regards,
Kai


PS: On gdb there is at the moment in gdb/common part the include-path
to intl for libintl.h missing

[-- Attachment #2: b_dw2_inc.txt --]
[-- Type: text/plain, Size: 23095 bytes --]

Index: src/binutils/dwarf.c
===================================================================
--- src.orig/binutils/dwarf.c	2011-02-17 11:00:34.000000000 +0100
+++ src/binutils/dwarf.c	2011-02-17 14:30:11.291550300 +0100
@@ -123,10 +123,10 @@ print_dwarf_vma (dwarf_vma val, unsigned
   fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
 }
 
-unsigned long int
+dw2_vma_t
 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
-  unsigned long int result = 0;
+  dw2_vma_t result = 0;
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte;
@@ -136,7 +136,7 @@ read_leb128 (unsigned char *data, unsign
       byte = *data++;
       num_read++;
 
-      result |= ((unsigned long int) (byte & 0x7f)) << shift;
+      result |= ((dw2_vma_t) (byte & 0x7f)) << shift;
 
       shift += 7;
 
@@ -193,7 +193,7 @@ process_extended_line_op (unsigned char 
   unsigned int bytes_read;
   unsigned int len;
   unsigned char *name;
-  unsigned long adr;
+  dw2_vma_t adr;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -218,7 +218,7 @@ process_extended_line_op (unsigned char 
 
     case DW_LNE_set_address:
       adr = byte_get (data, len - bytes_read - 1);
-      printf (_("set Address to 0x%lx\n"), adr);
+      printf (_("set Address to 0x%" DW2_VMA_FMT "x\n"), adr);
       state_machine_regs.address = adr;
       state_machine_regs.op_index = 0;
       break;
@@ -230,16 +230,17 @@ process_extended_line_op (unsigned char 
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
       name = data;
       data += strlen ((char *) data) + 1;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" DW2_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" DW2_VMA_FMT "u\t",
+	      read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" DW2_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       printf ("%s\n\n", name);
       break;
 
     case DW_LNE_set_discriminator:
-      printf (_("set Discriminator to %lu\n"),
+      printf (_("set Discriminator to %" DW2_VMA_FMT "u\n"),
               read_leb128 (data, & bytes_read, 0));
       break;
 
@@ -291,7 +292,7 @@ process_extended_line_op (unsigned char 
 }
 
 static const char *
-fetch_indirect_string (unsigned long offset)
+fetch_indirect_string (dw2_vma_t offset)
 {
   struct dwarf_section *section = &debug_displays [str].section;
 
@@ -302,7 +303,7 @@ fetch_indirect_string (unsigned long off
   offset -= section->address;
   if (offset > section->size)
     {
-      warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
+      warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset);
       return _("<offset is too big>");
     }
 
@@ -605,13 +606,13 @@ decode_location_expression (unsigned cha
 			    unsigned int pointer_size,
 			    unsigned int offset_size,
 			    int dwarf_version,
-			    unsigned long length,
-			    unsigned long cu_offset,
+			    dw2_vma_t length,
+			    dw2_vma_t cu_offset,
 			    struct dwarf_section * section)
 {
   unsigned op;
   unsigned int bytes_read;
-  unsigned long uvalue;
+  dw2_vma_t uvalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
 
@@ -662,11 +663,13 @@ decode_location_expression (unsigned cha
 	  data += 8;
 	  break;
 	case DW_OP_constu:
-	  printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_constu: %" DW2_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_consts:
-	  printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_consts: %" DW2_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_dup:
@@ -721,7 +724,7 @@ decode_location_expression (unsigned cha
 	  printf ("DW_OP_plus");
 	  break;
 	case DW_OP_plus_uconst:
-	  printf ("DW_OP_plus_uconst: %lu",
+	  printf ("DW_OP_plus_uconst: %" DW2_VMA_FMT "u",
 		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
@@ -867,7 +870,8 @@ decode_location_expression (unsigned cha
 	case DW_OP_breg29:
 	case DW_OP_breg30:
 	case DW_OP_breg31:
-	  printf ("DW_OP_breg%d (%s): %ld", op - DW_OP_breg0,
+	  printf ("DW_OP_breg%d (%s): %" DW2_VMA_FMT "d",
+		  op - DW_OP_breg0,
 		  regname (op - DW_OP_breg0, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
@@ -876,22 +880,26 @@ decode_location_expression (unsigned cha
 	case DW_OP_regx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_regx: %lu (%s)", uvalue, regname (uvalue, 1));
+	  printf ("DW_OP_regx: %" DW2_VMA_FMT "u (%s)",
+		  uvalue, regname (uvalue, 1));
 	  break;
 	case DW_OP_fbreg:
 	  need_frame_base = 1;
-	  printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_fbreg: %" DW2_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_bregx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_bregx: %lu (%s) %ld", uvalue, regname (uvalue, 1),
+	  printf ("DW_OP_bregx: %" DW2_VMA_FMT "u (%s) %" DW2_VMA_FMT "d",
+		  uvalue, regname (uvalue, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_piece:
-	  printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_piece: %" DW2_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_deref_size:
@@ -911,13 +919,15 @@ 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%lx>", (long) byte_get (data, 2) + cu_offset);
+	  printf ("DW_OP_call2: <0x%" DW2_VMA_FMT "x>",
+		  (dw2_svma_t) 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%lx>", (long) byte_get (data, 4) + cu_offset);
+	  printf ("DW_OP_call4: <0x%" DW2_VMA_FMT "x>",
+		  (dw2_svma_t) byte_get (data, 4) + cu_offset);
 	  data += 4;
 	  break;
 	case DW_OP_call_ref:
@@ -950,9 +960,11 @@ decode_location_expression (unsigned cha
 	  break;
 	case DW_OP_bit_piece:
 	  printf ("DW_OP_bit_piece: ");
-	  printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("size: %" DW2_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
-	  printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("offset: %" DW2_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 
@@ -1001,16 +1013,20 @@ decode_location_expression (unsigned cha
 	    }
 	  if (dwarf_version == 2)
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, pointer_size),
-		      read_leb128 (data + pointer_size, &bytes_read, 1));
+	      printf ("DW_OP_GNU_implicit_pointer: "
+		      "<0x%" DW2_VMA_FMT "x> %" DW2_VMA_FMT "d",
+		      (dw2_vma_t) byte_get (data, pointer_size),
+		      (dw2_svma_t) read_leb128 (data + pointer_size,
+						&bytes_read, 1));
 	      data += pointer_size + bytes_read;
 	    }
 	  else
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, offset_size),
-		      read_leb128 (data + offset_size, &bytes_read, 1));
+	      printf ("DW_OP_GNU_implicit_pointer: "
+		      "<0x%" DW2_VMA_FMT "x> %" DW2_VMA_FMT "d",
+		      (dw2_vma_t) byte_get (data, offset_size),
+		      (dw2_svma_t) read_leb128 (data + offset_size,
+						&bytes_read, 1));
 	      data += offset_size + bytes_read;
 	    }
 	  break;
@@ -1072,15 +1088,15 @@ static unsigned char *
 read_and_display_attr_value (unsigned long attribute,
 			     unsigned long form,
 			     unsigned char * data,
-			     unsigned long cu_offset,
-			     unsigned long pointer_size,
-			     unsigned long offset_size,
+			     dw2_vma_t cu_offset,
+			     dw2_vma_t pointer_size,
+			     dw2_vma_t offset_size,
 			     int dwarf_version,
 			     debug_info * debug_info_p,
 			     int do_loc,
 			     struct dwarf_section * section)
 {
-  unsigned long uvalue = 0;
+  dw2_vma_t uvalue = 0;
   unsigned char *block_start = NULL;
   unsigned char * orig_data = data;
   unsigned int bytes_read;
@@ -1167,7 +1183,7 @@ read_and_display_attr_value (unsigned lo
     {
     case DW_FORM_ref_addr:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue);
+	printf (" <0x%" DW2_VMA_FMT "x>", uvalue);
       break;
 
     case DW_FORM_ref1:
@@ -1175,14 +1191,14 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_ref4:
     case DW_FORM_ref_udata:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue + cu_offset);
+	printf (" <0x%" DW2_VMA_FMT "x>", uvalue + cu_offset);
       break;
 
     case DW_FORM_data4:
     case DW_FORM_addr:
     case DW_FORM_sec_offset:
       if (!do_loc)
-	printf (" 0x%lx", uvalue);
+	printf (" 0x%" DW2_VMA_FMT "x", uvalue);
       break;
 
     case DW_FORM_flag_present:
@@ -1192,7 +1208,7 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_sdata:
     case DW_FORM_udata:
       if (!do_loc)
-	printf (" %ld", uvalue);
+	printf (" %" DW2_VMA_FMT "d", uvalue);
       break;
 
     case DW_FORM_ref8:
@@ -1200,7 +1216,7 @@ read_and_display_attr_value (unsigned lo
       if (!do_loc)
 	{
 	  uvalue = byte_get (data, 4);
-	  printf (" 0x%lx", uvalue);
+	  printf (" 0x%" DW2_VMA_FMT "x", uvalue);
 	  printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
 	}
       if ((do_loc || do_debug_loc || do_debug_ranges)
@@ -1209,7 +1225,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 (unsigned long) != 8\n"));
+	    error (_("DW_FORM_data8 is unsupported when sizeof (dw2_vma_t) != 8\n"));
 	}
       data += 8;
       break;
@@ -1259,7 +1275,7 @@ read_and_display_attr_value (unsigned lo
 
     case DW_FORM_strp:
       if (!do_loc)
-	printf (_(" (indirect string, offset: 0x%lx): %s"),
+	printf (_(" (indirect string, offset: 0x%" DW2_VMA_FMT "x): %s"),
 		uvalue, fetch_indirect_string (uvalue));
       break;
 
@@ -1313,7 +1329,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->loc_offsets = (long unsigned int *)
+		  debug_info_p->loc_offsets = (dw2_vma_t *)
                       xcrealloc (debug_info_p->loc_offsets,
 				 lmax, sizeof (*debug_info_p->loc_offsets));
 		  debug_info_p->have_frame_base = (int *)
@@ -1344,7 +1360,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->range_lists = (long unsigned int *)
+		  debug_info_p->range_lists = (dw2_vma_t *)
                       xcrealloc (debug_info_p->range_lists,
 				 lmax, sizeof (*debug_info_p->range_lists));
 		  debug_info_p->max_range_lists = lmax;
@@ -1383,7 +1399,8 @@ read_and_display_attr_value (unsigned lo
 	  printf (_("(declared as inline and inlined)"));
 	  break;
 	default:
-	  printf (_("  (Unknown inline attribute value: %lx)"), uvalue);
+	  printf (_("  (Unknown inline attribute value: %" DW2_VMA_FMT "x)"),
+	  	  uvalue);
 	  break;
 	}
       break;
@@ -1421,9 +1438,9 @@ 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: %lx)", uvalue);
+	    printf ("(implementation defined: %" DW2_VMA_FMT "x)", uvalue);
 	  else
-	    printf ("(Unknown: %lx)", uvalue);
+	    printf ("(Unknown: %" DW2_VMA_FMT "x)", uvalue);
 	  break;
 	}
       break;
@@ -1584,7 +1601,7 @@ read_and_display_attr_value (unsigned lo
 	  uvalue += cu_offset;
 
 	if (uvalue >= section->size)
-	  warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
+	  warn (_("Offset %" DW2_VMA_FMT "x used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
 		uvalue, (unsigned long) (orig_data - section->start));
 	else
 	  {
@@ -1786,9 +1803,9 @@ static unsigned char *
 read_and_display_attr (unsigned long attribute,
 		       unsigned long form,
 		       unsigned char * data,
-		       unsigned long cu_offset,
-		       unsigned long pointer_size,
-		       unsigned long offset_size,
+		       dw2_vma_t cu_offset,
+		       dw2_vma_t pointer_size,
+		       dw2_vma_t offset_size,
 		       int dwarf_version,
 		       debug_info * debug_info_p,
 		       int do_loc,
@@ -1900,7 +1917,7 @@ process_debug_info (struct dwarf_section
       unsigned char *hdrptr;
       unsigned char *tags;
       int level;
-      unsigned long cu_offset;
+      dw2_vma_t cu_offset;
       int offset_size;
       int initial_length_size;
       unsigned char signature[8] = { 0 };
@@ -1970,11 +1987,13 @@ process_debug_info (struct dwarf_section
 
       if (!do_loc)
 	{
-	  printf (_("  Compilation Unit @ offset 0x%lx:\n"), cu_offset);
-	  printf (_("   Length:        0x%lx (%s)\n"), compunit.cu_length,
+	  printf (_("  Compilation Unit @ offset 0x%" DW2_VMA_FMT "x:\n"), cu_offset);
+	  printf (_("   Length:        0x%" DW2_VMA_FMT "x (%s)\n"),
+		  compunit.cu_length,
 		  initial_length_size == 8 ? "64-bit" : "32-bit");
 	  printf (_("   Version:       %d\n"), compunit.cu_version);
-	  printf (_("   Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
+	  printf (_("   Abbrev Offset: %" DW2_VMA_FMT "d\n"),
+		  compunit.cu_abbrev_offset);
 	  printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
 	  if (do_types)
 	    {
@@ -1990,7 +2009,9 @@ process_debug_info (struct dwarf_section
       if (cu_offset + compunit.cu_length + initial_length_size
 	  > section->size)
 	{
-	  warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
+	  warn (_("Debug info is corrupted, length of CU at %"
+	  	  DW2_VMA_FMT "x extends beyond end of section (length = %"
+	  	  DW2_VMA_FMT "x)\n"),
 		cu_offset, compunit.cu_length);
 	  break;
 	}
@@ -2001,7 +2022,8 @@ process_debug_info (struct dwarf_section
 	  && compunit.cu_version != 3
 	  && compunit.cu_version != 4)
 	{
-	  warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
+	  warn (_("CU at offset %" DW2_VMA_FMT "x contains corrupt or "
+		  "unsupported version number: %d.\n"),
 		cu_offset, compunit.cu_version);
 	  continue;
 	}
@@ -2268,7 +2290,7 @@ display_debug_lines_raw (struct dwarf_se
       linfo.li_line_base >>= 24;
 
       printf (_("  Offset:                      0x%lx\n"), hdroff);
-      printf (_("  Length:                      %ld\n"), linfo.li_length);
+      printf (_("  Length:                      %ld\n"), (long) linfo.li_length);
       printf (_("  DWARF Version:               %d\n"), linfo.li_version);
       printf (_("  Prologue Length:             %d\n"), linfo.li_prologue_length);
       printf (_("  Minimum Instruction Length:  %d\n"), linfo.li_min_insn_length);
@@ -2329,11 +2351,14 @@ display_debug_lines_raw (struct dwarf_se
 
 	      data += strlen ((char *) data) + 1;
 
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" DW2_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" DW2_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" DW2_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
 	      printf ("%s\n", name);
 	    }
@@ -2505,7 +2530,8 @@ display_debug_lines_raw (struct dwarf_se
 
 	      for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
 		{
-		  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+		  printf ("0x%" DW2_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
 			  i == 1 ? "" : ", ");
 		  data += bytes_read;
 		}
@@ -2918,7 +2944,8 @@ display_debug_lines_decoded (struct dwar
 
               for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                 {
-                  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+                  printf ("0x%" DW2_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
                           i == 1 ? "" : ", ");
                   data += bytes_read;
                 }
@@ -3076,7 +3103,7 @@ display_debug_pubnames (struct dwarf_sec
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (names.pn_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      names.pn_offset, section->name);
+	      (unsigned long) names.pn_offset, section->name);
 
       names.pn_size = byte_get (data, offset_size);
       data += offset_size;
@@ -3097,13 +3124,13 @@ display_debug_pubnames (struct dwarf_sec
 	}
 
       printf (_("  Length:                              %ld\n"),
-	      names.pn_length);
+	      (long) names.pn_length);
       printf (_("  Version:                             %d\n"),
 	      names.pn_version);
       printf (_("  Offset into .debug_info section:     0x%lx\n"),
-	      names.pn_offset);
+	      (unsigned long) names.pn_offset);
       printf (_("  Size of area in .debug_info section: %ld\n"),
-	      names.pn_size);
+	      (long) names.pn_size);
 
       printf (_("\n    Offset\tName\n"));
 
@@ -3323,7 +3350,7 @@ display_debug_loc (struct dwarf_section 
   /* DWARF sections under Mach-O have non-zero addresses.  */
   if (debug_information [first].num_loc_offsets > 0
       && debug_information [first].loc_offsets [0] != section->address)
-    warn (_("Location lists in %s section start at 0x%lx\n"),
+    warn (_("Location lists in %s section start at 0x%" DW2_VMA_FMT "x\n"),
 	  section->name, debug_information [first].loc_offsets [0]);
 
   printf (_("Contents of the %s section:\n\n"), section->name);
@@ -3596,7 +3623,7 @@ display_debug_aranges (struct dwarf_sect
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      arange.ar_info_offset, section->name);
+	      (unsigned long) arange.ar_info_offset, section->name);
 
       arange.ar_pointer_size = byte_get (hdrptr, 1);
       hdrptr += 1;
@@ -3610,9 +3637,11 @@ display_debug_aranges (struct dwarf_sect
 	  break;
 	}
 
-      printf (_("  Length:                   %ld\n"), arange.ar_length);
+      printf (_("  Length:                   %ld\n"),
+	      (long) arange.ar_length);
       printf (_("  Version:                  %d\n"), arange.ar_version);
-      printf (_("  Offset into .debug_info:  0x%lx\n"), arange.ar_info_offset);
+      printf (_("  Offset into .debug_info:  0x%lx\n"),
+	      (unsigned long) arange.ar_info_offset);
       printf (_("  Pointer Size:             %d\n"), arange.ar_pointer_size);
       printf (_("  Segment Size:             %d\n"), arange.ar_segment_size);
 
Index: src/binutils/dwarf.h
===================================================================
--- src.orig/binutils/dwarf.h	2011-02-17 11:00:34.000000000 +0100
+++ src/binutils/dwarf.h	2011-02-17 11:18:37.972034400 +0100
@@ -19,6 +19,8 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+#include "dwarf2.h"
+
 typedef unsigned HOST_WIDEST_INT dwarf_vma;
 typedef unsigned HOST_WIDEST_INT dwarf_size_type;
 
@@ -79,15 +81,15 @@ typedef struct
   unsigned int   pointer_size;
   unsigned int   offset_size;
   int            dwarf_version;
-  unsigned long  cu_offset;
-  unsigned long	 base_address;
+  dw2_vma_t	 cu_offset;
+  dw2_vma_t	 base_address;
   /* This is an array of offsets to the location list table.  */
-  unsigned long *loc_offsets;
+  dw2_vma_t	*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.  */
-  unsigned long *range_lists;
+  dw2_vma_t	*range_lists;
   unsigned int   num_range_lists;
   unsigned int   max_range_lists;
 }
@@ -131,5 +133,5 @@ void *cmalloc (size_t, size_t);
 void *xcmalloc (size_t, size_t);
 void *xcrealloc (void *, size_t, size_t);
 
-unsigned long int read_leb128 (unsigned char *data,
-			       unsigned int *length_return, int sign);
+dw2_vma_t read_leb128 (unsigned char *data,
+		       unsigned int *length_return, int sign);
Index: src/include/dwarf2.h
===================================================================
--- src.orig/include/dwarf2.h	2011-02-17 11:00:34.000000000 +0100
+++ src/include/dwarf2.h	2011-02-17 12:22:16.839408800 +0100
@@ -47,6 +47,35 @@
 #ifndef _ELF_DWARF2_H
 #define _ELF_DWARF2_H
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+/* We need here widest integer type so that even for cross scenarios
+   a wide enough integer scalar value is used to hold address vma.
+   Additionally it is necessary here to use for non-LP64 targets the
+   proper integer scalar value to hold an address.  */
+#ifdef __GNUC__
+__extension__
+#endif
+typedef unsigned long long dw2_vma_t;
+#ifdef __GNUC__
+__extension__
+#endif
+typedef signed long long dw2_svma_t;
+
+#ifndef __MINGW32__
+#define DW2_VMA_FMT	"ll"
+#else
+#define DW2_VMA_FMT	"I64"
+#endif
+
+#else
+
+typedef unsigned long dw2_vma_t;
+typedef signed long dw2_svma_t;
+
+#define DW2_VMA_FMT	"l"
+
+#endif
+
 /* Structure found in the .debug_line section.  */
 typedef struct
 {
@@ -63,7 +92,7 @@ DWARF2_External_LineInfo;
 
 typedef struct
 {
-  unsigned long  li_length;
+  dw2_vma_t	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -87,10 +116,10 @@ DWARF2_External_PubNames;
 
 typedef struct
 {
-  unsigned long  pn_length;
+  dw2_vma_t	 pn_length;
   unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
+  dw2_vma_t	 pn_offset;
+  dw2_vma_t	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -106,9 +135,9 @@ DWARF2_External_CompUnit;
 
 typedef struct
 {
-  unsigned long  cu_length;
+  dw2_vma_t	 cu_length;
   unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
+  dw2_vma_t	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -125,9 +154,9 @@ DWARF2_External_ARange;
 
 typedef struct
 {
-  unsigned long  ar_length;
+  dw2_vma_t	 ar_length;
   unsigned short ar_version;
-  unsigned long  ar_info_offset;
+  dw2_vma_t	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }

[-- Attachment #3: d_dw2.txt --]
[-- Type: text/plain, Size: 2146 bytes --]

Index: src/include/dwarf2.h
===================================================================
--- src.orig/include/dwarf2.h	2011-02-17 12:26:40.000000000 +0100
+++ src/include/dwarf2.h	2011-02-17 12:25:06.183158800 +0100
@@ -47,6 +47,35 @@
 #ifndef _ELF_DWARF2_H
 #define _ELF_DWARF2_H
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+/* We need here widest integer type so that even for cross scenarios
+   a wide enough integer scalar value is used to hold address vma.
+   Additionally it is necessary here to use for non-LP64 targets the
+   proper integer scalar value to hold an address.  */
+#ifdef __GNUC__
+__extension__
+#endif
+typedef unsigned long long dw2_vma_t;
+#ifdef __GNUC__
+__extension__
+#endif
+typedef signed long long dw2_svma_t;
+
+#ifndef __MINGW32__
+#define DW2_VMA_FMT	"ll"
+#else
+#define DW2_VMA_FMT	"I64"
+#endif
+
+#else
+
+typedef unsigned long dw2_vma_t;
+typedef signed long dw2_svma_t;
+
+#define DW2_VMA_FMT	"l"
+
+#endif
+
 /* Structure found in the .debug_line section.  */
 typedef struct
 {
@@ -63,7 +92,7 @@ DWARF2_External_LineInfo;
 
 typedef struct
 {
-  unsigned long  li_length;
+  dw2_vma_t	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -87,10 +116,10 @@ DWARF2_External_PubNames;
 
 typedef struct
 {
-  unsigned long  pn_length;
+  dw2_vma_t	 pn_length;
   unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
+  dw2_vma_t	 pn_offset;
+  dw2_vma_t	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -106,9 +135,9 @@ DWARF2_External_CompUnit;
 
 typedef struct
 {
-  unsigned long  cu_length;
+  dw2_vma_t	 cu_length;
   unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
+  dw2_vma_t	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -125,9 +154,9 @@ DWARF2_External_ARange;
 
 typedef struct
 {
-  unsigned long  ar_length;
+  dw2_vma_t	 ar_length;
   unsigned short ar_version;
-  unsigned long  ar_info_offset;
+  dw2_vma_t	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }

[-- Attachment #4: g_dwarf2.txt --]
[-- Type: text/plain, Size: 2841 bytes --]

Index: gcc/include/dwarf2.h
===================================================================
--- gcc.orig/include/dwarf2.h	2011-01-13 11:59:21.000000000 +0100
+++ gcc/include/dwarf2.h	2011-02-17 14:00:16.175818900 +0100
@@ -47,6 +47,35 @@
 #ifndef _ELF_DWARF2_H
 #define _ELF_DWARF2_H
 
+#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
+/* We need here widest integer type so that even for cross scenarios
+   a wide enough integer scalar value is used to hold address vma.
+   Additionally it is necessary here to use for non-LP64 targets the
+   proper integer scalar value to hold an address.  */
+#ifdef __GNUC__
+__extension__
+#endif
+typedef unsigned long long dw2_vma_t;
+#ifdef __GNUC__
+__extension__
+#endif
+typedef signed long long dw2_svma_t;
+
+#ifndef __MINGW32__
+#define DW2_VMA_FMT	"ll"
+#else
+#define DW2_VMA_FMT	"I64"
+#endif
+
+#else
+
+typedef unsigned long dw2_vma_t;
+typedef signed long dw2_svma_t;
+
+#define DW2_VMA_FMT	"l"
+
+#endif
+
 /* Structure found in the .debug_line section.  */
 typedef struct
 {
@@ -63,7 +92,7 @@ DWARF2_External_LineInfo;
 
 typedef struct
 {
-  unsigned long  li_length;
+  dw2_vma_t	 li_length;
   unsigned short li_version;
   unsigned int   li_prologue_length;
   unsigned char  li_min_insn_length;
@@ -87,10 +116,10 @@ DWARF2_External_PubNames;
 
 typedef struct
 {
-  unsigned long  pn_length;
+  dw2_vma_t	 pn_length;
   unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
+  dw2_vma_t	 pn_offset;
+  dw2_vma_t	 pn_size;
 }
 DWARF2_Internal_PubNames;
 
@@ -106,9 +135,9 @@ DWARF2_External_CompUnit;
 
 typedef struct
 {
-  unsigned long  cu_length;
+  dw2_vma_t	 cu_length;
   unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
+  dw2_vma_t	 cu_abbrev_offset;
   unsigned char  cu_pointer_size;
 }
 DWARF2_Internal_CompUnit;
@@ -125,9 +154,9 @@ DWARF2_External_ARange;
 
 typedef struct
 {
-  unsigned long  ar_length;
+  dw2_vma_t	 ar_length;
   unsigned short ar_version;
-  unsigned long  ar_info_offset;
+  dw2_vma_t	 ar_info_offset;
   unsigned char  ar_pointer_size;
   unsigned char  ar_segment_size;
 }
@@ -754,7 +783,15 @@ enum dwarf_calling_convention
     DW_CC_hi_user = 0xff,
 
     DW_CC_GNU_renesas_sh = 0x40,
-    DW_CC_GNU_borland_fastcall_i386 = 0x41
+    DW_CC_GNU_borland_fastcall_i386 = 0x41,
+
+    /* This DW_CC_ value is not currently generated by any toolchain.  It is
+       used internally to GDB to indicate OpenCL C functions that have been
+       compiled with the IBM XL C for OpenCL compiler and use a non-platform
+       calling convention for passing OpenCL C vector types.  This value may
+       be changed freely as long as it does not conflict with any other DW_CC_
+       value defined here.  */
+    DW_CC_GDB_IBM_OpenCL = 0xff
   };
 
 /* Inline attribute.  */

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-17 14:21 [RFC patch]: Adjust the use of 'long' type in dwarf2.h header Kai Tietz
@ 2011-02-17 18:59 ` Kai Tietz
  2011-02-17 19:03   ` Jakub Jelinek
  2011-02-21 13:10 ` Pierre Muller
       [not found] ` <-8460070221060995487@unknownmsgid>
  2 siblings, 1 reply; 30+ messages in thread
From: Kai Tietz @ 2011-02-17 18:59 UTC (permalink / raw)
  To: GCC Patches, Binutils, gdb; +Cc: Jakub Jelinek, Joel Brobecker

2011/2/17 Kai Tietz <ktietz70@googlemail.com>:
> Hello,
>
> This patch addresses issues I've seen in binutils about
> cross-compilers and dwarf2 display via objdump -W on hosts, which have
> sizeof (long) < target's sizeof(void *). Additionally same issue of
> course can be seen on LLP64 targets, too.
> Those issues are caused by the fact that the dwarf2.h header in
> include/ is using unconditionally the type 'unsigned long' for
> vma-scalars.
>
> This patch address additionally the binutils' dwarf.(c|h) files and
> make them host bitness independent for gcc base toolchains supporting
> the 'long long' type.
>
> I've tested the attached patches for gdb, binutils, and gcc on
> i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
> cygwin. And I didn't found until now regressions. Later this day I
> want to do a regression test for linux64, too.
>
>
> binutils, gdb, gcc
>
> ChangeLog include/
>
> 2011-02-17  Kai Tietz
>
>        * dwarf2.h (dw2_vma_t): New type.
>        (dw2_svma_t): New type.
>        (DW2_VMA_FMT): New macro specifying
>        to be used width-sepecifier for printing
>        new types.
>
>
> ChangeLog binutils/
>
> 2011-02-17  Kai Tietz
>
>        * dwarf.c (read_leb128): Use dw2_vma_t instead of
>        long type.
>        (process_extended_line_op): Use for adr new type
>        and print dw2 values via DW2_VMA_FMT.
>        (fetch_indirect_string): Adjust offset's type.
>        (decode_location_expression): Adjust argument types
>        and uvalue type.
>        (read_and_display_attr_value): Likewise.
>        (read_and_display_attr): Likewise.
>        (decode_location_expression): Adjust printf format.
>        (process_debug_info): Likewise.
>        (display_debug_lines_raw): Likewise.
>        (display_debug_lines_decoded): Likewise.
>        (display_debug_pubnames): Likewise.
>        (display_debug_loc): Likewise.
>        (display_debug_aranges): Likewise.
>        * dwarf.h: Add include of dwarf2.h header and
>        use of dw2_vma_t instead of long types.
>        (read_leb128): Adjust return type.
>
>
> Regards,
> Kai
>
>
> PS: On gdb there is at the moment in gdb/common part the include-path
> to intl for libintl.h missing
>

I tested those patches for x86_64-pc-linux-gnu too and had no
regressions. Ok for apply, or any comments?

Regards,
Kai

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-17 18:59 ` Kai Tietz
@ 2011-02-17 19:03   ` Jakub Jelinek
  2011-02-17 19:07     ` Kai Tietz
  0 siblings, 1 reply; 30+ messages in thread
From: Jakub Jelinek @ 2011-02-17 19:03 UTC (permalink / raw)
  To: Kai Tietz; +Cc: GCC Patches, Binutils, gdb, Joel Brobecker

On Thu, Feb 17, 2011 at 07:58:56PM +0100, Kai Tietz wrote:
> 2011/2/17 Kai Tietz <ktietz70@googlemail.com>:
> > This patch addresses issues I've seen in binutils about
> > cross-compilers and dwarf2 display via objdump -W on hosts, which have
> > sizeof (long) < target's sizeof(void *). Additionally same issue of
> > course can be seen on LLP64 targets, too.
> > Those issues are caused by the fact that the dwarf2.h header in
> > include/ is using unconditionally the type 'unsigned long' for
> > vma-scalars.
> >
> > This patch address additionally the binutils' dwarf.(c|h) files and
> > make them host bitness independent for gcc base toolchains supporting
> > the 'long long' type.
> >
> > I've tested the attached patches for gdb, binutils, and gcc on
> > i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
> > cygwin. And I didn't found until now regressions. Later this day I
> > want to do a regression test for linux64, too.

I'd prefer if we could move those binutils specific internal implementation
details out of the dwarf2.h header, keep it really just for the stuff
defined in the standard, and add a new binutils specific header somewhere
else which would contain binutils specific details.

	Jakub

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-17 19:03   ` Jakub Jelinek
@ 2011-02-17 19:07     ` Kai Tietz
  2011-02-17 19:17       ` Jakub Jelinek
  0 siblings, 1 reply; 30+ messages in thread
From: Kai Tietz @ 2011-02-17 19:07 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches, Binutils, gdb, Joel Brobecker

2011/2/17 Jakub Jelinek <jakub@redhat.com>:
> On Thu, Feb 17, 2011 at 07:58:56PM +0100, Kai Tietz wrote:
>> 2011/2/17 Kai Tietz <ktietz70@googlemail.com>:
>> > This patch addresses issues I've seen in binutils about
>> > cross-compilers and dwarf2 display via objdump -W on hosts, which have
>> > sizeof (long) < target's sizeof(void *). Additionally same issue of
>> > course can be seen on LLP64 targets, too.
>> > Those issues are caused by the fact that the dwarf2.h header in
>> > include/ is using unconditionally the type 'unsigned long' for
>> > vma-scalars.
>> >
>> > This patch address additionally the binutils' dwarf.(c|h) files and
>> > make them host bitness independent for gcc base toolchains supporting
>> > the 'long long' type.
>> >
>> > I've tested the attached patches for gdb, binutils, and gcc on
>> > i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
>> > cygwin. And I didn't found until now regressions. Later this day I
>> > want to do a regression test for linux64, too.
>
> I'd prefer if we could move those binutils specific internal implementation
> details out of the dwarf2.h header, keep it really just for the stuff
> defined in the standard, and add a new binutils specific header somewhere
> else which would contain binutils specific details.
>
>        Jakub

Well, so we make dwarf2.h in include just host-specific and isn't able
to cover things for foreign target, like 32-bit host can't use this
header for 64-bit dwarf2 information. I am fine by this, but
nevertheless is then the use of 'unsigned long' type within this
header still an issue. Here should be used instead then 'intptr_t'. As
on LLP64 unsigned long isn't wide-enough.

Regards,
Kai

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-17 19:07     ` Kai Tietz
@ 2011-02-17 19:17       ` Jakub Jelinek
  2011-02-18  9:50         ` Kai Tietz
  0 siblings, 1 reply; 30+ messages in thread
From: Jakub Jelinek @ 2011-02-17 19:17 UTC (permalink / raw)
  To: Kai Tietz; +Cc: GCC Patches, Binutils, gdb, Joel Brobecker

On Thu, Feb 17, 2011 at 08:06:53PM +0100, Kai Tietz wrote:
> > I'd prefer if we could move those binutils specific internal implementation
> > details out of the dwarf2.h header, keep it really just for the stuff
> > defined in the standard, and add a new binutils specific header somewhere
> > else which would contain binutils specific details.
> 
> Well, so we make dwarf2.h in include just host-specific and isn't able
> to cover things for foreign target, like 32-bit host can't use this
> header for 64-bit dwarf2 information. I am fine by this, but
> nevertheless is then the use of 'unsigned long' type within this
> header still an issue. Here should be used instead then 'intptr_t'. As
> on LLP64 unsigned long isn't wide-enough.

I mean that none of the DWARF2_Internal types should be in the
include/dwarf2.h headers (that's implementation specific stuff),
and the DWARF2_External types are questionable too, to me they look
very much like implementation detail too.  E.g. DWARF2_External_LineInfo
type is dubious, because it might somehow describe version 2 or 3
.debug_line header, but version 4 looks differently, etc.
So IMHO the DWARF2_External stuff should be moved too.
And the guard should be probably renamed from _ELF_DWARF2_H to _DWARF2_H,
I don't see anything ELF specific in the header.

	Jakub

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-17 19:17       ` Jakub Jelinek
@ 2011-02-18  9:50         ` Kai Tietz
  2011-02-21 12:37           ` NightStrike
  0 siblings, 1 reply; 30+ messages in thread
From: Kai Tietz @ 2011-02-18  9:50 UTC (permalink / raw)
  To: Alan Modra; +Cc: GCC Patches, Binutils, gdb, Joel Brobecker, Jakub Jelinek

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

2011/2/17 Jakub Jelinek <jakub@redhat.com>:
> On Thu, Feb 17, 2011 at 08:06:53PM +0100, Kai Tietz wrote:
>> > I'd prefer if we could move those binutils specific internal implementation
>> > details out of the dwarf2.h header, keep it really just for the stuff
>> > defined in the standard, and add a new binutils specific header somewhere
>> > else which would contain binutils specific details.
>>
>> Well, so we make dwarf2.h in include just host-specific and isn't able
>> to cover things for foreign target, like 32-bit host can't use this
>> header for 64-bit dwarf2 information. I am fine by this, but
>> nevertheless is then the use of 'unsigned long' type within this
>> header still an issue. Here should be used instead then 'intptr_t'. As
>> on LLP64 unsigned long isn't wide-enough.
>
> I mean that none of the DWARF2_Internal types should be in the
> include/dwarf2.h headers (that's implementation specific stuff),
> and the DWARF2_External types are questionable too, to me they look
> very much like implementation detail too.  E.g. DWARF2_External_LineInfo
> type is dubious, because it might somehow describe version 2 or 3
> .debug_line header, but version 4 looks differently, etc.
> So IMHO the DWARF2_External stuff should be moved too.
> And the guard should be probably renamed from _ELF_DWARF2_H to _DWARF2_H,
> I don't see anything ELF specific in the header.
>
>        Jakub
>

So I reworked my patch as Jakub suggested and retested it for
x86_64-w64-mingw32, i686-w64-mingw32, and x86_64-pc-linux-gnu for gcc,
binutils, and gdb. Ok for apply?

binutils, gdb, gcc

ChangeLog include/

2011-02-18  Kai Tietz

		 * dwarf2.h (_ELF_DWARF2_H): Renamed to
		 _DWARF2_H.
		 (DWARF2_External_LineInfo, DWARF2_Internal_LineInfo,
		 DWARF2_External_PubNames, DWARF2_Internal_PubNames,
		 DWARF2_External_CompUnit, DWARF2_Internal_CompUnit,
		 DWARF2_External_ARange, DWARF2_Internal_ARange): Removed.


ChangeLog binutils/

2011-02-18  Kai Tietz

		 * dwarf.c (read_leb128): Use dw2_vma_t instead of
		 long type.
		 (process_extended_line_op): Use for adr bfd_vma
		 type and print those typed values via BFD_VMA_FMT.
		 (fetch_indirect_string): Adjust offset's type.
		 (decode_location_expression): Adjust argument types
		 and uvalue type.
		 (read_and_display_attr_value): Likewise.
		 (read_and_display_attr): Likewise.
		 (decode_location_expression): Adjust printf format.
		 (process_debug_info): Likewise.
		 (display_debug_lines_raw): Likewise.
		 (display_debug_lines_decoded): Likewise.
		 (display_debug_pubnames): Likewise.
		 (display_debug_loc): Likewise.
		 (display_debug_aranges): Likewise.
		 * dwarf.h (DWARF2_External_LineInfo,
		 DWARF2_Internal_LineInfo, DWARF2_External_PubNames,
		 DWARF2_Internal_PubNames, DWARF2_External_CompUnit,
		 DWARF2_Internal_CompUnit, DWARF2_External_ARange,
		 DWARF2_Internal_ARange): Added..
		 (read_leb128): Adjust return type.

Regards,
Kai

PS: A lot of those moved structures aren't used at all in binutils
dwarf.c (which is the only consumer of some of those structures as a
grep over binutils/gdb/gcc had shown). So maybe the unused could be
removed in a second patch completely.

[-- Attachment #2: b_dw2_inc.txt --]
[-- Type: text/plain, Size: 25628 bytes --]

Index: src/binutils/dwarf.c
===================================================================
--- src.orig/binutils/dwarf.c	2011-02-17 11:00:34.000000000 +0100
+++ src/binutils/dwarf.c	2011-02-18 10:27:10.941857600 +0100
@@ -123,10 +123,10 @@ print_dwarf_vma (dwarf_vma val, unsigned
   fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
 }
 
-unsigned long int
+bfd_vma
 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
-  unsigned long int result = 0;
+  bfd_vma result = 0;
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte;
@@ -136,7 +136,7 @@ read_leb128 (unsigned char *data, unsign
       byte = *data++;
       num_read++;
 
-      result |= ((unsigned long int) (byte & 0x7f)) << shift;
+      result |= ((bfd_vma) (byte & 0x7f)) << shift;
 
       shift += 7;
 
@@ -193,7 +193,7 @@ process_extended_line_op (unsigned char 
   unsigned int bytes_read;
   unsigned int len;
   unsigned char *name;
-  unsigned long adr;
+  bfd_vma adr;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -218,7 +218,7 @@ process_extended_line_op (unsigned char 
 
     case DW_LNE_set_address:
       adr = byte_get (data, len - bytes_read - 1);
-      printf (_("set Address to 0x%lx\n"), adr);
+      printf (_("set Address to 0x%" BFD_VMA_FMT "x\n"), adr);
       state_machine_regs.address = adr;
       state_machine_regs.op_index = 0;
       break;
@@ -230,16 +230,17 @@ process_extended_line_op (unsigned char 
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
       name = data;
       data += strlen ((char *) data) + 1;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" BFD_VMA_FMT "u\t",
+	      read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       printf ("%s\n\n", name);
       break;
 
     case DW_LNE_set_discriminator:
-      printf (_("set Discriminator to %lu\n"),
+      printf (_("set Discriminator to %" BFD_VMA_FMT "u\n"),
               read_leb128 (data, & bytes_read, 0));
       break;
 
@@ -291,7 +292,7 @@ process_extended_line_op (unsigned char 
 }
 
 static const char *
-fetch_indirect_string (unsigned long offset)
+fetch_indirect_string (bfd_vma offset)
 {
   struct dwarf_section *section = &debug_displays [str].section;
 
@@ -302,7 +303,7 @@ fetch_indirect_string (unsigned long off
   offset -= section->address;
   if (offset > section->size)
     {
-      warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
+      warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset);
       return _("<offset is too big>");
     }
 
@@ -605,13 +606,13 @@ decode_location_expression (unsigned cha
 			    unsigned int pointer_size,
 			    unsigned int offset_size,
 			    int dwarf_version,
-			    unsigned long length,
-			    unsigned long cu_offset,
+			    bfd_vma length,
+			    bfd_vma cu_offset,
 			    struct dwarf_section * section)
 {
   unsigned op;
   unsigned int bytes_read;
-  unsigned long uvalue;
+  bfd_vma uvalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
 
@@ -662,11 +663,13 @@ decode_location_expression (unsigned cha
 	  data += 8;
 	  break;
 	case DW_OP_constu:
-	  printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_constu: %" BFD_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_consts:
-	  printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_consts: %" BFD_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_dup:
@@ -721,7 +724,7 @@ decode_location_expression (unsigned cha
 	  printf ("DW_OP_plus");
 	  break;
 	case DW_OP_plus_uconst:
-	  printf ("DW_OP_plus_uconst: %lu",
+	  printf ("DW_OP_plus_uconst: %" BFD_VMA_FMT "u",
 		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
@@ -867,7 +870,8 @@ decode_location_expression (unsigned cha
 	case DW_OP_breg29:
 	case DW_OP_breg30:
 	case DW_OP_breg31:
-	  printf ("DW_OP_breg%d (%s): %ld", op - DW_OP_breg0,
+	  printf ("DW_OP_breg%d (%s): %" BFD_VMA_FMT "d",
+		  op - DW_OP_breg0,
 		  regname (op - DW_OP_breg0, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
@@ -876,22 +880,26 @@ decode_location_expression (unsigned cha
 	case DW_OP_regx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_regx: %lu (%s)", uvalue, regname (uvalue, 1));
+	  printf ("DW_OP_regx: %" BFD_VMA_FMT "u (%s)",
+		  uvalue, regname (uvalue, 1));
 	  break;
 	case DW_OP_fbreg:
 	  need_frame_base = 1;
-	  printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_fbreg: %" BFD_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_bregx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_bregx: %lu (%s) %ld", uvalue, regname (uvalue, 1),
+	  printf ("DW_OP_bregx: %" BFD_VMA_FMT "u (%s) %" BFD_VMA_FMT "d",
+		  uvalue, regname (uvalue, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_piece:
-	  printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_piece: %" BFD_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_deref_size:
@@ -911,13 +919,15 @@ 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%lx>", (long) byte_get (data, 2) + cu_offset);
+	  printf ("DW_OP_call2: <0x%" BFD_VMA_FMT "x>",
+		  (bfd_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%lx>", (long) byte_get (data, 4) + cu_offset);
+	  printf ("DW_OP_call4: <0x%" BFD_VMA_FMT "x>",
+		  (bfd_signed_vma) byte_get (data, 4) + cu_offset);
 	  data += 4;
 	  break;
 	case DW_OP_call_ref:
@@ -950,9 +960,11 @@ decode_location_expression (unsigned cha
 	  break;
 	case DW_OP_bit_piece:
 	  printf ("DW_OP_bit_piece: ");
-	  printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("size: %" BFD_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
-	  printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("offset: %" BFD_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 
@@ -1001,16 +1013,20 @@ decode_location_expression (unsigned cha
 	    }
 	  if (dwarf_version == 2)
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, pointer_size),
-		      read_leb128 (data + pointer_size, &bytes_read, 1));
+	      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));
 	      data += pointer_size + bytes_read;
 	    }
 	  else
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, offset_size),
-		      read_leb128 (data + offset_size, &bytes_read, 1));
+	      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));
 	      data += offset_size + bytes_read;
 	    }
 	  break;
@@ -1072,15 +1088,15 @@ static unsigned char *
 read_and_display_attr_value (unsigned long attribute,
 			     unsigned long form,
 			     unsigned char * data,
-			     unsigned long cu_offset,
-			     unsigned long pointer_size,
-			     unsigned long offset_size,
+			     bfd_vma cu_offset,
+			     bfd_vma pointer_size,
+			     bfd_vma offset_size,
 			     int dwarf_version,
 			     debug_info * debug_info_p,
 			     int do_loc,
 			     struct dwarf_section * section)
 {
-  unsigned long uvalue = 0;
+  bfd_vma uvalue = 0;
   unsigned char *block_start = NULL;
   unsigned char * orig_data = data;
   unsigned int bytes_read;
@@ -1167,7 +1183,7 @@ read_and_display_attr_value (unsigned lo
     {
     case DW_FORM_ref_addr:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue);
+	printf (" <0x%" BFD_VMA_FMT "x>", uvalue);
       break;
 
     case DW_FORM_ref1:
@@ -1175,14 +1191,14 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_ref4:
     case DW_FORM_ref_udata:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue + cu_offset);
+	printf (" <0x%" BFD_VMA_FMT "x>", uvalue + cu_offset);
       break;
 
     case DW_FORM_data4:
     case DW_FORM_addr:
     case DW_FORM_sec_offset:
       if (!do_loc)
-	printf (" 0x%lx", uvalue);
+	printf (" 0x%" BFD_VMA_FMT "x", uvalue);
       break;
 
     case DW_FORM_flag_present:
@@ -1192,7 +1208,7 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_sdata:
     case DW_FORM_udata:
       if (!do_loc)
-	printf (" %ld", uvalue);
+	printf (" %" BFD_VMA_FMT "d", uvalue);
       break;
 
     case DW_FORM_ref8:
@@ -1200,7 +1216,7 @@ read_and_display_attr_value (unsigned lo
       if (!do_loc)
 	{
 	  uvalue = byte_get (data, 4);
-	  printf (" 0x%lx", uvalue);
+	  printf (" 0x%" BFD_VMA_FMT "x", uvalue);
 	  printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
 	}
       if ((do_loc || do_debug_loc || do_debug_ranges)
@@ -1209,7 +1225,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 (unsigned long) != 8\n"));
+	    error (_("DW_FORM_data8 is unsupported when sizeof (bfd_vma) != 8\n"));
 	}
       data += 8;
       break;
@@ -1259,7 +1275,7 @@ read_and_display_attr_value (unsigned lo
 
     case DW_FORM_strp:
       if (!do_loc)
-	printf (_(" (indirect string, offset: 0x%lx): %s"),
+	printf (_(" (indirect string, offset: 0x%" BFD_VMA_FMT "x): %s"),
 		uvalue, fetch_indirect_string (uvalue));
       break;
 
@@ -1313,7 +1329,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->loc_offsets = (long unsigned int *)
+		  debug_info_p->loc_offsets = (bfd_vma *)
                       xcrealloc (debug_info_p->loc_offsets,
 				 lmax, sizeof (*debug_info_p->loc_offsets));
 		  debug_info_p->have_frame_base = (int *)
@@ -1344,7 +1360,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->range_lists = (long unsigned int *)
+		  debug_info_p->range_lists = (bfd_vma *)
                       xcrealloc (debug_info_p->range_lists,
 				 lmax, sizeof (*debug_info_p->range_lists));
 		  debug_info_p->max_range_lists = lmax;
@@ -1383,7 +1399,8 @@ read_and_display_attr_value (unsigned lo
 	  printf (_("(declared as inline and inlined)"));
 	  break;
 	default:
-	  printf (_("  (Unknown inline attribute value: %lx)"), uvalue);
+	  printf (_("  (Unknown inline attribute value: %" BFD_VMA_FMT "x)"),
+	  	  uvalue);
 	  break;
 	}
       break;
@@ -1421,9 +1438,9 @@ 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: %lx)", uvalue);
+	    printf ("(implementation defined: %" BFD_VMA_FMT "x)", uvalue);
 	  else
-	    printf ("(Unknown: %lx)", uvalue);
+	    printf ("(Unknown: %" BFD_VMA_FMT "x)", uvalue);
 	  break;
 	}
       break;
@@ -1584,7 +1601,7 @@ read_and_display_attr_value (unsigned lo
 	  uvalue += cu_offset;
 
 	if (uvalue >= section->size)
-	  warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
+	  warn (_("Offset %" BFD_VMA_FMT "x used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
 		uvalue, (unsigned long) (orig_data - section->start));
 	else
 	  {
@@ -1786,9 +1803,9 @@ static unsigned char *
 read_and_display_attr (unsigned long attribute,
 		       unsigned long form,
 		       unsigned char * data,
-		       unsigned long cu_offset,
-		       unsigned long pointer_size,
-		       unsigned long offset_size,
+		       bfd_vma cu_offset,
+		       bfd_vma pointer_size,
+		       bfd_vma offset_size,
 		       int dwarf_version,
 		       debug_info * debug_info_p,
 		       int do_loc,
@@ -1900,7 +1917,7 @@ process_debug_info (struct dwarf_section
       unsigned char *hdrptr;
       unsigned char *tags;
       int level;
-      unsigned long cu_offset;
+      bfd_vma cu_offset;
       int offset_size;
       int initial_length_size;
       unsigned char signature[8] = { 0 };
@@ -1970,11 +1987,13 @@ process_debug_info (struct dwarf_section
 
       if (!do_loc)
 	{
-	  printf (_("  Compilation Unit @ offset 0x%lx:\n"), cu_offset);
-	  printf (_("   Length:        0x%lx (%s)\n"), compunit.cu_length,
+	  printf (_("  Compilation Unit @ offset 0x%" BFD_VMA_FMT "x:\n"), cu_offset);
+	  printf (_("   Length:        0x%" BFD_VMA_FMT "x (%s)\n"),
+		  compunit.cu_length,
 		  initial_length_size == 8 ? "64-bit" : "32-bit");
 	  printf (_("   Version:       %d\n"), compunit.cu_version);
-	  printf (_("   Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
+	  printf (_("   Abbrev Offset: %" BFD_VMA_FMT "d\n"),
+		  compunit.cu_abbrev_offset);
 	  printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
 	  if (do_types)
 	    {
@@ -1990,7 +2009,9 @@ process_debug_info (struct dwarf_section
       if (cu_offset + compunit.cu_length + initial_length_size
 	  > section->size)
 	{
-	  warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
+	  warn (_("Debug info is corrupted, length of CU at %"
+	  	  BFD_VMA_FMT "x extends beyond end of section (length = %"
+	  	  BFD_VMA_FMT "x)\n"),
 		cu_offset, compunit.cu_length);
 	  break;
 	}
@@ -2001,7 +2022,8 @@ process_debug_info (struct dwarf_section
 	  && compunit.cu_version != 3
 	  && compunit.cu_version != 4)
 	{
-	  warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
+	  warn (_("CU at offset %" BFD_VMA_FMT "x contains corrupt or "
+		  "unsupported version number: %d.\n"),
 		cu_offset, compunit.cu_version);
 	  continue;
 	}
@@ -2268,7 +2290,7 @@ display_debug_lines_raw (struct dwarf_se
       linfo.li_line_base >>= 24;
 
       printf (_("  Offset:                      0x%lx\n"), hdroff);
-      printf (_("  Length:                      %ld\n"), linfo.li_length);
+      printf (_("  Length:                      %ld\n"), (long) linfo.li_length);
       printf (_("  DWARF Version:               %d\n"), linfo.li_version);
       printf (_("  Prologue Length:             %d\n"), linfo.li_prologue_length);
       printf (_("  Minimum Instruction Length:  %d\n"), linfo.li_min_insn_length);
@@ -2329,11 +2351,14 @@ display_debug_lines_raw (struct dwarf_se
 
 	      data += strlen ((char *) data) + 1;
 
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" BFD_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" BFD_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" BFD_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
 	      printf ("%s\n", name);
 	    }
@@ -2505,7 +2530,8 @@ display_debug_lines_raw (struct dwarf_se
 
 	      for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
 		{
-		  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+		  printf ("0x%" BFD_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
 			  i == 1 ? "" : ", ");
 		  data += bytes_read;
 		}
@@ -2918,7 +2944,8 @@ display_debug_lines_decoded (struct dwar
 
               for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                 {
-                  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+                  printf ("0x%" BFD_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
                           i == 1 ? "" : ", ");
                   data += bytes_read;
                 }
@@ -3076,7 +3103,7 @@ display_debug_pubnames (struct dwarf_sec
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (names.pn_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      names.pn_offset, section->name);
+	      (unsigned long) names.pn_offset, section->name);
 
       names.pn_size = byte_get (data, offset_size);
       data += offset_size;
@@ -3097,13 +3124,13 @@ display_debug_pubnames (struct dwarf_sec
 	}
 
       printf (_("  Length:                              %ld\n"),
-	      names.pn_length);
+	      (long) names.pn_length);
       printf (_("  Version:                             %d\n"),
 	      names.pn_version);
       printf (_("  Offset into .debug_info section:     0x%lx\n"),
-	      names.pn_offset);
+	      (unsigned long) names.pn_offset);
       printf (_("  Size of area in .debug_info section: %ld\n"),
-	      names.pn_size);
+	      (long) names.pn_size);
 
       printf (_("\n    Offset\tName\n"));
 
@@ -3323,7 +3350,7 @@ display_debug_loc (struct dwarf_section 
   /* DWARF sections under Mach-O have non-zero addresses.  */
   if (debug_information [first].num_loc_offsets > 0
       && debug_information [first].loc_offsets [0] != section->address)
-    warn (_("Location lists in %s section start at 0x%lx\n"),
+    warn (_("Location lists in %s section start at 0x%" BFD_VMA_FMT "x\n"),
 	  section->name, debug_information [first].loc_offsets [0]);
 
   printf (_("Contents of the %s section:\n\n"), section->name);
@@ -3596,7 +3623,7 @@ display_debug_aranges (struct dwarf_sect
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      arange.ar_info_offset, section->name);
+	      (unsigned long) arange.ar_info_offset, section->name);
 
       arange.ar_pointer_size = byte_get (hdrptr, 1);
       hdrptr += 1;
@@ -3610,9 +3637,11 @@ display_debug_aranges (struct dwarf_sect
 	  break;
 	}
 
-      printf (_("  Length:                   %ld\n"), arange.ar_length);
+      printf (_("  Length:                   %ld\n"),
+	      (long) arange.ar_length);
       printf (_("  Version:                  %d\n"), arange.ar_version);
-      printf (_("  Offset into .debug_info:  0x%lx\n"), arange.ar_info_offset);
+      printf (_("  Offset into .debug_info:  0x%lx\n"),
+	      (unsigned long) arange.ar_info_offset);
       printf (_("  Pointer Size:             %d\n"), arange.ar_pointer_size);
       printf (_("  Segment Size:             %d\n"), arange.ar_segment_size);
 
Index: src/binutils/dwarf.h
===================================================================
--- src.orig/binutils/dwarf.h	2011-02-17 11:00:34.000000000 +0100
+++ src/binutils/dwarf.h	2011-02-18 10:25:34.608846800 +0100
@@ -22,6 +22,92 @@
 typedef unsigned HOST_WIDEST_INT dwarf_vma;
 typedef unsigned HOST_WIDEST_INT dwarf_size_type;
 
+/* Structure found in the .debug_line section.  */
+typedef struct
+{
+  unsigned char li_length          [4];
+  unsigned char li_version         [2];
+  unsigned char li_prologue_length [4];
+  unsigned char li_min_insn_length [1];
+  unsigned char li_default_is_stmt [1];
+  unsigned char li_line_base       [1];
+  unsigned char li_line_range      [1];
+  unsigned char li_opcode_base     [1];
+}
+DWARF2_External_LineInfo;
+
+typedef struct
+{
+  bfd_vma	 li_length;
+  unsigned short li_version;
+  unsigned int   li_prologue_length;
+  unsigned char  li_min_insn_length;
+  unsigned char  li_max_ops_per_insn;
+  unsigned char  li_default_is_stmt;
+  int            li_line_base;
+  unsigned char  li_line_range;
+  unsigned char  li_opcode_base;
+}
+DWARF2_Internal_LineInfo;
+
+/* Structure found in .debug_pubnames section.  */
+typedef struct
+{
+  unsigned char pn_length  [4];
+  unsigned char pn_version [2];
+  unsigned char pn_offset  [4];
+  unsigned char pn_size    [4];
+}
+DWARF2_External_PubNames;
+
+typedef struct
+{
+  bfd_vma	 pn_length;
+  unsigned short pn_version;
+  bfd_vma	 pn_offset;
+  bfd_vma	 pn_size;
+}
+DWARF2_Internal_PubNames;
+
+/* Structure found in .debug_info section.  */
+typedef struct
+{
+  unsigned char  cu_length        [4];
+  unsigned char  cu_version       [2];
+  unsigned char  cu_abbrev_offset [4];
+  unsigned char  cu_pointer_size  [1];
+}
+DWARF2_External_CompUnit;
+
+typedef struct
+{
+  bfd_vma	 cu_length;
+  unsigned short cu_version;
+  bfd_vma	 cu_abbrev_offset;
+  unsigned char  cu_pointer_size;
+}
+DWARF2_Internal_CompUnit;
+
+typedef struct
+{
+  unsigned char  ar_length       [4];
+  unsigned char  ar_version      [2];
+  unsigned char  ar_info_offset  [4];
+  unsigned char  ar_pointer_size [1];
+  unsigned char  ar_segment_size [1];
+}
+DWARF2_External_ARange;
+
+typedef struct
+{
+  bfd_vma	 ar_length;
+  unsigned short ar_version;
+  bfd_vma	 ar_info_offset;
+  unsigned char  ar_pointer_size;
+  unsigned char  ar_segment_size;
+}
+DWARF2_Internal_ARange;
+
 struct dwarf_section
 {
   /* A debug section has a different name when it's stored compressed
@@ -79,15 +165,15 @@ typedef struct
   unsigned int   pointer_size;
   unsigned int   offset_size;
   int            dwarf_version;
-  unsigned long  cu_offset;
-  unsigned long	 base_address;
+  bfd_vma	 cu_offset;
+  bfd_vma	 base_address;
   /* This is an array of offsets to the location list table.  */
-  unsigned long *loc_offsets;
+  bfd_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.  */
-  unsigned long *range_lists;
+  bfd_vma	*range_lists;
   unsigned int   num_range_lists;
   unsigned int   max_range_lists;
 }
@@ -131,5 +217,5 @@ void *cmalloc (size_t, size_t);
 void *xcmalloc (size_t, size_t);
 void *xcrealloc (void *, size_t, size_t);
 
-unsigned long int read_leb128 (unsigned char *data,
-			       unsigned int *length_return, int sign);
+bfd_vma read_leb128 (unsigned char *data,
+		     unsigned int *length_return, int sign);
Index: src/include/dwarf2.h
===================================================================
--- src.orig/include/dwarf2.h	2011-02-17 11:00:34.000000000 +0100
+++ src/include/dwarf2.h	2011-02-18 10:20:13.267332800 +0100
@@ -44,95 +44,8 @@
 /* This file is shared between GCC and GDB, and should not contain
    prototypes.  */
 
-#ifndef _ELF_DWARF2_H
-#define _ELF_DWARF2_H
-
-/* Structure found in the .debug_line section.  */
-typedef struct
-{
-  unsigned char li_length          [4];
-  unsigned char li_version         [2];
-  unsigned char li_prologue_length [4];
-  unsigned char li_min_insn_length [1];
-  unsigned char li_default_is_stmt [1];
-  unsigned char li_line_base       [1];
-  unsigned char li_line_range      [1];
-  unsigned char li_opcode_base     [1];
-}
-DWARF2_External_LineInfo;
-
-typedef struct
-{
-  unsigned long  li_length;
-  unsigned short li_version;
-  unsigned int   li_prologue_length;
-  unsigned char  li_min_insn_length;
-  unsigned char  li_max_ops_per_insn;
-  unsigned char  li_default_is_stmt;
-  int            li_line_base;
-  unsigned char  li_line_range;
-  unsigned char  li_opcode_base;
-}
-DWARF2_Internal_LineInfo;
-
-/* Structure found in .debug_pubnames section.  */
-typedef struct
-{
-  unsigned char pn_length  [4];
-  unsigned char pn_version [2];
-  unsigned char pn_offset  [4];
-  unsigned char pn_size    [4];
-}
-DWARF2_External_PubNames;
-
-typedef struct
-{
-  unsigned long  pn_length;
-  unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
-}
-DWARF2_Internal_PubNames;
-
-/* Structure found in .debug_info section.  */
-typedef struct
-{
-  unsigned char  cu_length        [4];
-  unsigned char  cu_version       [2];
-  unsigned char  cu_abbrev_offset [4];
-  unsigned char  cu_pointer_size  [1];
-}
-DWARF2_External_CompUnit;
-
-typedef struct
-{
-  unsigned long  cu_length;
-  unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
-  unsigned char  cu_pointer_size;
-}
-DWARF2_Internal_CompUnit;
-
-typedef struct
-{
-  unsigned char  ar_length       [4];
-  unsigned char  ar_version      [2];
-  unsigned char  ar_info_offset  [4];
-  unsigned char  ar_pointer_size [1];
-  unsigned char  ar_segment_size [1];
-}
-DWARF2_External_ARange;
-
-typedef struct
-{
-  unsigned long  ar_length;
-  unsigned short ar_version;
-  unsigned long  ar_info_offset;
-  unsigned char  ar_pointer_size;
-  unsigned char  ar_segment_size;
-}
-DWARF2_Internal_ARange;
-
+#ifndef _DWARF2_H
+#define _DWARF2_H
 
 /* Tag names and codes.  */
 enum dwarf_tag
@@ -953,4 +866,4 @@ enum dwarf_macinfo_record_type
 
 #define DW_EH_PE_indirect	0x80
 
-#endif /* _ELF_DWARF2_H */
+#endif /* _DWARF2_H */

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-18  9:50         ` Kai Tietz
@ 2011-02-21 12:37           ` NightStrike
  0 siblings, 0 replies; 30+ messages in thread
From: NightStrike @ 2011-02-21 12:37 UTC (permalink / raw)
  To: Kai Tietz
  Cc: Alan Modra, GCC Patches, Binutils, gdb, Joel Brobecker, Jakub Jelinek

Ping

On Fri, Feb 18, 2011 at 4:50 AM, Kai Tietz <ktietz70@googlemail.com> wrote:
> 2011/2/17 Jakub Jelinek <jakub@redhat.com>:
>> On Thu, Feb 17, 2011 at 08:06:53PM +0100, Kai Tietz wrote:
>>> > I'd prefer if we could move those binutils specific internal implementation
>>> > details out of the dwarf2.h header, keep it really just for the stuff
>>> > defined in the standard, and add a new binutils specific header somewhere
>>> > else which would contain binutils specific details.
>>>
>>> Well, so we make dwarf2.h in include just host-specific and isn't able
>>> to cover things for foreign target, like 32-bit host can't use this
>>> header for 64-bit dwarf2 information. I am fine by this, but
>>> nevertheless is then the use of 'unsigned long' type within this
>>> header still an issue. Here should be used instead then 'intptr_t'. As
>>> on LLP64 unsigned long isn't wide-enough.
>>
>> I mean that none of the DWARF2_Internal types should be in the
>> include/dwarf2.h headers (that's implementation specific stuff),
>> and the DWARF2_External types are questionable too, to me they look
>> very much like implementation detail too.  E.g. DWARF2_External_LineInfo
>> type is dubious, because it might somehow describe version 2 or 3
>> .debug_line header, but version 4 looks differently, etc.
>> So IMHO the DWARF2_External stuff should be moved too.
>> And the guard should be probably renamed from _ELF_DWARF2_H to _DWARF2_H,
>> I don't see anything ELF specific in the header.
>>
>>        Jakub
>>
>
> So I reworked my patch as Jakub suggested and retested it for
> x86_64-w64-mingw32, i686-w64-mingw32, and x86_64-pc-linux-gnu for gcc,
> binutils, and gdb. Ok for apply?
>
> binutils, gdb, gcc
>
> ChangeLog include/
>
> 2011-02-18  Kai Tietz
>
>                 * dwarf2.h (_ELF_DWARF2_H): Renamed to
>                 _DWARF2_H.
>                 (DWARF2_External_LineInfo, DWARF2_Internal_LineInfo,
>                 DWARF2_External_PubNames, DWARF2_Internal_PubNames,
>                 DWARF2_External_CompUnit, DWARF2_Internal_CompUnit,
>                 DWARF2_External_ARange, DWARF2_Internal_ARange): Removed.
>
>
> ChangeLog binutils/
>
> 2011-02-18  Kai Tietz
>
>                 * dwarf.c (read_leb128): Use dw2_vma_t instead of
>                 long type.
>                 (process_extended_line_op): Use for adr bfd_vma
>                 type and print those typed values via BFD_VMA_FMT.
>                 (fetch_indirect_string): Adjust offset's type.
>                 (decode_location_expression): Adjust argument types
>                 and uvalue type.
>                 (read_and_display_attr_value): Likewise.
>                 (read_and_display_attr): Likewise.
>                 (decode_location_expression): Adjust printf format.
>                 (process_debug_info): Likewise.
>                 (display_debug_lines_raw): Likewise.
>                 (display_debug_lines_decoded): Likewise.
>                 (display_debug_pubnames): Likewise.
>                 (display_debug_loc): Likewise.
>                 (display_debug_aranges): Likewise.
>                 * dwarf.h (DWARF2_External_LineInfo,
>                 DWARF2_Internal_LineInfo, DWARF2_External_PubNames,
>                 DWARF2_Internal_PubNames, DWARF2_External_CompUnit,
>                 DWARF2_Internal_CompUnit, DWARF2_External_ARange,
>                 DWARF2_Internal_ARange): Added..
>                 (read_leb128): Adjust return type.
>
> Regards,
> Kai
>
> PS: A lot of those moved structures aren't used at all in binutils
> dwarf.c (which is the only consumer of some of those structures as a
> grep over binutils/gdb/gcc had shown). So maybe the unused could be
> removed in a second patch completely.
>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-17 14:21 [RFC patch]: Adjust the use of 'long' type in dwarf2.h header Kai Tietz
  2011-02-17 18:59 ` Kai Tietz
@ 2011-02-21 13:10 ` Pierre Muller
       [not found] ` <-8460070221060995487@unknownmsgid>
  2 siblings, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-21 13:10 UTC (permalink / raw)
  To: 'Kai Tietz', 'GCC Patches', 'Binutils',
	'gdb'
  Cc: 'Jakub Jelinek', 'Joel Brobecker'

  I was just wondering about all those
  _("Text with some 0x" BFD_VMA_FMT "x\n"), adr);
constructs:
  If we do the translations on a 64-bit unix machine
we will have translations for
"Text with some 0xllx\n" 
but a mingw 64-bit executable will look for
"Text with some 0xI64x\n"
while a 32-bit system will look for
"Text with some 0xlx\n"
and in both cases, no translation will be found.

  Wouldn't it be better to use something similar 
to paddress in src/gdb/utils.c
let's call it dwarf_vma function,
so that we have:
 _("Text with some 0x%s\n"), dwarf_vma (adr));
with a unique "Text with some 0x%s\n"
string that gets internationalized correctly?


Pierre Muller
GDB pascal language maintainer


> -----Message d'origine-----
> De : gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] De la
> part de Kai Tietz
> Envoyé : jeudi 17 février 2011 15:22
> À : GCC Patches; Binutils; gdb
> Cc : Jakub Jelinek; Joel Brobecker
> Objet : [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
> 
> Hello,
> 
> This patch addresses issues I've seen in binutils about
> cross-compilers and dwarf2 display via objdump -W on hosts, which have
> sizeof (long) < target's sizeof(void *). Additionally same issue of
> course can be seen on LLP64 targets, too.
> Those issues are caused by the fact that the dwarf2.h header in
> include/ is using unconditionally the type 'unsigned long' for
> vma-scalars.
> 
> This patch address additionally the binutils' dwarf.(c|h) files and
> make them host bitness independent for gcc base toolchains supporting
> the 'long long' type.
> 
> I've tested the attached patches for gdb, binutils, and gcc on
> i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
> cygwin. And I didn't found until now regressions. Later this day I
> want to do a regression test for linux64, too.
> 
> 
> binutils, gdb, gcc
> 
> ChangeLog include/
> 
> 2011-02-17  Kai Tietz
> 
> 	* dwarf2.h (dw2_vma_t): New type.
> 	(dw2_svma_t): New type.
> 	(DW2_VMA_FMT): New macro specifying
> 	to be used width-sepecifier for printing
> 	new types.
> 
> 
> ChangeLog binutils/
> 
> 2011-02-17  Kai Tietz
> 
> 	* dwarf.c (read_leb128): Use dw2_vma_t instead of
> 	long type.
> 	(process_extended_line_op): Use for adr new type
> 	and print dw2 values via DW2_VMA_FMT.
> 	(fetch_indirect_string): Adjust offset's type.
> 	(decode_location_expression): Adjust argument types
> 	and uvalue type.
> 	(read_and_display_attr_value): Likewise.
> 	(read_and_display_attr): Likewise.
> 	(decode_location_expression): Adjust printf format.
> 	(process_debug_info): Likewise.
> 	(display_debug_lines_raw): Likewise.
> 	(display_debug_lines_decoded): Likewise.
> 	(display_debug_pubnames): Likewise.
> 	(display_debug_loc): Likewise.
> 	(display_debug_aranges): Likewise.
> 	* dwarf.h: Add include of dwarf2.h header and
> 	use of dw2_vma_t instead of long types.
> 	(read_leb128): Adjust return type.
> 
> 
> Regards,
> Kai
> 
> 
> PS: On gdb there is at the moment in gdb/common part the include-path
> to intl for libintl.h missing

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
       [not found] ` <-8460070221060995487@unknownmsgid>
@ 2011-02-21 13:27   ` Kai Tietz
  2011-02-21 13:46     ` Pierre Muller
       [not found]     ` <-6930711422310680743@unknownmsgid>
  0 siblings, 2 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-21 13:27 UTC (permalink / raw)
  To: Pierre Muller; +Cc: GCC Patches, Binutils, gdb, Jakub Jelinek, Joel Brobecker

2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>  I was just wondering about all those
>  _("Text with some 0x" BFD_VMA_FMT "x\n"), adr);
> constructs:
>  If we do the translations on a 64-bit unix machine
> we will have translations for
> "Text with some 0xllx\n"
> but a mingw 64-bit executable will look for
> "Text with some 0xI64x\n"
> while a 32-bit system will look for
> "Text with some 0xlx\n"
> and in both cases, no translation will be found.
>
>  Wouldn't it be better to use something similar
> to paddress in src/gdb/utils.c
> let's call it dwarf_vma function,
> so that we have:
>  _("Text with some 0x%s\n"), dwarf_vma (adr));
> with a unique "Text with some 0x%s\n"
> string that gets internationalized correctly?
>
>
> Pierre Muller
> GDB pascal language maintainer
>
>
>> -----Message d'origine-----
>> De : gdb-owner@sourceware.org [mailto:gdb-owner@sourceware.org] De la
>> part de Kai Tietz
>> Envoyé : jeudi 17 février 2011 15:22
>> À : GCC Patches; Binutils; gdb
>> Cc : Jakub Jelinek; Joel Brobecker
>> Objet : [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
>>
>> Hello,
>>
>> This patch addresses issues I've seen in binutils about
>> cross-compilers and dwarf2 display via objdump -W on hosts, which have
>> sizeof (long) < target's sizeof(void *). Additionally same issue of
>> course can be seen on LLP64 targets, too.
>> Those issues are caused by the fact that the dwarf2.h header in
>> include/ is using unconditionally the type 'unsigned long' for
>> vma-scalars.
>>
>> This patch address additionally the binutils' dwarf.(c|h) files and
>> make them host bitness independent for gcc base toolchains supporting
>> the 'long long' type.
>>
>> I've tested the attached patches for gdb, binutils, and gcc on
>> i686-w64-mingw32, and x86_64-w64-mingw32 cross-toolchains hosted on
>> cygwin. And I didn't found until now regressions. Later this day I
>> want to do a regression test for linux64, too.
>>
>>
>> binutils, gdb, gcc
>>
>> ChangeLog include/
>>
>> 2011-02-17  Kai Tietz
>>
>>       * dwarf2.h (dw2_vma_t): New type.
>>       (dw2_svma_t): New type.
>>       (DW2_VMA_FMT): New macro specifying
>>       to be used width-sepecifier for printing
>>       new types.
>>
>>
>> ChangeLog binutils/
>>
>> 2011-02-17  Kai Tietz
>>
>>       * dwarf.c (read_leb128): Use dw2_vma_t instead of
>>       long type.
>>       (process_extended_line_op): Use for adr new type
>>       and print dw2 values via DW2_VMA_FMT.
>>       (fetch_indirect_string): Adjust offset's type.
>>       (decode_location_expression): Adjust argument types
>>       and uvalue type.
>>       (read_and_display_attr_value): Likewise.
>>       (read_and_display_attr): Likewise.
>>       (decode_location_expression): Adjust printf format.
>>       (process_debug_info): Likewise.
>>       (display_debug_lines_raw): Likewise.
>>       (display_debug_lines_decoded): Likewise.
>>       (display_debug_pubnames): Likewise.
>>       (display_debug_loc): Likewise.
>>       (display_debug_aranges): Likewise.
>>       * dwarf.h: Add include of dwarf2.h header and
>>       use of dw2_vma_t instead of long types.
>>       (read_leb128): Adjust return type.
>>
>>
>> Regards,
>> Kai
>>
>>
>> PS: On gdb there is at the moment in gdb/common part the include-path
>> to intl for libintl.h missing
>
>

Yes, I saw this too and it is a thorn here. But the issue about a
transformation function (like dwarf_vma) is that we have memory leaks
- as this function is to be used on some printf's more then once - as
static buffer would be overriden. Well printfs can be splitted into
smaller parts, but this then would make localization even harder.

Maybe it would be better here to remove those localizations?

Regards,
Kai



-- 
|  (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-21 13:27   ` Kai Tietz
@ 2011-02-21 13:46     ` Pierre Muller
       [not found]     ` <-6930711422310680743@unknownmsgid>
  1 sibling, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-21 13:46 UTC (permalink / raw)
  To: 'Kai Tietz'
  Cc: 'GCC Patches', 'Binutils', 'gdb',
	'Jakub Jelinek', 'Joel Brobecker'

> Yes, I saw this too and it is a thorn here. But the issue about a
> transformation function (like dwarf_vma) is that we have memory leaks
> - as this function is to be used on some printf's more then once - as
> static buffer would be overriden. Well printfs can be splitted into
> smaller parts, but this then would make localization even harder.

 In GDB code, this is solved in utils.c source by the use of the
get_cell function, which rotates over 16 char arrays of size 50 each
currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
64-bit)
for this dwarf_vma function would probably be enough, no?


Pierre Muller
GDB pascal language maintainer





^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
       [not found]     ` <-6930711422310680743@unknownmsgid>
@ 2011-02-21 14:30       ` Kai Tietz
  2011-02-21 15:25         ` Kai Tietz
  0 siblings, 1 reply; 30+ messages in thread
From: Kai Tietz @ 2011-02-21 14:30 UTC (permalink / raw)
  To: Pierre Muller; +Cc: GCC Patches, Binutils, gdb, Jakub Jelinek, Joel Brobecker

2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>> Yes, I saw this too and it is a thorn here. But the issue about a
>> transformation function (like dwarf_vma) is that we have memory leaks
>> - as this function is to be used on some printf's more then once - as
>> static buffer would be overriden. Well printfs can be splitted into
>> smaller parts, but this then would make localization even harder.
>
>  In GDB code, this is solved in utils.c source by the use of the
> get_cell function, which rotates over 16 char arrays of size 50 each
> currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
> 64-bit)
> for this dwarf_vma function would probably be enough, no?
>
>
> Pierre Muller
> GDB pascal language maintainer

Yes, this sounds ok. I think maximum here are right now 3 dwarf_vma
prints within one printf. So it should be ok. I'll add here such a
rotating function. I don't assume we need here to handle
multi-threading, so rotation code can be pretty simple.

Kai

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-21 14:30       ` Kai Tietz
@ 2011-02-21 15:25         ` Kai Tietz
  2011-02-21 15:43           ` Mark Kettenis
  2011-02-22 15:21           ` Nick Clifton
  0 siblings, 2 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-21 15:25 UTC (permalink / raw)
  To: Pierre Muller; +Cc: GCC Patches, Binutils, gdb, Jakub Jelinek, Joel Brobecker

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

2011/2/21 Kai Tietz <ktietz70@googlemail.com>:
> 2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>>> Yes, I saw this too and it is a thorn here. But the issue about a
>>> transformation function (like dwarf_vma) is that we have memory leaks
>>> - as this function is to be used on some printf's more then once - as
>>> static buffer would be overriden. Well printfs can be splitted into
>>> smaller parts, but this then would make localization even harder.
>>
>>  In GDB code, this is solved in utils.c source by the use of the
>> get_cell function, which rotates over 16 char arrays of size 50 each
>> currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
>> 64-bit)
>> for this dwarf_vma function would probably be enough, no?
>>
>>
>> Pierre Muller
>> GDB pascal language maintainer
>
> Yes, this sounds ok. I think maximum here are right now 3 dwarf_vma
> prints within one printf. So it should be ok. I'll add here such a
> rotating function. I don't assume we need here to handle
> multi-threading, so rotation code can be pretty simple.
>
> Kai
>

So this version uses new function dwarf_vma_print function for
printf-messages, which are getting localized.

Tested for x86_64-w64-mingw32 and x86_64-pc-linux-gnu. Ok for apply?

Regards,
Kai

[-- Attachment #2: b_dw2_inc.txt --]
[-- Type: text/plain, Size: 26569 bytes --]

Index: src/binutils/dwarf.c
===================================================================
--- src.orig/binutils/dwarf.c	2011-02-05 21:34:39.000000000 +0100
+++ src/binutils/dwarf.c	2011-02-21 16:20:00.124265900 +0100
@@ -123,10 +123,28 @@ print_dwarf_vma (dwarf_vma val, unsigned
   fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
 }
 
-unsigned long int
+static const char *
+dwarf_vma_print (const char *fmtch, bfd_vma value)
+{
+  static int buf_pos = 0;
+  static struct dwarf_vma_print_buf {
+    char place[64];
+  } buf[16];
+  char fmt[32];
+  char *ret;
+
+  sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
+  ret = &buf[buf_pos++].place[0];
+  buf_pos &= 15;
+
+  snprintf (ret, 64, fmt, value);
+  return ret;
+}
+
+bfd_vma
 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
-  unsigned long int result = 0;
+  bfd_vma result = 0;
   unsigned int num_read = 0;
   unsigned int shift = 0;
   unsigned char byte;
@@ -136,7 +154,7 @@ read_leb128 (unsigned char *data, unsign
       byte = *data++;
       num_read++;
 
-      result |= ((unsigned long int) (byte & 0x7f)) << shift;
+      result |= ((bfd_vma) (byte & 0x7f)) << shift;
 
       shift += 7;
 
@@ -193,7 +211,7 @@ process_extended_line_op (unsigned char
   unsigned int bytes_read;
   unsigned int len;
   unsigned char *name;
-  unsigned long adr;
+  bfd_vma adr;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -218,7 +236,7 @@ process_extended_line_op (unsigned char
 
     case DW_LNE_set_address:
       adr = byte_get (data, len - bytes_read - 1);
-      printf (_("set Address to 0x%lx\n"), adr);
+      printf (_("set Address to 0x%s\n"), dwarf_vma_print ("x", adr));
       state_machine_regs.address = adr;
       state_machine_regs.op_index = 0;
       break;
@@ -230,17 +248,19 @@ process_extended_line_op (unsigned char
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
       name = data;
       data += strlen ((char *) data) + 1;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" BFD_VMA_FMT "u\t",
+	      read_leb128 (data, & bytes_read, 0));
       data += bytes_read;
-      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+      printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
       printf ("%s\n\n", name);
       break;
 
     case DW_LNE_set_discriminator:
-      printf (_("set Discriminator to %lu\n"),
-              read_leb128 (data, & bytes_read, 0));
+      printf (_("set Discriminator to %s\n"),
+	      dwarf_vma_print ("u",
+			       read_leb128 (data, & bytes_read, 0)));
       break;
 
     /* HP extensions.  */
@@ -291,7 +311,7 @@ process_extended_line_op (unsigned char
 }
 
 static const char *
-fetch_indirect_string (unsigned long offset)
+fetch_indirect_string (bfd_vma offset)
 {
   struct dwarf_section *section = &debug_displays [str].section;
 
@@ -302,7 +322,7 @@ fetch_indirect_string (unsigned long off
   offset -= section->address;
   if (offset > section->size)
     {
-      warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
+      warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset);
       return _("<offset is too big>");
     }
 
@@ -605,13 +625,13 @@ decode_location_expression (unsigned cha
 			    unsigned int pointer_size,
 			    unsigned int offset_size,
 			    int dwarf_version,
-			    unsigned long length,
-			    unsigned long cu_offset,
+			    bfd_vma length,
+			    bfd_vma cu_offset,
 			    struct dwarf_section * section)
 {
   unsigned op;
   unsigned int bytes_read;
-  unsigned long uvalue;
+  bfd_vma uvalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
 
@@ -662,11 +682,13 @@ decode_location_expression (unsigned cha
 	  data += 8;
 	  break;
 	case DW_OP_constu:
-	  printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_constu: %" BFD_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_consts:
-	  printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_consts: %" BFD_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_dup:
@@ -721,7 +743,7 @@ decode_location_expression (unsigned cha
 	  printf ("DW_OP_plus");
 	  break;
 	case DW_OP_plus_uconst:
-	  printf ("DW_OP_plus_uconst: %lu",
+	  printf ("DW_OP_plus_uconst: %" BFD_VMA_FMT "u",
 		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
@@ -867,7 +889,8 @@ decode_location_expression (unsigned cha
 	case DW_OP_breg29:
 	case DW_OP_breg30:
 	case DW_OP_breg31:
-	  printf ("DW_OP_breg%d (%s): %ld", op - DW_OP_breg0,
+	  printf ("DW_OP_breg%d (%s): %" BFD_VMA_FMT "d",
+		  op - DW_OP_breg0,
 		  regname (op - DW_OP_breg0, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
@@ -876,22 +899,26 @@ decode_location_expression (unsigned cha
 	case DW_OP_regx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_regx: %lu (%s)", uvalue, regname (uvalue, 1));
+	  printf ("DW_OP_regx: %" BFD_VMA_FMT "u (%s)",
+		  uvalue, regname (uvalue, 1));
 	  break;
 	case DW_OP_fbreg:
 	  need_frame_base = 1;
-	  printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
+	  printf ("DW_OP_fbreg: %" BFD_VMA_FMT "d",
+		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_bregx:
 	  uvalue = read_leb128 (data, &bytes_read, 0);
 	  data += bytes_read;
-	  printf ("DW_OP_bregx: %lu (%s) %ld", uvalue, regname (uvalue, 1),
+	  printf ("DW_OP_bregx: %" BFD_VMA_FMT "u (%s) %" BFD_VMA_FMT "d",
+		  uvalue, regname (uvalue, 1),
 		  read_leb128 (data, &bytes_read, 1));
 	  data += bytes_read;
 	  break;
 	case DW_OP_piece:
-	  printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
+	  printf ("DW_OP_piece: %" BFD_VMA_FMT "u",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 	case DW_OP_deref_size:
@@ -911,13 +938,15 @@ 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%lx>", (long) byte_get (data, 2) + cu_offset);
+	  printf ("DW_OP_call2: <0x%" BFD_VMA_FMT "x>",
+		  (bfd_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%lx>", (long) byte_get (data, 4) + cu_offset);
+	  printf ("DW_OP_call4: <0x%" BFD_VMA_FMT "x>",
+		  (bfd_signed_vma) byte_get (data, 4) + cu_offset);
 	  data += 4;
 	  break;
 	case DW_OP_call_ref:
@@ -950,9 +979,11 @@ decode_location_expression (unsigned cha
 	  break;
 	case DW_OP_bit_piece:
 	  printf ("DW_OP_bit_piece: ");
-	  printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("size: %" BFD_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
-	  printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
+	  printf ("offset: %" BFD_VMA_FMT "u ",
+		  read_leb128 (data, &bytes_read, 0));
 	  data += bytes_read;
 	  break;
 
@@ -1001,16 +1032,20 @@ decode_location_expression (unsigned cha
 	    }
 	  if (dwarf_version == 2)
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, pointer_size),
-		      read_leb128 (data + pointer_size, &bytes_read, 1));
+	      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));
 	      data += pointer_size + bytes_read;
 	    }
 	  else
 	    {
-	      printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
-		      (long) byte_get (data, offset_size),
-		      read_leb128 (data + offset_size, &bytes_read, 1));
+	      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));
 	      data += offset_size + bytes_read;
 	    }
 	  break;
@@ -1072,15 +1107,15 @@ static unsigned char *
 read_and_display_attr_value (unsigned long attribute,
 			     unsigned long form,
 			     unsigned char * data,
-			     unsigned long cu_offset,
-			     unsigned long pointer_size,
-			     unsigned long offset_size,
+			     bfd_vma cu_offset,
+			     bfd_vma pointer_size,
+			     bfd_vma offset_size,
 			     int dwarf_version,
 			     debug_info * debug_info_p,
 			     int do_loc,
 			     struct dwarf_section * section)
 {
-  unsigned long uvalue = 0;
+  bfd_vma uvalue = 0;
   unsigned char *block_start = NULL;
   unsigned char * orig_data = data;
   unsigned int bytes_read;
@@ -1167,7 +1202,7 @@ read_and_display_attr_value (unsigned lo
     {
     case DW_FORM_ref_addr:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue);
+	printf (" <0x%" BFD_VMA_FMT "x>", uvalue);
       break;
 
     case DW_FORM_ref1:
@@ -1175,14 +1210,14 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_ref4:
     case DW_FORM_ref_udata:
       if (!do_loc)
-	printf (" <0x%lx>", uvalue + cu_offset);
+	printf (" <0x%" BFD_VMA_FMT "x>", uvalue + cu_offset);
       break;
 
     case DW_FORM_data4:
     case DW_FORM_addr:
     case DW_FORM_sec_offset:
       if (!do_loc)
-	printf (" 0x%lx", uvalue);
+	printf (" 0x%" BFD_VMA_FMT "x", uvalue);
       break;
 
     case DW_FORM_flag_present:
@@ -1192,7 +1227,7 @@ read_and_display_attr_value (unsigned lo
     case DW_FORM_sdata:
     case DW_FORM_udata:
       if (!do_loc)
-	printf (" %ld", uvalue);
+	printf (" %" BFD_VMA_FMT "d", uvalue);
       break;
 
     case DW_FORM_ref8:
@@ -1200,7 +1235,7 @@ read_and_display_attr_value (unsigned lo
       if (!do_loc)
 	{
 	  uvalue = byte_get (data, 4);
-	  printf (" 0x%lx", uvalue);
+	  printf (" 0x%" BFD_VMA_FMT "x", uvalue);
 	  printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
 	}
       if ((do_loc || do_debug_loc || do_debug_ranges)
@@ -1209,7 +1244,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 (unsigned long) != 8\n"));
+	    error (_("DW_FORM_data8 is unsupported when sizeof (bfd_vma) != 8\n"));
 	}
       data += 8;
       break;
@@ -1259,8 +1294,9 @@ read_and_display_attr_value (unsigned lo
 
     case DW_FORM_strp:
       if (!do_loc)
-	printf (_(" (indirect string, offset: 0x%lx): %s"),
-		uvalue, fetch_indirect_string (uvalue));
+	printf (_(" (indirect string, offset: 0x%s): %s"),
+		dwarf_vma_print ("x", uvalue),
+		fetch_indirect_string (uvalue));
       break;
 
     case DW_FORM_indirect:
@@ -1313,7 +1349,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->loc_offsets = (long unsigned int *)
+		  debug_info_p->loc_offsets = (bfd_vma *)
                       xcrealloc (debug_info_p->loc_offsets,
 				 lmax, sizeof (*debug_info_p->loc_offsets));
 		  debug_info_p->have_frame_base = (int *)
@@ -1344,7 +1380,7 @@ read_and_display_attr_value (unsigned lo
 	      if (lmax == 0 || num >= lmax)
 		{
 		  lmax += 1024;
-		  debug_info_p->range_lists = (long unsigned int *)
+		  debug_info_p->range_lists = (bfd_vma *)
                       xcrealloc (debug_info_p->range_lists,
 				 lmax, sizeof (*debug_info_p->range_lists));
 		  debug_info_p->max_range_lists = lmax;
@@ -1383,7 +1419,8 @@ read_and_display_attr_value (unsigned lo
 	  printf (_("(declared as inline and inlined)"));
 	  break;
 	default:
-	  printf (_("  (Unknown inline attribute value: %lx)"), uvalue);
+	  printf (_("  (Unknown inline attribute value: %s)"),
+		  dwarf_vma_print ("x", uvalue));
 	  break;
 	}
       break;
@@ -1421,9 +1458,9 @@ 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: %lx)", uvalue);
+	    printf ("(implementation defined: %" BFD_VMA_FMT "x)", uvalue);
 	  else
-	    printf ("(Unknown: %lx)", uvalue);
+	    printf ("(Unknown: %" BFD_VMA_FMT "x)", uvalue);
 	  break;
 	}
       break;
@@ -1584,8 +1621,9 @@ read_and_display_attr_value (unsigned lo
 	  uvalue += cu_offset;
 
 	if (uvalue >= section->size)
-	  warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
-		uvalue, (unsigned long) (orig_data - section->start));
+	  warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
+		dwarf_vma_print ("x", uvalue),
+		(unsigned long) (orig_data - section->start));
 	else
 	  {
 	    unsigned long abbrev_number;
@@ -1786,9 +1824,9 @@ static unsigned char *
 read_and_display_attr (unsigned long attribute,
 		       unsigned long form,
 		       unsigned char * data,
-		       unsigned long cu_offset,
-		       unsigned long pointer_size,
-		       unsigned long offset_size,
+		       bfd_vma cu_offset,
+		       bfd_vma pointer_size,
+		       bfd_vma offset_size,
 		       int dwarf_version,
 		       debug_info * debug_info_p,
 		       int do_loc,
@@ -1900,7 +1938,7 @@ process_debug_info (struct dwarf_section
       unsigned char *hdrptr;
       unsigned char *tags;
       int level;
-      unsigned long cu_offset;
+      bfd_vma cu_offset;
       int offset_size;
       int initial_length_size;
       unsigned char signature[8] = { 0 };
@@ -1970,11 +2008,14 @@ process_debug_info (struct dwarf_section
 
       if (!do_loc)
 	{
-	  printf (_("  Compilation Unit @ offset 0x%lx:\n"), cu_offset);
-	  printf (_("   Length:        0x%lx (%s)\n"), compunit.cu_length,
+	  printf (_("  Compilation Unit @ offset 0x%s:\n"),
+		  dwarf_vma_print ("x", cu_offset));
+	  printf (_("   Length:        0x%s (%s)\n"),
+		  dwarf_vma_print ("x", compunit.cu_length),
 		  initial_length_size == 8 ? "64-bit" : "32-bit");
 	  printf (_("   Version:       %d\n"), compunit.cu_version);
-	  printf (_("   Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
+	  printf (_("   Abbrev Offset: %s\n"),
+		  dwarf_vma_print ("d", compunit.cu_abbrev_offset));
 	  printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
 	  if (do_types)
 	    {
@@ -1990,8 +2031,10 @@ process_debug_info (struct dwarf_section
       if (cu_offset + compunit.cu_length + initial_length_size
 	  > section->size)
 	{
-	  warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
-		cu_offset, compunit.cu_length);
+	  warn (_("Debug info is corrupted, length of CU at %s"
+	  	  " extends beyond end of section (length = %s)\n"),
+		dwarf_vma_print ("x", cu_offset),
+		dwarf_vma_print ("x", compunit.cu_length));
 	  break;
 	}
       tags = hdrptr;
@@ -2001,8 +2044,9 @@ process_debug_info (struct dwarf_section
 	  && compunit.cu_version != 3
 	  && compunit.cu_version != 4)
 	{
-	  warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
-		cu_offset, compunit.cu_version);
+	  warn (_("CU at offset %s contains corrupt or "
+		  "unsupported version number: %d.\n"),
+		dwarf_vma_print ("x", cu_offset), compunit.cu_version);
 	  continue;
 	}
 
@@ -2268,7 +2312,7 @@ display_debug_lines_raw (struct dwarf_se
       linfo.li_line_base >>= 24;
 
       printf (_("  Offset:                      0x%lx\n"), hdroff);
-      printf (_("  Length:                      %ld\n"), linfo.li_length);
+      printf (_("  Length:                      %ld\n"), (long) linfo.li_length);
       printf (_("  DWARF Version:               %d\n"), linfo.li_version);
       printf (_("  Prologue Length:             %d\n"), linfo.li_prologue_length);
       printf (_("  Minimum Instruction Length:  %d\n"), linfo.li_min_insn_length);
@@ -2329,11 +2373,14 @@ display_debug_lines_raw (struct dwarf_se
 
 	      data += strlen ((char *) data) + 1;
 
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" BFD_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" BFD_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
-	      printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
+	      printf ("%" BFD_VMA_FMT "u\t",
+		      read_leb128 (data, & bytes_read, 0));
 	      data += bytes_read;
 	      printf ("%s\n", name);
 	    }
@@ -2505,7 +2552,8 @@ display_debug_lines_raw (struct dwarf_se
 
 	      for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
 		{
-		  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+		  printf ("0x%" BFD_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
 			  i == 1 ? "" : ", ");
 		  data += bytes_read;
 		}
@@ -2918,7 +2966,8 @@ display_debug_lines_decoded (struct dwar
 
               for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
                 {
-                  printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
+                  printf ("0x%" BFD_VMA_FMT "x%s",
+			  read_leb128 (data, &bytes_read, 0),
                           i == 1 ? "" : ", ");
                   data += bytes_read;
                 }
@@ -3076,7 +3125,7 @@ display_debug_pubnames (struct dwarf_sec
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (names.pn_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      names.pn_offset, section->name);
+	      (unsigned long) names.pn_offset, section->name);
 
       names.pn_size = byte_get (data, offset_size);
       data += offset_size;
@@ -3097,13 +3146,13 @@ display_debug_pubnames (struct dwarf_sec
 	}
 
       printf (_("  Length:                              %ld\n"),
-	      names.pn_length);
+	      (long) names.pn_length);
       printf (_("  Version:                             %d\n"),
 	      names.pn_version);
       printf (_("  Offset into .debug_info section:     0x%lx\n"),
-	      names.pn_offset);
+	      (unsigned long) names.pn_offset);
       printf (_("  Size of area in .debug_info section: %ld\n"),
-	      names.pn_size);
+	      (long) names.pn_size);
 
       printf (_("\n    Offset\tName\n"));
 
@@ -3323,8 +3372,9 @@ display_debug_loc (struct dwarf_section
   /* DWARF sections under Mach-O have non-zero addresses.  */
   if (debug_information [first].num_loc_offsets > 0
       && debug_information [first].loc_offsets [0] != section->address)
-    warn (_("Location lists in %s section start at 0x%lx\n"),
-	  section->name, debug_information [first].loc_offsets [0]);
+    warn (_("Location lists in %s section start at 0x%s\n"),
+	  section->name,
+	  dwarf_vma_print ("x", debug_information [first].loc_offsets [0]));
 
   printf (_("Contents of the %s section:\n\n"), section->name);
   printf (_("    Offset   Begin    End      Expression\n"));
@@ -3596,7 +3646,7 @@ display_debug_aranges (struct dwarf_sect
 	  && num_debug_info_entries > 0
 	  && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
 	warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
-	      arange.ar_info_offset, section->name);
+	      (unsigned long) arange.ar_info_offset, section->name);
 
       arange.ar_pointer_size = byte_get (hdrptr, 1);
       hdrptr += 1;
@@ -3610,9 +3660,11 @@ display_debug_aranges (struct dwarf_sect
 	  break;
 	}
 
-      printf (_("  Length:                   %ld\n"), arange.ar_length);
+      printf (_("  Length:                   %ld\n"),
+	      (long) arange.ar_length);
       printf (_("  Version:                  %d\n"), arange.ar_version);
-      printf (_("  Offset into .debug_info:  0x%lx\n"), arange.ar_info_offset);
+      printf (_("  Offset into .debug_info:  0x%lx\n"),
+	      (unsigned long) arange.ar_info_offset);
       printf (_("  Pointer Size:             %d\n"), arange.ar_pointer_size);
       printf (_("  Segment Size:             %d\n"), arange.ar_segment_size);
 
Index: src/binutils/dwarf.h
===================================================================
--- src.orig/binutils/dwarf.h	2010-12-18 12:26:24.000000000 +0100
+++ src/binutils/dwarf.h	2011-02-21 15:44:39.467971300 +0100
@@ -22,6 +22,92 @@
 typedef unsigned HOST_WIDEST_INT dwarf_vma;
 typedef unsigned HOST_WIDEST_INT dwarf_size_type;
 
+/* Structure found in the .debug_line section.  */
+typedef struct
+{
+  unsigned char li_length          [4];
+  unsigned char li_version         [2];
+  unsigned char li_prologue_length [4];
+  unsigned char li_min_insn_length [1];
+  unsigned char li_default_is_stmt [1];
+  unsigned char li_line_base       [1];
+  unsigned char li_line_range      [1];
+  unsigned char li_opcode_base     [1];
+}
+DWARF2_External_LineInfo;
+
+typedef struct
+{
+  bfd_vma	 li_length;
+  unsigned short li_version;
+  unsigned int   li_prologue_length;
+  unsigned char  li_min_insn_length;
+  unsigned char  li_max_ops_per_insn;
+  unsigned char  li_default_is_stmt;
+  int            li_line_base;
+  unsigned char  li_line_range;
+  unsigned char  li_opcode_base;
+}
+DWARF2_Internal_LineInfo;
+
+/* Structure found in .debug_pubnames section.  */
+typedef struct
+{
+  unsigned char pn_length  [4];
+  unsigned char pn_version [2];
+  unsigned char pn_offset  [4];
+  unsigned char pn_size    [4];
+}
+DWARF2_External_PubNames;
+
+typedef struct
+{
+  bfd_vma	 pn_length;
+  unsigned short pn_version;
+  bfd_vma	 pn_offset;
+  bfd_vma	 pn_size;
+}
+DWARF2_Internal_PubNames;
+
+/* Structure found in .debug_info section.  */
+typedef struct
+{
+  unsigned char  cu_length        [4];
+  unsigned char  cu_version       [2];
+  unsigned char  cu_abbrev_offset [4];
+  unsigned char  cu_pointer_size  [1];
+}
+DWARF2_External_CompUnit;
+
+typedef struct
+{
+  bfd_vma	 cu_length;
+  unsigned short cu_version;
+  bfd_vma	 cu_abbrev_offset;
+  unsigned char  cu_pointer_size;
+}
+DWARF2_Internal_CompUnit;
+
+typedef struct
+{
+  unsigned char  ar_length       [4];
+  unsigned char  ar_version      [2];
+  unsigned char  ar_info_offset  [4];
+  unsigned char  ar_pointer_size [1];
+  unsigned char  ar_segment_size [1];
+}
+DWARF2_External_ARange;
+
+typedef struct
+{
+  bfd_vma	 ar_length;
+  unsigned short ar_version;
+  bfd_vma	 ar_info_offset;
+  unsigned char  ar_pointer_size;
+  unsigned char  ar_segment_size;
+}
+DWARF2_Internal_ARange;
+
 struct dwarf_section
 {
   /* A debug section has a different name when it's stored compressed
@@ -79,15 +165,15 @@ typedef struct
   unsigned int   pointer_size;
   unsigned int   offset_size;
   int            dwarf_version;
-  unsigned long  cu_offset;
-  unsigned long	 base_address;
+  bfd_vma	 cu_offset;
+  bfd_vma	 base_address;
   /* This is an array of offsets to the location list table.  */
-  unsigned long *loc_offsets;
+  bfd_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.  */
-  unsigned long *range_lists;
+  bfd_vma	*range_lists;
   unsigned int   num_range_lists;
   unsigned int   max_range_lists;
 }
@@ -131,5 +217,5 @@ void *cmalloc (size_t, size_t);
 void *xcmalloc (size_t, size_t);
 void *xcrealloc (void *, size_t, size_t);
 
-unsigned long int read_leb128 (unsigned char *data,
-			       unsigned int *length_return, int sign);
+bfd_vma read_leb128 (unsigned char *data,
+		     unsigned int *length_return, int sign);
Index: src/include/dwarf2.h
===================================================================
--- src.orig/include/dwarf2.h	2011-02-08 19:52:32.000000000 +0100
+++ src/include/dwarf2.h	2011-02-21 15:44:39.471971600 +0100
@@ -44,95 +44,8 @@
 /* This file is shared between GCC and GDB, and should not contain
    prototypes.  */
 
-#ifndef _ELF_DWARF2_H
-#define _ELF_DWARF2_H
-
-/* Structure found in the .debug_line section.  */
-typedef struct
-{
-  unsigned char li_length          [4];
-  unsigned char li_version         [2];
-  unsigned char li_prologue_length [4];
-  unsigned char li_min_insn_length [1];
-  unsigned char li_default_is_stmt [1];
-  unsigned char li_line_base       [1];
-  unsigned char li_line_range      [1];
-  unsigned char li_opcode_base     [1];
-}
-DWARF2_External_LineInfo;
-
-typedef struct
-{
-  unsigned long  li_length;
-  unsigned short li_version;
-  unsigned int   li_prologue_length;
-  unsigned char  li_min_insn_length;
-  unsigned char  li_max_ops_per_insn;
-  unsigned char  li_default_is_stmt;
-  int            li_line_base;
-  unsigned char  li_line_range;
-  unsigned char  li_opcode_base;
-}
-DWARF2_Internal_LineInfo;
-
-/* Structure found in .debug_pubnames section.  */
-typedef struct
-{
-  unsigned char pn_length  [4];
-  unsigned char pn_version [2];
-  unsigned char pn_offset  [4];
-  unsigned char pn_size    [4];
-}
-DWARF2_External_PubNames;
-
-typedef struct
-{
-  unsigned long  pn_length;
-  unsigned short pn_version;
-  unsigned long  pn_offset;
-  unsigned long  pn_size;
-}
-DWARF2_Internal_PubNames;
-
-/* Structure found in .debug_info section.  */
-typedef struct
-{
-  unsigned char  cu_length        [4];
-  unsigned char  cu_version       [2];
-  unsigned char  cu_abbrev_offset [4];
-  unsigned char  cu_pointer_size  [1];
-}
-DWARF2_External_CompUnit;
-
-typedef struct
-{
-  unsigned long  cu_length;
-  unsigned short cu_version;
-  unsigned long  cu_abbrev_offset;
-  unsigned char  cu_pointer_size;
-}
-DWARF2_Internal_CompUnit;
-
-typedef struct
-{
-  unsigned char  ar_length       [4];
-  unsigned char  ar_version      [2];
-  unsigned char  ar_info_offset  [4];
-  unsigned char  ar_pointer_size [1];
-  unsigned char  ar_segment_size [1];
-}
-DWARF2_External_ARange;
-
-typedef struct
-{
-  unsigned long  ar_length;
-  unsigned short ar_version;
-  unsigned long  ar_info_offset;
-  unsigned char  ar_pointer_size;
-  unsigned char  ar_segment_size;
-}
-DWARF2_Internal_ARange;
-
+#ifndef _DWARF2_H
+#define _DWARF2_H
 
 /* Tag names and codes.  */
 enum dwarf_tag
@@ -953,4 +866,4 @@ enum dwarf_macinfo_record_type
 
 #define DW_EH_PE_indirect	0x80
 
-#endif /* _ELF_DWARF2_H */
+#endif /* _DWARF2_H */

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-21 15:25         ` Kai Tietz
@ 2011-02-21 15:43           ` Mark Kettenis
  2011-02-21 15:53             ` Kai Tietz
  2011-02-22 15:21           ` Nick Clifton
  1 sibling, 1 reply; 30+ messages in thread
From: Mark Kettenis @ 2011-02-21 15:43 UTC (permalink / raw)
  To: ktietz70; +Cc: pierre.muller, gcc-patches, binutils, gdb, jakub, brobecker

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]

> Date: Mon, 21 Feb 2011 16:25:35 +0100
> From: Kai Tietz <ktietz70@googlemail.com>
> 
> 2011/2/21 Kai Tietz <ktietz70@googlemail.com>:
> > 2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
> >>> Yes, I saw this too and it is a thorn here. But the issue about a
> >>> transformation function (like dwarf_vma) is that we have memory leaks
> >>> - as this function is to be used on some printf's more then once - as
> >>> static buffer would be overriden. Well printfs can be splitted into
> >>> smaller parts, but this then would make localization even harder.
> >>
> >>  In GDB code, this is solved in utils.c source by the use of the
> >> get_cell function, which rotates over 16 char arrays of size 50 each
> >> currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
> >> 64-bit)
> >> for this dwarf_vma function would probably be enough, no?
> >>
> >>
> >> Pierre Muller
> >> GDB pascal language maintainer
> >
> > Yes, this sounds ok. I think maximum here are right now 3 dwarf_vma
> > prints within one printf. So it should be ok. I'll add here such a
> > rotating function. I don't assume we need here to handle
> > multi-threading, so rotation code can be pretty simple.
> >
> > Kai
> >
> 
> So this version uses new function dwarf_vma_print function for
> printf-messages, which are getting localized.

dwarf_vma_print is a really bad name for that function since it
doesn't print anything.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-21 15:43           ` Mark Kettenis
@ 2011-02-21 15:53             ` Kai Tietz
  0 siblings, 0 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-21 15:53 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: pierre.muller, gcc-patches, binutils, gdb, jakub, brobecker

2011/2/21 Mark Kettenis <mark.kettenis@xs4all.nl>:
>> Date: Mon, 21 Feb 2011 16:25:35 +0100
>> From: Kai Tietz <ktietz70@googlemail.com>
>>
>> 2011/2/21 Kai Tietz <ktietz70@googlemail.com>:
>> > 2011/2/21 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>> >>> Yes, I saw this too and it is a thorn here. But the issue about a
>> >>> transformation function (like dwarf_vma) is that we have memory leaks
>> >>> - as this function is to be used on some printf's more then once - as
>> >>> static buffer would be overriden. Well printfs can be splitted into
>> >>> smaller parts, but this then would make localization even harder.
>> >>
>> >>  In GDB code, this is solved in utils.c source by the use of the
>> >> get_cell function, which rotates over 16 char arrays of size 50 each
>> >> currently, in dwarf.c 4 arrays of 16 char (as long as longest address is
>> >> 64-bit)
>> >> for this dwarf_vma function would probably be enough, no?
>> >>
>> >>
>> >> Pierre Muller
>> >> GDB pascal language maintainer
>> >
>> > Yes, this sounds ok. I think maximum here are right now 3 dwarf_vma
>> > prints within one printf. So it should be ok. I'll add here such a
>> > rotating function. I don't assume we need here to handle
>> > multi-threading, so rotation code can be pretty simple.
>> >
>> > Kai
>> >
>>
>> So this version uses new function dwarf_vma_print function for
>> printf-messages, which are getting localized.
>
> dwarf_vma_print is a really bad name for that function since it
> doesn't print anything.
>

well, it doesn't output, but it uses sprintf. So what's about
dwarf_vmatoa instead?

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-21 15:25         ` Kai Tietz
  2011-02-21 15:43           ` Mark Kettenis
@ 2011-02-22 15:21           ` Nick Clifton
  2011-02-23  8:59             ` Kai Tietz
  1 sibling, 1 reply; 30+ messages in thread
From: Nick Clifton @ 2011-02-22 15:21 UTC (permalink / raw)
  To: Kai Tietz
  Cc: Pierre Muller, GCC Patches, Binutils, gdb, Jakub Jelinek, Joel Brobecker

Hi Kai,


> So this version uses new function dwarf_vma_print function for
> printf-messages, which are getting localized.
>
> Tested for x86_64-w64-mingw32 and x86_64-pc-linux-gnu. Ok for apply?

> +static const char *
> +dwarf_vma_print (const char *fmtch, bfd_vma value)

I think that I prefer your suggestion of dwarf_vmatoa.

> +{
> +  static int buf_pos = 0;
> +  static struct dwarf_vma_print_buf {
> +    char place[64];
> +  } buf[16];

Ideally you should have a comment here explaining why you have an array 
of these string buffers.

> +  char fmt[32];
> +  char *ret;
> +
> +  sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
> +  ret = &buf[buf_pos++].place[0];

Or, more simply:

   ret = buf[buf_pos++].place;

> +  buf_pos &= 15;

That "15" should be: "ARRAY_SIZE (buf) - 1", and it would be safer to write:

   buf_pos %= ARRAY_SIZE (buf);

and leave it to the compiler to optimize this into an AND operation if 
it can.

 > snprintf (ret, 64, fmt, value);

And the "64" here should be "sizeof (buf[0].place)".

Cheers
   Nick

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-22 15:21           ` Nick Clifton
@ 2011-02-23  8:59             ` Kai Tietz
  2011-02-23 15:12               ` Pierre Muller
       [not found]               ` <-2339605939192327273@unknownmsgid>
  0 siblings, 2 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-23  8:59 UTC (permalink / raw)
  To: Nick Clifton
  Cc: Pierre Muller, GCC Patches, Binutils, gdb, Jakub Jelinek, Joel Brobecker

2011/2/22 Nick Clifton <nickc@redhat.com>:
> Hi Kai,
>
>
>> So this version uses new function dwarf_vma_print function for
>> printf-messages, which are getting localized.
>>
>> Tested for x86_64-w64-mingw32 and x86_64-pc-linux-gnu. Ok for apply?
>
>> +static const char *
>> +dwarf_vma_print (const char *fmtch, bfd_vma value)
>
> I think that I prefer your suggestion of dwarf_vmatoa.
>
>> +{
>> +  static int buf_pos = 0;
>> +  static struct dwarf_vma_print_buf {
>> +    char place[64];
>> +  } buf[16];
>
> Ideally you should have a comment here explaining why you have an array of
> these string buffers.
>
>> +  char fmt[32];
>> +  char *ret;
>> +
>> +  sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
>> +  ret = &buf[buf_pos++].place[0];
>
> Or, more simply:
>
>  ret = buf[buf_pos++].place;
>
>> +  buf_pos &= 15;
>
> That "15" should be: "ARRAY_SIZE (buf) - 1", and it would be safer to write:
>
>  buf_pos %= ARRAY_SIZE (buf);
>
> and leave it to the compiler to optimize this into an AND operation if it
> can.
>
>> snprintf (ret, 64, fmt, value);
>
> And the "64" here should be "sizeof (buf[0].place)".
>
> Cheers
>  Nick
>
>

Hello Nick,

adjust the binutils part as you suggested. Applied to binutils and gcc
(rev. 170433) tree.

Regards,
Kai

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-23  8:59             ` Kai Tietz
@ 2011-02-23 15:12               ` Pierre Muller
       [not found]               ` <-2339605939192327273@unknownmsgid>
  1 sibling, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-23 15:12 UTC (permalink / raw)
  To: 'Kai Tietz'; +Cc: 'Binutils'

  Kai,

please excuse me for asking this so late,
but I don't really understand why you had to introduce
a new 'dwarf_vma' type when we already have a 'bfd_signed_vma'
type that must be signed 64-bit as soon as 
BFD64 macro is defined...
See definitions in bfd/bfd-in.h or bfd/bfd-in2.h

This macro should be set if any of the supported target is a 64-bit target
so it should be possible to use that type, no?

  But of course, I might be missing some important point,
could you please explain to me in which case
a 64-bit dwarf_vma could be necessary without BFD64 being set.


Pierre Muller
GDB pascal language maintainer



> -----Message d'origine-----
> De : binutils-owner@sourceware.org [mailto:binutils-
> owner@sourceware.org] De la part de Kai Tietz
> Envoyé : mercredi 23 février 2011 10:00
> À : Nick Clifton
> Cc : Pierre Muller; GCC Patches; Binutils; gdb; Jakub Jelinek; Joel
> Brobecker
> Objet : Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h
> header
> 
> 2011/2/22 Nick Clifton <nickc@redhat.com>:
> > Hi Kai,
> >
> >
> >> So this version uses new function dwarf_vma_print function for
> >> printf-messages, which are getting localized.
> >>
> >> Tested for x86_64-w64-mingw32 and x86_64-pc-linux-gnu. Ok for apply?
> >
> >> +static const char *
> >> +dwarf_vma_print (const char *fmtch, bfd_vma value)
> >
> > I think that I prefer your suggestion of dwarf_vmatoa.
> >
> >> +{
> >> +  static int buf_pos = 0;
> >> +  static struct dwarf_vma_print_buf {
> >> +    char place[64];
> >> +  } buf[16];
> >
> > Ideally you should have a comment here explaining why you have an
> array of
> > these string buffers.
> >
> >> +  char fmt[32];
> >> +  char *ret;
> >> +
> >> +  sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
> >> +  ret = &buf[buf_pos++].place[0];
> >
> > Or, more simply:
> >
> >  ret = buf[buf_pos++].place;
> >
> >> +  buf_pos &= 15;
> >
> > That "15" should be: "ARRAY_SIZE (buf) - 1", and it would be safer to
> write:
> >
> >  buf_pos %= ARRAY_SIZE (buf);
> >
> > and leave it to the compiler to optimize this into an AND operation
> if it
> > can.
> >
> >> snprintf (ret, 64, fmt, value);
> >
> > And the "64" here should be "sizeof (buf[0].place)".
> >
> > Cheers
> >  Nick
> >
> >
> 
> Hello Nick,
> 
> adjust the binutils part as you suggested. Applied to binutils and gcc
> (rev. 170433) tree.
> 
> Regards,
> Kai


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
       [not found]               ` <-2339605939192327273@unknownmsgid>
@ 2011-02-23 17:42                 ` Kai Tietz
  2011-02-23 21:55                   ` Pierre Muller
       [not found]                   ` <-3886800211494155692@unknownmsgid>
  0 siblings, 2 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-23 17:42 UTC (permalink / raw)
  To: Pierre Muller; +Cc: Binutils

2011/2/23 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>  Kai,
>
> please excuse me for asking this so late,
> but I don't really understand why you had to introduce
> a new 'dwarf_vma' type when we already have a 'bfd_signed_vma'
> type that must be signed 64-bit as soon as
> BFD64 macro is defined...
> See definitions in bfd/bfd-in.h or bfd/bfd-in2.h
>
> This macro should be set if any of the supported target is a 64-bit target
> so it should be possible to use that type, no?
>
>  But of course, I might be missing some important point,
> could you please explain to me in which case
> a 64-bit dwarf_vma could be necessary without BFD64 being set.
>
>
> Pierre Muller
> GDB pascal language maintainer
>
>
>
>> -----Message d'origine-----
>> De : binutils-owner@sourceware.org [mailto:binutils-
>> owner@sourceware.org] De la part de Kai Tietz
>> Envoyé : mercredi 23 février 2011 10:00
>> À : Nick Clifton
>> Cc : Pierre Muller; GCC Patches; Binutils; gdb; Jakub Jelinek; Joel
>> Brobecker
>> Objet : Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h
>> header
>>
>> 2011/2/22 Nick Clifton <nickc@redhat.com>:
>> > Hi Kai,
>> >
>> >
>> >> So this version uses new function dwarf_vma_print function for
>> >> printf-messages, which are getting localized.
>> >>
>> >> Tested for x86_64-w64-mingw32 and x86_64-pc-linux-gnu. Ok for apply?
>> >
>> >> +static const char *
>> >> +dwarf_vma_print (const char *fmtch, bfd_vma value)
>> >
>> > I think that I prefer your suggestion of dwarf_vmatoa.
>> >
>> >> +{
>> >> +  static int buf_pos = 0;
>> >> +  static struct dwarf_vma_print_buf {
>> >> +    char place[64];
>> >> +  } buf[16];
>> >
>> > Ideally you should have a comment here explaining why you have an
>> array of
>> > these string buffers.
>> >
>> >> +  char fmt[32];
>> >> +  char *ret;
>> >> +
>> >> +  sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
>> >> +  ret = &buf[buf_pos++].place[0];
>> >
>> > Or, more simply:
>> >
>> >  ret = buf[buf_pos++].place;
>> >
>> >> +  buf_pos &= 15;
>> >
>> > That "15" should be: "ARRAY_SIZE (buf) - 1", and it would be safer to
>> write:
>> >
>> >  buf_pos %= ARRAY_SIZE (buf);
>> >
>> > and leave it to the compiler to optimize this into an AND operation
>> if it
>> > can.
>> >
>> >> snprintf (ret, 64, fmt, value);
>> >
>> > And the "64" here should be "sizeof (buf[0].place)".
>> >
>> > Cheers
>> >  Nick
>> >
>> >
>>
>> Hello Nick,
>>
>> adjust the binutils part as you suggested. Applied to binutils and gcc
>> (rev. 170433) tree.
>>
>> Regards,
>> Kai

Applied patch don't have those types any more. I introduced them in
initial patch under assumption structures in include/dwarf2.h should
be host-independent. As now those structures are moved into binutils
private header binutils/dwarf.h there is no need to have here new
types and patch uses bfd_vma/bfd_signed_vma.

So what exactly is the point where you see here still the use of
dw2_vma_t/dw2_svma_t?

Regards,
Kai

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-23 17:42                 ` Kai Tietz
@ 2011-02-23 21:55                   ` Pierre Muller
       [not found]                   ` <-3886800211494155692@unknownmsgid>
  1 sibling, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-23 21:55 UTC (permalink / raw)
  To: 'Kai Tietz', 'H.J. Lu'; +Cc: 'Binutils'

> Applied patch don't have those types any more. I introduced them in
> initial patch under assumption structures in include/dwarf2.h should
> be host-independent. As now those structures are moved into binutils
> private header binutils/dwarf.h there is no need to have here new
> types and patch uses bfd_vma/bfd_signed_vma.

  Whoops, my fault, indeed!
 
> So what exactly is the point where you see here still the use of
> dw2_vma_t/dw2_svma_t?

  Oh, sorry, you are right,
I didn't realize that the new
introduced type called 'dwarf_vma' 
was in fact introduced back to 2010 ...
by a commit by H.J. Lu from 2010-11-21.

  So that my question in fact should have been sent to 
H.J. Lu, not to you.

So let me re-ask the question to the right person:


please excuse me for asking this so late,
but I don't really understand why you had to introduce
a new 'dwarf_vma' type when we already have a 'bfd_vma'
type that must be unsigned 64-bit as soon as 
BFD64 macro is defined...
See definitions in bfd/bfd-in.h or bfd/bfd-in2.h

This macro should be set if any of the supported target is a 64-bit target
so it should be possible to use that type, no?

  But of course, I might be missing some important point,
could you please explain to me in which case
a 64-bit dwarf_vma could be necessary without BFD64 being set.
(I just realized in between that dwarf_vma is an unsigned type.)
 
 I still think that my question is valid,
but I was unable to find the discussion about the
patch in the mailing list which might contain
an explanation.

  H.J., could you please give me a pointer
to the thread where the patch is explained or
comment on my question?

  Thanks in advance,


Pierre Muller
GDB pascal language maintainer



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
       [not found]                   ` <-3886800211494155692@unknownmsgid>
@ 2011-02-23 22:51                     ` H.J. Lu
  2011-02-24 11:33                       ` Pierre Muller
       [not found]                       ` <1561346207520594884@unknownmsgid>
  0 siblings, 2 replies; 30+ messages in thread
From: H.J. Lu @ 2011-02-23 22:51 UTC (permalink / raw)
  To: Pierre Muller; +Cc: Kai Tietz, Binutils

On Wed, Feb 23, 2011 at 1:55 PM, Pierre Muller
<pierre.muller@ics-cnrs.unistra.fr> wrote:
>> Applied patch don't have those types any more. I introduced them in
>> initial patch under assumption structures in include/dwarf2.h should
>> be host-independent. As now those structures are moved into binutils
>> private header binutils/dwarf.h there is no need to have here new
>> types and patch uses bfd_vma/bfd_signed_vma.
>
>  Whoops, my fault, indeed!
>
>> So what exactly is the point where you see here still the use of
>> dw2_vma_t/dw2_svma_t?
>
>  Oh, sorry, you are right,
> I didn't realize that the new
> introduced type called 'dwarf_vma'
> was in fact introduced back to 2010 ...
> by a commit by H.J. Lu from 2010-11-21.
>
>  So that my question in fact should have been sent to
> H.J. Lu, not to you.
>
> So let me re-ask the question to the right person:
>
>
> please excuse me for asking this so late,
> but I don't really understand why you had to introduce
> a new 'dwarf_vma' type when we already have a 'bfd_vma'
> type that must be unsigned 64-bit as soon as
> BFD64 macro is defined...
> See definitions in bfd/bfd-in.h or bfd/bfd-in2.h
>
> This macro should be set if any of the supported target is a 64-bit target
> so it should be possible to use that type, no?
>
>  But of course, I might be missing some important point,
> could you please explain to me in which case
> a 64-bit dwarf_vma could be necessary without BFD64 being set.
> (I just realized in between that dwarf_vma is an unsigned type.)
>
>  I still think that my question is valid,
> but I was unable to find the discussion about the
> patch in the mailing list which might contain
> an explanation.
>
>  H.J., could you please give me a pointer
> to the thread where the patch is explained or
> comment on my question?

dwarf.h is also used by readelf.c, whose feature isn't
controlled by BFD64:

---
#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.


-- 
H.J.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
  2011-02-23 22:51                     ` H.J. Lu
@ 2011-02-24 11:33                       ` Pierre Muller
       [not found]                       ` <1561346207520594884@unknownmsgid>
  1 sibling, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-24 11:33 UTC (permalink / raw)
  To: 'H.J. Lu'; +Cc: 'Kai Tietz', 'Binutils'

> #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?

Pierre


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header
       [not found]                       ` <1561346207520594884@unknownmsgid>
@ 2011-02-24 13:50                         ` H.J. Lu
  2011-02-25 10:40                           ` [RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header) Pierre Muller
       [not found]                           ` <5095785081977025060@unknownmsgid>
  0 siblings, 2 replies; 30+ messages in thread
From: H.J. Lu @ 2011-02-24 13:50 UTC (permalink / raw)
  To: Pierre Muller; +Cc: Kai Tietz, Binutils

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.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header)
  2011-02-24 13:50                         ` H.J. Lu
@ 2011-02-25 10:40                           ` Pierre Muller
       [not found]                           ` <5095785081977025060@unknownmsgid>
  1 sibling, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-25 10:40 UTC (permalink / raw)
  To: 'H.J. Lu'; +Cc: 'Kai Tietz', 'Binutils'

  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.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header)
       [not found]                           ` <5095785081977025060@unknownmsgid>
@ 2011-02-25 12:23                             ` Kai Tietz
  2011-02-25 13:31                               ` Pierre Muller
  2011-02-25 13:35                               ` [RFC-v2] Use only dwarf_vma types in dwarf code Pierre Muller
  0 siblings, 2 replies; 30+ messages in thread
From: Kai Tietz @ 2011-02-25 12:23 UTC (permalink / raw)
  To: Pierre Muller; +Cc: H.J. Lu, Binutils

2011/2/25 Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>:
>  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

> 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)

Whitespace issue. should be ... && 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__
Please don't use here __MSVCRT__, instead use
#if !defined (__MSVCRT__) && !defined (__MINGW32__)

As __MSVCRT__ is just declared by VC, and __MINGW32__ for gcc. IMHO
__MINGW32__ should be the only guard necessary here, as VC neither
defines __STDC_VERSION__ > 199901L and it doesn't defines __GNUC__,
too.

> +#define  DWARF_VMA_FMT "ll"
> +#else
> +#define  DWARF_VMA_FMT "I64"
> +#endif
> +#else
> +#define  DWARF_VMA_FMT "l"
> +#endif
> +

> -bfd_vma
> +static char *
> +dwarf_svmatoa (const char *fmtch, dwarf_signed_vma value)

Why you are using here dwarf_svmatoa? It should be dwarf_vmatoa
As the formatter is specified here as argument and in dwarf_vmatoa the
formatter-buffer is constructed, I see no point in adding a signed
variant.

This is just a first glance, and well, I can't approve this patch. But
in general I appreachiate your modification.

Regards,
Kai

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header)
  2011-02-25 12:23                             ` Kai Tietz
@ 2011-02-25 13:31                               ` Pierre Muller
  2011-02-25 13:35                               ` [RFC-v2] Use only dwarf_vma types in dwarf code Pierre Muller
  1 sibling, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-02-25 13:31 UTC (permalink / raw)
  To: 'Kai Tietz'; +Cc: 'Binutils'

> > +    if (byte_size > 0 && byte_size <=8)
> 
> Whitespace issue. should be ... && byte_size <= 8)

  Indeed, I still make silly formatting errors, sorry.
 
> > +      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__
> Please don't use here __MSVCRT__, instead use
> #if !defined (__MSVCRT__) && !defined (__MINGW32__)
> 
> As __MSVCRT__ is just declared by VC, and __MINGW32__ for gcc. IMHO
> __MINGW32__ should be the only guard necessary here, as VC neither
> defines __STDC_VERSION__ > 199901L and it doesn't defines __GNUC__,
> too.

  This is just a copy of what is already present 
in dwarf_print_vma function a few lines above in the patched 
file, so that we should fixed both occurrences 
 
> > +#define  DWARF_VMA_FMT "ll"
> > +#else
> > +#define  DWARF_VMA_FMT "I64"
> > +#endif
> > +#else
> > +#define  DWARF_VMA_FMT "l"
> > +#endif
> > +
> 
> > -bfd_vma
> > +static char *
> > +dwarf_svmatoa (const char *fmtch, dwarf_signed_vma value)
> 
> Why you are using here dwarf_svmatoa? It should be dwarf_vmatoa
> As the formatter is specified here as argument and in dwarf_vmatoa the
> formatter-buffer is constructed, I see no point in adding a signed
> variant.

  I was worried about possible signed values in a signed type
that is shorter than dwarf_vma...
  Suppose that you have a 32-bit integer that has a value of -5,
but this is probably due to my lack of knowledge of C integer
signed<->unsigned conversion rules...
  I made a short check and it seems that indeed this is not necessary...

 
> This is just a first glance, and well, I can't approve this patch. But
> in general I appreachiate your modification.

  Thanks for your appreciation!
I will send a modified version of the patch shortly.

Pierre

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [RFC-v2] Use only dwarf_vma types in dwarf code
  2011-02-25 12:23                             ` Kai Tietz
  2011-02-25 13:31                               ` Pierre Muller
@ 2011-02-25 13:35                               ` Pierre Muller
  2011-03-25 15:16                                 ` Nick Clifton
  1 sibling, 1 reply; 30+ messages in thread
From: Pierre Muller @ 2011-02-25 13:35 UTC (permalink / raw)
  To: 'Kai Tietz'; +Cc: 'H.J. Lu', 'Binutils'

  I corrected the patch according to the remarks made before
by Kai,

 I put again the main message of my first RFC
starting here:
>>>>>>>>>>>>>>>>
  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): Use __MINGW32__ conditional and
	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.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);
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,12 +106,13 @@ 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
      the precision we need.  */
 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
-#ifndef __MSVCRT__
+#ifndef __MINGW32__
   snprintf (buff, sizeof (buff), "%16.16llx ", val);
 #else
   snprintf (buff, sizeof (buff), "%016I64x ", val);
@@ -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 __MINGW32__
+#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,35 @@ dwarf_vmatoa (const char *fmtch, bfd_vma
   return ret;
 }
 
-bfd_vma
+#if 0
+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;
+}
+#endif
+
+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 +203,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 +219,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 +267,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 +304,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 +365,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 +376,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 +665,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 +680,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 +737,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_vmatoa ("d", read_sleb128 (data, &bytes_read)));
 	  data += bytes_read;
 	  break;
 	case DW_OP_dup:
@@ -748,8 +798,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 +944,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_vmatoa ("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_vmatoa ("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_vmatoa ("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 +994,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 +1018,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 +1037,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 +1090,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_vmatoa ("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_vmatoa ("d", read_sleb128 (data + offset_size,
+				     &bytes_read)));
 	      data += offset_size + bytes_read;
 	    }
 	  break;
@@ -1112,15 +1163,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 +1258,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 +1266,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 +1283,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 +1291,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 +1300,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 +1405,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 +1436,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 +1514,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 +1881,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 +1995,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 +2430,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 +2452,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 +2466,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 +2480,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 +2508,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 +2521,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_vmatoa ("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_vmatoa ("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_vmatoa("d", adv));
 	      state_machine_regs.is_stmt = adv;
 	      break;
 
@@ -2511,8 +2571,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 +2584,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 +2596,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 +2612,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 +2620,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 +2951,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 +3034,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 +3070,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 +4173,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,

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFC-v2] Use only dwarf_vma types in dwarf code
  2011-02-25 13:35                               ` [RFC-v2] Use only dwarf_vma types in dwarf code Pierre Muller
@ 2011-03-25 15:16                                 ` Nick Clifton
  2011-03-25 15:48                                   ` [RFA] Supplemtal patch for use " Pierre Muller
  0 siblings, 1 reply; 30+ messages in thread
From: Nick Clifton @ 2011-03-25 15:16 UTC (permalink / raw)
  To: Pierre Muller; +Cc: 'Kai Tietz', 'H.J. Lu', 'Binutils'

Hi Pierre,

   [only a month late...]

> 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): Use __MINGW32__ conditional and
> 	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.

Approved and applied - along with a little tidying up.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [RFA] Supplemtal patch for use only dwarf_vma types in dwarf code
  2011-03-25 15:16                                 ` Nick Clifton
@ 2011-03-25 15:48                                   ` Pierre Muller
  2011-03-25 18:04                                     ` Nick Clifton
  0 siblings, 1 reply; 30+ messages in thread
From: Pierre Muller @ 2011-03-25 15:48 UTC (permalink / raw)
  To: 'Nick Clifton'
  Cc: 'Kai Tietz', 'H.J. Lu', 'Binutils'



> -----Message d'origine-----
> De : binutils-owner@sourceware.org [mailto:binutils-owner@sourceware.org]
De
> la part de Nick Clifton
> Envoyé : vendredi 25 mars 2011 16:17
> À : Pierre Muller
> Cc : 'Kai Tietz'; 'H.J. Lu'; 'Binutils'
> Objet : Re: [RFC-v2] Use only dwarf_vma types in dwarf code
> 
> Hi Pierre,
> 
>    [only a month late...]
> Approved and applied - along with a little tidying up.

Thanks,

  I have a few remaining changes to propose:
always in the spirit of the previous RFC,
use dwarf_vma whenever we are not sure that a 'long'
(which can be shorter than a pointer in byte size 
on mingw64 system) is enough.
  I have no real idea if those three cases are 
really variables that can reach up to values that
do not fit in 4-bytes but it can not really hurt, can it?

Pierre Muller


ChangeLog entry:
2011-03-25  Pierre Muller  <muller@ics.u-strasbg.fr>

	* dwarf.c (decode_location_expression): Use dwarf_vmatoa
	function to display DW_OP_addr OP.
	(process_debug_info): Use dwarf_vma type for local variables
	length and type_offset.



Index: dwarf.c
===================================================================
RCS file: /cvs/src/src/binutils/dwarf.c,v
retrieving revision 1.86
diff -u -p -r1.86 dwarf.c
--- dwarf.c     25 Mar 2011 15:15:52 -0000      1.86
+++ dwarf.c     25 Mar 2011 15:39:49 -0000
@@ -674,8 +674,8 @@ decode_location_expression (unsigned cha
       switch (op)
        {
        case DW_OP_addr:
-         printf ("DW_OP_addr: %lx",
-                 (unsigned long) byte_get (data, pointer_size));
+         printf ("DW_OP_addr: %s",
+                 dwarf_vmatoa("x", byte_get (data, pointer_size)));
          data += pointer_size;
          break;
        case DW_OP_deref:
@@ -1926,7 +1926,7 @@ process_debug_info (struct dwarf_section
       && num_debug_info_entries == 0
       && ! do_types)
     {
-      unsigned long length;
+      dwarf_vma length;

       /* First scan the section to get the number of comp units.  */
       for (section_begin = start, num_units = 0; section_begin < end;
@@ -2002,7 +2002,7 @@ process_debug_info (struct dwarf_section
       int offset_size;
       int initial_length_size;
       unsigned char signature[8] = { 0 };
-      unsigned long type_offset = 0;
+      dwarf_vma type_offset = 0;

       hdrptr = start;

@@ -2084,7 +2084,8 @@ process_debug_info (struct dwarf_section
              for (i = 0; i < 8; i++)
                printf ("%02x", signature[i]);
              printf ("\n");
-             printf (_("   Type Offset:   0x%lx\n"), type_offset);
+             printf (_("   Type Offset:   0x%s\n"),
+                     dwarf_vmatoa ("x", type_offset));
            }
        }


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [RFA] Supplemtal patch for use only dwarf_vma types in dwarf code
  2011-03-25 15:48                                   ` [RFA] Supplemtal patch for use " Pierre Muller
@ 2011-03-25 18:04                                     ` Nick Clifton
  2011-03-25 21:44                                       ` Pierre Muller
  0 siblings, 1 reply; 30+ messages in thread
From: Nick Clifton @ 2011-03-25 18:04 UTC (permalink / raw)
  To: Pierre Muller; +Cc: 'Kai Tietz', 'H.J. Lu', 'Binutils'

Hi Pierre,

>    I have no real idea if those three cases are
> really variables that can reach up to values that
> do not fit in 4-bytes but it can not really hurt, can it?

Agreed.

> ChangeLog entry:
> 2011-03-25  Pierre Muller<muller@ics.u-strasbg.fr>
>
> 	* dwarf.c (decode_location_expression): Use dwarf_vmatoa
> 	function to display DW_OP_addr OP.
> 	(process_debug_info): Use dwarf_vma type for local variables
> 	length and type_offset.

Approved and applied - note: there were a couple of places where the 
"length" variable was being displayed in a printf() style output, so I 
updated these to use the dwarf_vmatoa() function as well.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 30+ messages in thread

* RE: [RFA] Supplemtal patch for use only dwarf_vma types in dwarf code
  2011-03-25 18:04                                     ` Nick Clifton
@ 2011-03-25 21:44                                       ` Pierre Muller
  0 siblings, 0 replies; 30+ messages in thread
From: Pierre Muller @ 2011-03-25 21:44 UTC (permalink / raw)
  To: 'Nick Clifton'; +Cc: 'Binutils'



> -----Message d'origine-----
> De : binutils-owner@sourceware.org [mailto:binutils-owner@sourceware.org]
De
> la part de Nick Clifton
> Envoyé : vendredi 25 mars 2011 19:05
> À : Pierre Muller
> Cc : 'Kai Tietz'; 'H.J. Lu'; 'Binutils'
> Objet : Re: [RFA] Supplemtal patch for use only dwarf_vma types in dwarf
> code
> 
> Hi Pierre,
> 
> >    I have no real idea if those three cases are
> > really variables that can reach up to values that
> > do not fit in 4-bytes but it can not really hurt, can it?
> 
> Agreed.
> 
> > ChangeLog entry:
> > 2011-03-25  Pierre Muller<muller@ics.u-strasbg.fr>
> >
> > 	* dwarf.c (decode_location_expression): Use dwarf_vmatoa
> > 	function to display DW_OP_addr OP.
> > 	(process_debug_info): Use dwarf_vma type for local variables
> > 	length and type_offset.
> 
> Approved and applied - note: there were a couple of places where the
> "length" variable was being displayed in a printf() style output, so I
> updated these to use the dwarf_vmatoa() function as well.
Thanks for the approval.

  Just a small nit:
I noticed that the indentation of the patch seems strange
(modified lines are 1 column less indented)
I think it is related to tab/spaces issues...

Pierre


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2011-03-25 21:44 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-17 14:21 [RFC patch]: Adjust the use of 'long' type in dwarf2.h header Kai Tietz
2011-02-17 18:59 ` Kai Tietz
2011-02-17 19:03   ` Jakub Jelinek
2011-02-17 19:07     ` Kai Tietz
2011-02-17 19:17       ` Jakub Jelinek
2011-02-18  9:50         ` Kai Tietz
2011-02-21 12:37           ` NightStrike
2011-02-21 13:10 ` Pierre Muller
     [not found] ` <-8460070221060995487@unknownmsgid>
2011-02-21 13:27   ` Kai Tietz
2011-02-21 13:46     ` Pierre Muller
     [not found]     ` <-6930711422310680743@unknownmsgid>
2011-02-21 14:30       ` Kai Tietz
2011-02-21 15:25         ` Kai Tietz
2011-02-21 15:43           ` Mark Kettenis
2011-02-21 15:53             ` Kai Tietz
2011-02-22 15:21           ` Nick Clifton
2011-02-23  8:59             ` Kai Tietz
2011-02-23 15:12               ` Pierre Muller
     [not found]               ` <-2339605939192327273@unknownmsgid>
2011-02-23 17:42                 ` Kai Tietz
2011-02-23 21:55                   ` Pierre Muller
     [not found]                   ` <-3886800211494155692@unknownmsgid>
2011-02-23 22:51                     ` H.J. Lu
2011-02-24 11:33                       ` Pierre Muller
     [not found]                       ` <1561346207520594884@unknownmsgid>
2011-02-24 13:50                         ` H.J. Lu
2011-02-25 10:40                           ` [RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header) Pierre Muller
     [not found]                           ` <5095785081977025060@unknownmsgid>
2011-02-25 12:23                             ` Kai Tietz
2011-02-25 13:31                               ` Pierre Muller
2011-02-25 13:35                               ` [RFC-v2] Use only dwarf_vma types in dwarf code Pierre Muller
2011-03-25 15:16                                 ` Nick Clifton
2011-03-25 15:48                                   ` [RFA] Supplemtal patch for use " Pierre Muller
2011-03-25 18:04                                     ` Nick Clifton
2011-03-25 21:44                                       ` Pierre Muller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).