+2018-04-28 Mark Wielaard <mark@klomp.org>
+
+ * readelf.c (print_debug): If .debug_info is needed implicitly by
+ then handle it first before handling any other debug section.
+ (parse_opt): Set implicit_debug_sections to section_info when
+ showing all debug sections.
+
2018-05-05 Mark Wielaard <mark@klomp.org>
* readelf.c (attr_callback): Handle DW_FORM_ref_sup4 and
break;
case 'w':
if (arg == NULL)
- print_debug_sections = section_all;
+ {
+ print_debug_sections = section_all;
+ implicit_debug_sections = section_info;
+ }
else if (strcmp (arg, "abbrev") == 0)
print_debug_sections |= section_abbrev;
else if (strcmp (arg, "aranges") == 0)
error (EXIT_FAILURE, 0,
gettext ("cannot get section header string table index"));
+ /* If the .debug_info section is listed as implicitly required then
+ we must make sure to handle it before handling any other debug
+ section. Various other sections depend on the CU DIEs being
+ scanned (silently) first. */
+ if ((implicit_debug_sections & section_info) != 0)
+ {
+ Elf_Scn *scn = NULL;
+ while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)
+ {
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+
+ if (shdr != NULL && shdr->sh_type == SHT_PROGBITS)
+ {
+ const char *name = elf_strptr (ebl->elf, shstrndx,
+ shdr->sh_name);
+ if (name == NULL)
+ continue;
+
+ if (strcmp (name, ".debug_info") == 0
+ || strcmp (name, ".debug_info.dwo") == 0
+ || strcmp (name, ".zdebug_info") == 0
+ || strcmp (name, ".zdebug_info.dwo") == 0)
+ {
+ print_debug_info_section (dwflmod, ebl, ehdr,
+ scn, shdr, dbg);
+ break;
+ }
+ }
+ }
+ print_debug_sections &= ~section_info;
+ implicit_debug_sections &= ~section_info;
+ }
+
/* Look through all the sections for the debugging sections to print. */
Elf_Scn *scn = NULL;
while ((scn = elf_nextscn (ebl->elf, scn)) != NULL)