[PATCH i-g-t v8 09/14] lib/igt_core: Add a dummy workaround when libunwind is not present

Jeevaka Prabu Badrappan jeevaka.badrappan at intel.com
Fri May 16 18:26:59 UTC 2025


If HAVE_LIBUNWIND is not defined, print a log message indicating
"backtrace not implemented" in the print_backtrace* functions and
return.

Signed-off-by: Jeevaka Prabu Badrappan <jeevaka.badrappan at intel.com>
---
 lib/igt_core.c | 11 +++++++++++
 meson.build    |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/lib/igt_core.c b/lib/igt_core.c
index 2cea47214..9d1d0fbd5 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -86,7 +86,9 @@
 #include "runnercomms.h"
 
 #define UNW_LOCAL_ONLY
+#ifdef HAVE_LIBUNWIND
 #include <libunwind.h>
+#endif
 #include <elfutils/libdwfl.h>
 
 #ifdef HAVE_LIBGEN_H
@@ -379,6 +381,9 @@ static int _igt_dynamic_tests_executed = -1;
 
 static void print_backtrace(void)
 {
+#ifndef HAVE_LIBUNWIND
+	igt_info("backtrace not implemented\n");
+#else
 	unw_cursor_t cursor;
 	unw_context_t uc;
 	int stack_num = 0;
@@ -436,6 +441,7 @@ static void print_backtrace(void)
 
 	if (dwfl)
 		dwfl_end(dwfl);
+#endif
 }
 
 __attribute__((format(printf, 2, 3)))
@@ -2237,6 +2243,10 @@ xprintf(const char *fmt, ...)
 
 static void print_backtrace_sig_safe(void)
 {
+
+#ifndef HAVE_LIBUNWIND
+	igt_info("backtrace not implemented\n");
+#else
 	unw_cursor_t cursor;
 	unw_context_t uc;
 	int stack_num = 0;
@@ -2256,6 +2266,7 @@ static void print_backtrace_sig_safe(void)
 				(unsigned int) off);
 
 	}
+#endif
 }
 
 void __igt_fail_assert(const char *domain, const char *file, const int line,
diff --git a/meson.build b/meson.build
index 6a580bd7e..b88098234 100644
--- a/meson.build
+++ b/meson.build
@@ -147,6 +147,9 @@ else
 endif
 
 libunwind = dependency('libunwind', required : get_option('libunwind'))
+if libunwind.found()
+	config.set('HAVE_LIBUNWIND', 1)
+endif
 build_info += 'With libunwind: @0@'.format(libunwind.found())
 
 libdw = dependency('libdw', required : true)
-- 
2.49.0



More information about the igt-dev mailing list