summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2021-01-22 14:12:27 +0100
committerWilly Tarreau <w@1wt.eu>2021-01-22 14:15:36 +0100
commita8459b28c32c95898916c073b5ffb616eb86862f (patch)
treec43861660f91b584407eb4aa2577deff7925e7d2
parent123fc9786a570187e8221f7f359b39b03667a14c (diff)
downloadhaproxy-a8459b28c32c95898916c073b5ffb616eb86862f.tar.gz
MINOR: debug: create ha_backtrace_to_stderr() to dump an instant backtrace
This function calls the ha_dump_backtrace() function with a locally allocated buffer and sends the output slightly indented to fd #2. It's meant to be used as an emergency backtrace dump.
-rw-r--r--include/haproxy/debug.h1
-rw-r--r--src/debug.c19
2 files changed, 17 insertions, 3 deletions
diff --git a/include/haproxy/debug.h b/include/haproxy/debug.h
index 12456b5f5..5cec24326 100644
--- a/include/haproxy/debug.h
+++ b/include/haproxy/debug.h
@@ -29,6 +29,7 @@ extern unsigned int debug_commands_issued;
void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx);
void ha_thread_dump(struct buffer *buf, int thr, int calling_tid);
void ha_dump_backtrace(struct buffer *buf, const char *prefix);
+void ha_backtrace_to_stderr();
void ha_thread_dump_all_to_trash();
void ha_panic();
diff --git a/src/debug.c b/src/debug.c
index 465def264..2a5e164c6 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -91,9 +91,10 @@ void ha_dump_backtrace(struct buffer *buf, const char *prefix)
addr = resolve_sym_name(buf, ": ", callers[j]);
if (dump == 0) {
/* dump not started, will start *after*
- * ha_thread_dump_all_to_trash and ha_panic
+ * ha_thread_dump_all_to_trash, ha_panic and ha_backtrace_to_stderr
*/
- if (addr == ha_thread_dump_all_to_trash || addr == ha_panic)
+ if (addr == ha_thread_dump_all_to_trash || addr == ha_panic ||
+ addr == ha_backtrace_to_stderr)
dump = 1;
*buf = bak;
continue;
@@ -101,7 +102,8 @@ void ha_dump_backtrace(struct buffer *buf, const char *prefix)
if (dump == 1) {
/* starting */
- if (addr == ha_thread_dump_all_to_trash || addr == ha_panic) {
+ if (addr == ha_thread_dump_all_to_trash || addr == ha_panic ||
+ addr == ha_backtrace_to_stderr) {
*buf = bak;
continue;
}
@@ -121,6 +123,17 @@ void ha_dump_backtrace(struct buffer *buf, const char *prefix)
}
}
+/* dump a backtrace of current thread's stack to stderr. */
+void ha_backtrace_to_stderr()
+{
+ char area[2048];
+ struct buffer b = b_make(area, sizeof(area), 0, 0);
+
+ ha_dump_backtrace(&b, " ");
+ if (b.data)
+ write(2, b.area, b.data);
+}
+
/* Dumps to the buffer some known information for the desired thread, and
* optionally extra info for the current thread. The dump will be appended to
* the buffer, so the caller is responsible for preliminary initializing it.