From e7b451941b92e2bdbb9c08bb4283c9a39d5571c6 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Fri, 10 May 2024 10:19:48 +1000 Subject: [PATCH] zdb/ztest: use libspl backtrace for crashes We can show much nicer backtraces these days, lets use them. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf Signed-off-by: Rob Norris Closes #16181 --- cmd/zdb/zdb.c | 12 +----------- cmd/ztest.c | 12 +----------- lib/libspl/assert.c | 9 ++++++--- lib/libspl/include/assert.h | 2 ++ 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index f3274a65db..908e4e0ab2 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -85,9 +85,6 @@ #include #include #include -#if (__GLIBC__ && !__UCLIBC__) -#include /* for backtrace() */ -#endif #include #include @@ -843,18 +840,11 @@ dump_debug_buffer(void) zfs_dbgmsg_print("zdb"); } -#define BACKTRACE_SZ 100 - static void sig_handler(int signo) { struct sigaction action; -#if (__GLIBC__ && !__UCLIBC__) /* backtrace() is a GNU extension */ - int nptrs; - void *buffer[BACKTRACE_SZ]; - nptrs = backtrace(buffer, BACKTRACE_SZ); - backtrace_symbols_fd(buffer, nptrs, STDERR_FILENO); -#endif + libspl_dump_backtrace(); dump_debug_buffer(); /* diff --git a/cmd/ztest.c b/cmd/ztest.c index 56eb01618c..ccfe71c295 100644 --- a/cmd/ztest.c +++ b/cmd/ztest.c @@ -136,9 +136,6 @@ #include #include #include -#if (__GLIBC__ && !__UCLIBC__) -#include /* for backtrace() */ -#endif static int ztest_fd_data = -1; static int ztest_fd_rand = -1; @@ -621,18 +618,11 @@ dump_debug_buffer(void) zfs_dbgmsg_print("ztest"); } -#define BACKTRACE_SZ 100 - static void sig_handler(int signo) { struct sigaction action; -#if (__GLIBC__ && !__UCLIBC__) /* backtrace() is a GNU extension */ - int nptrs; - void *buffer[BACKTRACE_SZ]; - nptrs = backtrace(buffer, BACKTRACE_SZ); - backtrace_symbols_fd(buffer, nptrs, STDERR_FILENO); -#endif + libspl_dump_backtrace(); dump_debug_buffer(); /* diff --git a/lib/libspl/assert.c b/lib/libspl/assert.c index 5b12c14acd..79b640d895 100644 --- a/lib/libspl/assert.c +++ b/lib/libspl/assert.c @@ -55,7 +55,7 @@ #define UNW_LOCAL_ONLY #include -static inline void +void libspl_dump_backtrace(void) { unw_context_t uc; @@ -85,7 +85,7 @@ libspl_dump_backtrace(void) #elif defined(HAVE_BACKTRACE) #include -static inline void +void libspl_dump_backtrace(void) { void *btptrs[100]; @@ -97,7 +97,10 @@ libspl_dump_backtrace(void) free(bt); } #else -#define libspl_dump_backtrace() +void +libspl_dump_backtrace(void) +{ +} #endif #if defined(__APPLE__) diff --git a/lib/libspl/include/assert.h b/lib/libspl/include/assert.h index 155bbab302..126f2db241 100644 --- a/lib/libspl/include/assert.h +++ b/lib/libspl/include/assert.h @@ -60,6 +60,8 @@ libspl_assert(const char *buf, const char *file, const char *func, int line) return (0); } +extern void libspl_dump_backtrace(void); + #ifdef verify #undef verify #endif