All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Improve guest stack traces
@ 2006-01-13 23:13 John Levon
  2006-01-14  9:15 ` Keir Fraser
  0 siblings, 1 reply; 6+ messages in thread
From: John Levon @ 2006-01-13 23:13 UTC (permalink / raw)
  To: xen-devel


# 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

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

end of thread, other threads:[~2006-01-14 15:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-13 23:13 [PATCH] Improve guest stack traces John Levon
2006-01-14  9:15 ` 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

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.