public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] readelf: Report error when decl_file or call_file attribute is invalid.
Date: Tue, 20 Mar 2018 12:34:00 -0000	[thread overview]
Message-ID: <1521549237-15410-1-git-send-email-mark@klomp.org> (raw)

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

             reply	other threads:[~2018-03-20 12:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 12:34 Mark Wielaard [this message]
2018-03-27 13:42 ` Mark Wielaard
2018-03-27 14:26   ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1521549237-15410-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).