This is the mail archive of the binutils@sources.redhat.com 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]

[PATCH] Fix readelf -wa, handle DW_FORM_strp in -wi


Hi!

readelf -wa would show only the first CU's abbreviations (and show them
twice).
This patch also adds support for displaying DW_FORM_strp strings.
I'm not sure how should they be displayed though. This patch prints them the
same as DW_FORM_string, which is very readable, but the difference between
DW_FORM_string vs. DW_FORM_strp must be looked in -wa.
Ideas?

2001-11-06  Jakub Jelinek  <jakub@redhat.com>

	* readelf.c (debug_str, debug_str_size): New.
	(display_debug_abbrev): If no abbrevs were read, skip the CU.
	Call free_abbrevs.
	(read_and_display_addr): Handle DW_FORM_strp.
	(display_debug_info): Read .debug_str section if present,
	so that DW_FORM_strp can be handled.

--- binutils/readelf.c.jj	Mon Oct  8 18:53:35 2001
+++ binutils/readelf.c	Tue Nov  6 13:32:02 2001
@@ -6268,6 +6268,9 @@ get_FORM_name (form)
     }
 }
 
+static const char *debug_str;
+bfd_vma debug_str_size;
+
 /* FIXME:  There are better and more effiecint ways to handle
    these structures.  For now though, I just want something that
    is simple to implement.  */
@@ -6518,6 +6521,9 @@ display_debug_abbrev (section, start, fi
     {
       start = process_abbrev_section (start, end);
 
+      if (first_abbrev == NULL)
+	continue;
+
       printf (_("  Number TAG\n"));
 
       for (entry = first_abbrev; entry; entry = entry->next)
@@ -6536,6 +6542,8 @@ display_debug_abbrev (section, start, fi
 		      get_FORM_name (attr->form));
 	    }
 	}
+
+      free_abbrevs ();
     }
   while (start);
 
@@ -6907,6 +6915,7 @@ read_and_display_attr (attribute, form, 
 
     case DW_FORM_ref_addr:
     case DW_FORM_addr:
+    case DW_FORM_strp:
       uvalue = byte_get (data, pointer_size);
       data += pointer_size;
       break;
@@ -7004,6 +7013,15 @@ read_and_display_attr (attribute, form, 
       break;
 
     case DW_FORM_strp:
+      if (debug_str == NULL)
+	warn (_("DW_FORM_strp used but no .debug_str section"));
+      else if (uvalue >= debug_str_size)
+	warn (_("DW_FORM_strp %lx points outside of .debug_str section"),
+	      uvalue);
+      else
+        printf (" %s", debug_str + uvalue);
+      break;
+
     case DW_FORM_indirect:
       warn (_("Unable to handle FORM: %d"), form);
       break;
@@ -7179,6 +7197,26 @@ display_debug_info (section, start, file
 
   printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
 
+  {
+    Elf32_Internal_Shdr * sec;
+    int i;
+
+    /* Locate the .debug_str section and read it.  */
+    for (i = 0, sec = section_headers;
+	 i < elf_header.e_shnum;
+	 i ++, sec ++)
+      if (strcmp (SECTION_NAME (sec), ".debug_str") == 0)
+	break;
+
+    if (i != -1 && sec->sh_size != 0)
+      {
+	debug_str = (const char *)
+		    get_data (NULL, file, sec->sh_offset, sec->sh_size,
+			      _("debug_str section data"));
+	debug_str_size = sec->sh_size;
+      }
+  }
+
   while (start < end)
     {
       DWARF2_External_CompUnit * external;
@@ -7363,6 +7401,12 @@ display_debug_info (section, start, file
 	}
     }
 
+  if (debug_str != NULL)
+    {
+      free ((char *) debug_str);
+      debug_str = NULL;
+    }
+
   printf ("\n");
 
   return 1;

	Jakub


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