dump code

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 );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值