summaryrefslogtreecommitdiff
path: root/lib/igt_core.c
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2015-03-13 17:02:12 +0000
committerThomas Wood <thomas.wood@intel.com>2015-03-26 15:50:05 +0000
commit277ca2b992c766581ef6ef01ea210808f456fbe0 (patch)
treed5002e6dba2c2e5287e4eac9c918ba40a096ed63 /lib/igt_core.c
parent2659cbbf643f2fdbf2f9acf8008edd4c6980cd2f (diff)
lib: print a stack trace when a test assertion fails
Add an optional dependency on libunwind to print stack traces when a test assertion fails. Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib/igt_core.c')
-rw-r--r--lib/igt_core.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 7c68d4eb..4cc040f5 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -962,6 +962,33 @@ static bool run_under_gdb(void)
strncmp(basename(buf), "gdb", 3) == 0);
}
+#ifdef HAVE_LIBUNWIND
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+
+static void print_backtrace(void)
+{
+ unw_cursor_t cursor;
+ unw_context_t uc;
+ int stack_num = 0;
+
+ printf("Stack trace:\n");
+
+ unw_getcontext(&uc);
+ unw_init_local(&cursor, &uc);
+ while (unw_step(&cursor) > 0) {
+ char name[255];
+ unw_word_t off;
+
+ if (unw_get_proc_name(&cursor, name, 255, &off) < 0)
+ strcpy(name, "<unknown>");
+
+ printf(" #%d [%s+0x%x]\n", stack_num++, name,
+ (unsigned int) off);
+ }
+}
+#endif
+
void __igt_fail_assert(int exitcode, const char *domain, const char *file,
const int line, const char *func, const char *assertion,
const char *f, ...)
@@ -983,6 +1010,10 @@ void __igt_fail_assert(int exitcode, const char *domain, const char *file,
va_end(args);
}
+#ifdef HAVE_LIBUNWIND
+ print_backtrace();
+#endif
+
if (run_under_gdb())
abort();
igt_fail(exitcode);