public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/4] Make the backtrace-data test helper more robust
@ 2017-02-10 14:19 Ulf Hermann
  2017-02-12 21:16 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Ulf Hermann @ 2017-02-10 14:19 UTC (permalink / raw)
  To: elfutils-devel

When unwinding by frame pointer the unwinder might ask for invalid
addresses. We don't have to fail the test in this case. In fact
any broken dwarf information can lead to requests for invalid
addresses, also without frame pointer unwinding.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
---
  tests/ChangeLog        |  6 ++++++
  tests/backtrace-data.c | 16 +++++++++++++---
  2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 7031cf5..7040ac8 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-09  Ulf Hermann  <ulf.hermann@qt.io>
+
+	* backtrace-data.c: Don't assert that symbols are found.
+	The unwinder is allowed to ask for invalid addresses. We deny
+	such requests, rather than make the test fail.
+
  2016-11-17  Mark Wielaard  <mjw@redhat.com>
  
  	* run-readelf-s.sh: Add --symbols=.dynsym and --symbols=.symtab tests.
diff --git a/tests/backtrace-data.c b/tests/backtrace-data.c
index b7158da..a387d8f 100644
--- a/tests/backtrace-data.c
+++ b/tests/backtrace-data.c
@@ -76,10 +76,15 @@ memory_read (Dwfl *dwfl, Dwarf_Addr addr, Dwarf_Word *result,
  
    errno = 0;
    long l = ptrace (PTRACE_PEEKDATA, child, (void *) (uintptr_t) addr, NULL);
-  assert (errno == 0);
+
+  // The unwinder can ask for an invalid address.
+  // Don't assert on that but just politely refuse.
+  if (errno != 0) {
+      errno = 0;
+      return false;
+  }
    *result = l;
  
-  /* We could also return false for failed ptrace.  */
    return true;
  }
  
@@ -103,7 +108,8 @@ maps_lookup (pid_t pid, Dwarf_Addr addr, GElf_Addr *basep)
        unsigned long start, end, offset;
        i = fscanf (f, "%lx-%lx %*s %lx %*x:%*x %*x", &start, &end, &offset);
        assert (errno == 0);
-      assert (i == 3);
+      if (i != 3)
+          break;
        char *filename = strdup ("");
        assert (filename);
        size_t filename_len = 0;
@@ -131,6 +137,8 @@ maps_lookup (pid_t pid, Dwarf_Addr addr, GElf_Addr *basep)
  	}
        free (filename);
      }
+  *basep = 0;
+  return NULL;
  }
  
  /* Add module containing ADDR to the DWFL address space.
@@ -145,6 +153,8 @@ report_module (Dwfl *dwfl, pid_t child, Dwarf_Addr addr)
  {
    GElf_Addr base;
    char *long_name = maps_lookup (child, addr, &base);
+  if (!long_name)
+      return NULL; // not found
    Dwfl_Module *mod = dwfl_report_elf (dwfl, long_name, long_name, -1,
  				      base, false /* add_p_vaddr */);
    assert (mod);
-- 
2.1.4

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

* Re: [PATCH 2/4] Make the backtrace-data test helper more robust
  2017-02-10 14:19 [PATCH 2/4] Make the backtrace-data test helper more robust Ulf Hermann
@ 2017-02-12 21:16 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2017-02-12 21:16 UTC (permalink / raw)
  To: Ulf Hermann; +Cc: elfutils-devel

On Fri, 2017-02-10 at 15:19 +0100, Ulf Hermann wrote:
> When unwinding by frame pointer the unwinder might ask for invalid
> addresses. We don't have to fail the test in this case. In fact
> any broken dwarf information can lead to requests for invalid
> addresses, also without frame pointer unwinding.
> 
> Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>

Thanks. This makes sense to me. Applied.

Note the patch had the same issue as the previous one
(lines starting with a space had the first space doubled).

Cheers,

Mark

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

end of thread, other threads:[~2017-02-12 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 14:19 [PATCH 2/4] Make the backtrace-data test helper more robust Ulf Hermann
2017-02-12 21:16 ` 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).