I am using the following code to create a minidump file whenever there is a structured exception generated from my code:
void CreateMiniDump( EXCEPTION_POINTERS* pep )
{
// Open the file
typedef BOOL (*PDUMPFN)(
HANDLE hProcess,
DWORD ProcessId,
HANDLE hFile,
MINIDUMP_TYPE DumpType,
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
PMINIDUMP_CALLBACK_INFORMATION CallbackParam
);
HANDLE hFile = CreateFile( _T("C:/temp/MiniDump.dmp"), GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
HMODULE h = ::LoadLibrary(L"DbgHelp.dll");
PDUMPFN pFn = (PDUMPFN)GetProcAddress(h, "MiniDumpWriteDump");
if( ( hFile != NULL ) && ( hFile != INVALID_HANDLE_VALUE ) )
{
// Create the minidump
MINIDUMP_EXCEPTION_INFORMATION mdei;
mdei.ThreadId = GetCurrentThreadId();
mdei.ExceptionPointers = pep;
mdei.ClientPointers = TRUE;
MINIDUMP_TYPE mdt = MiniDumpNormal;
BOOL rv = (*pFn)( GetCurrentProcess(), GetCurrentProcessId(),
hFile, mdt, (pep != 0) ? &mdei : 0, 0, 0 );
// Close the file
CloseHandle( hFile );
}
}
LONG WINAPI MyUnhandledExceptionFilter(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
CreateMiniDump(ExceptionInfo);
return EXCEPTION_EXECUTE_HANDLER;
}
And I am doing SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
from the main entry point of my app ( I am not setting it for each thread though). After this to test this code I did the following to generate an access violation: int* p = 0; *p = 0;
The dump file did get generated. Then I used windbg and opened the dump file and used .ecxr
command to get the exception record. However, no information is coming there (i.e. I am not getting the call stack). Also if I use !analyze -v
command then it is able to show the line where the crash occured. Does anybody know what I am missing and how to solve this?
BTW, I am using VC7 compiler with /EHa (asynchronuos exception model) flag.
typedef BOOL (__stdcall *PDUMPFN) (
– egorFiNE Feb 27 '13 at 19:21