void bt_sighandler(int sig, siginfo_t *info,
void *secret)
{
#ifdef N_DEBUG
void *trace[ trace_max_size ];
char **messages = (char **)NULL;
int i, trace_size = 0;
ucontext_t *uc = (ucontext_t *)secret;
// Do something useful with siginfo_t
if (sig == SIGSEGV)
printf("******* SEGMENTATION FAULT *******, faulty address is %p, "
"from %p\n", info->si_addr,
uc->uc_mcontext.gregs[REG_EIP]);
trace_size = backtrace(trace, trace_max_size );
// overwrite sigaction with caller's address
trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
messages = backtrace_symbols(trace, trace_size);
// skip first stack frame (points here)
printf("[***] Execution path:\n");
for (i=1; i<trace_size; ++i)
printf("[%3d] %s\n", trace_size - i, messages[i]);
free( messages );
#else
printf( "[***] Backtrace not supported when compiled without N_DEBUG defined\n" );
#endif
}
void bt_sighandler(int sig, siginfo_t *info,
void *secret)
{
#ifdef N_DEBUG
void *trace[ trace_max_size ];
char **messages = (char **)NULL;
int i, trace_size = 0;
ucontext_t *uc = (ucontext_t *)secret;
// Do something useful with siginfo_t
if (sig == SIGSEGV)
printf("******* SEGMENTATION FAULT *******, faulty address is %p, "
"from %p\n", info->si_addr,
uc->uc_mcontext.gregs[REG_EIP]);
trace_size = backtrace(trace, trace_max_size );
// overwrite sigaction with caller's address
trace[1] = (void *) uc->uc_mcontext.gregs[REG_EIP];
messages = backtrace_symbols(trace, trace_size);
// skip first stack frame (points here)
printf("[***] Execution path:\n");
for (i=1; i<trace_size; ++i)
printf("[%3d] %s\n", trace_size - i, messages[i]);
free( messages );
#else
printf( "[***] Backtrace not supported when compiled without N_DEBUG defined\n" );
#endif
}
To copy to clipboard, switch view to plain text mode
Bookmarks