public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Handle .debug_info first if any other debug section needs it.
@ 2018-05-08 14:49 Mark Wielaard
  2018-05-11 15:37 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2018-05-08 14:49 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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 <mark@klomp.org>
---
 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  <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
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] readelf: Handle .debug_info first if any other debug section needs it.
  2018-05-08 14:49 [PATCH] readelf: Handle .debug_info first if any other debug section needs it Mark Wielaard
@ 2018-05-11 15:37 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2018-05-11 15:37 UTC (permalink / raw)
  To: elfutils-devel

On Tue, 2018-05-08 at 16:49 +0200, Mark Wielaard wrote:
> 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.

Pushed to master.

The observant reader noticed this patch also "handles" .dwo
files/sections, while the general support for that isn't in yet. I'll
post that patch soon. It is already present as WIP here:
https://code.wildebeest.org/git/user/mjw/elfutils/log/?h=dwarf5

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-11 15:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-08 14:49 [PATCH] readelf: Handle .debug_info first if any other debug section needs it Mark Wielaard
2018-05-11 15:37 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).