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>, Dodji Seketeli <dodji@seketeli.org>
Subject: Re: [PATCH] readelf: Print DIE offset in attribute reading error messages.
Date: Wed, 22 Nov 2017 11:59:00 -0000	[thread overview]
Message-ID: <1511351982.3112.22.camel@klomp.org> (raw)
In-Reply-To: <1511259709.3112.12.camel@klomp.org>

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

On Tue, 2017-11-21 at 11:21 +0100, Mark Wielaard wrote:
> On Thu, 2017-11-16 at 15:31 +0100, Mark Wielaard wrote:
> > On Tue, 2017-10-03 at 16:59 +0200, Mark Wielaard wrote:
> > > 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
> > 
> > Got another report about a large debug file where this improved error
> > message would have been really handy. So I pushed it to master now.
> 
> This has been really useful to debug some DWARF format issues, but it
> could be even more useful. Since we know the attribute name and form
> (or we would have generated an error earlier) add those to the error
> message too.

I made one other tweak to not abort, but keep trying to print the other
attributes of the DIE. It might just be this one attribute whose value
cannot be retrieved/resolved. Other errors (like not being able to
decode the attribute code or form still abort because then we really
don't know how to continue and the abbrev is probably bogus.

[-- Attachment #2: 0001-readelf-Print-attribute-name-and-form-in-error-messa.patch --]
[-- Type: text/x-patch, Size: 2012 bytes --]

From 62ac40bfb52df30048e2c3dc64a53296da5eb066 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Tue, 21 Nov 2017 11:13:00 +0100
Subject: [PATCH] readelf: Print attribute name and form in error message.

Now an error getting the attribute value will not only print the DIE offset
and the reason, but also the attribute name and form. e.g.

  DIE [b] cannot get attribute 'ranges' (sec_offset) value: .debug_ranges
  section missing

Also we don't abort, but try to print the other attributes of the DIE
anyway. It might just be one attribute whose value cannot be resolved.

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

diff --git a/src/ChangeLog b/src/ChangeLog
index d112cd2..c56c323 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-21  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (attr_callback): Print attribute name and form in error
+	message. If only the value cannot be retrieved/resolved don't abort.
+
 2017-10-03  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (attr_callback): Print DIE offset in error messages.
diff --git a/src/readelf.c b/src/readelf.c
index 9a03af6..ca7a19d 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6044,9 +6044,14 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
 	    attrval_out:
 	      if (!cbargs->silent)
 		error (0, 0, gettext ("DIE [%" PRIx64 "] "
-				      "cannot get attribute value: %s"),
-		       dwarf_dieoffset (die), dwarf_errmsg (-1));
-	      return DWARF_CB_ABORT;
+				      "cannot get attribute '%s' (%s) value: "
+				      "%s"),
+		       dwarf_dieoffset (die),
+		       dwarf_attr_name (attr),
+		       dwarf_form_name (form),
+		       dwarf_errmsg (-1));
+	      /* Don't ABORT, it might be other attributes can be resolved.  */
+	      return DWARF_CB_OK;
 	    }
 	  char *a = format_dwarf_addr (cbargs->dwflmod, cbargs->addrsize,
 				       addr, addr);
-- 
1.8.3.1


      parent reply	other threads:[~2017-11-22 11:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03 14:59 Mark Wielaard
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 [this message]

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=1511351982.3112.22.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=dodji@seketeli.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).