* [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 *)®s->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* Re: [PATCH] Improve guest stack traces
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
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Keir Fraser @ 2006-01-14 9:15 UTC (permalink / raw)
To: John Levon; +Cc: xen-devel
On 13 Jan 2006, at 23:13, John Levon wrote:
> 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>
Improved guest backtraces belong in the xenctx utility
(tools/xentrace/xenctx.c). It already has the clear advantage that it
can print kernel symbols as well as addresses. The stack dump code in
Xen is mainly for very early crashes in dom0, and it's quite sufficient
for that.
So, if you want a frame-walking mode, put it in xenctx.
-- Keir
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Improve guest stack traces
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
2 siblings, 0 replies; 6+ messages in thread
From: Ian Campbell @ 2006-01-14 9:21 UTC (permalink / raw)
To: Keir Fraser; +Cc: xen-devel, John Levon
On Sat, 2006-01-14 at 09:15 +0000, Keir Fraser wrote:
> if you want a frame-walking mode, put it in xenctx.
xenctx will already use frame-pointers if you pass it -f on the command
line.
Ian.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Improve guest stack traces
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
2 siblings, 0 replies; 6+ messages in thread
From: Kip Macy @ 2006-01-14 9:51 UTC (permalink / raw)
To: Keir Fraser; +Cc: xen-devel, John Levon
[-- Attachment #1.1: Type: text/plain, Size: 1173 bytes --]
And if you're using a compiler that generates symbols that gdb supports, you
can get a *lot* more info by using gdb + gdbserver. Writing a script to wrap
execing those two and dumping a crashed VMs state would be a fairly trivial
exercise.
-Kip
On 1/14/06, Keir Fraser <Keir.Fraser@cl.cam.ac.uk> wrote:
>
>
> On 13 Jan 2006, at 23:13, John Levon wrote:
>
> > 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>
>
> Improved guest backtraces belong in the xenctx utility
> (tools/xentrace/xenctx.c). It already has the clear advantage that it
> can print kernel symbols as well as addresses. The stack dump code in
> Xen is mainly for very early crashes in dom0, and it's quite sufficient
> for that.
>
> So, if you want a frame-walking mode, put it in xenctx.
>
> -- Keir
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>
[-- Attachment #1.2: Type: text/html, Size: 1760 bytes --]
[-- Attachment #2: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] Improve guest stack traces
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
2 siblings, 1 reply; 6+ messages in thread
From: John Levon @ 2006-01-14 11:43 UTC (permalink / raw)
To: Keir Fraser; +Cc: xen-devel
On Sat, Jan 14, 2006 at 09:15:54AM +0000, Keir Fraser wrote:
> Improved guest backtraces belong in the xenctx utility
> (tools/xentrace/xenctx.c).
Aha, thanks. It's currently very Linux-specific, but I suppose
we can improve that.
thanks,
john
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Improve guest stack traces
2006-01-14 11:43 ` John Levon
@ 2006-01-14 15:05 ` Keir Fraser
0 siblings, 0 replies; 6+ messages in thread
From: Keir Fraser @ 2006-01-14 15:05 UTC (permalink / raw)
To: John Levon; +Cc: xen-devel
On 14 Jan 2006, at 11:43, John Levon wrote:
>> Improved guest backtraces belong in the xenctx utility
>> (tools/xentrace/xenctx.c).
>
> Aha, thanks. It's currently very Linux-specific, but I suppose
> we can improve that.
Yep, we'll be delighted to take patches that generalise and extend it.
-- Keir
^ 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.