mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-02-05 19:23:27 +00:00
Added ability to generate Dump file on crash, on Windows
This commit is contained in:
@@ -2105,20 +2105,23 @@ ILibExportMethod void ILibChain_EndContinue(void *chain)
|
||||
}
|
||||
|
||||
char* g_ILibCrashID = NULL;
|
||||
char* g_ILibCrashDump_path = NULL;
|
||||
|
||||
#if defined(WIN32)
|
||||
int ILib_WindowsExceptionFilter(DWORD exceptionCode, void *exceptionInfo, CONTEXT *exceptionContext)
|
||||
int ILib_WindowsExceptionFilterEx(DWORD exceptionCode, void *exceptionInfo, ILib_DumpEnabledContext *exceptionContext)
|
||||
{
|
||||
if (IsDebuggerPresent()) { return(EXCEPTION_CONTINUE_SEARCH); }
|
||||
if (exceptionCode == EXCEPTION_ACCESS_VIOLATION || exceptionCode == EXCEPTION_STACK_OVERFLOW || exceptionCode == EXCEPTION_INVALID_HANDLE)
|
||||
{
|
||||
memcpy_s(exceptionContext, sizeof(CONTEXT), ((EXCEPTION_POINTERS*)exceptionInfo)->ContextRecord, sizeof(CONTEXT));
|
||||
exceptionContext->pctx = &(exceptionContext->ctx); exceptionContext->prec = &(exceptionContext->rec);
|
||||
memcpy_s(exceptionContext->pctx, sizeof(CONTEXT), ((EXCEPTION_POINTERS*)exceptionInfo)->ContextRecord, sizeof(CONTEXT));
|
||||
memcpy_s(exceptionContext->prec, sizeof(EXCEPTION_RECORD), ((EXCEPTION_POINTERS*)exceptionInfo)->ExceptionRecord, sizeof(EXCEPTION_RECORD));
|
||||
return(EXCEPTION_EXECUTE_HANDLER);
|
||||
}
|
||||
return(EXCEPTION_CONTINUE_SEARCH);
|
||||
}
|
||||
|
||||
void ILib_WindowsExceptionDebug(CONTEXT *exceptionContext)
|
||||
void ILib_WindowsExceptionDebugEx(ILib_DumpEnabledContext *dumpEnabledExceptionContext)
|
||||
{
|
||||
char buffer[4096];
|
||||
STACKFRAME64 StackFrame;
|
||||
@@ -2126,10 +2129,30 @@ void ILib_WindowsExceptionDebug(CONTEXT *exceptionContext)
|
||||
char imgBuffer[4096];
|
||||
DWORD MachineType;
|
||||
int len = 0;
|
||||
CONTEXT *exceptionContext = dumpEnabledExceptionContext->pctx;
|
||||
|
||||
ZeroMemory(&StackFrame, sizeof(STACKFRAME64));
|
||||
buffer[0] = 0;
|
||||
|
||||
if (g_ILibCrashDump_path != NULL)
|
||||
{
|
||||
HANDLE hDumpFile = CreateFileW(g_ILibCrashDump_path, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
MINIDUMP_EXCEPTION_INFORMATION i;
|
||||
i.ClientPointers = FALSE;
|
||||
i.ExceptionPointers = dumpEnabledExceptionContext;
|
||||
i.ThreadId = GetCurrentThreadId();
|
||||
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile,
|
||||
MiniDumpWithIndirectlyReferencedMemory |
|
||||
MiniDumpWithPrivateReadWriteMemory |
|
||||
MiniDumpWithDataSegs |
|
||||
MiniDumpWithHandleData |
|
||||
MiniDumpWithFullMemoryInfo |
|
||||
MiniDumpWithThreadInfo |
|
||||
MiniDumpWithUnloadedModules , &i, NULL, NULL);
|
||||
CloseHandle(hDumpFile);
|
||||
}
|
||||
|
||||
|
||||
#ifndef WIN64
|
||||
MachineType = IMAGE_FILE_MACHINE_I386;
|
||||
StackFrame.AddrPC.Offset = exceptionContext->Eip;
|
||||
|
||||
@@ -1382,9 +1382,18 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
void ILibChain_DebugOffset(char *buffer, int bufferLen, uint64_t addrOffset);
|
||||
char* ILibChain_Debug(void *chain, char* buffer, int bufferLen);
|
||||
extern char* g_ILibCrashID;
|
||||
extern char* g_ILibCrashDump_path;
|
||||
|
||||
#if defined(WIN32)
|
||||
int ILib_WindowsExceptionFilter(DWORD exceptionCode, void *exceptionInfo, CONTEXT *exceptionContext);
|
||||
void ILib_WindowsExceptionDebug(CONTEXT *exceptionContext);
|
||||
typedef struct ILib_DumpEnabledContext
|
||||
{
|
||||
PEXCEPTION_RECORD prec;
|
||||
PCONTEXT pctx;
|
||||
EXCEPTION_RECORD rec;
|
||||
CONTEXT ctx;
|
||||
}ILib_DumpEnabledContext;
|
||||
int ILib_WindowsExceptionFilterEx(DWORD exceptionCode, void *exceptionInfo, ILib_DumpEnabledContext *dumpEnabledExceptionContext);
|
||||
void ILib_WindowsExceptionDebugEx(ILib_DumpEnabledContext *dumpEnabledExceptionContext);
|
||||
#elif defined(_POSIX)
|
||||
char* ILib_POSIX_InstallCrashHandler(char *exename);
|
||||
#endif
|
||||
|
||||
@@ -453,14 +453,14 @@ void ILibProcessPipe_Manager_WindowsRunLoopEx(void *arg)
|
||||
}
|
||||
ILibProcessPipe_Manager_WindowsRunLoop(void *arg)
|
||||
{
|
||||
CONTEXT winException;
|
||||
ILib_DumpEnabledContext winException;
|
||||
__try
|
||||
{
|
||||
ILibProcessPipe_Manager_WindowsRunLoopEx(arg);
|
||||
}
|
||||
__except (ILib_WindowsExceptionFilter(GetExceptionCode(), GetExceptionInformation(), &winException))
|
||||
__except (ILib_WindowsExceptionFilterEx(GetExceptionCode(), GetExceptionInformation(), &winException))
|
||||
{
|
||||
ILib_WindowsExceptionDebug(&winException);
|
||||
ILib_WindowsExceptionDebugEx(&winException);
|
||||
}
|
||||
}
|
||||
void ILibProcessPipe_Manager_Start(void* chain, void* user)
|
||||
|
||||
Reference in New Issue
Block a user