This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Handle multiple .debug_info sections


The ARM RealView compiler creates object files with multiple
.debug_info sections.  They're merged in the final executable, but
I've had a number of occasions this week to run readelf -wi on RVCT
object files, and the output is confusing: we loop through the list of
sections, check each section's name, and then if the name is
recognized we dump it... by searching the section list for it again,
by name.  So if you have an object file with three .debug_info
sections, readelf -wi dumps the first one three times.

This patch improves the situation.  If readelf wants the contents of
.debug_info or .debug_abbrev to aid in decoding a different section,
then it will continue to use the first one in the file; this is not
perfect, but it's a step in the right direction.

Tested on arm-none-eabi and x86_64-linux-gnu, then checked in.

-- 
Daniel Jacobowitz
CodeSourcery

2008-09-05  Daniel Jacobowitz  <dan@codesourcery.com>

	* readelf.c (load_specific_debug_section): New function, from
	load_debug_section.
	(load_debug_section): Use load_specific_debug_section.
	(display_debug_section): Use load_specific_debug_section.  Check for
	multiple sections with the same name.

Index: readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.424
diff -u -p -r1.424 readelf.c
--- readelf.c	21 Aug 2008 19:38:58 -0000	1.424
+++ readelf.c	5 Sep 2008 14:48:19 -0000
@@ -8486,11 +8486,11 @@ debug_apply_relocations (void *file,
     }
 }
 
-int
-load_debug_section (enum dwarf_section_display_enum debug, void *file)
+static int
+load_specific_debug_section (enum dwarf_section_display_enum debug,
+			     Elf_Internal_Shdr *sec, void *file)
 {
   struct dwarf_section *section = &debug_displays [debug].section;
-  Elf_Internal_Shdr *sec;
   char buf [64];
   int section_is_compressed;
 
@@ -8498,18 +8498,6 @@ load_debug_section (enum dwarf_section_d
   if (section->start != NULL)
     return 1;
 
-  /* Locate the debug section.  */
-  sec = find_section (section->uncompressed_name);
-  if (sec != NULL)
-    section->name = section->uncompressed_name;
-  else
-    {
-      sec = find_section (section->compressed_name);
-      if (sec != NULL)
-	section->name = section->compressed_name;
-    }
-  if (sec == NULL)
-    return 0;
   section_is_compressed = section->name == section->compressed_name;
 
   snprintf (buf, sizeof (buf), _("%s section data"), section->name);
@@ -8530,6 +8518,28 @@ load_debug_section (enum dwarf_section_d
   return 1;
 }
 
+int
+load_debug_section (enum dwarf_section_display_enum debug, void *file)
+{
+  struct dwarf_section *section = &debug_displays [debug].section;
+  Elf_Internal_Shdr *sec;
+
+  /* Locate the debug section.  */
+  sec = find_section (section->uncompressed_name);
+  if (sec != NULL)
+    section->name = section->uncompressed_name;
+  else
+    {
+      sec = find_section (section->compressed_name);
+      if (sec != NULL)
+	section->name = section->compressed_name;
+    }
+  if (sec == NULL)
+    return 0;
+
+  return load_specific_debug_section (debug, sec, file);
+}
+
 void
 free_debug_section (enum dwarf_section_display_enum debug)
 {
@@ -8568,12 +8578,20 @@ display_debug_section (Elf_Internal_Shdr
         || streq (debug_displays[i].section.compressed_name, name))
       {
 	struct dwarf_section *sec = &debug_displays [i].section;
+	int secondary = (section != find_section (name));
+
+	if (secondary)
+	  free_debug_section (i);
 
-	if (load_debug_section (i, file))
+	if (streq (debug_displays[i].section.uncompressed_name, name))
+	  sec->name = sec->uncompressed_name;
+	else
+	  sec->name = sec->compressed_name;
+	if (load_specific_debug_section (i, section, file))
 	  {
 	    result &= debug_displays[i].display (sec, file);
 
-	    if (i != info && i != abbrev)
+	    if (secondary || (i != info && i != abbrev))
 	      free_debug_section (i);
 	  }
 


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