PATCHES: Add DWARF dump to objdump

H. J. Lu hjl@lucon.org
Thu Sep 29 17:00:00 GMT 2005


On Wed, Sep 28, 2005 at 02:46:01PM -0700, Eric Christopher wrote:
> >
> >binutils-darwin-1.patch
> >readelf-reloc-1.patch
> >readelf-gen-9.patch
> >readelf-dwarf-16.patch
> >objdump-dump-7.patch
> >objdump-mach-o-3.patch
> >
> 
> These, in general, look good for me. I'd prefer someone else look at  
> the objdump bits for the objdump-mach-o-3.patch though.

Here is the updated one to save/restore DWARF section names.

> 
> Do you have more bfd mach-o bits sitting around for some of this?
> 

No, I don't. I don't think the current bfd knows mach-o relocations.
But it is good enough to dump DWARF info in mach-o executables.


H.J.
-------------- next part --------------
2005-09-29  H.J. Lu  <hongjiu.lu@intel.com>

	* dwarf.c (fetch_indirect_string): Adjust for section address.
	(process_debug_info): Likewise.
	(display_debug_loc): Likewise.
	(display_debug_ranges): Likewise.

	* objdump.c (mach_o_dwarf_sections): New.
	(generic_dwarf_sections): Likewise.
	(check_mach_o_dwarf): Likewise.
	(dump_dwarf): Call check_mach_o_dwarf.

--- binutils/dwarf.c.mach-o	2005-09-29 08:39:26.000000000 -0700
+++ binutils/dwarf.c	2005-09-29 08:39:26.000000000 -0700
@@ -287,6 +287,8 @@ fetch_indirect_string (unsigned long off
   if (section->start == NULL)
     return _("<no .debug_str section>");
 
+  /* DWARF sections under Mach-O have non-zero addresses.  */
+  offset -= section->address;
   if (offset > section->size)
     {
       warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
@@ -1645,10 +1647,11 @@ process_debug_info (struct dwarf_section
 
       free_abbrevs ();
 
-      /* Process the abbrevs used by this compilation unit.  */
+      /* Process the abbrevs used by this compilation unit. DWARF
+	 sections under Mach-O have non-zero addresses.  */
       process_abbrev_section
 	((unsigned char *) debug_displays [abbrev].section.start
-	 + compunit.cu_abbrev_offset,
+	 + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
 	 (unsigned char *) debug_displays [abbrev].section.start
 	 + debug_displays [abbrev].section.size);
 
@@ -2371,7 +2374,8 @@ display_debug_loc (struct dwarf_section 
   if (!seen_first_offset)
     error (_("No location lists in .debug_info section!\n"));
 
-  if (debug_information [first].loc_offsets [0] != 0)
+  /* DWARF sections under Mach-O have non-zero addresses.  */
+  if (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]);
 
@@ -2397,7 +2401,8 @@ display_debug_loc (struct dwarf_section 
       for (j = 0; j < debug_information [i].num_loc_offsets; j++)
 	{
 	  has_frame_base = debug_information [i].have_frame_base [j];
-	  offset = debug_information [i].loc_offsets [j];
+	  /* DWARF sections under Mach-O have non-zero addresses.  */
+	  offset = debug_information [i].loc_offsets [j] - section->address; 
 	  next = section_begin + offset;
 	  base_address = debug_information [i].base_address;
 
@@ -2726,7 +2731,8 @@ display_debug_ranges (struct dwarf_secti
   if (!seen_first_offset)
     error (_("No range lists in .debug_info section!\n"));
 
-  if (debug_information [first].range_lists [0] != 0)
+  /* DWARF sections under Mach-O have non-zero addresses.  */
+  if (debug_information [first].range_lists [0] != section->address)
     warn (_("Range lists in %s section start at 0x%lx\n"),
 	  section->name, debug_information [first].range_lists [0]);
 
@@ -2746,7 +2752,8 @@ display_debug_ranges (struct dwarf_secti
 
       for (j = 0; j < debug_information [i].num_range_lists; j++)
 	{
-	  offset = debug_information [i].range_lists [j];
+	  /* DWARF sections under Mach-O have non-zero addresses.  */
+	  offset = debug_information [i].range_lists [j] - section->address;
 	  next = section_begin + offset;
 	  base_address = debug_information [i].base_address;
 
--- binutils/objdump.c.mach-o	2005-09-29 08:39:26.000000000 -0700
+++ binutils/objdump.c	2005-09-29 08:55:27.000000000 -0700
@@ -2055,6 +2055,51 @@ dump_dwarf_section (bfd *abfd, asection 
       }
 }
 
+static const char *mach_o_dwarf_sections [] = {
+  "LC_SEGMENT.__DWARFA.__debug_abbrev",		/* .debug_abbrev */
+  "LC_SEGMENT.__DWARFA.__debug_aranges",	/* .debug_aranges */
+  "LC_SEGMENT.__DWARFA.__debug_frame",		/* .debug_frame */
+  "LC_SEGMENT.__DWARFA.__debug_info",		/* .debug_info */
+  "LC_SEGMENT.__DWARFA.__debug_line",		/* .debug_line */
+  "LC_SEGMENT.__DWARFA.__debug_pubnames",	/* .debug_pubnames */
+  ".eh_frame",					/* .eh_frame */
+  "LC_SEGMENT.__DWARFA.__debug_macinfo",	/* .debug_macinfo */
+  "LC_SEGMENT.__DWARFA.__debug_str",		/* .debug_str */
+  "LC_SEGMENT.__DWARFA.__debug_loc",		/* .debug_loc */
+  "LC_SEGMENT.__DWARFA.__debug_pubtypes",	/* .debug_pubtypes */
+  "LC_SEGMENT.__DWARFA.__debug_ranges",		/* .debug_ranges */
+  "LC_SEGMENT.__DWARFA.__debug_static_func",	/* .debug_static_func */
+  "LC_SEGMENT.__DWARFA.__debug_static_vars",	/* .debug_static_vars */
+  "LC_SEGMENT.__DWARFA.__debug_types",		/* .debug_types */
+  "LC_SEGMENT.__DWARFA.__debug_weaknames"	/* .debug_weaknames */
+};
+
+static const char *generic_dwarf_sections [max];
+
+static void
+check_mach_o_dwarf (bfd *abfd)
+{
+  static enum bfd_flavour old_flavour = bfd_target_unknown_flavour;
+  enum bfd_flavour current_flavour = bfd_get_flavour (abfd);
+  enum dwarf_section_display_enum i;
+
+  if (generic_dwarf_sections [0] == NULL)
+    for (i = 0; i < max; i++)
+      generic_dwarf_sections [i] = debug_displays[i].section.name;
+
+  if (old_flavour != current_flavour)
+    {
+      if (current_flavour == bfd_target_mach_o_flavour)
+	for (i = 0; i < max; i++)
+	  debug_displays[i].section.name = mach_o_dwarf_sections [i];
+      else if (old_flavour == bfd_target_mach_o_flavour)
+	for (i = 0; i < max; i++)
+	  debug_displays[i].section.name = generic_dwarf_sections [i];
+
+      old_flavour = current_flavour;
+    }
+}
+
 /* Dump the dwarf debugging information.  */
 
 static void
@@ -2074,6 +2119,8 @@ dump_dwarf (bfd *abfd)
   else
     abort ();
 
+  check_mach_o_dwarf (abfd);
+
   bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
 
   free_debug_memory ();


More information about the Binutils mailing list