[tip:perf/urgent] perf ui/tui: Print backtrace symbols when segfault occurs

From: tip-bot for Namhyung Kim
Date: Thu Jan 01 2015 - 16:29:42 EST


Commit-ID: b11bc8e28f4829f693ef6c0178fe1811386ac828
Gitweb: http://git.kernel.org/tip/b11bc8e28f4829f693ef6c0178fe1811386ac828
Author: Namhyung Kim <namhyung@xxxxxxxxxx>
AuthorDate: Mon, 22 Dec 2014 13:44:11 +0900
Committer: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
CommitDate: Tue, 23 Dec 2014 12:05:59 -0300

perf ui/tui: Print backtrace symbols when segfault occurs

The output will look like below. (I added an error into ui__init() for
the test).

$ perf report
perf: Segmentation fault
-------- backtrace --------
perf[0x503781]
/usr/lib/libc.so.6(+0x33b20)[0x7f1a14f04b20]
perf(ui__init+0xd5)[0x503645]
perf(setup_browser+0x97)[0x4ce4e7]
perf(cmd_report+0xcea)[0x4392ba]
perf[0x428493]
perf(main+0x60a)[0x427c0a]
/usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7f1a14ef1040]
perf[0x427d29]
[0x0]

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Link: http://lkml.kernel.org/r/1419223455-4362-4-git-send-email-namhyung@xxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/ui/tui/setup.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index 2f61256..3c38f25 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -1,5 +1,8 @@
#include <signal.h>
#include <stdbool.h>
+#ifdef HAVE_BACKTRACE_SUPPORT
+#include <execinfo.h>
+#endif

#include "../../util/cache.h"
#include "../../util/debug.h"
@@ -88,6 +91,25 @@ int ui__getch(int delay_secs)
return SLkp_getkey();
}

+#ifdef HAVE_BACKTRACE_SUPPORT
+static void ui__signal_backtrace(int sig)
+{
+ void *stackdump[32];
+ size_t size;
+
+ ui__exit(false);
+ psignal(sig, "perf");
+
+ printf("-------- backtrace --------\n");
+ size = backtrace(stackdump, ARRAY_SIZE(stackdump));
+ backtrace_symbols_fd(stackdump, size, STDOUT_FILENO);
+
+ exit(0);
+}
+#else
+# define ui__signal_backtrace ui__signal
+#endif
+
static void ui__signal(int sig)
{
ui__exit(false);
@@ -122,8 +144,8 @@ int ui__init(void)
ui_browser__init();
tui_progress__init();

- signal(SIGSEGV, ui__signal);
- signal(SIGFPE, ui__signal);
+ signal(SIGSEGV, ui__signal_backtrace);
+ signal(SIGFPE, ui__signal_backtrace);
signal(SIGINT, ui__signal);
signal(SIGQUIT, ui__signal);
signal(SIGTERM, ui__signal);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/