I tried to make my program dump and save its stack trace when crashes. I installed my own win32 SE handler with _set_se_translator
and tried to dump the stack trace with StackWalk64
and finally throw a C++ exception (which actually does the logging when caught).
The code looks like this:
...
_set_se_handlers(WIN32EXCEPTION::Win32ExceptionStuff);
...
void WIN32EXCEPTION::Win32ExceptionStuff(unsigned int Code, struct _EXCEPTION_POINTERS* Info) // static
{
STACKFRAME64 sf64;
sf64.AddrPC.Offset = Info->ContextRecord->Eip;
sf64.AddrStack.Offset = Info->ContextRecord->Esp;
sf64.AddrFrame.Offset = Info->ContextRecord->Ebp;
sf64.AddrPC.Mode= sf64.AddrStack.Mode= sf64.AddrFrame.Mode= AddrModeFlat;
while (StackWalk64(IMAGE_FILE_MACHINE_I386,GetCurrentProcess(),GetCurrentThread(),
&sf64,Info->ContextRecord,0,SymFunctionTableAccess64,SymGetModuleBase64,0))
{
//... Do something with the stack frames
}
throw WIN32EXCEPTION(/*...*/);
}
as I saw in some examples, but there is a problem: StackWalk64 always return true and that while
loop becomes infinite. The StackWalk64 only repeats the same frame.
What is the problem, and how to fix?