public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: [PATCH v3 4/6] tests/allfcts.c: Install alternate debug information
Date: Tue, 15 Apr 2014 16:58:39 +0200	[thread overview]
Message-ID: <3666d4ad5a9fd9f22a87529890c9a889edf81f12.1397586259.git.fweimer@redhat.com> (raw)
In-Reply-To: cover.1397586259.git.fweimer@redhat.com

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

This change also adds more error checking and reporting.

Signed-off-by: Florian Weimer <fweimer@redhat.com>
---
 tests/ChangeLog |  4 ++++
 tests/allfcts.c | 30 +++++++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index a5fc945..ca47d77 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -5,6 +5,10 @@
 	(TESTS): Add run-debugaltlink.sh.
 	(debugaltlink_LDADD): New variable.
 
+	* allfcts.c (setup_alt): New function.
+	(main): Call it.  Implementation additional error checking and
+	reporting.
+
 2014-04-11  Mark Wielaard  <mjw@redhat.com>
 
 	* Makefile.am (AM_CPPFLAGS): Add -I libdwelf.
diff --git a/tests/allfcts.c b/tests/allfcts.c
index 10e0f07..8d19594 100644
--- a/tests/allfcts.c
+++ b/tests/allfcts.c
@@ -18,8 +18,10 @@
 # include <config.h>
 #endif
 
+#include <err.h>
 #include <fcntl.h>
 #include ELFUTILS_HEADER(dw)
+#include ELFUTILS_HEADER(dwelf)
 #include <stdio.h>
 #include <unistd.h>
 
@@ -37,6 +39,23 @@ cb (Dwarf_Die *func, void *arg __attribute__ ((unused)))
   return DWARF_CB_ABORT;
 }
 
+static Dwarf *
+setup_alt (Dwarf *main)
+{
+  const void *build_id;
+  size_t build_id_len;
+  const char *alt_name = dwelf_dwarf_gnu_debugaltlink
+    (main, &build_id, &build_id_len);
+  if (alt_name == NULL)
+    return NULL;
+  int fd = open (alt_name, O_RDONLY);
+  if (fd < 0)
+    err (1, "open (%s)", alt_name);
+  Dwarf *dbg_alt = dwarf_begin (fd, DWARF_C_READ);
+  close (fd);
+  dwarf_setalt (main, dbg_alt);
+  return dbg_alt;
+}
 
 int
 main (int argc, char *argv[])
@@ -44,6 +63,8 @@ main (int argc, char *argv[])
   for (int i = 1; i < argc; ++i)
     {
       int fd = open (argv[i], O_RDONLY);
+      if (fd < 0)
+	err (1, "open (%s)", argv[i]);
 
       Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
       if (dbg != NULL)
@@ -51,6 +72,7 @@ main (int argc, char *argv[])
 	  Dwarf_Off off = 0;
 	  size_t cuhl;
 	  Dwarf_Off noff;
+	  Dwarf *dbg_alt = setup_alt (dbg);
 
 	  while (dwarf_nextcu (dbg, off, &noff, &cuhl, NULL, NULL, NULL) == 0)
 	    {
@@ -62,14 +84,20 @@ main (int argc, char *argv[])
 	      do
 		{
 		  doff = dwarf_getfuncs (die, cb, NULL, doff);
+		  if (dwarf_errno () != 0)
+		    errx (1, "dwarf_getfuncs (%s): %s",
+			  argv[i], dwarf_errmsg (-1));
 		}
-	      while (doff != 0 && dwarf_errno () == 0);
+	      while (doff != 0);
 
 	      off = noff;
 	    }
 
+	  dwarf_end (dbg_alt);
 	  dwarf_end (dbg);
 	}
+      else
+	errx (1, "dwarf_begin (%s): %s", argv[i], dwarf_errmsg (-1));
 
       close (fd);
     }
-- 
1.9.0


             reply	other threads:[~2014-04-15 14:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-15 14:58 Florian Weimer [this message]
2014-04-18 11:58 Mark Wielaard
2014-04-22  7:37 Florian Weimer

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=3666d4ad5a9fd9f22a87529890c9a889edf81f12.1397586259.git.fweimer@redhat.com \
    --to=fweimer@redhat.com \
    --cc=elfutils-devel@lists.fedorahosted.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).