]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Split the backtrace function
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 13 May 2024 18:52:27 +0000 (12:52 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 13 May 2024 18:54:16 +0000 (12:54 -0600)
src/lib/util/debug.c
src/lib/util/debug.h

index 8aed7962e2cebe1b77eba14d57eff598e95319e5..8179f79f37ddb529de20fd45c05345930bc2d6e1 100644 (file)
@@ -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') {
index b17c91913d8f6f27cc1d30e38af1032f4544b0d7..a40c7321e60653f7fc201b7bdc5a33447a49f64a 100644 (file)
@@ -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);