All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Levon <john.levon@sun.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH] Improve guest stack traces
Date: Fri, 13 Jan 2006 23:13:12 +0000	[thread overview]
Message-ID: <20060113231311.GA18017@barman.uk.sun.com> (raw)


# HG changeset patch
# User john.levon@sun.com
# Node ID 5dd67e9b7b07aa9a95d96e7b00a9fdbe6b49e214
# Parent  3f702887d4a62931182392c07436dcdba93a77ea
Improve guest stack traces.

Add an option to use the frame pointer for guest stack traces.
For stack dumps, avoid assumptions regarding stack size, and
continue past unreadable addresses, which helps when a guest
has overflowed its stack.

Signed-off-by: John Levon <john.levon@sun.com>

diff -r 3f702887d4a6 -r 5dd67e9b7b07 xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c	Fri Jan 13 16:56:09 2006 +0000
+++ b/xen/arch/x86/traps.c	Fri Jan 13 06:52:17 2006 -0800
@@ -100,15 +100,21 @@
 long do_set_debugreg(int reg, unsigned long value);
 unsigned long do_get_debugreg(int reg);
 
+static int debug_stack_usefp;
+boolean_param("debug_stack_usefp", debug_stack_usefp);
 static int debug_stack_lines = 20;
 integer_param("debug_stack_lines", debug_stack_lines);
 
 #ifdef CONFIG_X86_32
-#define stack_words_per_line 8
+#define stack_words_per_line 7
+#define trace_words_per_line 8
 #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)&regs->esp)
+#define UNREADABLE_ADDR "????????"
 #else
-#define stack_words_per_line 4
+#define stack_words_per_line 3
+#define trace_words_per_line 4
 #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
+#define UNREADABLE_ADDR "????????????????"
 #endif
 
 int is_kernel_text(unsigned long addr)
@@ -127,7 +133,52 @@
     return (unsigned long) &_etext;
 }
 
-static void show_guest_stack(struct cpu_user_regs *regs)
+struct frame {
+    unsigned long *fp;
+    unsigned long ret;
+};
+
+static void guest_stack_trace(struct cpu_user_regs *regs)
+{
+    unsigned long *fp = (unsigned long *)regs->ebp;
+    int i = 0;
+
+    printk("Guest stack trace from "__OP"bp=%p:\n", (void *)fp);
+
+    for ( i = 0; i < (debug_stack_lines*trace_words_per_line); i++ )
+    {
+        struct frame frame;
+
+        if ( (i % trace_words_per_line) == 0 )
+        {
+            if ( i != 0 )
+                printk("\n");
+            printk(" ");
+        }
+
+        if ( copy_from_user(&frame, (void *)fp, sizeof(struct frame)) )
+        {
+            printk(UNREADABLE_ADDR " ");
+            break;
+        }
+        else
+        {
+            if (frame.ret == 0)
+                break;
+            printk("%p ", _p(frame.ret));
+        }
+
+        /* Frames should progress strictly up the stack. */
+        if ( fp >= frame.fp )
+            break;
+        fp = frame.fp;
+    }
+
+    if ( i != 0 )
+        printk("\n");
+}
+
+static void guest_stack_dump(struct cpu_user_regs *regs)
 {
     int i;
     unsigned long *stack, addr;
@@ -135,35 +186,41 @@
     if ( VM86_MODE(regs) )
     {
         stack = (unsigned long *)((regs->ss << 4) + (regs->esp & 0xffff));
-        printk("Guest stack trace from ss:sp = %04x:%04x (VM86)\n   ",
+        printk("Guest stack dump from ss:sp = %04x:%04x (VM86)\n",
                regs->ss, (uint16_t)(regs->esp & 0xffff));
     }
     else
     {
         stack = (unsigned long *)regs->esp;
-        printk("Guest stack trace from "__OP"sp=%p:\n   ", stack);
+        printk("Guest stack dump from "__OP"sp=%p:\n", stack);
     }
 
     for ( i = 0; i < (debug_stack_lines*stack_words_per_line); i++ )
     {
-        if ( ((long)stack & (STACK_SIZE-BYTES_PER_LONG)) == 0 )
-            break;
+        if ( (i % stack_words_per_line) == 0 )
+        {
+            if ( i != 0 )
+                printk("\n");
+            printk(" %p: ", _p(stack));
+        }
+
         if ( get_user(addr, stack) )
-        {
-            if ( i != 0 )
-                printk("\n    ");
-            printk("Fault while accessing guest memory.");
-            i = 1;
-            break;
-        }
-        if ( (i != 0) && ((i % stack_words_per_line) == 0) )
-            printk("\n   ");
-        printk("%p ", _p(addr));
+            printk(UNREADABLE_ADDR " ");
+        else
+            printk("%p ", _p(addr));
+
         stack++;
     }
-    if ( i == 0 )
-        printk("Stack empty.");
+
     printk("\n");
+}
+
+static void show_guest_stack(struct cpu_user_regs *regs)
+{
+    if ( VM86_MODE(regs) || !debug_stack_usefp)
+        guest_stack_dump(regs);
+    else
+        guest_stack_trace(regs);
 }
 
 #ifdef NDEBUG

             reply	other threads:[~2006-01-13 23:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-13 23:13 John Levon [this message]
2006-01-14  9:15 ` [PATCH] Improve guest stack traces Keir Fraser
2006-01-14  9:21   ` Ian Campbell
2006-01-14  9:51   ` Kip Macy
2006-01-14 11:43   ` John Levon
2006-01-14 15:05     ` Keir Fraser

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=20060113231311.GA18017@barman.uk.sun.com \
    --to=john.levon@sun.com \
    --cc=xen-devel@lists.xensource.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.