Commit b11bc8e2 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

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: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1419223455-4362-4-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 740b97f9
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
#ifdef HAVE_BACKTRACE_SUPPORT
#include <execinfo.h>
#endif
#include "../../util/cache.h" #include "../../util/cache.h"
#include "../../util/debug.h" #include "../../util/debug.h"
...@@ -88,6 +91,25 @@ int ui__getch(int delay_secs) ...@@ -88,6 +91,25 @@ int ui__getch(int delay_secs)
return SLkp_getkey(); 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) static void ui__signal(int sig)
{ {
ui__exit(false); ui__exit(false);
...@@ -122,8 +144,8 @@ int ui__init(void) ...@@ -122,8 +144,8 @@ int ui__init(void)
ui_browser__init(); ui_browser__init();
tui_progress__init(); tui_progress__init();
signal(SIGSEGV, ui__signal); signal(SIGSEGV, ui__signal_backtrace);
signal(SIGFPE, ui__signal); signal(SIGFPE, ui__signal_backtrace);
signal(SIGINT, ui__signal); signal(SIGINT, ui__signal);
signal(SIGQUIT, ui__signal); signal(SIGQUIT, ui__signal);
signal(SIGTERM, ui__signal); signal(SIGTERM, ui__signal);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment