Advertisement
danielhilst

Untitled

Sep 6th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. static struct sigaction oldsigact;
  2. static void armbacktrace_segv_handler(int sig, siginfo_t *info, void *ucontext)
  3. {
  4.         static bool busy = false;
  5.         if (busy) /* forbids concurrent call */
  6.                 return;
  7.         busy = true;
  8.         static void *stack_addresses[128];
  9.         int size = backtrace(stack_addresses, 128);
  10.         fprintf(stderr, "\n---------- STACKTRACE ---------- %d\n", size);
  11.         backtrace_symbols_fd(stack_addresses, size, STDERR_FILENO);
  12.         fprintf(stderr, "---------- STACKTRACE ----------\n\n");
  13.         oldsigact.sa_sigaction(sig, info, ucontext);
  14. }
  15.  
  16. void armbacktrace_init(void)
  17. {
  18.         struct sigaction sigact = {
  19.                 .sa_sigaction = armbacktrace_segv_handler,
  20.                 .sa_flags     = SA_RESTART | SA_SIGINFO,
  21.         };
  22.  
  23.         if (sigaction(SIGSEGV, &sigact, &oldsigact) != 0) {
  24.                 fprintf(stderr, "Error installing SEGV signal");
  25.                 exit(EXIT_FAILURE);
  26.         }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement