I’m using ‘backtrace()’ and ‘backtrace_symbols’ functions in a signal handler to generate a backtrace for debugging (without gdb).
On Tx2, the backtrace() on SIGABRT signal shows only three frames: the signal handler and two from within libc, which is not useful.
Stack Trace:
Signal (6), Aborted
[Bt0] status(0), ./App: pfnExceptionHandler_linux(int, siginfo_t*, void*) + 0x17c [0x555eaef9fc]
[Bt1] status(-2), linux-vdso.so.1: __kernel_rt_sigreturn + 0 [0x7f7b09f6c0]
[Bt2] status(-2), /lib/aarch64-linux-gnu/libc.so.6: raise + 0xb0 [0x7f7ad514a8]
Backtrace on SIGSEGV does produce a good backtrace.
Stack Trace:
Signal (11), Segmentation fault
[Bt0] status(0), ./App: pfnExceptionHandler_linux(int, siginfo_t*, void*) + 0x17c [0x55785579ac]
[Bt1] status(-2), linux-vdso.so.1: __kernel_rt_sigreturn + 0 [0x7fa97046c0]
[Bt2] status(0), ./App: testfunc() + 0x10 [0x5578558038]
[Bt3] status(-2), ./App: main + 0x24 [0x557855806c]
[Bt4] status(-2), /lib/aarch64-linux-gnu/libc.so.6: __libc_start_main + 0xe0 [0x7fa93a46e0]
[Bt5] status(-2), ./App: + 0x70a4 [0x55785570a4]
How can I get a useful backbrace on SIGABRT on Tx2?
some codes
-
signal handler
void pfnExceptionHandler_linux(int signum, siginfo_t* info, void* ctx)
{
signal(signum, SIG_DFL);…
const size_t sFrameSize = 100;
void* pStackBuffer[sFrameSize] = { 0 };
int iSize = backtrace(pStackBuffer, sFrameSize);
char** symbols = backtrace_symbols(pStackBuffer, iSize);
if (!symbols)
{
return;
}
… -
test function
void testfunc()
{
int *a = NULL;
//assert(a != NULL);
*a = 1;
}
int main(int argc, char **argv)
{
registerExceptionHandler();
printf("Hello world\n");
testfunc();
return 0;
}