mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2026-08-21 13:23:02 +00:00
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>
This commit is contained in:
+2
-3
@@ -9,12 +9,11 @@ noinst_LTLIBRARIES = libintel_tools.la
|
||||
noinst_HEADERS = check-ndebug.h
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)
|
||||
AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
|
||||
AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) $(LIBUNWIND_CFLAGS) \
|
||||
-DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
|
||||
-DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\" \
|
||||
-pthread
|
||||
|
||||
|
||||
LDADD = $(CAIRO_LIBS)
|
||||
LDADD = $(CAIRO_LIBS) $(LIBUNWIND_LIBS)
|
||||
AM_CFLAGS += $(CAIRO_CFLAGS)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user