WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] Improve guest stack traces

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] Improve guest stack traces
From: John Levon <john.levon@xxxxxxx>
Date: Fri, 13 Jan 2006 23:13:12 +0000
Delivery-date: Sat, 14 Jan 2006 03:10:20 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Resent-date: Sat, 14 Jan 2006 03:04:39 +0000
Resent-date: Sat, 14 Jan 2006 03:04:39 +0000
Resent-from: john.levon@xxxxxxx
Resent-message-id: <20060114030439.GA21028@xxxxxxxxxxxxxxxxx>
Resent-sender: John Levon <johnlev@xxxxxxxxxxxxxxxxx>
Resent-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.6i
# HG changeset patch
# User john.levon@xxxxxxx
# 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@xxxxxxx>

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

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel