|
@@ -8,7 +8,9 @@
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
#include <api/debug.h>
|
|
#include <api/debug.h>
|
|
#include <linux/time64.h>
|
|
#include <linux/time64.h>
|
|
-
|
|
|
|
|
|
+#ifdef HAVE_BACKTRACE_SUPPORT
|
|
|
|
+#include <execinfo.h>
|
|
|
|
+#endif
|
|
#include "cache.h"
|
|
#include "cache.h"
|
|
#include "color.h"
|
|
#include "color.h"
|
|
#include "event.h"
|
|
#include "event.h"
|
|
@@ -248,3 +250,31 @@ void perf_debug_setup(void)
|
|
{
|
|
{
|
|
libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper);
|
|
libapi_set_print(pr_warning_wrapper, pr_warning_wrapper, pr_debug_wrapper);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/* Obtain a backtrace and print it to stdout. */
|
|
|
|
+#ifdef HAVE_BACKTRACE_SUPPORT
|
|
|
|
+void dump_stack(void)
|
|
|
|
+{
|
|
|
|
+ void *array[16];
|
|
|
|
+ size_t size = backtrace(array, ARRAY_SIZE(array));
|
|
|
|
+ char **strings = backtrace_symbols(array, size);
|
|
|
|
+ size_t i;
|
|
|
|
+
|
|
|
|
+ printf("Obtained %zd stack frames.\n", size);
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < size; i++)
|
|
|
|
+ printf("%s\n", strings[i]);
|
|
|
|
+
|
|
|
|
+ free(strings);
|
|
|
|
+}
|
|
|
|
+#else
|
|
|
|
+void dump_stack(void) {}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+void sighandler_dump_stack(int sig)
|
|
|
|
+{
|
|
|
|
+ psignal(sig, "perf");
|
|
|
|
+ dump_stack();
|
|
|
|
+ signal(sig, SIG_DFL);
|
|
|
|
+ raise(sig);
|
|
|
|
+}
|