summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@kernel.org>2022-05-24 12:03:43 +0200
committerMauro Carvalho Chehab <mchehab@kernel.org>2022-05-25 15:52:17 +0200
commitcdbd3e9148ca9ac760dc7f80046e20e60289bc70 (patch)
tree8171efdb3080c777413a461b40d4d03a2fc7aa0b /lib
parentaa0c811ebcd27a0f330f60ae5c4aff35178d6abf (diff)
lib/igt_core: use print_backtrace() on internal_assert()
When internal_assert() hits, it is desired to know what part of the code actually hit the issue. Reviewed-by: Petri Latvala <petri.latvala@intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_core.c124
1 files changed, 63 insertions, 61 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c
index b7116f4e..e7425326 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -351,6 +351,67 @@ static bool stderr_needs_sentinel = false;
static int _igt_dynamic_tests_executed = -1;
+static void print_backtrace(void)
+{
+ unw_cursor_t cursor;
+ unw_context_t uc;
+ int stack_num = 0;
+
+ Dwfl_Callbacks cbs = {
+ .find_elf = dwfl_linux_proc_find_elf,
+ .find_debuginfo = dwfl_standard_find_debuginfo,
+ };
+
+ Dwfl *dwfl = dwfl_begin(&cbs);
+
+ if (dwfl_linux_proc_report(dwfl, getpid())) {
+ dwfl_end(dwfl);
+ dwfl = NULL;
+ } else
+ dwfl_report_end(dwfl, NULL, NULL);
+
+ igt_info("Stack trace:\n");
+
+ unw_getcontext(&uc);
+ unw_init_local(&cursor, &uc);
+ while (unw_step(&cursor) > 0) {
+ char name[255];
+ unw_word_t off, ip;
+ Dwfl_Module *mod = NULL;
+
+ unw_get_reg(&cursor, UNW_REG_IP, &ip);
+
+ if (dwfl)
+ mod = dwfl_addrmodule(dwfl, ip);
+
+ if (mod) {
+ const char *src, *dwfl_name;
+ Dwfl_Line *line;
+ int lineno;
+ GElf_Sym sym;
+
+ line = dwfl_module_getsrc(mod, ip);
+ dwfl_name = dwfl_module_addrsym(mod, ip, &sym, NULL);
+
+ if (line && dwfl_name) {
+ src = dwfl_lineinfo(line, NULL, &lineno, NULL, NULL, NULL);
+ igt_info(" #%d %s:%d %s()\n", stack_num++, src, lineno, dwfl_name);
+ continue;
+ }
+ }
+
+ if (unw_get_proc_name(&cursor, name, 255, &off) < 0)
+ igt_info(" #%d [<unknown>+0x%x]\n", stack_num++,
+ (unsigned int) ip);
+ else
+ igt_info(" #%d [%s+0x%x]\n", stack_num++, name,
+ (unsigned int) off);
+ }
+
+ if (dwfl)
+ dwfl_end(dwfl);
+}
+
__attribute__((format(printf, 2, 3)))
static void internal_assert(bool cond, const char *format, ...)
{
@@ -362,6 +423,8 @@ static void internal_assert(bool cond, const char *format, ...)
va_end(ap);
fprintf(stderr, "please refer to lib/igt_core documentation\n");
+ print_backtrace();
+
assert(0);
}
}
@@ -1766,67 +1829,6 @@ static void write_stderr(const char *str)
__write_stderr(str, strlen(str));
}
-static void print_backtrace(void)
-{
- unw_cursor_t cursor;
- unw_context_t uc;
- int stack_num = 0;
-
- Dwfl_Callbacks cbs = {
- .find_elf = dwfl_linux_proc_find_elf,
- .find_debuginfo = dwfl_standard_find_debuginfo,
- };
-
- Dwfl *dwfl = dwfl_begin(&cbs);
-
- if (dwfl_linux_proc_report(dwfl, getpid())) {
- dwfl_end(dwfl);
- dwfl = NULL;
- } else
- dwfl_report_end(dwfl, NULL, NULL);
-
- igt_info("Stack trace:\n");
-
- unw_getcontext(&uc);
- unw_init_local(&cursor, &uc);
- while (unw_step(&cursor) > 0) {
- char name[255];
- unw_word_t off, ip;
- Dwfl_Module *mod = NULL;
-
- unw_get_reg(&cursor, UNW_REG_IP, &ip);
-
- if (dwfl)
- mod = dwfl_addrmodule(dwfl, ip);
-
- if (mod) {
- const char *src, *dwfl_name;
- Dwfl_Line *line;
- int lineno;
- GElf_Sym sym;
-
- line = dwfl_module_getsrc(mod, ip);
- dwfl_name = dwfl_module_addrsym(mod, ip, &sym, NULL);
-
- if (line && dwfl_name) {
- src = dwfl_lineinfo(line, NULL, &lineno, NULL, NULL, NULL);
- igt_info(" #%d %s:%d %s()\n", stack_num++, src, lineno, dwfl_name);
- continue;
- }
- }
-
- if (unw_get_proc_name(&cursor, name, 255, &off) < 0)
- igt_info(" #%d [<unknown>+0x%x]\n", stack_num++,
- (unsigned int) ip);
- else
- igt_info(" #%d [%s+0x%x]\n", stack_num++, name,
- (unsigned int) off);
- }
-
- if (dwfl)
- dwfl_end(dwfl);
-}
-
static const char hex[] = "0123456789abcdef";
static void