Skip to content

Commit

Permalink
added:crash core-dump support for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xengine-qyt committed Oct 11, 2024
1 parent 7653f36 commit ce875f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Empty file.
2 changes: 2 additions & 0 deletions XEngine_Source/XEngine_StorageApp/StorageApp_Hdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <windows.h>
#include <tchar.h>
#include <io.h>
#include <minidumpapiset.h>
#else
#include <unistd.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -123,6 +124,7 @@ extern XENGINE_LBCONFIG st_LoadbalanceCfg;

#ifdef _MSC_BUILD
#pragma comment(lib,"Ws2_32.lib")
#pragma comment(lib,"Dbghelp.lib")
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib.lib")
#pragma comment(lib,"XEngine_BaseLib/XEngine_Algorithm.lib")
#pragma comment(lib,"XEngine_Core/XEngine_Core.lib")
Expand Down
27 changes: 27 additions & 0 deletions XEngine_Source/XEngine_StorageApp/XEngine_StorageApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,39 @@ static int ServiceApp_Deamon(int wait)
#endif
return 0;
}
#ifdef _MSC_BUILD
LONG WINAPI Coredump_ExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers)
{
static int i = 0;
XCHAR tszFileStr[MAX_PATH] = {};
XCHAR tszTimeStr[128] = {};
BaseLib_OperatorTime_TimeToStr(tszTimeStr);
_xstprintf(tszFileStr, _X("./XEngine_Coredump/dumpfile_%s_%d.dmp"), tszTimeStr, i++);

XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_FATAL, _X("主程序:软件崩溃,写入dump:%s"), tszFileStr);

HANDLE hDumpFile = CreateFileA(tszFileStr, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hDumpFile)
{
MINIDUMP_EXCEPTION_INFORMATION st_DumpInfo = {};
st_DumpInfo.ExceptionPointers = pExceptionPointers;
st_DumpInfo.ThreadId = GetCurrentThreadId();
st_DumpInfo.ClientPointers = TRUE;

// 写入 dump 文件
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &st_DumpInfo, NULL, NULL);
CloseHandle(hDumpFile);
}
return EXCEPTION_EXECUTE_HANDLER;
}
#endif
int main(int argc, char** argv)
{
#ifdef _MSC_BUILD
WSADATA st_WSAData;
WSAStartup(MAKEWORD(2, 2), &st_WSAData);

SetUnhandledExceptionFilter(Coredump_ExceptionFilter);
#endif
bIsRun = true;
int nRet = -1;
Expand Down

0 comments on commit ce875f0

Please sign in to comment.