74ba718
diff -cpr ../binutils-2.21.53.0.1.orig/bfd/dwarf2.c ./bfd/dwarf2.c
74ba718
*** ../binutils-2.21.53.0.1.orig/bfd/dwarf2.c	2011-07-27 09:57:26.018568001 +0100
74ba718
--- ./bfd/dwarf2.c	2011-07-27 10:00:21.176567999 +0100
74ba718
*************** const struct dwarf_debug_section dwarf_d
74ba718
*** 287,292 ****
74ba718
--- 287,293 ----
74ba718
    { ".debug_line",		".zdebug_line" },
74ba718
    { ".debug_loc",		".zdebug_loc" },
74ba718
    { ".debug_macinfo",		".zdebug_macinfo" },
74ba718
+   { ".debug_macro",		".zdebug_macro" },
74ba718
    { ".debug_pubnames",		".zdebug_pubnames" },
74ba718
    { ".debug_pubtypes",		".zdebug_pubtypes" },
74ba718
    { ".debug_ranges",		".zdebug_ranges" },
74ba718
*************** enum dwarf_debug_section_enum
74ba718
*** 314,319 ****
74ba718
--- 315,321 ----
74ba718
    debug_line,
74ba718
    debug_loc,
74ba718
    debug_macinfo,
74ba718
+   debug_macro,
74ba718
    debug_pubnames,
74ba718
    debug_pubtypes,
74ba718
    debug_ranges,
74ba718
diff -cpr ../binutils-2.21.53.0.1.orig/binutils/dwarf.c ./binutils/dwarf.c
74ba718
*** ../binutils-2.21.53.0.1.orig/binutils/dwarf.c	2011-07-27 09:57:55.204568001 +0100
74ba718
--- ./binutils/dwarf.c	2011-07-27 10:00:17.247568001 +0100
74ba718
*************** read_and_display_attr_value (unsigned lo
74ba718
*** 1542,1548 ****
74ba718
  	}
74ba718
      }
74ba718
  
74ba718
!   if (do_loc)
74ba718
      return data;
74ba718
  
74ba718
    /* For some attributes we can display further information.  */
74ba718
--- 1542,1548 ----
74ba718
  	}
74ba718
      }
74ba718
  
74ba718
!   if (do_loc || attribute == 0)
74ba718
      return data;
74ba718
  
74ba718
    /* For some attributes we can display further information.  */
74ba718
*************** get_AT_name (unsigned long attribute)
74ba718
*** 1960,1965 ****
74ba718
--- 1960,1966 ----
74ba718
      case DW_AT_GNU_all_tail_call_sites:		return "DW_AT_GNU_all_tail_call_sites";
74ba718
      case DW_AT_GNU_all_call_sites:		return "DW_AT_GNU_all_call_sites";
74ba718
      case DW_AT_GNU_all_source_call_sites:	return "DW_AT_GNU_all_source_call_sites";
74ba718
+     case DW_AT_GNU_macros:			return "DW_AT_GNU_macros";
74ba718
  
74ba718
        /* UPC extension.  */
74ba718
      case DW_AT_upc_threads_scaled:	return "DW_AT_upc_threads_scaled";
74ba718
*************** display_debug_macinfo (struct dwarf_sect
74ba718
*** 3450,3455 ****
74ba718
--- 3451,3771 ----
74ba718
    return 1;
74ba718
  }
74ba718
  
74ba718
+ /* Given LINE_OFFSET into the .debug_line section, attempt to return
74ba718
+    filename and dirname corresponding to file name table entry with index
74ba718
+    FILEIDX.  Return NULL on failure.  */
74ba718
+ 
74ba718
+ static unsigned char *
74ba718
+ get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
74ba718
+ 			       unsigned char **dir_name)
74ba718
+ {
74ba718
+   struct dwarf_section *section = &debug_displays [line].section;
74ba718
+   unsigned char *hdrptr, *dirtable, *file_name;
74ba718
+   unsigned int offset_size, initial_length_size;
74ba718
+   unsigned int version, opcode_base, bytes_read;
74ba718
+   dwarf_vma length, diridx;
74ba718
+ 
74ba718
+   *dir_name = NULL;
74ba718
+   if (section->start == NULL
74ba718
+       || line_offset >= section->size
74ba718
+       || fileidx == 0)
74ba718
+     return NULL;
74ba718
+ 
74ba718
+   hdrptr = section->start + line_offset;
74ba718
+   length = byte_get (hdrptr, 4);
74ba718
+   hdrptr += 4;
74ba718
+   if (length == 0xffffffff)
74ba718
+     {
74ba718
+       /* This section is 64-bit DWARF 3.  */
74ba718
+       length = byte_get (hdrptr, 8);
74ba718
+       hdrptr += 8;
74ba718
+       offset_size = 8;
74ba718
+       initial_length_size = 12;
74ba718
+     }
74ba718
+   else
74ba718
+     {
74ba718
+       offset_size = 4;
74ba718
+       initial_length_size = 4;
74ba718
+     }
74ba718
+   if (length + initial_length_size > section->size)
74ba718
+     return NULL;
74ba718
+   version = byte_get (hdrptr, 2);
74ba718
+   hdrptr += 2;
74ba718
+   if (version != 2 && version != 3 && version != 4)
74ba718
+     return NULL;
74ba718
+   hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length.  */
74ba718
+   if (version >= 4)
74ba718
+     hdrptr++;		    /* Skip max_ops_per_insn.  */
74ba718
+   hdrptr += 3;		    /* Skip default_is_stmt, line_base, line_range.  */
74ba718
+   opcode_base = byte_get (hdrptr, 1);
74ba718
+   if (opcode_base == 0)
74ba718
+     return NULL;
74ba718
+   hdrptr++;
74ba718
+   hdrptr += opcode_base - 1;
74ba718
+   dirtable = hdrptr;
74ba718
+   /* Skip over dirname table.  */
74ba718
+   while (*hdrptr != '\0')
74ba718
+     hdrptr += strlen ((char *) hdrptr) + 1;
74ba718
+   hdrptr++;		    /* Skip the NUL at the end of the table.  */
74ba718
+   /* Now skip over preceding filename table entries.  */
74ba718
+   for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
74ba718
+     {
74ba718
+       hdrptr += strlen ((char *) hdrptr) + 1;
74ba718
+       read_leb128 (hdrptr, &bytes_read, 0);
74ba718
+       hdrptr += bytes_read;
74ba718
+       read_leb128 (hdrptr, &bytes_read, 0);
74ba718
+       hdrptr += bytes_read;
74ba718
+       read_leb128 (hdrptr, &bytes_read, 0);
74ba718
+       hdrptr += bytes_read;
74ba718
+     }
74ba718
+   if (*hdrptr == '\0')
74ba718
+     return NULL;
74ba718
+   file_name = hdrptr;
74ba718
+   hdrptr += strlen ((char *) hdrptr) + 1;
74ba718
+   diridx = read_leb128 (hdrptr, &bytes_read, 0);
74ba718
+   if (diridx == 0)
74ba718
+     return file_name;
74ba718
+   for (; *dirtable != '\0' && diridx > 1; diridx--)
74ba718
+     dirtable += strlen ((char *) dirtable) + 1;
74ba718
+   if (*dirtable == '\0')
74ba718
+     return NULL;
74ba718
+   *dir_name = dirtable;
74ba718
+   return file_name;
74ba718
+ }
74ba718
+ 
74ba718
+ static int
74ba718
+ display_debug_macro (struct dwarf_section *section,
74ba718
+ 		     void *file)
74ba718
+ {
74ba718
+   unsigned char *start = section->start;
74ba718
+   unsigned char *end = start + section->size;
74ba718
+   unsigned char *curr = start;
74ba718
+   unsigned char *extended_op_buf[256];
74ba718
+   unsigned int bytes_read;
74ba718
+ 
74ba718
+   load_debug_section (str, file);
74ba718
+   load_debug_section (line, file);
74ba718
+ 
74ba718
+   printf (_("Contents of the %s section:\n\n"), section->name);
74ba718
+ 
74ba718
+   while (curr < end)
74ba718
+     {
74ba718
+       unsigned int lineno, version, flags;
74ba718
+       unsigned int offset_size = 4;
74ba718
+       const char *string;
74ba718
+       dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
74ba718
+       unsigned char **extended_ops = NULL;
74ba718
+ 
74ba718
+       version = byte_get (curr, 2);
74ba718
+       curr += 2;
74ba718
+ 
74ba718
+       if (version != 4)
74ba718
+ 	{
74ba718
+ 	  error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
74ba718
+ 		 section->name);
74ba718
+ 	  return 0;
74ba718
+ 	}
74ba718
+ 
74ba718
+       flags = byte_get (curr++, 1);
74ba718
+       if (flags & 1)
74ba718
+ 	offset_size = 8;
74ba718
+       printf (_("  Offset:                      0x%lx\n"),
74ba718
+ 	      (unsigned long) sec_offset);
74ba718
+       printf (_("  Version:                     %d\n"), version);
74ba718
+       printf (_("  Offset size:                 %d\n"), offset_size);
74ba718
+       if (flags & 2)
74ba718
+ 	{
74ba718
+ 	  line_offset = byte_get (curr, offset_size);
74ba718
+ 	  curr += offset_size;
74ba718
+ 	  printf (_("  Offset into .debug_line:     0x%lx\n"),
74ba718
+ 		  (unsigned long) line_offset);
74ba718
+ 	}
74ba718
+       if (flags & 4)
74ba718
+ 	{
74ba718
+ 	  unsigned int i, count = byte_get (curr++, 1), op;
74ba718
+ 	  dwarf_vma nargs, n;
74ba718
+ 	  memset (extended_op_buf, 0, sizeof (extended_op_buf));
74ba718
+ 	  extended_ops = extended_op_buf;
74ba718
+ 	  if (count)
74ba718
+ 	    {
74ba718
+ 	      printf (_("  Extension opcode arguments:\n"));
74ba718
+ 	      for (i = 0; i < count; i++)
74ba718
+ 		{
74ba718
+ 		  op = byte_get (curr++, 1);
74ba718
+ 		  extended_ops[op] = curr;
74ba718
+ 		  nargs = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 		  curr += bytes_read;
74ba718
+ 		  if (nargs == 0)
74ba718
+ 		    printf (_("    DW_MACRO_GNU_%02x has no arguments\n"), op);
74ba718
+ 		  else
74ba718
+ 		    {
74ba718
+ 		      printf (_("    DW_MACRO_GNU_%02x arguments: "), op);
74ba718
+ 		      for (n = 0; n < nargs; n++)
74ba718
+ 			{
74ba718
+ 			  unsigned int form = byte_get (curr++, 1);
74ba718
+ 			  printf ("%s%s", get_FORM_name (form),
74ba718
+ 				  n == nargs - 1 ? "\n" : ", ");
74ba718
+ 			  switch (form)
74ba718
+ 			    {
74ba718
+ 			    case DW_FORM_data1:
74ba718
+ 			    case DW_FORM_data2:
74ba718
+ 			    case DW_FORM_data4:
74ba718
+ 			    case DW_FORM_data8:
74ba718
+ 			    case DW_FORM_sdata:
74ba718
+ 			    case DW_FORM_udata:
74ba718
+ 			    case DW_FORM_block:
74ba718
+ 			    case DW_FORM_block1:
74ba718
+ 			    case DW_FORM_block2:
74ba718
+ 			    case DW_FORM_block4:
74ba718
+ 			    case DW_FORM_flag:
74ba718
+ 			    case DW_FORM_string:
74ba718
+ 			    case DW_FORM_strp:
74ba718
+ 			    case DW_FORM_sec_offset:
74ba718
+ 			      break;
74ba718
+ 			    default:
74ba718
+ 			      error (_("Invalid extension opcode form %s\n"),
74ba718
+ 				     get_FORM_name (form));
74ba718
+ 			      return 0;
74ba718
+ 			    }
74ba718
+ 			}
74ba718
+ 		    }
74ba718
+ 		}
74ba718
+ 	    }
74ba718
+ 	}
74ba718
+       printf ("\n");
74ba718
+ 
74ba718
+       while (1)
74ba718
+ 	{
74ba718
+ 	  unsigned int op;
74ba718
+ 
74ba718
+ 	  if (curr >= end)
74ba718
+ 	    {
74ba718
+ 	      error (_(".debug_macro section not zero terminated\n"));
74ba718
+ 	      return 0;
74ba718
+ 	    }
74ba718
+ 
74ba718
+ 	  op = byte_get (curr++, 1);
74ba718
+ 	  if (op == 0)
74ba718
+ 	    break;
74ba718
+ 
74ba718
+ 	  switch (op)
74ba718
+ 	    {
74ba718
+ 	    case DW_MACRO_GNU_start_file:
74ba718
+ 	      {
74ba718
+ 		unsigned int filenum;
74ba718
+ 		unsigned char *file_name = NULL, *dir_name = NULL;
74ba718
+ 
74ba718
+ 		lineno = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 		curr += bytes_read;
74ba718
+ 		filenum = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 		curr += bytes_read;
74ba718
+ 
74ba718
+ 		if ((flags & 2) == 0)
74ba718
+ 		  error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
74ba718
+ 		else
74ba718
+ 		  file_name
74ba718
+ 		    = get_line_filename_and_dirname (line_offset, filenum,
74ba718
+ 						     &dir_name);
74ba718
+ 		if (file_name == NULL)
74ba718
+ 		  printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
74ba718
+ 			  lineno, filenum);
74ba718
+ 		else
74ba718
+ 		  printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
74ba718
+ 			  lineno, filenum,
74ba718
+ 			  dir_name != NULL ? (const char *) dir_name : "",
74ba718
+ 			  dir_name != NULL ? "/" : "", file_name);
74ba718
+ 	      }
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    case DW_MACRO_GNU_end_file:
74ba718
+ 	      printf (_(" DW_MACRO_GNU_end_file\n"));
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    case DW_MACRO_GNU_define:
74ba718
+ 	      lineno = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 	      curr += bytes_read;
74ba718
+ 	      string = (char *) curr;
74ba718
+ 	      curr += strlen (string) + 1;
74ba718
+ 	      printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
74ba718
+ 		      lineno, string);
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    case DW_MACRO_GNU_undef:
74ba718
+ 	      lineno = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 	      curr += bytes_read;
74ba718
+ 	      string = (char *) curr;
74ba718
+ 	      curr += strlen (string) + 1;
74ba718
+ 	      printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
74ba718
+ 		      lineno, string);
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    case DW_MACRO_GNU_define_indirect:
74ba718
+ 	      lineno = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 	      curr += bytes_read;
74ba718
+ 	      offset = byte_get (curr, offset_size);
74ba718
+ 	      curr += offset_size;
74ba718
+ 	      string = fetch_indirect_string (offset);
74ba718
+ 	      printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
74ba718
+ 		      lineno, string);
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    case DW_MACRO_GNU_undef_indirect:
74ba718
+ 	      lineno = read_leb128 (curr, &bytes_read, 0);
74ba718
+ 	      curr += bytes_read;
74ba718
+ 	      offset = byte_get (curr, offset_size);
74ba718
+ 	      curr += offset_size;
74ba718
+ 	      string = fetch_indirect_string (offset);
74ba718
+ 	      printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
74ba718
+ 		      lineno, string);
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    case DW_MACRO_GNU_transparent_include:
74ba718
+ 	      offset = byte_get (curr, offset_size);
74ba718
+ 	      curr += offset_size;
74ba718
+ 	      printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
74ba718
+ 		      (unsigned long) offset);
74ba718
+ 	      break;
74ba718
+ 
74ba718
+ 	    default:
74ba718
+ 	      if (extended_ops == NULL || extended_ops[op] == NULL)
74ba718
+ 		{
74ba718
+ 		  error (_(" Unknown macro opcode %02x seen\n"), op);
74ba718
+ 		  return 0;
74ba718
+ 		}
74ba718
+ 	      else
74ba718
+ 		{
74ba718
+ 		  /* Skip over unhandled opcodes.  */
74ba718
+ 		  dwarf_vma nargs, n;
74ba718
+ 		  unsigned char *desc = extended_ops[op];
74ba718
+ 		  nargs = read_leb128 (desc, &bytes_read, 0);
74ba718
+ 		  desc += bytes_read;
74ba718
+ 		  if (nargs == 0)
74ba718
+ 		    {
74ba718
+ 		      printf (_(" DW_MACRO_GNU_%02x\n"), op);
74ba718
+ 		      break;
74ba718
+ 		    }
74ba718
+ 		  printf (_(" DW_MACRO_GNU_%02x -"), op);
74ba718
+ 		  for (n = 0; n < nargs; n++)
74ba718
+ 		    {
74ba718
+ 		      curr
74ba718
+ 			= read_and_display_attr_value (0, byte_get (desc++, 1),
74ba718
+ 						       curr, 0, 0, offset_size,
74ba718
+ 						       version, NULL, 0, NULL);
74ba718
+ 		      if (n != nargs - 1)
74ba718
+ 			printf (",");
74ba718
+ 		    }
74ba718
+ 		  printf ("\n");
74ba718
+ 		}
74ba718
+ 	      break;
74ba718
+ 	    }
74ba718
+ 	}
74ba718
+ 
74ba718
+       printf ("\n");
74ba718
+     }	
74ba718
+ 
74ba718
+   return 1;
74ba718
+ }
74ba718
+ 
74ba718
  static int
74ba718
  display_debug_abbrev (struct dwarf_section *section,
74ba718
  		      void *file ATTRIBUTE_UNUSED)
74ba718
*************** struct dwarf_section_display debug_displ
74ba718
*** 5536,5541 ****
74ba718
--- 5852,5859 ----
74ba718
      display_debug_frames,		&do_debug_frames,	1 },
74ba718
    { { ".debug_macinfo",		".zdebug_macinfo",	NULL, NULL, 0, 0 },
74ba718
      display_debug_macinfo,		&do_debug_macinfo,	0 },
74ba718
+   { { ".debug_macro",		".zdebug_macro",	NULL, NULL, 0, 0 },
74ba718
+     display_debug_macro,		&do_debug_macinfo,	1 },
74ba718
    { { ".debug_str",		".zdebug_str",		NULL, NULL, 0, 0 },
74ba718
      display_debug_str,			&do_debug_str,		0 },
74ba718
    { { ".debug_loc",		".zdebug_loc",		NULL, NULL, 0, 0 },
74ba718
diff -cpr ../binutils-2.21.53.0.1.orig/binutils/dwarf.h ./binutils/dwarf.h
74ba718
*** ../binutils-2.21.53.0.1.orig/binutils/dwarf.h	2011-07-27 09:57:54.835568000 +0100
74ba718
--- ./binutils/dwarf.h	2011-07-27 10:00:27.506568001 +0100
74ba718
*************** enum dwarf_section_display_enum
74ba718
*** 143,148 ****
74ba718
--- 143,149 ----
74ba718
    pubnames,
74ba718
    eh_frame,
74ba718
    macinfo,
74ba718
+   macro,
74ba718
    str,
74ba718
    loc,
74ba718
    pubtypes,
74ba718
diff -cpr ../binutils-2.21.53.0.1.orig/binutils/readelf.c ./binutils/readelf.c
74ba718
*** ../binutils-2.21.53.0.1.orig/binutils/readelf.c	2011-07-27 09:57:55.019568001 +0100
74ba718
--- ./binutils/readelf.c	2011-07-27 10:00:35.362568001 +0100
74ba718
*************** process_section_headers (FILE * file)
74ba718
*** 4614,4619 ****
74ba718
--- 4614,4620 ----
74ba718
  	      || (do_debug_ranges   && streq (name, "ranges"))
74ba718
  	      || (do_debug_frames   && streq (name, "frame"))
74ba718
  	      || (do_debug_macinfo  && streq (name, "macinfo"))
74ba718
+ 	      || (do_debug_macinfo  && streq (name, "macro"))
74ba718
  	      || (do_debug_str      && streq (name, "str"))
74ba718
  	      || (do_debug_loc      && streq (name, "loc"))
74ba718
  	      )
74ba718
*** ../binutils-2.21.53.0.1.orig/include/dwarf2.h	2011-07-27 09:57:55.773568001 +0100
74ba718
--- include/dwarf2.h	2011-07-27 10:20:37.147568000 +0100
74ba718
*************** enum dwarf_attribute
74ba718
*** 366,371 ****
74ba718
--- 366,373 ----
74ba718
      DW_AT_GNU_all_tail_call_sites = 0x2116,
74ba718
      DW_AT_GNU_all_call_sites = 0x2117,
74ba718
      DW_AT_GNU_all_source_call_sites = 0x2118,
74ba718
+     /* Section offset into .debug_macro section.  */
74ba718
+     DW_AT_GNU_macros = 0x2119,
74ba718
      /* VMS extensions.  */
74ba718
      DW_AT_VMS_rtnbeg_pd_address = 0x2201,
74ba718
      /* GNAT extensions.  */
74ba718
*************** enum dwarf_macinfo_record_type
74ba718
*** 880,885 ****
74ba718
--- 882,901 ----
74ba718
      DW_MACINFO_vendor_ext = 255
74ba718
    };
74ba718
  
74ba718
+ /* Names and codes for new style macro information.  */
74ba718
+ enum dwarf_macro_record_type
74ba718
+   {
74ba718
+     DW_MACRO_GNU_define = 1,
74ba718
+     DW_MACRO_GNU_undef = 2,
74ba718
+     DW_MACRO_GNU_start_file = 3,
74ba718
+     DW_MACRO_GNU_end_file = 4,
74ba718
+     DW_MACRO_GNU_define_indirect = 5,
74ba718
+     DW_MACRO_GNU_undef_indirect = 6,
74ba718
+     DW_MACRO_GNU_transparent_include = 7,
74ba718
+     DW_MACRO_GNU_lo_user = 0xe0,
74ba718
+     DW_MACRO_GNU_hi_user = 0xff
74ba718
+   };
74ba718
+ 
74ba718
  /* @@@ For use with GNU frame unwind information.  */
74ba718
  
74ba718
  #define DW_EH_PE_absptr		0x00