public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Ulf Hermann <ulf.hermann@qt.io>
To: Mark Wielaard <mark@klomp.org>
Cc: <elfutils-devel@sourceware.org>
Subject: Re: [PATCH 5/5] Add frame pointer unwinding for aarch64
Date: Thu, 27 Apr 2017 14:02:00 -0000	[thread overview]
Message-ID: <14b0cd1d-5737-2c7a-3fab-f197011c7fc6@qt.io> (raw)
In-Reply-To: <1493217200.31726.59.camel@klomp.org>

On 04/26/2017 04:33 PM, Mark Wielaard wrote:
> On Tue, 2017-04-25 at 15:38 +0200, Ulf Hermann wrote:
>>> My question is about this "initial frame". In our testcase we don't have
>>> this case since the backtrace starts in a function that has some CFI.
>>> But I assume you have some tests that rely on this behavior.
>>
>> Actually the test I provided does exercise this code. The initial
>> __libc_do_syscall() frame does not have CFI. Only raise() has. You can
>> check that by dropping the code for pc & 0x1.
> 
> Maybe I am using the wrong binaries (exec and core), but for me there is
> no difference.

In fact, with the new binaries there is no difference. I was confused, sorry.

However, if you strip .eh_frame and .eh_frame_hdr from the exe (thus triggering the fp unwinding on the first frame), you will see that it skips sigusr2. At the same time it invents another frame 0x403f40 on the main thread. Apparently pthread_join creates two stack frames. As it correctly unwinds the rest, the latter seemed harmless to me.

With .eh_frame and .eh_frame_hdr:

ulf@zebra:~/dev/build-elfutils/tests$ ./backtrace --core=backtrace.aarch64.fp.core -e backtrace.aarch64.fp.exec
0x400000        0x4a3000        /home/ulf/backtrace.aarch64.fp.exec
0x7fb6380000    0x7fb6381000    linux-vdso.so.1
TID 350:
# 0 0x40583c            raise
# 1 0x401aac - 1        sigusr2
# 2 0x401ba8 - 1        stdarg
# 3 0x401c04 - 1        backtracegen
# 4 0x401c10 - 1        start
# 5 0x402f44 - 1        start_thread
# 6 0x41dc70 - 1        __clone
TID 349:
# 0 0x403fcc            pthread_join
# 1 0x401810 - 1        main
# 2 0x406544 - 1        __libc_start_main
# 3 0x401918 - 1        $x
./backtrace: dwfl_thread_getframes: address out of range

Without .eh_frame and .eh_frame_hdr, code from PATCH V2:

ulf@zebra:~/dev/build-elfutils/tests$ ./backtrace --core=backtrace.aarch64.fp.core -e backtrace.aarch64.fp.stripped 
0x400000        0x4a3000        /home/ulf/backtrace.aarch64.fp.exec
0x7fb6380000    0x7fb6381000    linux-vdso.so.1
TID 350:
# 0 0x40583c            (null)
# 1 0x401aac - 1        (null)
# 2 0x401ba8 - 1        (null)
# 3 0x401c04 - 1        (null)
# 4 0x401c10 - 1        (null)
# 5 0x402f44 - 1        (null)
# 6 0x41dc70 - 1        (null)
./backtrace: dwfl_thread_getframes: address out of range
TID 349:
# 0 0x403fcc            (null)
# 1 0x403f40 - 1        (null)
# 2 0x401810 - 1        (null)
# 3 0x406544 - 1        (null)
# 4 0x401918 - 1        (null)
./backtrace: dwfl_thread_getframes: address out of range

Without .eh_frame and .eh_frame_hdr, without initial frame adjustment:

ulf@zebra:~/dev/build-elfutils/tests$ ./backtrace --core=backtrace.aarch64.fp.core -e backtrace.aarch64.fp.stripped 
0x400000        0x4a3000        /home/ulf/backtrace.aarch64.fp.exec
0x7fb6380000    0x7fb6381000    linux-vdso.so.1
TID 350:
# 0 0x40583c            (null)
# 1 0x401ba8 - 1        (null)
# 2 0x401c04 - 1        (null)
# 3 0x401c10 - 1        (null)
# 4 0x402f44 - 1        (null)
# 5 0x41dc70 - 1        (null)
./backtrace: dwfl_thread_getframes: address out of range
TID 349:
# 0 0x403fcc            (null)
# 1 0x401810 - 1        (null)
# 2 0x406544 - 1        (null)
# 3 0x401918 - 1        (null)
./backtrace: dwfl_thread_getframes: address out of range

You have to drop all the asserts from backtrace.c to actually test this:

diff --git a/tests/backtrace.c b/tests/backtrace.c
index 1ff6353..a910a77 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -71,14 +71,14 @@ static void
 callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
 		 const char *symname, Dwfl *dwfl)
 {
-  static bool seen_main = false;
+//  static bool seen_main = false;
   if (symname && *symname == '.')
     symname++;
-  if (symname && strcmp (symname, "main") == 0)
-    seen_main = true;
+//  if (symname && strcmp (symname, "main") == 0)
+//    seen_main = true;
   if (pc == 0)
     {
-      assert (seen_main);
+//      assert (seen_main);
       return;
     }
   if (check_tid == 0)
@@ -103,11 +103,11 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
 	       && (strcmp (symname, "__kernel_vsyscall") == 0
 		   || strcmp (symname, "__libc_do_syscall") == 0))
 	reduce_frameno = true;
-      else
-	assert (symname && strcmp (symname, "raise") == 0);
+//      else
+//	assert (symname && strcmp (symname, "raise") == 0);
       break;
     case 1:
-      assert (symname != NULL && strcmp (symname, "sigusr2") == 0);
+//      assert (symname != NULL && strcmp (symname, "sigusr2") == 0);
       break;
     case 2: // x86_64 only
       /* __restore_rt - glibc maybe does not have to have this symbol.  */
@@ -125,11 +125,11 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
 	}
       /* FALLTHRU */
     case 4:
-      assert (symname != NULL && strcmp (symname, "stdarg") == 0);
+//      assert (symname != NULL && strcmp (symname, "stdarg") == 0);
       break;
     case 5:
       /* Verify we trapped on the very last instruction of child.  */
-      assert (symname != NULL && strcmp (symname, "backtracegen") == 0);
+//      assert (symname != NULL && strcmp (symname, "backtracegen") == 0);
       mod = dwfl_addrmodule (dwfl, pc);
       if (mod)
 	symname2 = dwfl_module_addrname (mod, pc);

  reply	other threads:[~2017-04-26 15:27 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15 23:34 frame unwinding patches Mark Wielaard
2017-02-15 23:34 ` [PATCH 3/3] Add frame pointer unwinding for aarch64 Mark Wielaard
2017-02-15 23:34 ` [PATCH 2/3] Add frame pointer unwinding as fallback on arm Mark Wielaard
2017-02-15 23:34 ` [PATCH 1/3] Add frame pointer unwinding as fallback on x86_64 Mark Wielaard
2017-02-16  9:13 ` frame unwinding patches Ulf Hermann
2017-04-03  9:00 ` Milian Wolff
2017-04-03  9:03   ` Ulf Hermann
2017-04-03 21:14     ` Mark Wielaard
2017-04-07 10:27       ` Mark Wielaard
2017-04-11 10:16         ` Ulf Hermann
2017-04-19 19:48           ` Mark Wielaard
2017-04-20  9:26             ` Ulf Hermann
2017-04-25 12:50               ` Mark Wielaard
2017-04-25 12:54                 ` [PATCH 1/5] Revert "Optionally allow unknown symbols in the backtrace tests" Mark Wielaard
2017-04-25 12:50                   ` [PATCH 2/5] tests: Add core backtracegen chec and regenerate ppc32 backtrace test files Mark Wielaard
2017-04-25 13:04                     ` Ulf Hermann
2017-04-25 12:55                   ` [PATCH 3/5] Add frame pointer unwinding as fallback on x86_64 Mark Wielaard
2017-04-25 13:05                     ` Ulf Hermann
2017-04-25 12:56                   ` [PATCH 1/5] Revert "Optionally allow unknown symbols in the backtrace tests" Ulf Hermann
2017-04-25 12:56                   ` [PATCH 4/5] Add i386 frame pointer unwinder Mark Wielaard
2017-04-25 13:38                     ` Ulf Hermann
2017-04-25 13:11                   ` [PATCH 5/5] Add frame pointer unwinding for aarch64 Mark Wielaard
2017-04-25 21:55                     ` Ulf Hermann
2017-04-25 22:13                     ` Mark Wielaard
2017-04-25 22:23                       ` Ulf Hermann
2017-04-26 15:24                         ` Mark Wielaard
2017-04-27 14:02                           ` Ulf Hermann [this message]
2017-04-27 14:29                             ` Mark Wielaard
2017-04-27 14:35                               ` Ulf Hermann
2017-04-27 15:09                                 ` Mark Wielaard
2017-04-27 15:42                                   ` Ulf Hermann
2017-05-03  8:46                                 ` Mark Wielaard
2017-04-26 15:20                 ` frame unwinding patches Ulf Hermann
2017-04-03 21:23   ` Jan Kratochvil
2017-04-04  7:40     ` Milian Wolff
2017-04-04  7:55       ` Jan Kratochvil
2017-04-04  8:25         ` Ulf Hermann

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=14b0cd1d-5737-2c7a-3fab-f197011c7fc6@qt.io \
    --to=ulf.hermann@qt.io \
    --cc=elfutils-devel@sourceware.org \
    --cc=mark@klomp.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).