mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
libspl/assert: use libunwind for backtrace when available
libunwind seems to do a better job of resolving a symbols than backtrace(), and is also useful on platforms that don't have backtrace() (eg musl). If it's available, use it. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <robn@despairlabs.com> Sponsored-by: https://despairlabs.com/sponsor/ Closes #16140
This commit is contained in:
committed by
Brian Behlendorf
parent
2152c405ba
commit
051460b8b2
@@ -1,6 +1,6 @@
|
||||
include $(srcdir)/%D%/include/Makefile.am
|
||||
|
||||
libspl_assert_la_CFLAGS = $(AM_CFLAGS) $(LIBRARY_CFLAGS)
|
||||
libspl_assert_la_CFLAGS = $(AM_CFLAGS) $(LIBRARY_CFLAGS) $(LIBUNWIND_CFLAGS)
|
||||
libspl_la_CFLAGS = $(libspl_assert_la_CFLAGS)
|
||||
|
||||
noinst_LTLIBRARIES += libspl_assert.la libspl.la
|
||||
@@ -44,4 +44,4 @@ libspl_la_LIBADD = \
|
||||
|
||||
libspl_la_LIBADD += $(LIBATOMIC_LIBS) $(LIBCLOCK_GETTIME)
|
||||
|
||||
libspl_assert_la_LIBADD = $(BACKTRACE_LIBS)
|
||||
libspl_assert_la_LIBADD = $(BACKTRACE_LIBS) $(LIBUNWIND_LIBS)
|
||||
|
||||
+32
-1
@@ -49,7 +49,38 @@
|
||||
pthread_getname_np(pthread_self(), buf, len);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_BACKTRACE)
|
||||
#if defined(HAVE_LIBUNWIND)
|
||||
#define UNW_LOCAL_ONLY
|
||||
#include <libunwind.h>
|
||||
|
||||
static inline void
|
||||
libspl_dump_backtrace(void)
|
||||
{
|
||||
unw_context_t uc;
|
||||
unw_cursor_t cp;
|
||||
unw_word_t ip, off;
|
||||
char funcname[128];
|
||||
#ifdef HAVE_LIBUNWIND_ELF
|
||||
char objname[128];
|
||||
unw_word_t objoff;
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "Call trace:\n");
|
||||
unw_getcontext(&uc);
|
||||
unw_init_local(&cp, &uc);
|
||||
while (unw_step(&cp) > 0) {
|
||||
unw_get_reg(&cp, UNW_REG_IP, &ip);
|
||||
unw_get_proc_name(&cp, funcname, sizeof (funcname), &off);
|
||||
#ifdef HAVE_LIBUNWIND_ELF
|
||||
unw_get_elf_filename(&cp, objname, sizeof (objname), &objoff);
|
||||
fprintf(stderr, " [0x%08lx] %s+0x%2lx (in %s +0x%2lx)\n",
|
||||
ip, funcname, off, objname, objoff);
|
||||
#else
|
||||
fprintf(stderr, " [0x%08lx] %s+0x%2lx\n", ip, funcname, off);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_BACKTRACE)
|
||||
#include <execinfo.h>
|
||||
|
||||
static inline void
|
||||
|
||||
Reference in New Issue
Block a user