]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Use raw section data if nothing is available through libdw.
authorMark Wielaard <mark@klomp.org>
Tue, 24 Apr 2018 14:14:19 +0000 (16:14 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 11 May 2018 16:14:50 +0000 (18:14 +0200)
For various debug data sections readelf has its own parsers that don't
rely on libdw data structures or functions. But we still like to get the
data through libdw since that will be uncompressed and/or relocated.
But there can be reasons for libdw to have rejected the section data.
In that case we want to try to parse the "raw" section data.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c

index a6ee30b2b231a0d02f2e459b03444057584006c1..0a8b86c8dadbfd4ba7337356088c360a1ece35ba 100644 (file)
@@ -1,3 +1,14 @@
+2018-04-24  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (print_debug_aranges_section): Try elf_rawdata if no
+       sectiondata.
+       (print_debug_ranges_section): Likewise.
+       (print_debug_frame_section): Likewise.
+       (print_debug_line_section): Likewise. Check for data == NULL.
+       (print_debug_loc_section): Likewise.
+       (print_debug_macinfo_section): Likewise.
+       (print_debug_macro_section): Likewise.
+
 2018-04-28  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_debug): If .debug_info is needed implicitly by
index e44b2a39f0c22107de0e75f770aed41408c0b6b1..4b66cd0dd35068b401086be5468e9e0452211f8c 100644 (file)
@@ -4920,7 +4920,8 @@ print_debug_aranges_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
       return;
     }
 
-  Elf_Data *data = dbg->sectiondata[IDX_debug_aranges];
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_aranges]
+                   ?: elf_rawdata (scn, NULL));
 
   if (unlikely (data == NULL))
     {
@@ -5074,8 +5075,8 @@ print_debug_ranges_section (Dwfl_Module *dwflmod,
                            Elf_Scn *scn, GElf_Shdr *shdr,
                            Dwarf *dbg)
 {
-  Elf_Data *data = dbg->sectiondata[IDX_debug_ranges];
-
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_ranges]
+                   ?: elf_rawdata (scn, NULL));
   if (unlikely (data == NULL))
     {
       error (0, 0, gettext ("cannot get .debug_ranges content: %s"),
@@ -5671,7 +5672,8 @@ print_debug_frame_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
   bool is_eh_frame = strcmp (scnname, ".eh_frame") == 0;
   Elf_Data *data = (is_eh_frame
                    ? elf_rawdata (scn, NULL)
-                   : dbg->sectiondata[IDX_debug_frame]);
+                   : (dbg->sectiondata[IDX_debug_frame]
+                      ?: elf_rawdata (scn, NULL)));
 
   if (unlikely (data == NULL))
     {
@@ -6767,8 +6769,9 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
 
   /* There is no functionality in libdw to read the information in the
      way it is represented here.  Hardcode the decoder.  */
-  Elf_Data *data = dbg->sectiondata[IDX_debug_line];
-  if (unlikely (data == NULL || data->d_buf == NULL))
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_line]
+                   ?: elf_rawdata (scn, NULL));
+  if (unlikely (data == NULL))
     {
       error (0, 0, gettext ("cannot get line data section data: %s"),
             elf_errmsg (-1));
@@ -7280,7 +7283,8 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
                         Ebl *ebl, GElf_Ehdr *ehdr,
                         Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
 {
-  Elf_Data *data = dbg->sectiondata[IDX_debug_loc];
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_loc]
+                   ?: elf_rawdata (scn, NULL));
 
   if (unlikely (data == NULL))
     {
@@ -7475,8 +7479,9 @@ print_debug_macinfo_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
 
   /* There is no function in libdw to iterate over the raw content of
      the section but it is easy enough to do.  */
-  Elf_Data *data = dbg->sectiondata[IDX_debug_macinfo];
-  if (unlikely (data == NULL || data->d_buf == NULL))
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_macinfo]
+                   ?: elf_rawdata (scn, NULL));
+  if (unlikely (data == NULL))
     {
       error (0, 0, gettext ("cannot get macro information section data: %s"),
             elf_errmsg (-1));
@@ -7637,8 +7642,9 @@ print_debug_macro_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
          (uint64_t) shdr->sh_offset);
   putc_unlocked ('\n', stdout);
 
-  Elf_Data *data = dbg->sectiondata[IDX_debug_macro];
-  if (unlikely (data == NULL || data->d_buf == NULL))
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_macro]
+                   ?: elf_rawdata (scn, NULL));
+  if (unlikely (data == NULL))
     {
       error (0, 0, gettext ("cannot get macro information section data: %s"),
             elf_errmsg (-1));