Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static struct sigaction oldsigact;
- static void armbacktrace_segv_handler(int sig, siginfo_t *info, void *ucontext)
- {
- static bool busy = false;
- if (busy) /* forbids concurrent call */
- return;
- busy = true;
- static void *stack_addresses[128];
- int size = backtrace(stack_addresses, 128);
- fprintf(stderr, "\n---------- STACKTRACE ---------- %d\n", size);
- backtrace_symbols_fd(stack_addresses, size, STDERR_FILENO);
- fprintf(stderr, "---------- STACKTRACE ----------\n\n");
- oldsigact.sa_sigaction(sig, info, ucontext);
- }
- void armbacktrace_init(void)
- {
- struct sigaction sigact = {
- .sa_sigaction = armbacktrace_segv_handler,
- .sa_flags = SA_RESTART | SA_SIGINFO,
- };
- if (sigaction(SIGSEGV, &sigact, &oldsigact) != 0) {
- fprintf(stderr, "Error installing SEGV signal");
- exit(EXIT_FAILURE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement