summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2021-01-22 12:12:29 +0100
committerWilly Tarreau <w@1wt.eu>2021-01-22 12:12:29 +0100
commit2f1227eb3f1c7f08d9c0dbecc426c3960e98c867 (patch)
tree0b984682bfc150abb469f7773f13aab7934bc23b
parent3d4631fec626c5aa8f12582ee3713563b5e38519 (diff)
downloadhaproxy-2f1227eb3f1c7f08d9c0dbecc426c3960e98c867.tar.gz
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.
-rw-r--r--include/haproxy/tools.h6
-rw-r--r--src/debug.c8
2 files changed, 5 insertions, 9 deletions
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);