From: "Jan Beulich" Subject: [PATCH] x86: slightly improve stack trace on debug builds Date: Tue, 25 Sep 2012 16:07:27 +0100 Message-ID: <5061E4CF020000780009DB98@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2E1F12BF.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part2E1F12BF.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline As was rather obvious from crashes recently happening in stage testing, the debug hypervisor, in that special case, has a drawback compared to the non-debug one: When a call through a bad pointer happens, there's no frame, and the top level (and frequently most important for analysis) stack entry would get skipped: (XEN) ----[ Xen-4.3-unstable x86_64 debug=3Dy Not tainted ]---- (XEN) CPU: 1 (XEN) RIP: e008:[<0000000000000000>] ??? (XEN) RFLAGS: 0000000000010046 CONTEXT: hypervisor (XEN) rax: 0000000000000008 rbx: 0000000000000001 rcx: 0000000000000003= (XEN) rdx: 0000003db54eb700 rsi: 7fffffffffffffff rdi: 0000000000000001= (XEN) rbp: ffff8302357e7ee0 rsp: ffff8302357e7e58 r8: 0000000000000000= (XEN) r9: 000000000000003e r10: ffff8302357e7f18 r11: ffff8302357e7f18= (XEN) r12: ffff8302357ee340 r13: ffff82c480263980 r14: ffff8302357ee3d0= (XEN) r15: 0000000000000001 cr0: 000000008005003b cr4: 00000000000026f0= (XEN) cr3: 00000000bf473000 cr2: 0000000000000000 (XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: 0000 cs: e008 (XEN) Xen stack trace from rsp=3Dffff8302357e7e58: (XEN) ffff82c4801a3d05 ffff8302357eca70 0000000800000020 ffff82c4802ead6= 0 (XEN) 0000000000000001 ffff8302357e7ea0 ffff82c48016bf07 000000000000000= 0 (XEN) 0000000000000000 ffff8302357e7ee0 fffff830fffff830 000000000000004= 6 (XEN) ffff8302357e7f18 ffff82c480263980 ffff8302357e7f18 000000000000000= 0 (XEN) 0000000000000000 ffff8302357e7f10 ffff82c48015c2be 8302357dc0000ff= f ... (XEN) Xen call trace: (XEN) [<0000000000000000>] ??? (XEN) [] idle_loop+0x6c/0x7a (XEN) =20 (XEN) Pagetable walk from 0000000000000000: Since the bad pointer is being printed anyway (as part of the register state), replace it with the top of stack value in such a case. Signed-off-by: Jan Beulich --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -217,8 +217,18 @@ static void show_trace(struct cpu_user_r =20 printk("Xen call trace:\n "); =20 - printk("[<%p>]", _p(regs->eip)); - print_symbol(" %s\n ", regs->eip); + addr =3D regs->eip; + while ( !is_kernel_text(addr) && + (system_state > SYS_STATE_boot || !is_kernel_inittext(addr)) = ) + { + /* Special case when a bad pointer was called. */ + addr ^=3D regs->eip ^ *ESP_BEFORE_EXCEPTION(regs); + if ( addr =3D=3D regs->eip ) + break; + } + + printk("[<%p>]", _p(addr)); + print_symbol(" %s\n ", addr); =20 /* Bounds for range of valid frame pointer. */ low =3D (unsigned long)(ESP_BEFORE_EXCEPTION(regs) - 2); --=__Part2E1F12BF.0__= Content-Type: text/plain; name="x86-debug-dump-TOS.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-debug-dump-TOS.patch" x86: slightly improve stack trace on debug builds=0A=0AAs was rather = obvious from crashes recently happening in stage testing,=0Athe debug = hypervisor, in that special case, has a drawback compared to=0Athe = non-debug one: When a call through a bad pointer happens, there's=0Ano = frame, and the top level (and frequently most important for=0Aanalysis) = stack entry would get skipped:=0A=0A(XEN) ----[ Xen-4.3-unstable x86_64 = debug=3Dy Not tainted ]----=0A(XEN) CPU: 1=0A(XEN) RIP: e008:[<00000= 00000000000>] ???=0A(XEN) RFLAGS: 0000000000010046 CONTEXT: hypervisor=0A= (XEN) rax: 0000000000000008 rbx: 0000000000000001 rcx: 0000000000000003= =0A(XEN) rdx: 0000003db54eb700 rsi: 7fffffffffffffff rdi: 0000000000000= 001=0A(XEN) rbp: ffff8302357e7ee0 rsp: ffff8302357e7e58 r8: 0000000000= 000000=0A(XEN) r9: 000000000000003e r10: ffff8302357e7f18 r11: = ffff8302357e7f18=0A(XEN) r12: ffff8302357ee340 r13: ffff82c480263980 = r14: ffff8302357ee3d0=0A(XEN) r15: 0000000000000001 cr0: 000000008005003b= cr4: 00000000000026f0=0A(XEN) cr3: 00000000bf473000 cr2: 0000000000000= 000=0A(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: 0000 cs: = e008=0A(XEN) Xen stack trace from rsp=3Dffff8302357e7e58:=0A(XEN) = ffff82c4801a3d05 ffff8302357eca70 0000000800000020 ffff82c4802ead60=0A(XEN)= 0000000000000001 ffff8302357e7ea0 ffff82c48016bf07 0000000000000000=0A(= XEN) 0000000000000000 ffff8302357e7ee0 fffff830fffff830 0000000000000046= =0A(XEN) ffff8302357e7f18 ffff82c480263980 ffff8302357e7f18 000000000000= 0000=0A(XEN) 0000000000000000 ffff8302357e7f10 ffff82c48015c2be = 8302357dc0000fff=0A...=0A(XEN) Xen call trace:=0A(XEN) [<000000000000000= 0>] ???=0A(XEN) [] idle_loop+0x6c/0x7a=0A(XEN) = =0A(XEN) Pagetable walk from 0000000000000000:=0A=0ASince the bad pointer = is being printed anyway (as part of the register=0Astate), replace it with = the top of stack value in such a case.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/tr= aps.c=0A@@ -217,8 +217,18 @@ static void show_trace(struct cpu_user_r=0A = =0A printk("Xen call trace:\n ");=0A =0A- printk("[<%p>]", = _p(regs->eip));=0A- print_symbol(" %s\n ", regs->eip);=0A+ addr = =3D regs->eip;=0A+ while ( !is_kernel_text(addr) &&=0A+ = (system_state > SYS_STATE_boot || !is_kernel_inittext(addr)) )=0A+ = {=0A+ /* Special case when a bad pointer was called. */=0A+ = addr ^=3D regs->eip ^ *ESP_BEFORE_EXCEPTION(regs);=0A+ if ( addr = =3D=3D regs->eip )=0A+ break;=0A+ }=0A+=0A+ printk("[<%p>]= ", _p(addr));=0A+ print_symbol(" %s\n ", addr);=0A =0A /* Bounds = for range of valid frame pointer. */=0A low =3D (unsigned long)(ESP_BE= FORE_EXCEPTION(regs) - 2);=0A --=__Part2E1F12BF.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part2E1F12BF.0__=--