Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have build an application in release mode and there no such compile time error or run time error.

I have written my own unit test and tested. No Error.


when my application went to production envirnoment and exe is crashing.

how can i handle it and how can i check where its crashing in which line number?.


I have created log file , whenever any transaction is happen , that is logging into the log file but exe is crashing nothing is logging.


i am not able to find out?
Posted
Comments
thatraja 23-Jan-14 2:30am    
Check "event log viewer" for log messages related to that application
[no name] 23-Jan-14 2:47am    
Go back to debug build with many asserts.

Have a look ath the oldie-goldie Surviving the Release Version[^] Code Project article.
 
Share this answer
 
Comments
Rage 11-Mar-14 8:37am    
Ah ! This one and the C++ FAQ, good' ol' references !
ranjithkumar81 3-Apr-14 7:02am    
dbghelp header file is not supporting into Win32 or SDK Application.

Any one have any idea , how to achieve for "MiniDumpWriteDump" API in Win32 Application.
Hi All,


The Best-way to find,which CPP File & Line to generate SelfCrashDump File .

Write the following code in WinMain() or Main() or InitInstance()


C++
//for crash dump analysis
//added for CrashDump Analysis
typedef BOOL (__stdcall *tMDWD)( 
    IN HANDLE hProcess, 
    IN DWORD ProcessId, 
    IN HANDLE hFile, 
    IN MINIDUMP_TYPE DumpType, 
    IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL 
    IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL 
    IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL 
    ); 

static tMDWD s_pMDWD; 
static HMODULE s_hDbgHelpMod; 
static MINIDUMP_TYPE s_dumpTyp = MiniDumpNormal; 

static LONG __stdcall MyCrashHandlerExceptionFilter(EXCEPTION_POINTERS* pEx) 
{   
//#ifdef _M_IX86 
    if (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_ARRAY_BOUNDS_EXCEEDED) 
        || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) || (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_DATATYPE_MISALIGNMENT)
        || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_STACK_CHECK) || (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION)
        || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_INT_OVERFLOW) || (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_INVALID_HANDLE) 
        || ( pEx->ExceptionRecord->ExceptionCode == STATUS_UNWIND_CONSOLIDATE ))   
    { 
        // be sure that we have enought space... 
        static char MyStack[1024*128];   
        // it assumes that DS and SS are the same!!! (this is the case for Win32) 
        // change the stack only if the selectors are the same (this is the case for Win32) 
        //__asm push offset MyStack[1024*128]; 
        //__asm pop esp; 
        __asm mov eax,offset MyStack[1024*128]; 
        __asm mov esp,eax; 
    } 
//#endif 
    bool bFailed = true; 
    HANDLE hFile; 
    time_t tNow = time( NULL );
    struct tm *pTm = localtime( &tNow );
    CString strDumpFileName;
    strDumpFileName.Format(_T("IML_CRASHDUMP_%d%d%d_%02d%02d%02d.dmp"),pTm->tm_mday,
           pTm->tm_mon,
           pTm->tm_year,
           pTm->tm_hour, 
           pTm->tm_min, 
           pTm->tm_sec );

    hFile = CreateFile(strDumpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
    if (hFile != INVALID_HANDLE_VALUE) 
    { 
        MINIDUMP_EXCEPTION_INFORMATION stMDEI; 
        stMDEI.ThreadId = GetCurrentThreadId(); 
        stMDEI.ExceptionPointers = pEx; 
        stMDEI.ClientPointers = TRUE; 

        // try to create an miniDump: 
        if (s_pMDWD( 
            GetCurrentProcess(), 
            GetCurrentProcessId(), 
            hFile, 
            s_dumpTyp, 
            &stMDEI, 
            NULL, 
            NULL 
            )) 
        { 
            bFailed = false;  // suceeded 
        } 
        CloseHandle(hFile); 
    } 

    if (bFailed) 
    { 
        return EXCEPTION_CONTINUE_SEARCH; 
    } 

    // Optional display an error message 
    FatalAppExit(-1, _T("Application failed!")); 


    // or return one of the following: 
    // - EXCEPTION_CONTINUE_SEARCH 
    // - EXCEPTION_CONTINUE_EXECUTION 
    // - EXCEPTION_EXECUTE_HANDLER 
    return EXCEPTION_CONTINUE_SEARCH;  // this will trigger the "normal" OS error-dialog 
} 
void InitMiniDumpWriter() 
{ 
    if (s_hDbgHelpMod != NULL) 
        return; 

    // Initialize the member, so we do not load the dll after the exception has occured 
    // which might be not possible anymore... 
    s_hDbgHelpMod = LoadLibrary(_T("dbghelp.dll")); 
    if (s_hDbgHelpMod != NULL) 
        s_pMDWD = (tMDWD) GetProcAddress(s_hDbgHelpMod, "MiniDumpWriteDump"); 

    // Register Unhandled Exception-Filter: 
    SetUnhandledExceptionFilter(MyCrashHandlerExceptionFilter); 

    //_set_invalid_parameter_handler(MyCrashHandlerExceptionFilter);
    // Additional call "PreventSetUnhandledExceptionFilter"... 
    // See also: "SetUnhandledExceptionFilter" and VC8 (and later) 
     
}



It will generate a dumpfile(DMP), when it crashes the EXE.


Open dmp using VisualStudio IDE there u can find the line number and CPP File.




Regards,
Ranjith
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900