public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Tom Tromey <tom@tromey.com>,	Mark Wielaard <mark@klomp.org>
Subject: [PATCH] readelf: Print DIE offset in attribute reading error messages.
Date: Tue, 03 Oct 2017 14:59:00 -0000	[thread overview]
Message-ID: <1507042757-27353-1-git-send-email-mark@klomp.org> (raw)

When processing large files it is useful to know the DIE offset if
printing of attributes fails (especially when redirecting the output).
With this change the error message looks like:

  eu-readelf: DIE [2aeb8ef1] cannot get attribute value: invalid DWARF

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

diff --git a/src/ChangeLog b/src/ChangeLog
index 0d3bfc1..ba7d46d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2017-10-03  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (attr_callback): Print DIE offset in error messages.
+
 2017-09-10  Mark Wielaard  <mark@klomp.org>
 
 	* ar.c (do_oper_delete): Remove DEBUG conditional check.
diff --git a/src/readelf.c b/src/readelf.c
index 5e2f3fc..16d2033 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -5934,13 +5934,15 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 {
   struct attrcb_args *cbargs = (struct attrcb_args *) arg;
   const int level = cbargs->level;
+  Dwarf_Die *die = cbargs->die;
 
   unsigned int attr = dwarf_whatattr (attrp);
   if (unlikely (attr == 0))
     {
       if (!cbargs->silent)
-	error (0, 0, gettext ("cannot get attribute code: %s"),
-	       dwarf_errmsg (-1));
+	error (0, 0, gettext ("DIE [%" PRIx64 "] "
+			      "cannot get attribute code: %s"),
+	       dwarf_dieoffset (die), dwarf_errmsg (-1));
       return DWARF_CB_ABORT;
     }
 
@@ -5948,8 +5950,9 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
   if (unlikely (form == 0))
     {
       if (!cbargs->silent)
-	error (0, 0, gettext ("cannot get attribute form: %s"),
-	       dwarf_errmsg (-1));
+	error (0, 0, gettext ("DIE [%" PRIx64 "] "
+			      "cannot get attribute form: %s"),
+	       dwarf_dieoffset (die), dwarf_errmsg (-1));
       return DWARF_CB_ABORT;
     }
 
@@ -5963,8 +5966,9 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 	    {
 	    attrval_out:
 	      if (!cbargs->silent)
-		error (0, 0, gettext ("cannot get attribute value: %s"),
-		       dwarf_errmsg (-1));
+		error (0, 0, gettext ("DIE [%" PRIx64 "] "
+				      "cannot get attribute value: %s"),
+		       dwarf_dieoffset (die), dwarf_errmsg (-1));
 	      return DWARF_CB_ABORT;
 	    }
 	  char *a = format_dwarf_addr (cbargs->dwflmod, cbargs->addrsize,
-- 
1.8.3.1

             reply	other threads:[~2017-10-03 14:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03 14:59 Mark Wielaard [this message]
2017-11-16 14:31 ` Mark Wielaard
2017-11-21 10:21   ` Mark Wielaard
2017-11-21 19:19     ` Tom Tromey
2017-11-22 11:36       ` Mark Wielaard
2017-11-23  8:39       ` Dodji Seketeli
2017-11-24 10:22         ` Mark Wielaard
2017-11-22 11:59     ` 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=1507042757-27353-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=tom@tromey.com \
    /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).