lib: debug: add dump frame info in panic

Dump frame info when panic occurs.

Change-Id: I7332a9dcb31c842ff549e806a1a3acc598ce4681
diff --git a/lib/debug/debug.c b/lib/debug/debug.c
index 84d0678..f239bbe 100644
--- a/lib/debug/debug.c
+++ b/lib/debug/debug.c
@@ -35,6 +35,9 @@
 #include <kernel/thread.h>
 #include <kernel/timer.h>
 #include <rand.h>
+#if ARCH_ARM
+#include <arch/arm.h>
+#endif
 
 void __attribute__ ((noreturn))
 __stack_chk_fail (void)
@@ -56,8 +59,19 @@
 	platform_halt();
 }
 
+void dump_frame(void *frame)
+{
+	enter_critical_section(); // disable ints
+#if ARCH_ARM
+	dump_fault_frame((struct arm_fault_frame *)frame);
+#endif
+	exit_critical_section(); // disable ints
+}
+
 void _panic(void *caller, const char *fmt, ...)
 {
+	dprintf(ALWAYS, "panic (frame %p): \n", __GET_FRAME());
+	dump_frame(__GET_FRAME());
 	dprintf(ALWAYS, "panic (caller %p): ", caller);
 
 	va_list ap;