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

Kamil Konieczny kamil.konieczny at linux.intel.com
Wed May 21 16:44:39 UTC 2025


Hi Jeevaka,
On 2025-05-19 at 15:11:30 +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.
> 
> As xputch, xpow, printnum, xstrlcpy, xprintfmt, xprintf are used
> by backtrace functions, enabled those only if HAVE_LIBUNWIND is defined.
> 
> Signed-off-by: Jeevaka Prabu Badrappan <jeevaka.badrappan at intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>

I will merge this and also few others:

lib/igt_device_scan: Replace rindex with strrchr
lib/igt_core: Add a dummy workaround when libunwind is not present
lib/igt_core: Conditionally define __noreturn
tools/intel_gpu_top: Replace index with strchr
tools/gputop: find program name from command line

Regards,
Kamil

> ---
>  lib/igt_core.c | 13 +++++++++++++
>  meson.build    |  3 +++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 2cea47214..679683958 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)))
> @@ -2082,6 +2088,7 @@ static void write_stderr(const char *str)
>  	__write_stderr(str, strlen(str));
>  }
>  
> +#ifdef HAVE_LIBUNWIND
>  static const char hex[] = "0123456789abcdef";
>  
>  static void
> @@ -2234,9 +2241,14 @@ xprintf(const char *fmt, ...)
>  	xprintfmt(fmt, ap);
>  	va_end(ap);
>  }
> +#endif /* HAVE_LIBUNWIND */
>  
>  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 +2268,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