]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: always export the my_backtrace function
authorWilly Tarreau <w@1wt.eu>
Fri, 22 Jan 2021 11:12:29 +0000 (12:12 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 22 Jan 2021 11:12:29 +0000 (12:12 +0100)
In order to simplify the code and remove annoying ifdefs everywhere,
let's always export my_backtrace() and make it adapt to the situation
and return zero if not supported. A small update in the thread dump
function was needed to make sure we don't use its results if it fails
now.

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

index 76e6e730c0eaa2710f0b96a144752e1fdd43b081..5be00b7fcb99f6fbf45758a48dc312bab05661db 100644 (file)
@@ -993,13 +993,14 @@ int may_access(const void *ptr);
 const void *resolve_sym_name(struct buffer *buf, const char *pfx, const void *addr);
 const char *get_exec_path();
 
-#if defined(USE_BACKTRACE)
 /* Note that this may result in opening libgcc() on first call, so it may need
  * to have been called once before chrooting.
  */
 static forceinline int my_backtrace(void **buffer, int max)
 {
-#ifdef HA_HAVE_WORKING_BACKTRACE
+#if !defined(USE_BACKTRACE)
+       return 0;
+#elif defined(HA_HAVE_WORKING_BACKTRACE)
        return backtrace(buffer, max);
 #else
        const struct frame {
@@ -1016,7 +1017,6 @@ static forceinline int my_backtrace(void **buffer, int max)
        return count;
 #endif
 }
-#endif
 
 /* same as realloc() except that ptr is also freed upon failure */
 static inline void *my_realloc2(void *ptr, size_t size)
index 460ee4d3c50f4a87498e0a2f7bcc688e34718884..3202814732180405cd7272116c22b723a585e0e3 100644 (file)
@@ -100,7 +100,6 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
        chunk_appendf(buf, "             curr_task=");
        ha_task_dump(buf, sched->current, "             ");
 
-#ifdef USE_BACKTRACE
        if (stuck) {
                /* We only emit the backtrace for stuck threads in order not to
                 * waste precious output buffer space with non-interesting data.
@@ -119,7 +118,7 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
                if (nptrs)
                        chunk_appendf(buf, "             call trace(%d):\n", nptrs);
 
-               for (j = 0; j < nptrs || dump < 2; j++) {
+               for (j = 0; nptrs && (j < nptrs || dump < 2); j++) {
                        if (j == nptrs && !dump) {
                                /* we failed to spot the starting point of the
                                 * dump, let's start over dumping everything we
@@ -162,7 +161,6 @@ void ha_thread_dump(struct buffer *buf, int thr, int calling_tid)
                        chunk_appendf(buf, "\n");
                }
        }
-#endif
 }
 
 
@@ -1094,15 +1092,13 @@ static int init_debug_per_thread()
 static int init_debug()
 {
        struct sigaction sa;
+       void *callers[1];
 
-#ifdef USE_BACKTRACE
        /* calling backtrace() will access libgcc at runtime. We don't want to
         * do it after the chroot, so let's perform a first call to have it
         * ready in memory for later use.
         */
-       void *callers[1];
        my_backtrace(callers, sizeof(callers)/sizeof(*callers));
-#endif
        sa.sa_handler = NULL;
        sa.sa_sigaction = debug_handler;
        sigemptyset(&sa.sa_mask);