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.
diff --git a/src/debug.c b/src/debug.c
index 465def2..2a5e164 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -91,9 +91,10 @@
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 @@
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 @@
}
}
+/* 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.