Skip to content

Commit

Permalink
zdb/ztest: use libspl backtrace for crashes
Browse files Browse the repository at this point in the history
We can show much nicer backtraces these days, lets use them.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Rob Norris <[email protected]>
Closes openzfs#16181
  • Loading branch information
robn authored and behlendorf committed May 14, 2024
1 parent 91c46d4 commit e7b4519
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
12 changes: 1 addition & 11 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
#include <sys/brt_impl.h>
#include <zfs_comutil.h>
#include <sys/zstd/zstd.h>
#if (__GLIBC__ && !__UCLIBC__)
#include <execinfo.h> /* for backtrace() */
#endif

#include <libnvpair.h>
#include <libzutil.h>
Expand Down Expand Up @@ -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();

/*
Expand Down
12 changes: 1 addition & 11 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@
#include <libzutil.h>
#include <sys/crypto/icp.h>
#include <sys/zfs_impl.h>
#if (__GLIBC__ && !__UCLIBC__)
#include <execinfo.h> /* for backtrace() */
#endif

static int ztest_fd_data = -1;
static int ztest_fd_rand = -1;
Expand Down Expand Up @@ -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();

/*
Expand Down
9 changes: 6 additions & 3 deletions lib/libspl/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#define UNW_LOCAL_ONLY
#include <libunwind.h>

static inline void
void
libspl_dump_backtrace(void)
{
unw_context_t uc;
Expand Down Expand Up @@ -85,7 +85,7 @@ libspl_dump_backtrace(void)
#elif defined(HAVE_BACKTRACE)
#include <execinfo.h>

static inline void
void
libspl_dump_backtrace(void)
{
void *btptrs[100];
Expand All @@ -97,7 +97,10 @@ libspl_dump_backtrace(void)
free(bt);
}
#else
#define libspl_dump_backtrace()
void
libspl_dump_backtrace(void)
{
}
#endif

#if defined(__APPLE__)
Expand Down
2 changes: 2 additions & 0 deletions lib/libspl/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7b4519

Please sign in to comment.