From: Willy Tarreau Date: Wed, 5 Aug 2026 14:22:40 +0000 (+0200) Subject: MINOR: debug: move printing of the hint to ha_backtrace_to_stderr() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acbf369e678d5fdc83a7f3bd1630c4fa9f7552d2;p=thirdparty%2Fhaproxy.git MINOR: debug: move printing of the hint to ha_backtrace_to_stderr() 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. --- diff --git a/include/haproxy/bug.h b/include/haproxy/bug.h index 7ac643e75..c61693800 100644 --- a/include/haproxy/bug.h +++ b/include/haproxy/bug.h @@ -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) diff --git a/src/debug.c b/src/debug.c index 26b442a14..faf98110c 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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,