From: Arran Cudbard-Bell Date: Mon, 13 May 2024 18:52:27 +0000 (-0600) Subject: Split the backtrace function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cce72bb88f2a9f50f11f84da09dd8fcc45af42c;p=thirdparty%2Ffreeradius-server.git Split the backtrace function --- diff --git a/src/lib/util/debug.c b/src/lib/util/debug.c index 8aed7962e2c..8179f79f37d 100644 --- a/src/lib/util/debug.c +++ b/src/lib/util/debug.c @@ -939,6 +939,35 @@ static int fr_fault_check_permissions(void) return 0; } +/** Split out so it can be sprinkled throughout the server and called via a debugger + * + */ +void fr_fault_backtrace(void) +{ + + /* + * Produce a simple backtrace - They're very basic but at least give us an + * idea of the area of the code we hit the issue in. + * + * See below in fr_fault_setup() and + * https://sourceware.org/bugzilla/show_bug.cgi?id=16159 + * for why we only print backtraces in debug builds if we're using GLIBC. + */ +#if defined(HAVE_EXECINFO) && (!defined(NDEBUG) || !defined(__GNUC__)) + if (fr_fault_log_fd >= 0) { + size_t frame_count; + void *stack[MAX_BT_FRAMES]; + + frame_count = backtrace(stack, MAX_BT_FRAMES); + + FR_FAULT_LOG("Backtrace of last %zu frames:", frame_count); + + backtrace_symbols_fd(stack, frame_count, fr_fault_log_fd); + } +#endif + return; +} + /** Prints a simple backtrace (if execinfo is available) and calls panic_action if set. * * @param sig caught @@ -977,26 +1006,7 @@ NEVER_RETURNS void fr_fault(int sig) */ if (panic_cb && (panic_cb(sig) < 0)) goto finish; - /* - * Produce a simple backtrace - They're very basic but at least give us an - * idea of the area of the code we hit the issue in. - * - * See below in fr_fault_setup() and - * https://sourceware.org/bugzilla/show_bug.cgi?id=16159 - * for why we only print backtraces in debug builds if we're using GLIBC. - */ -#if defined(HAVE_EXECINFO) && (!defined(NDEBUG) || !defined(__GNUC__)) - if (fr_fault_log_fd >= 0) { - size_t frame_count; - void *stack[MAX_BT_FRAMES]; - - frame_count = backtrace(stack, MAX_BT_FRAMES); - - FR_FAULT_LOG("Backtrace of last %zu frames:", frame_count); - - backtrace_symbols_fd(stack, frame_count, fr_fault_log_fd); - } -#endif + fr_fault_backtrace(); /* No panic action set... */ if (panic_action[0] == '\0') { diff --git a/src/lib/util/debug.h b/src/lib/util/debug.h index b17c91913d8..a40c7321e60 100644 --- a/src/lib/util/debug.h +++ b/src/lib/util/debug.h @@ -89,6 +89,8 @@ int fr_reset_dumpable(void); int fr_log_talloc_report(TALLOC_CTX const *ctx); +void fr_fault_backtrace(void); + void fr_fault(int sig); void fr_talloc_fault_setup(void);