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

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Mon May 19 07:38:08 UTC 2025


On Fri, May 16, 2025 at 06:26:59PM +0000, Jeevaka Prabu Badrappan wrote:
> 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

With libunwind-dev package not installed there're warnings:

[234/1981] Compiling C object lib/libigt-igt_core_c.a.p/igt_core.c.o
../lib/igt_core.c:2235:1: warning: ‘xprintf’ defined but not used [-Wunused-function]
 2235 | xprintf(const char *fmt, ...)
      | ^~~~~~~
../lib/igt_core.c:2130:1: warning: ‘xstrlcpy’ defined but not used [-Wunused-function]
 2130 | xstrlcpy(char *dst, const char *src, size_t size)
      | ^~~~~~~~

--
Zbigniew

>  }
>  
>  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