From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51430 invoked by alias); 8 May 2018 14:49:51 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 51406 invoked by uid 89); 8 May 2018 14:49:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=ebl, 20180428, 2018-04-28 X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 May 2018 14:49:48 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id DB95330DD243; Tue, 8 May 2018 16:49:45 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id AEDAF4000AE1; Tue, 8 May 2018 16:49:45 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] readelf: Handle .debug_info first if any other debug section needs it. Date: Tue, 08 May 2018 14:49:00 -0000 Message-Id: <1525790979-2067-1-git-send-email-mark@klomp.org> X-Mailer: git-send-email 1.8.3.1 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q2/txt/msg00028.txt.bz2 Some debug sections need information from the CU DIEs to properly parse the data. Normally the .debug_info section is one of the first. But some DWARF producers reorder the sections and put it after some other debug sections. Make sure we first handle .debug_info if it is needed by any other debug section. Signed-off-by: Mark Wielaard --- src/ChangeLog | 7 +++++++ src/readelf.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index b1041a8..a6ee30b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2018-04-28 Mark Wielaard + + * 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 * readelf.c (attr_callback): Handle DW_FORM_ref_sup4 and diff --git a/src/readelf.c b/src/readelf.c index c69910a..e44b2a3 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -420,7 +420,10 @@ parse_opt (int key, char *arg, 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) @@ -8730,6 +8733,40 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr) 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) -- 1.8.3.1