dump code

    xiaoxiao2021-03-25  56

    string AccurateTimeStr(void) { SYSTEMTIME sys; GetLocalTime( &sys ); ostringstream oss; oss << sys.wYear << "-" << sys.wMonth << "-" <<sys.wDay <<"_" <<sys.wHour<<sys.wMinute << sys.wSecond <<sys.wMilliseconds; return oss.str(); } void GenerateDump(EXCEPTION_POINTERS * pExPtrs, const string& strDumpFilePath, int nFullDump) { HANDLE hFile = CreateFile(strDumpFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE != hFile) { PEXCEPTION_POINTERS pExceptionInfo = NULL; pExceptionInfo = (PEXCEPTION_POINTERS)pExPtrs; MINIDUMP_EXCEPTION_INFORMATION MiniExceptionInfo = { 0 }; MiniExceptionInfo.ThreadId = GetCurrentThreadId(); MiniExceptionInfo.ExceptionPointers = pExceptionInfo; MiniExceptionInfo.ClientPointers = TRUE; MINIDUMP_TYPE dumpType = nFullDump ? MiniDumpValidTypeFlags : MiniDumpNormal /*MiniDumpWithFullMemory | MiniDumpWithDataSegs | MiniDumpWithHandleData | MiniDumpWithProcessThreadData | MiniDumpScanMemory | MiniDumpWithIndirectlyReferencedMemory*/; MiniDumpWriteDump(GetCurrentProcess(), ::GetCurrentProcessId(), hFile, dumpType, &MiniExceptionInfo, NULL, NULL); CloseHandle(hFile); } } NBFileSystem * g_pFileSystem = NULL; CAdoSqlEx * g_pAdoDB = NULL; GNIManagerOE * g_pGNIManager = NULL; CNBLiveAdapterASImpl* g_pLiveAdapter = NULL; bool g_bInit = false; static BOOL bGetStackTraceString = TRUE ; static BOOL bShowRegs = TRUE ; static BOOL bLetItCrash = FALSE ; static DWORD dwOpts = GSTSO_MODULE | GSTSO_SYMBOL | GSTSO_SRCLINE ; static HINSTANCE g_dllInstance = NULL; static LONG __stdcall MyExceptionFunc( EXCEPTION_POINTERS * pExPtrs ) { //Record Task List FILE* fp = NULL; char buffer[1024]={0}; ::GetModuleFileName( NULL , buffer , MAX_PATH ); char * pFind = strrchr( buffer , '\\' ); if( NULL == pFind ) return EXCEPTION_EXECUTE_HANDLER; pFind[0] = 0; pFind = strrchr( buffer ,'\\'); if( NULL == pFind ) return EXCEPTION_EXECUTE_HANDLER; pFind[1] = 0; char conf[1024] = { '\0' }; strcpy(conf, buffer); strcat(conf, "conf\\fix_graphics.ini"); string logdir = DiscoverInfo::Instance()->RuntimeLogFolder() + string("crashinfo.log"); strcpy( pFind , logdir.c_str()); fp = fopen( logdir.c_str() , "wb" ); char newline[2] = { 0x0d , 0x0a }; if ( TRUE == bShowRegs ) { const char* str = GetRegisterString ( pExPtrs ) ; fwrite( str , strlen( str ) , 1 , fp ); fwrite( newline , 2 , 1 , fp ); } if ( TRUE == bGetStackTraceString ) { const char * str = GetFirstStackTraceString ( dwOpts , pExPtrs ) ; do { fwrite( str , strlen( str ) , 1 , fp ); fwrite( newline , 2 , 1 , fp ); str = GetNextStackTraceString ( dwOpts , pExPtrs ) ; } while ( NULL != str ) ; } fclose( fp ); string strDump = AccurateTimeStr() + string(".dmp"); strDump = DiscoverInfo::Instance()->RuntimeLogFolder() + strDump; int nFullDump = 0; if( access(conf, 0) == 0 ) { nFullDump = GetPrivateProfileInt("BugTrace", "FullDump", 0, conf); } GenerateDump(pExPtrs, strDump, nFullDump); if ( TRUE == bLetItCrash ) { return ( EXCEPTION_CONTINUE_SEARCH ) ; } else { return ( EXCEPTION_EXECUTE_HANDLER ) ; } } BOOL CMyTestApp::InitInstance()中添加如下 SetCrashHandlerFilter( MyExceptionFunc );
    转载请注明原文地址: https://ju.6miu.com/read-38924.html

    最新回复(0)