backtrace: Print backtrace in assert() and panic()
authorAntonio Nino Diaz <[email protected]>
Thu, 23 Aug 2018 14:13:58 +0000 (15:13 +0100)
committerAntonio Nino Diaz <[email protected]>
Thu, 30 Aug 2018 08:21:53 +0000 (09:21 +0100)
When any of these functions is called the backtrace will be printed to
the console.

Change-Id: Id60842df824b320c485a9323ed6b80600f4ebe35
Signed-off-by: Antonio Nino Diaz <[email protected]>
include/common/debug.h
lib/libc/assert.c

index ee25af12047ecc0233a7be7e27b3e3d08d710b55..ab3e15a73dff427f4ed32088a128931abfc1095b 100644 (file)
@@ -27,7 +27,9 @@
 
 #ifndef __ASSEMBLY__
 #include <cdefs.h>
+#include <console.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 
 /*
@@ -90,7 +92,13 @@ void backtrace(const char *cookie);
 #endif
 
 void __dead2 do_panic(void);
-#define panic()        do_panic()
+
+#define panic()                                \
+       do {                            \
+               backtrace(__func__);    \
+               (void)console_flush();  \
+               do_panic();             \
+       } while (false)
 
 /* Function called when stack protection check code detects a corrupted stack */
 void __dead2 __stack_chk_fail(void);
index fa12cb6b0d5676ab4261f50ea4c3fb798328fa19..8fa8f72123652e35c1f1100ad866d93859098c19 100644 (file)
 void __assert(const char *file, unsigned int line, const char *assertion)
 {
        printf("ASSERT: %s:%d:%s\n", file, line, assertion);
-       console_flush();
+       backtrace("assert");
+       (void)console_flush();
        plat_panic_handler();
 }
 #elif PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO
 void __assert(const char *file, unsigned int line)
 {
        printf("ASSERT: %s:%d\n", file, line);
-       console_flush();
+       backtrace("assert");
+       (void)console_flush();
        plat_panic_handler();
 }
 #else
 void __assert(void)
 {
+       backtrace("assert");
+       (void)console_flush();
        plat_panic_handler();
 }
 #endif