This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] Fix readelf -wa, handle DW_FORM_strp in -wi (take 2)
- To: binutils at sources dot redhat dot com
- Subject: [PATCH] Fix readelf -wa, handle DW_FORM_strp in -wi (take 2)
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Wed, 7 Nov 2001 16:14:30 +0100
- References: <20011106134859.N739@sunsite.ms.mff.cuni.cz>
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
Hi!
Below is my yesterday's patch with some comments from
Keith Walker <Keith.Walker@arm.com> incorporated and with the DW_FORM_strp
fix for 64bit arches 32bit Dwarf-2.
Ok to commit?
2001-11-07 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.
Fix test for non-existant .debug_abbrev section.
--- binutils/readelf.c.jj Mon Oct 8 18:53:35 2001
+++ binutils/readelf.c Wed Nov 7 16:22:01 2001
@@ -6268,6 +6268,9 @@ get_FORM_name (form)
}
}
+static const char *debug_str;
+static 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);
@@ -6911,6 +6919,11 @@ read_and_display_attr (attribute, form,
data += pointer_size;
break;
+ case DW_FORM_strp:
+ uvalue = byte_get (data, /* offset_size */ 4);
+ data += /* offset_size */ 4;
+ break;
+
case DW_FORM_ref1:
case DW_FORM_flag:
case DW_FORM_data1:
@@ -7004,6 +7017,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 +7201,24 @@ 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 && 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;
+ break;
+ }
+ }
+
while (start < end)
{
DWARF2_External_CompUnit * external;
@@ -7296,7 +7336,7 @@ display_debug_info (section, start, file
if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
break;
- if (i == -1 || sec->sh_size == 0)
+ if (i == elf_header.e_shnum || sec->sh_size == 0)
{
warn (_("Unable to locate .debug_abbrev section!\n"));
return 0;
@@ -7363,6 +7403,12 @@ display_debug_info (section, start, file
}
}
+ if (debug_str != NULL)
+ {
+ free ((char *) debug_str);
+ debug_str = NULL;
+ }
+
printf ("\n");
return 1;
Jakub