public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Use raw section data if nothing is available through libdw.
@ 2018-04-24 14:17 Mark Wielaard
  2018-05-11 16:18 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2018-04-24 14:17 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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 | 13 +++++++++++++
 src/readelf.c | 33 +++++++++++++++++++++------------
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 3df62a0..55c5e76 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
+2018-04-24  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (print_debug_aranges_section): Try elf_rawdata if no
+	sectiondata.
+	(print_debug_rnglists_section): Likewise.
+	(print_debug_ranges_section): Likewise.
+	(print_debug_frame_section): Likewise.
+	(print_debug_loclists_section): Likewise.
+	(print_debug_loc_section): Likewise.
+	(print_debug_line_section): Likewise. Check for data == NULL.
+	(print_debug_macinfo_section): Likewise.
+	(print_debug_macro_section): Likewise.
+
 2018-04-12  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (dwarf_loc_list_encoding_string): New functions.
diff --git a/src/readelf.c b/src/readelf.c
index 0b9810f..2ae688a 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -5021,7 +5021,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))
     {
@@ -5179,7 +5180,8 @@ print_debug_rnglists_section (Dwfl_Module *dwflmod,
 	  elf_ndxscn (scn), section_name (ebl, ehdr, shdr),
 	  (uint64_t) shdr->sh_offset);
 
-  Elf_Data *data = dbg->sectiondata[IDX_debug_rnglists];
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_rnglists]
+		    ?: elf_rawdata (scn, NULL));
   if (unlikely (data == NULL))
     {
       error (0, 0, gettext ("cannot get .debug_rnglists content: %s"),
@@ -5503,7 +5505,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))
     {
@@ -6100,7 +6103,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))
     {
@@ -7340,8 +7344,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));
@@ -7859,7 +7864,8 @@ print_debug_loclists_section (Dwfl_Module *dwflmod,
 	  elf_ndxscn (scn), section_name (ebl, ehdr, shdr),
 	  (uint64_t) shdr->sh_offset);
 
-  Elf_Data *data = dbg->sectiondata[IDX_debug_loclists];
+  Elf_Data *data = (dbg->sectiondata[IDX_debug_loclists]
+		    ?: elf_rawdata (scn, NULL));
   if (unlikely (data == NULL))
     {
       error (0, 0, gettext ("cannot get .debug_loclists content: %s"),
@@ -8233,7 +8239,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))
     {
@@ -8428,8 +8435,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));
@@ -8590,8 +8598,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));
-- 
1.8.3.1

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

* Re: [PATCH] readelf: Use raw section data if nothing is available through libdw.
  2018-04-24 14:17 [PATCH] readelf: Use raw section data if nothing is available through libdw Mark Wielaard
@ 2018-05-11 16:18 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2018-05-11 16:18 UTC (permalink / raw)
  To: elfutils-devel

On Tue, 2018-04-24 at 16:17 +0200, Mark Wielaard wrote:
> 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.

Pushed this to master.

But rebases so the rnglists and loclists are no longer there.
They will appear correctly in the new patches (not yet posted) that
introduces parsing of those sections.

Cheers,

Mark

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24 14:17 [PATCH] readelf: Use raw section data if nothing is available through libdw Mark Wielaard
2018-05-11 16:18 ` 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).