MINOR: debug: always export the my_backtrace function
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.
diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h
index 76e6e73..5be00b7 100644
--- a/include/haproxy/tools.h
+++ b/include/haproxy/tools.h
@@ -993,13 +993,14 @@
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 @@
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 460ee4d..3202814 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -100,7 +100,6 @@
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 @@
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 @@
chunk_appendf(buf, "\n");
}
}
-#endif
}
@@ -1094,15 +1092,13 @@
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);