mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 17:01:51 +00:00
Untabify minidumper
git-svn-id: https://svn.eduke32.com/eduke32@7100 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
2b01ea19b1
commit
c0889dab31
1 changed files with 80 additions and 80 deletions
|
@ -9,105 +9,105 @@ MiniDumper g_dumper("eduke32");
|
|||
|
||||
MiniDumper::MiniDumper( LPCSTR szAppName )
|
||||
{
|
||||
// if this assert fires then you have two instances of MiniDumper
|
||||
// which is not allowed
|
||||
assert( m_szAppName==NULL );
|
||||
// if this assert fires then you have two instances of MiniDumper
|
||||
// which is not allowed
|
||||
assert( m_szAppName==NULL );
|
||||
|
||||
m_szAppName = szAppName ? _strdup(szAppName) : "Application";
|
||||
m_szAppName = szAppName ? _strdup(szAppName) : "Application";
|
||||
|
||||
::SetUnhandledExceptionFilter( TopLevelFilter );
|
||||
::SetUnhandledExceptionFilter( TopLevelFilter );
|
||||
}
|
||||
|
||||
LONG MiniDumper::TopLevelFilter( struct _EXCEPTION_POINTERS *pExceptionInfo )
|
||||
{
|
||||
LONG retval = EXCEPTION_CONTINUE_SEARCH;
|
||||
//HWND hParent = NULL; // find a better value for your app
|
||||
LONG retval = EXCEPTION_CONTINUE_SEARCH;
|
||||
//HWND hParent = NULL; // find a better value for your app
|
||||
|
||||
// firstly see if dbghelp.dll is around and has the function we need
|
||||
// look next to the EXE first, as the one in System32 might be old
|
||||
// (e.g. Windows 2000)
|
||||
HMODULE hDll = NULL;
|
||||
char szDbgHelpPath[_MAX_PATH];
|
||||
// firstly see if dbghelp.dll is around and has the function we need
|
||||
// look next to the EXE first, as the one in System32 might be old
|
||||
// (e.g. Windows 2000)
|
||||
HMODULE hDll = NULL;
|
||||
char szDbgHelpPath[_MAX_PATH];
|
||||
|
||||
if (GetModuleFileName( NULL, szDbgHelpPath, _MAX_PATH ))
|
||||
{
|
||||
char *pSlash = _tcsrchr( szDbgHelpPath, '\\' );
|
||||
if (pSlash)
|
||||
{
|
||||
_tcscpy( pSlash+1, "DBGHELP.DLL" );
|
||||
hDll = ::LoadLibrary( szDbgHelpPath );
|
||||
}
|
||||
}
|
||||
if (GetModuleFileName( NULL, szDbgHelpPath, _MAX_PATH ))
|
||||
{
|
||||
char *pSlash = _tcsrchr( szDbgHelpPath, '\\' );
|
||||
if (pSlash)
|
||||
{
|
||||
_tcscpy( pSlash+1, "DBGHELP.DLL" );
|
||||
hDll = ::LoadLibrary( szDbgHelpPath );
|
||||
}
|
||||
}
|
||||
|
||||
if (hDll==NULL)
|
||||
{
|
||||
// load any version we can
|
||||
hDll = ::LoadLibrary( "DBGHELP.DLL" );
|
||||
}
|
||||
if (hDll==NULL)
|
||||
{
|
||||
// load any version we can
|
||||
hDll = ::LoadLibrary( "DBGHELP.DLL" );
|
||||
}
|
||||
|
||||
LPCTSTR szResult = "DBGHELP.DLL not found";;
|
||||
char szScratch [_MAX_PATH];
|
||||
LPCTSTR szResult = "DBGHELP.DLL not found";;
|
||||
char szScratch [_MAX_PATH];
|
||||
|
||||
if (hDll)
|
||||
{
|
||||
MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
|
||||
if (pDump)
|
||||
{
|
||||
char szDumpPath[_MAX_PATH];
|
||||
if (hDll)
|
||||
{
|
||||
MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
|
||||
if (pDump)
|
||||
{
|
||||
char szDumpPath[_MAX_PATH];
|
||||
|
||||
// work out a good place for the dump file
|
||||
/*if (!GetTempPath( _MAX_PATH, szDumpPath ))
|
||||
_tcscpy( szDumpPath, "c:\\temp\\" );
|
||||
*/
|
||||
sprintf(szDumpPath,"%s_%u",m_szAppName,timeGetTime());
|
||||
_tcscat( szDumpPath, ".dmp" );
|
||||
// work out a good place for the dump file
|
||||
/*if (!GetTempPath( _MAX_PATH, szDumpPath ))
|
||||
_tcscpy( szDumpPath, "c:\\temp\\" );
|
||||
*/
|
||||
sprintf(szDumpPath,"%s_%u",m_szAppName,timeGetTime());
|
||||
_tcscat( szDumpPath, ".dmp" );
|
||||
|
||||
// ask the user if they want to save a dump file
|
||||
//if (::MessageBox( NULL, "Something bad happened in your program, would you like to save a diagnostic file?", m_szAppName, MB_YESNO )==IDYES)
|
||||
{
|
||||
// create the file
|
||||
HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
// ask the user if they want to save a dump file
|
||||
//if (::MessageBox( NULL, "Something bad happened in your program, would you like to save a diagnostic file?", m_szAppName, MB_YESNO )==IDYES)
|
||||
{
|
||||
// create the file
|
||||
HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL );
|
||||
|
||||
if (hFile!=INVALID_HANDLE_VALUE)
|
||||
{
|
||||
_MINIDUMP_EXCEPTION_INFORMATION ExInfo;
|
||||
if (hFile!=INVALID_HANDLE_VALUE)
|
||||
{
|
||||
_MINIDUMP_EXCEPTION_INFORMATION ExInfo;
|
||||
|
||||
ExInfo.ThreadId = ::GetCurrentThreadId();
|
||||
ExInfo.ExceptionPointers = pExceptionInfo;
|
||||
ExInfo.ClientPointers = NULL;
|
||||
ExInfo.ThreadId = ::GetCurrentThreadId();
|
||||
ExInfo.ExceptionPointers = pExceptionInfo;
|
||||
ExInfo.ClientPointers = NULL;
|
||||
|
||||
// write the dump
|
||||
BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
|
||||
if (bOK)
|
||||
{
|
||||
sprintf( szScratch, "Saved dump file to \"%s\"", szDumpPath );
|
||||
szResult = szScratch;
|
||||
retval = EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( szScratch, "Failed to save dump file to \"%s\" (error %d)", szDumpPath, GetLastError() );
|
||||
szResult = szScratch;
|
||||
}
|
||||
::CloseHandle(hFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( szScratch, "Failed to create dump file \"%s\" (error %d)", szDumpPath, GetLastError() );
|
||||
szResult = szScratch;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
szResult = "DBGHELP.DLL too old";
|
||||
}
|
||||
// write the dump
|
||||
BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
|
||||
if (bOK)
|
||||
{
|
||||
sprintf( szScratch, "Saved dump file to \"%s\"", szDumpPath );
|
||||
szResult = szScratch;
|
||||
retval = EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( szScratch, "Failed to save dump file to \"%s\" (error %d)", szDumpPath, GetLastError() );
|
||||
szResult = szScratch;
|
||||
}
|
||||
::CloseHandle(hFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( szScratch, "Failed to create dump file \"%s\" (error %d)", szDumpPath, GetLastError() );
|
||||
szResult = szScratch;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
szResult = "DBGHELP.DLL too old";
|
||||
}
|
||||
|
||||
::FreeLibrary(hDll);
|
||||
}
|
||||
}
|
||||
|
||||
::MessageBox( NULL, szResult, m_szAppName, MB_OK );
|
||||
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
Loading…
Reference in a new issue