public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Report error when decl_file or call_file attribute is invalid.
@ 2018-03-20 12:34 Mark Wielaard
  2018-03-27 13:42 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2018-03-20 12:34 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

Report an error for why the DW_AT_decl_file or DW_AT_call_file cannot
be resolved to a file name. This is likely invalid DWARF, a missing
DW_AT_stmt_list attribute on the CU or a missing .debug_line section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog |  5 +++++
 src/readelf.c | 18 +++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index c879712..f2f99ed 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-03-20  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (attr_callback): Report error when DW_AT_decl_file or
+	DW_AT_call_file cannot be resolved.
+
 2018-03-06  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (print_ops): Handle DW_OP_addrx, DW_OP_constx,
diff --git a/src/readelf.c b/src/readelf.c
index fcf5e2c..b1d63ef 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6247,11 +6247,23 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 		if (dwarf_getsrcfiles (&cudie, &files, &nfiles) == 0)
 		  {
 		    valuestr = dwarf_filesrc (files, num, NULL, NULL);
-		    char *filename = strrchr (valuestr, '/');
-		    if (filename != NULL)
-		      valuestr = filename + 1;
+		    if (valuestr != NULL)
+		      {
+			char *filename = strrchr (valuestr, '/');
+			if (filename != NULL)
+			  valuestr = filename + 1;
+		      }
+		    else
+		      error (0, 0, gettext ("invalid file (%" PRId64 "): %s"),
+			     num, dwarf_errmsg (-1));
 		  }
+		else
+		  error (0, 0, gettext ("no srcfiles for CU [%zx]"),
+			 dwarf_dieoffset (&cudie));
 	      }
+	    else
+	     error (0, 0, gettext ("couldn't get DWARF CU: %s"),
+		    dwarf_errmsg (-1));
 	  }
 	  break;
 	default:
-- 
1.8.3.1

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

* Re: [PATCH] readelf: Report error when decl_file or call_file attribute is invalid.
  2018-03-20 12:34 [PATCH] readelf: Report error when decl_file or call_file attribute is invalid Mark Wielaard
@ 2018-03-27 13:42 ` Mark Wielaard
  2018-03-27 14:26   ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2018-03-27 13:42 UTC (permalink / raw)
  To: elfutils-devel

On Tue, 2018-03-20 at 13:33 +0100, Mark Wielaard wrote:
> Report an error for why the DW_AT_decl_file or DW_AT_call_file cannot
> be resolved to a file name. This is likely invalid DWARF, a missing
> DW_AT_stmt_list attribute on the CU or a missing .debug_line section.

I pushed this to master with one tiny change, at the end of the error
checking this is added:

diff --git a/src/readelf.c b/src/readelf.c
index 72b5469..fc5aab7 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6780,6 +6780,8 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
            else
             error (0, 0, gettext ("couldn't get DWARF CU: %s"),
                    dwarf_errmsg (-1));
+           if (valuestr == NULL)
+             valuestr = "???";
          }
          break;

That way you don't just get a stderr message, but can also see in the
DIE tree output that the actual file name is missing. So with that the
output for a bogus DW_AT_decl_file would look like:

 [    1b]    typedef              abbrev: 2
             name                 (GNU_str_index) "size_t"
src/readelf: no srcfiles for CU [b]
             decl_file            (data1) ??? (5)
             decl_line            (data1) 216
             type                 (ref4) [    24]

Cheers,

Mark

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

* Re: [PATCH] readelf: Report error when decl_file or call_file attribute is invalid.
  2018-03-27 13:42 ` Mark Wielaard
@ 2018-03-27 14:26   ` Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2018-03-27 14:26 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

On Tue, 2018-03-27 at 15:42 +0200, Mark Wielaard wrote:
> On Tue, 2018-03-20 at 13:33 +0100, Mark Wielaard wrote:
> > Report an error for why the DW_AT_decl_file or DW_AT_call_file
> > cannot
> > be resolved to a file name. This is likely invalid DWARF, a missing
> > DW_AT_stmt_list attribute on the CU or a missing .debug_line
> > section.
> 
> I pushed this to master

And the buildbot flagged an issue on debian-i686:
https://builder.wildebeest.org/buildbot/#/builders/4/builds/110

readelf.c: In function ‘attr_callback’:
readelf.c:6261:27: error: format ‘%zx’ expects argument of type ‘size_t’, but argument 4 has type ‘Dwarf_Off {aka long long unsigned int}’ [-Werror=format=]
     error (0, 0, gettext ("no srcfiles for CU [%zx]"),
                           ^

Oops. Sorry about that. Fixed as attached.

[-- Attachment #2: 0001-readelf-Print-dwarf_dieoffset-as-PRIx64-not-zx.patch --]
[-- Type: text/x-patch, Size: 1199 bytes --]

From f0d7b3e14779cdf5facede98edc924ef1266b785 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Tue, 27 Mar 2018 16:22:16 +0200
Subject: [PATCH] readelf: Print dwarf_dieoffset as %PRIx64, not %zx.

On 32bit architectures size_t is not 64bit...

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 5 +++++
 src/readelf.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index f2f99ed..1ad6b3d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2018-03-27  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (attr_callback): Print dwarf_dieoffset as %PRIx64,
+	not %zx.
+
 2018-03-20  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (attr_callback): Report error when DW_AT_decl_file or
diff --git a/src/readelf.c b/src/readelf.c
index 8a96881..4e35b61 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6258,7 +6258,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 			     num, dwarf_errmsg (-1));
 		  }
 		else
-		  error (0, 0, gettext ("no srcfiles for CU [%zx]"),
+		  error (0, 0, gettext ("no srcfiles for CU [%" PRIx64 "]"),
 			 dwarf_dieoffset (&cudie));
 	      }
 	    else
-- 
1.8.3.1


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

end of thread, other threads:[~2018-03-27 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-20 12:34 [PATCH] readelf: Report error when decl_file or call_file attribute is invalid Mark Wielaard
2018-03-27 13:42 ` Mark Wielaard
2018-03-27 14:26   ` 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).