diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 76e6e730c..5be00b7fc 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -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) diff --git a/src/debug.c b/src/debug.c index 460ee4d3c..320281473 100644 --- a/src/debug.c +++ b/src/debug.c @@ -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);