]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: deduplicate __ABORT_NOW() between DEBUG_USE_ABORT and ha_crash_now()
authorWilly Tarreau <w@1wt.eu>
Mon, 10 Aug 2026 14:31:14 +0000 (16:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Aug 2026 15:43:30 +0000 (17:43 +0200)
The __ABORT_NOW() macro is defined for the two modes with a single,
insignificant difference, which is how to crash. Given that there's
already an #ifdef for the abort case, better make that macro point
to ha_crash_now() for the default case and eliminate one of the
definitions. This code is sufficiently difficult to read to avoid this.

include/haproxy/bug.h

index 0353a7db6b8550f1682fc8793af828fa35a6dc65..7ac643e75b8c95b8698d4aead210851023b42e6f 100644 (file)
@@ -269,24 +269,15 @@ static __attribute__((noinline,noreturn,unused)) void abort_with_line(uint line)
        abort();
 }
 
-#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)));                   \
-               abort_with_line(__LINE__);                              \
-       } while (0)
 #else
+
 /* More efficient than abort() because it does not mangle the
  * stack and stops at the exact location we need.
  */
+#define abort_with_line(...) ha_crash_now()
+
+#endif
+
 #define __ABORT_NOW(file, line, ...) do {                              \
                extern ssize_t write(int, const void *, size_t);        \
                extern size_t strlen(const char *s);                    \
@@ -299,9 +290,8 @@ static __attribute__((noinline,noreturn,unused)) void abort_with_line(uint line)
                      "      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_crash_now();                                         \
+               abort_with_line(__LINE__);                              \
        } while (0)
-#endif
 
 #if !defined(USE_OBSOLETE_LINKER)