I've got a Windows/C++ app (using JUCE) and I'd like to dump a stack trace to a file when the app crashes. In my initialization code, I've got:
signal(SIGABRT, abortHandler);
signal(SIGSEGV, abortHandler);
signal(SIGILL, abortHandler);
signal(SIGFPE, abortHandler);
And then my handler looks like:
void abortHandler(int signum)
{
juce::File log("stacktrace.txt");
log.appendText(juce::SystemStats::getStackBacktrace());
exit(signum);
}
However, the resulting stack trace is not the thread where the crash occurred:
0: AudulusDebug32: juce::SystemStats::getStackBacktrace + 0x7f
1: AudulusDebug32: abortHandler + 0x61
2: AudulusDebug32: _XcptFilter + 0x1e3
3: AudulusDebug32: __tmainCRTStartup + 0x15f
4: AudulusDebug32: WinMainCRTStartup + 0xd
5: BaseThreadInitThunk + 0xe
6: RtlInitializeExceptionChain + 0x84
7: RtlInitializeExceptionChain + 0x5a
Internally, getStackBacktrace
does the following:
HANDLE process = GetCurrentProcess();
SymInitialize (process, nullptr, TRUE);
void* stack[128];
int frames = (int) CaptureStackBackTrace (0, numElementsInArray (stack), stack, nullptr);
Is there a way I could get the stack trace for the thread where the crash occurred (or all threads)?