From 57daf1d8c589a025f1d06ad15468d04d20bd3fd5 Mon Sep 17 00:00:00 2001 From: Pan7 Date: Mon, 11 Apr 2016 22:16:12 +0200 Subject: [PATCH] MiniDump for msvc --- radiant/main.cpp | 72 ++++++++++++++++++++++++++++++++++++++++- radiant/radiant.vcxproj | 8 ++--- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/radiant/main.cpp b/radiant/main.cpp index bd095550..159f0fd5 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -414,7 +414,7 @@ void error_redirect( const gchar *domain, GLogLevelFlags log_level, const gchar #define GETTEXT_PACKAGE "radiant" #define LOCALEDIR "lang" -int main( int argc, char* argv[] ) { +int mainRadiant( int argc, char* argv[] ) { const char *libgl; int i, j, k; @@ -923,6 +923,76 @@ int main( int argc, char* argv[] ) { return 0; } + +#if defined( _WIN32 ) && defined( _MSC_VER ) +#include +#include +#include +#include //StringCchPrintf + +int GenerateDump( EXCEPTION_POINTERS* pExceptionPointers ) { + BOOL bMiniDumpSuccessful; + char szPath[MAX_PATH]; + char szFileName[MAX_PATH]; + char szAppName[] = "GTKRadiant"; + char* szVersion = RADIANT_VERSION; + DWORD dwBufferSize = MAX_PATH; + HANDLE hDumpFile; + SYSTEMTIME stLocalTime; + MINIDUMP_EXCEPTION_INFORMATION ExpParam; + + GetLocalTime( &stLocalTime ); + GetTempPath( dwBufferSize, szPath ); + + StringCchPrintf( szFileName, MAX_PATH, "%s%s", szPath, szAppName ); + CreateDirectory( szFileName, NULL ); + + StringCchPrintf( szFileName, MAX_PATH, "%s%s\\%s-%s-%04d%02d%02d-%02d%02d%02d.dmp", + szPath, szAppName, szAppName, szVersion, + stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, + stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond ); + hDumpFile = CreateFile(szFileName, GENERIC_READ|GENERIC_WRITE, + FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); + + ExpParam.ThreadId = GetCurrentThreadId(); + ExpParam.ExceptionPointers = pExceptionPointers; + ExpParam.ClientPointers = TRUE; + + bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), + hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL); + + return EXCEPTION_EXECUTE_HANDLER; +} +#endif + +int main( int argc, char* argv[] ) { + +#if defined( _WIN32 ) && defined( _MSC_VER ) + __try { + return mainRadiant( argc, argv ); + } __except( GenerateDump( GetExceptionInformation() ) ) { + + char szPath[MAX_PATH]; + char szText[MAX_PATH]; + char szFileName[MAX_PATH]; + char szAppName[] = "GTKRadiant"; + SYSTEMTIME stLocalTime; + DWORD dwBufferSize = MAX_PATH; + + GetLocalTime( &stLocalTime ); + GetTempPath( dwBufferSize, szPath ); + + StringCchPrintf( szFileName, MAX_PATH, "%s%s", szPath, szAppName ); + + StringCchPrintf( szText, MAX_PATH, _("Application crashed!\nCreated a dump file in: \n%s"), szFileName ); + + MessageBox( NULL, szText, NULL, MB_ICONERROR ); + } +#else + return mainRadiant( argc, argv ); +#endif +} + // ydnar: quick and dirty fix, just make the buffer bigger #define BIG_PATH_MAX 4096 diff --git a/radiant/radiant.vcxproj b/radiant/radiant.vcxproj index ffb03471..e00287aa 100644 --- a/radiant/radiant.vcxproj +++ b/radiant/radiant.vcxproj @@ -84,7 +84,7 @@ /STACK:8388608 %(AdditionalOptions) - Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;%(AdditionalDependencies) + Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;Dbghelp.lib;%(AdditionalDependencies) $(SolutionDir)\..\gtk-2.24.10\lib;$(SolutionDir)\..\libxml2-2.9.2/win32/bin.msvc;$(SolutionDir)\..\gtkglext-1.2.0\lib;$(SolutionDir)\build\$(Configuration)\libs;%(AdditionalLibraryDirectories) true Console @@ -106,7 +106,7 @@ /STACK:8388608 %(AdditionalOptions) - Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;%(AdditionalDependencies) + Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;Dbghelp.lib;%(AdditionalDependencies) $(SolutionDir)\..\gtk-2.24.10\lib;$(SolutionDir)\..\libxml2-2.9.2/win32/bin.msvc;$(SolutionDir)\..\gtkglext-1.2.0\lib;$(SolutionDir)\build\$(Configuration)\libs;%(AdditionalLibraryDirectories) true Console @@ -124,7 +124,7 @@ /STACK:8388608 %(AdditionalOptions) - Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;%(AdditionalDependencies) + Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;Dbghelp.lib;%(AdditionalDependencies) $(SolutionDir)\..\gtk-2.24.10\lib;$(SolutionDir)\..\libxml2-2.9.2/win32/bin.msvc;$(SolutionDir)\..\gtkglext-1.2.0\lib;$(SolutionDir)\build\$(Configuration)\libs;%(AdditionalLibraryDirectories) true Windows @@ -146,7 +146,7 @@ /STACK:8388608 %(AdditionalOptions) - Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;%(AdditionalDependencies) + Ws2_32.lib;glib-2.0.lib;gobject-2.0.lib;intl.lib;gtk-win32-2.0.lib;gdk-win32-2.0.lib;pango-1.0.lib;pangoft2-1.0.lib;gdkglext-win32-1.0.lib;gtkglext-win32-1.0.lib;libxml2_a.lib;mathlib.lib;synapse.lib;l_net.lib;cmdlib.lib;Dbghelp.lib;%(AdditionalDependencies) $(SolutionDir)\..\gtk-2.24.10\lib;$(SolutionDir)\..\libxml2-2.9.2/win32/bin.msvc;$(SolutionDir)\..\gtkglext-1.2.0\lib;$(SolutionDir)\build\$(Configuration)\libs;%(AdditionalLibraryDirectories) true Windows