summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Widawsky <ben@bwidawsk.net>2016-06-14 14:48:36 -0700
committerBen Widawsky <ben@bwidawsk.net>2016-06-14 14:48:36 -0700
commit1d552720afb0c936e4adb15a8aae995a5eadf002 (patch)
tree77e7db0074e6bb3671a476714ea6424513e2f641
parenta9ec77805b97072f630d64c386ce61564d1f9045 (diff)
-rw-r--r--src/util/debug.c26
-rw-r--r--src/util/debug.h8
2 files changed, 34 insertions, 0 deletions
diff --git a/src/util/debug.c b/src/util/debug.c
index 98b1853325..495b5310d0 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -76,3 +76,29 @@ env_var_as_boolean(const char *var_name, bool default_value)
return default_value;
}
}
+
+#ifdef HAVE_LIBUNWIND
+void
+show_backtrace(void)
+{
+ unw_context_t uc;
+ int stack_num = 0;
+
+ unw_getcontext(&uc);
+ unw_init_local(&cursor, &uc);
+
+ while (unw_step(&cursor) > 0) {
+ char func[256];
+ if (unw_get_proc_name(&cursor, func, 255, &off) < 0) {
+
+ unw_cursor_t cursor;
+ unw_word_t ip;
+
+ unw_get_reg(&cursor, UNW_REG_IP, &ip);
+ printf(" #%d [%s+0x%x]\n ip = %lx, sp = %lx\n", (long) ip );
+ } else {
+ printf(" #%d [%s+0x%x]\n", stack_num++, func, (unsigned int)off);
+ }
+ }
+}
+#endif
diff --git a/src/util/debug.h b/src/util/debug.h
index 11a8561eb5..cde0eb461d 100644
--- a/src/util/debug.h
+++ b/src/util/debug.h
@@ -42,6 +42,14 @@ parse_debug_string(const char *debug,
bool
env_var_as_boolean(const char *var_name, bool default_value);
+#ifdef HAVE_LIBUNWIND
+#define UNW_LOCAL_ONLY
+#include <libunwind.h>
+void show_backtrace(void);
+#else
+#define show_backtrace do { } while (0)
+#endif
+
#ifdef __cplusplus
} /* extern C */
#endif