xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xen.org
Cc: julien.grall@citrix.com, tim@xen.org,
	Ian Campbell <ian.campbell@citrix.com>,
	stefano.stabellini@eu.citrix.com
Subject: [PATCH] xen/arm64: fix stack dump in show_trace
Date: Tue, 4 Jun 2013 11:54:10 +0100	[thread overview]
Message-ID: <1370343250-24424-1-git-send-email-ian.campbell@citrix.com> (raw)

On aarch64 the frame pointer points to the next frame pointer and the return
address is the previous stack slot (so below on the downward growing stack,
therefore above in memory):

       |<RETURN ADDR>      ^addresses grow up
 FP -> |<NEXT FP>          |
       |                   |
       v                   |
       stack grows down.

This is contrary to aarch32 where the frame pointer points to the return
address and the next frame pointer is the next stack slot (so above on the
downward growing stack, below in memory):

 FP -> |<RETURN ADDR>       ^addresses grow up
       |<NEXT FP>           |
       |                    |
       v                    |
       stack grows down.

In addition print out LR as part of the trace, since it may contain the
penultimate return address e.g. if the ultimate function is a leaf function.

Lastly nuke some unnecessary braces.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 xen/arch/arm/traps.c |   69 +++++++++++++++++++++++++++++++------------------
 1 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 83a7fbc..398d209 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -519,7 +519,41 @@ static void show_guest_stack(struct cpu_user_regs *regs)
 }
 
 #define STACK_BEFORE_EXCEPTION(regs) ((register_t*)(regs)->sp)
-
+#ifdef CONFIG_ARM_32
+/* Frame pointer points to the return address:
+ * (largest address)
+ * | cpu_info
+ * | [...]                                   |
+ * | return addr      <-----------------,    |
+ * | fp --------------------------------+----'
+ * | [...]                              |
+ * | return addr      <------------,    |
+ * | fp ---------------------------+----'
+ * | [...]                         |
+ * | return addr      <- regs->fp  |
+ * | fp ---------------------------'
+ * |
+ * v (smallest address, sp)
+ */
+#define STACK_FRAME_BASE(fp)       ((register_t*)(fp) - 1)
+#else
+/* Frame pointer points to the next frame:
+ * (largest address)
+ * | cpu_info
+ * | [...]                                   |
+ * | return addr                             |
+ * | fp <-------------------------------, >--'
+ * | [...]                              |
+ * | return addr                        |
+ * | fp <--------------------------, >--'
+ * | [...]                         |
+ * | return addr      <- regs->fp  |
+ * | fp ---------------------------'
+ * |
+ * v (smallest address, sp)
+ */
+#define STACK_FRAME_BASE(fp)       ((register_t*)(fp))
+#endif
 static void show_trace(struct cpu_user_regs *regs)
 {
     register_t *frame, next, addr, low, high;
@@ -527,29 +561,15 @@ static void show_trace(struct cpu_user_regs *regs)
     printk("Xen call trace:\n   ");
 
     printk("[<%p>]", _p(regs->pc));
-    print_symbol(" %s\n   ", regs->pc);
+    print_symbol(" %s (PC)\n   ", regs->pc);
+    printk("[<%p>]", _p(regs->lr));
+    print_symbol(" %s (LR)\n   ", regs->lr);
 
     /* Bounds for range of valid frame pointer. */
-    low  = (register_t)(STACK_BEFORE_EXCEPTION(regs)/* - 2*/);
+    low  = (register_t)(STACK_BEFORE_EXCEPTION(regs));
     high = (low & ~(STACK_SIZE - 1)) +
         (STACK_SIZE - sizeof(struct cpu_info));
 
-    /* Frame:
-     * (largest address)
-     * | cpu_info
-     * | [...]                                   |
-     * | return addr      <-----------------,    |
-     * | fp --------------------------------+----'
-     * | [...]                              |
-     * | return addr      <------------,    |
-     * | fp ---------------------------+----'
-     * | [...]                         |
-     * | return addr      <- regs->fp  |
-     * | fp ---------------------------'
-     * |
-     * v (smallest address, sp)
-     */
-
     /* The initial frame pointer. */
     next = regs->fp;
 
@@ -557,12 +577,11 @@ static void show_trace(struct cpu_user_regs *regs)
     {
         if ( (next < low) || (next >= high) )
             break;
-        {
-            /* Ordinary stack frame. */
-            frame = (register_t *)next;
-            next  = frame[-1];
-            addr  = frame[0];
-        }
+
+        /* Ordinary stack frame. */
+        frame = STACK_FRAME_BASE(next);
+        next  = frame[0];
+        addr  = frame[1];
 
         printk("[<%p>]", _p(addr));
         print_symbol(" %s\n   ", addr);
-- 
1.7.2.5

             reply	other threads:[~2013-06-04 10:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-04 10:54 Ian Campbell [this message]
2013-06-13 17:28 ` [PATCH] xen/arm64: fix stack dump in show_trace Ian Campbell

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=1370343250-24424-1-git-send-email-ian.campbell@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=julien.grall@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xen.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 NNTP newsgroup(s).