]> xenbits.xensource.com Git - people/liuw/xtf.git/commitdiff
Print more information when dumping exceptions
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 29 Apr 2016 12:08:20 +0000 (13:08 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 29 Apr 2016 13:25:38 +0000 (14:25 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/traps.c
include/arch/x86/lib.h

index 8906e4729729329a15c72daca8c9b412d797f4e4..a54f6726914ede0b8425e66dce0ac911ba19ae77 100644 (file)
@@ -2,6 +2,7 @@
 #include <xtf/traps.h>
 #include <xtf/exlog.h>
 
+#include <arch/x86/decode.h>
 #include <arch/x86/processor.h>
 
 bool (*xtf_unhandled_exception_hook)(struct cpu_regs *regs);
@@ -78,9 +79,29 @@ void do_exception(struct cpu_regs *regs)
     if ( !safe && xtf_unhandled_exception_hook )
         safe = xtf_unhandled_exception_hook(regs);
 
+    /* Still unresolved? Give up and panic() with some relevent information. */
     if ( !safe )
-        panic("Unhandled exception: vec %u at %04x:%p\n",
-              regs->entry_vector, regs->cs, _p(regs->ip));
+    {
+        char buf[16];
+
+        x86_exc_decode_ec(buf, ARRAY_SIZE(buf),
+                          regs->entry_vector, regs->error_code);
+
+        if ( regs->entry_vector == X86_EXC_PF )
+        {
+            unsigned long cr2 = read_cr2();
+
+            panic("Unhandled exception at %04x:%p\n"
+                  "Vec %u %s[%s] %%cr2 %p\n",
+                  regs->cs, _p(regs->ip), regs->entry_vector,
+                  x86_exc_short_name(regs->entry_vector), buf, _p(cr2));
+        }
+        else
+            panic("Unhandled exception at %04x:%p\n"
+                  "Vec %u %s[%s]\n",
+                  regs->cs, _p(regs->ip), regs->entry_vector,
+                  x86_exc_short_name(regs->entry_vector), buf);
+    }
 }
 
 /*
index 67af0ddc84d75e503b7cd56baa1577df2994ca99..b1b2bf19a67ec0aba9b619232a942bd706040354 100644 (file)
@@ -195,6 +195,15 @@ static inline unsigned long read_dr7(void)
     return val;
 }
 
+static inline unsigned long read_cr2(void)
+{
+    unsigned long cr2;
+
+    asm volatile ("mov %%cr2, %0" : "=r" (cr2));
+
+    return cr2;
+}
+
 static inline unsigned long read_cr3(void)
 {
     unsigned long cr3;