I'm implementing a simple crash logger for my C++ application:
static void handler(int, siginfo_t * info, void *) {
void *array[1000];
switch (info->si_signo) {
case SIGILL:
Logger() << "Received SIGILL";
break;
case SIGSEGV:
Logger() << "Received SIGSEGV";
break;
case SIGBUS:
Logger() << "Received SIGBUS";
break;
case SIGSYS:
Logger() << "Received SIGSYS";
break;
default:
break;
}
// get void*'s for all entries on the stack
const size_t size = backtrace(array, 1000);
// print out all the frames
char ** symbols = backtrace_symbols(array, size);
for(size_t i = 0; i < size; ++i)
{
Logger() << symbols[i];
}
free(symbols);
exit(EXIT_FAILURE);
}
struct sigaction SignalAction;
SignalAction.sa_flags = SA_SIGINFO;
SignalAction.sa_sigaction = handler;
sigemptyset(&SignalAction.sa_mask);
sigaction(SIGSEGV, &SignalAction, NULL);
sigaction(SIGBUS, &SignalAction, NULL);
sigaction(SIGILL, &SignalAction, NULL);
I haven't tested it on Linux yet, but on OS X the specific trace item that I'm interested in, the one thatr has caused the signal, is not being printed (entry number 2):
: " Received SIGSEGV"
: " 0 App 0x0000000100253d15 _ZL7handleriP9__siginfoPv + 229"
: " 1 libsystem_platform.dylib 0x00007fff8ff0f5aa _sigtramp + 26"
: " 2 ??? 0x000000000000000c 0x0 + 12"
: " 3 App 0x000000010000dfa7 _ZN11CMainWindow13initShortcutsEv + 231"
: " 4 App 0x000000010000d059 _ZN11CMainWindowC2EP7QWidget + 1001"
: " 5 App 0x00000001000091d9 main + 6217"
: " 6 App 0x00000001000070a5 _start + 227"
: " 7 App 0x0000000100006fc1 start + 33"
Why is this happening, and can I fix this?
P. S. This is a debug build. There was no actual segfault, it was simulated with raise(SIGSEGV)
. raise
was called from a method , that, in turn, was called from MainWindow::initShortcuts
.