]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: move printing of the hint to ha_backtrace_to_stderr()
authorWilly Tarreau <w@1wt.eu>
Wed, 5 Aug 2026 14:22:40 +0000 (16:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Aug 2026 15:43:30 +0000 (17:43 +0200)
The hint suggesting the user to contact developers with a core is only
emitted along with a backtrace sent to stderr, and it's currently
present as a macro in many call places. Let's move it to the function
and pass an argument to ask for it to be emitted (i.e. only upon crash
since a warning doesn't produce a core).

This reduces the binary size by 38 kB.

include/haproxy/bug.h
src/debug.c

index 7ac643e75b8c95b8698d4aead210851023b42e6f..c61693800943b355330038ca0d2c8dad13860440 100644 (file)
@@ -169,7 +169,7 @@ struct debug_count {
 
 /* report a bug on stderr */
 void complain(int *counter, const char *msg, int taint);
-void ha_backtrace_to_stderr(void);
+void ha_backtrace_to_stderr(int hint);
 
 /* Let's make DEBUG_STRESS equal to zero if not set or not valid, or to
  * 1 if set. This way it is always set and should be easy to use in "if ()"
@@ -279,17 +279,9 @@ static __attribute__((noinline,noreturn,unused)) void abort_with_line(uint line)
 #endif
 
 #define __ABORT_NOW(file, line, ...) do {                              \
-               extern ssize_t write(int, const void *, size_t);        \
-               extern size_t strlen(const char *s);                    \
-               const char *msg;                                        \
                if (sizeof("" __VA_ARGS__) > 1)                         \
                        complain(NULL, "\nABORT at " file ":" #line ": " __VA_ARGS__ "\n", 1); \
-               ha_backtrace_to_stderr();                               \
-               msg = "\n"                                              \
-                     "Hint: when reporting this bug to developers, please check if a core file was\n" \
-                     "      produced, open it with 'gdb', issue 'bt' to produce a backtrace for the\n" \
-                     "      current thread only, then join it with the bug report.\n"; \
-               DISGUISE(write(2, msg, strlen(msg)));                   \
+               ha_backtrace_to_stderr(1);                              \
                abort_with_line(__LINE__);                              \
        } while (0)
 
@@ -405,7 +397,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt  HA_SECTION_S
                if (crash & 1)                                          \
                        ABORT_NOW();                                    \
                else                                                    \
-                       ha_backtrace_to_stderr();                       \
+                       ha_backtrace_to_stderr(0);                      \
        } while (0)
 
 /* This one is equivalent except that it only emits the message once by
@@ -433,7 +425,7 @@ extern __attribute__((__weak__)) struct debug_count __stop_dbg_cnt  HA_SECTION_S
                if (crash & 1)                                          \
                        ABORT_NOW();                                    \
                else                                                    \
-                       ha_backtrace_to_stderr();                       \
+                       ha_backtrace_to_stderr(0);                      \
        } while (0)
 
 
index 26b442a145ddc1992ae5bf1b37a0ff935b249de9..faf98110cd015df72566abfb1fab500308e3f980 100644 (file)
@@ -289,15 +289,25 @@ void ha_dump_backtrace(struct buffer *buf, const char *prefix, int dump)
        ha_sigmask(SIG_SETMASK, &old_mask, NULL);
 }
 
-/* dump a backtrace of current thread's stack to stderr. */
-void ha_backtrace_to_stderr(void)
+/* dump a backtrace of current thread's stack to stderr. Displays the hint about
+ * the core if hint & 1.
+ */
+void ha_backtrace_to_stderr(int hint)
 {
        char area[8192];
        struct buffer b = b_make(area, sizeof(area), 0, 0);
+       const char *msg;
 
        ha_dump_backtrace(&b, "  ", 4);
        if (b.data)
                DISGUISE(write(2, b.area, b.data));
+       if (hint & 1) {
+               msg = "\n"
+                     "Hint: when reporting this bug to developers, please check if a core file was\n"
+                     "      produced, open it with 'gdb', issue 'bt' to produce a backtrace for the\n"
+                     "      current thread only, then join it with the bug report.\n";
+               DISGUISE(write(2, msg, strlen(msg)));
+       }
 }
 
 /* Dumps some known information about the current thread into its dump buffer,