Improve guest stack traces
PATCH 1/1 Improve guest stack traces
# HG changeset patch
# User [email protected]
# 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.
xen/arch/x86/traps.c +76 -19
@@ -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
Quoted 6 lines · John Levon
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 <[email protected]>
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
Quoted 1 line · Keir Fraser
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.
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
Quoted 19 lines · Keir Fraser
Quoted 6 lines · John Levon
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 <[email protected]>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.
Quoted 8 lines
-- Keir
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 2 lines · Keir Fraser
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
Quoted 5 lines · John Levon
Quoted 2 lines
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