From: <sag...@us...> - 2014-09-11 23:33:41
|
Revision: 4277 http://sourceforge.net/p/modplug/code/4277 Author: saga-games Date: 2014-09-11 23:33:32 +0000 (Thu, 11 Sep 2014) Log Message: ----------- [Imp] The plugin bridge does now also create crash dumps automatically. OpenMPT's /fullMemDump command line switch also applies to these dumps. [Mod] OpenMPT: Version is now 1.24.00.03 Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/pluginBridge/Bridge.cpp trunk/OpenMPT/pluginBridge/Bridge.h trunk/OpenMPT/pluginBridge/BridgeCommon.h trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp Added Paths: ----------- trunk/OpenMPT/common/WriteMemoryDump.h Added: trunk/OpenMPT/common/WriteMemoryDump.h =================================================================== --- trunk/OpenMPT/common/WriteMemoryDump.h (rev 0) +++ trunk/OpenMPT/common/WriteMemoryDump.h 2014-09-11 23:33:32 UTC (rev 4277) @@ -0,0 +1,64 @@ +/* + * WriteMemoryDump.h + * ----------------- + * Purpose: Code for writing memory dumps to a file. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "dbghelp.h" + +OPENMPT_NAMESPACE_BEGIN + +typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, + CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, + CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, + CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam + ); + +static bool WriteMemoryDump(_EXCEPTION_POINTERS *pExceptionInfo, const WCHAR *filename, bool fullMemDump) +{ + bool result = false; + + HMODULE hDll = ::LoadLibraryW(L"DBGHELP.DLL"); + if (hDll) + { + MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump"); + if (pDump) + { + + HANDLE hFile = ::CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile != INVALID_HANDLE_VALUE) + { + _MINIDUMP_EXCEPTION_INFORMATION ExInfo; + + if(pExceptionInfo) + { + ExInfo.ThreadId = ::GetCurrentThreadId(); + ExInfo.ExceptionPointers = pExceptionInfo; + ExInfo.ClientPointers = NULL; + } + + pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, + fullMemDump ? + (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithProcessThreadData | MiniDumpWithFullMemoryInfo +#if MPT_COMPILER_MSVC && MPT_MSVC_AT_LEAST(2010,0) + | MiniDumpIgnoreInaccessibleMemory | MiniDumpWithTokenInformation +#endif + ) + : + MiniDumpNormal, + pExceptionInfo ? &ExInfo : NULL, NULL, NULL); + ::CloseHandle(hFile); + + result = true; + } + } + ::FreeLibrary(hDll); + } + return result; +} + +OPENMPT_NAMESPACE_END Property changes on: trunk/OpenMPT/common/WriteMemoryDump.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/common/versionNumber.h 2014-09-11 23:33:32 UTC (rev 4277) @@ -19,7 +19,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 24 #define VER_MINOR 00 -#define VER_MINORMINOR 02 +#define VER_MINORMINOR 03 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR) "." VER_STRINGIZE(VER_MAJOR) "." VER_STRINGIZE(VER_MINOR) "." VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2014-09-11 23:33:32 UTC (rev 4277) @@ -14,7 +14,7 @@ #include "Moddoc.h" #include <shlwapi.h> #include "ExceptionHandler.h" -#include "dbghelp.h" +#include "../common/WriteMemoryDump.h" #include "../common/version.h" @@ -23,20 +23,13 @@ bool ExceptionHandler::fullMemDump = false; - -typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, - CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, - CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, - CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam - ); - - enum DumpMode { DumpModeCrash = 0, DumpModeWarning = 1, }; + static void GenerateDump(CString &errorMessage, _EXCEPTION_POINTERS *pExceptionInfo=NULL, DumpMode mode=DumpModeCrash) //-------------------------------------------------------------------------------------------------------------------- { @@ -60,43 +53,11 @@ } // Create minidump... - HMODULE hDll = ::LoadLibraryW(L"DBGHELP.DLL"); - if (hDll) + const mpt::PathString filename = baseRescuePath + MPT_PATHSTRING("crash.dmp"); + if(WriteMemoryDump(pExceptionInfo, filename.AsNative().c_str(), ExceptionHandler::fullMemDump)) { - MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump"); - if (pDump) - { - const mpt::PathString filename = baseRescuePath + MPT_PATHSTRING("crash.dmp"); - - HANDLE hFile = ::CreateFileW(filename.AsNative().c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile != INVALID_HANDLE_VALUE) - { - _MINIDUMP_EXCEPTION_INFORMATION ExInfo; - - if(pExceptionInfo) - { - ExInfo.ThreadId = ::GetCurrentThreadId(); - ExInfo.ExceptionPointers = pExceptionInfo; - ExInfo.ClientPointers = NULL; - } - - pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, - ExceptionHandler::fullMemDump ? - (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithProcessThreadData | MiniDumpWithFullMemoryInfo -#if MPT_COMPILER_MSVC && MPT_MSVC_AT_LEAST(2010,0) - | MiniDumpIgnoreInaccessibleMemory | MiniDumpWithTokenInformation -#endif - ) - : - MiniDumpNormal, - pExceptionInfo ? &ExInfo : NULL, NULL, NULL); - ::CloseHandle(hFile); - - errorMessage += "\n\nDebug information has been saved to\n" - + mpt::ToCString(baseRescuePath.ToWide()); - } - } - ::FreeLibrary(hDll); + errorMessage += "\n\nDebug information has been saved to\n" + + mpt::ToCString(baseRescuePath.ToWide()); } // Rescue modified files... @@ -148,7 +109,6 @@ { Reporting::Error(errorMessage, "OpenMPT Crash", pMainFrame); } - } Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2014-09-11 23:33:32 UTC (rev 4277) @@ -1554,6 +1554,10 @@ > </File> <File + RelativePath="..\common\WriteMemoryDump.h" + > + </File> + <File RelativePath=".\view_com.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2014-09-11 23:33:32 UTC (rev 4277) @@ -659,6 +659,7 @@ <ClInclude Include="..\common\typedefs.h" /> <ClInclude Include="..\common\version.h" /> <ClInclude Include="..\common\versionNumber.h" /> + <ClInclude Include="..\common\WriteMemoryDump.h" /> <ClInclude Include="..\pluginBridge\AEffectWrapper.h" /> <ClInclude Include="..\pluginBridge\BridgeCommon.h" /> <ClInclude Include="..\pluginBridge\BridgeWrapper.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2014-09-11 23:33:32 UTC (rev 4277) @@ -1020,6 +1020,9 @@ <ClInclude Include="..\common\mptAtomic.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="..\common\WriteMemoryDump.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/pluginBridge/Bridge.cpp =================================================================== --- trunk/OpenMPT/pluginBridge/Bridge.cpp 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/pluginBridge/Bridge.cpp 2014-09-11 23:33:32 UTC (rev 4277) @@ -44,28 +44,35 @@ #define assert(x) #endif +#include "../common/CompilerDetect.h" +#include "../common/WriteMemoryDump.h" #include "Bridge.h" -#include "../common/thread.h" -OPENMPT_NAMESPACE_BEGIN +// Crash handler for writing memory dumps +static LONG WINAPI CrashHandler(_EXCEPTION_POINTERS *pExceptionInfo) +{ + WCHAR tempPath[MAX_PATH + 2]; + DWORD result = GetTempPathW(MAX_PATH + 1, tempPath); + if(result > 0 && result <= MAX_PATH + 1) + { + std::wstring filename = tempPath; + filename += L"OpenMPT Crash Files\\"; + CreateDirectoryW(filename.c_str(), nullptr); + tempPath[0] = 0; + const int ch = GetDateFormatW(LOCALE_SYSTEM_DEFAULT, 0, nullptr, L"'PluginBridge 'yyyy'-'MM'-'dd ", tempPath, CountOf(tempPath)); + if(ch) GetTimeFormatW(LOCALE_SYSTEM_DEFAULT, 0, nullptr, L"HH'.'mm'.'ss'.dmp'", tempPath + ch - 1, CountOf(tempPath) - ch + 1); + filename += tempPath; -LONG PluginBridge::instanceCount = 0; -Event PluginBridge::sigQuit; + WriteMemoryDump(pExceptionInfo, filename.c_str(), OPENMPT_NAMESPACE::PluginBridge::fullMemDump); + } -// This is kind of a back-up pointer in case we couldn't sneak our pointer into the AEffect struct yet. -// It always points to the last intialized PluginBridge object. -PluginBridge *PluginBridge::latestInstance = nullptr; -WNDCLASSEX PluginBridge::windowClass; -#define WINDOWCLASSNAME _T("OpenMPTPluginBridge") + // Let Windows handle the exception... + return EXCEPTION_CONTINUE_SEARCH; +} -enum { kVstTimeInfoInit = 1 << 31 }; - -OPENMPT_NAMESPACE_END - - int _tmain(int argc, TCHAR *argv[]) { if(argc != 2) @@ -74,6 +81,8 @@ return -1; } + ::SetUnhandledExceptionFilter(CrashHandler); + uint32_t parentProcessId = _ttoi(argv[1]); OPENMPT_NAMESPACE::PluginBridge::InitializeStaticVariables(); @@ -96,7 +105,19 @@ OPENMPT_NAMESPACE_BEGIN +LONG PluginBridge::instanceCount = 0; +Event PluginBridge::sigQuit; +bool PluginBridge::fullMemDump = false; +// This is kind of a back-up pointer in case we couldn't sneak our pointer into the AEffect struct yet. +// It always points to the last intialized PluginBridge object. +PluginBridge *PluginBridge::latestInstance = nullptr; +WNDCLASSEX PluginBridge::windowClass; +#define WINDOWCLASSNAME _T("OpenMPTPluginBridge") + +enum { kVstTimeInfoInit = 1 << 31 }; + + // Initialize static stuff like the editor window class void PluginBridge::InitializeStaticVariables() { @@ -363,9 +384,10 @@ { otherPtrSize = msg->hostPtrSize; mixBufSize = msg->mixBufSize; + fullMemDump = msg->fullMemDump != 0; msg->result = 0; msg->str[CountOf(msg->str) - 1] = 0; - + #ifdef _CONSOLE SetConsoleTitleW(msg->str); #endif Modified: trunk/OpenMPT/pluginBridge/Bridge.h =================================================================== --- trunk/OpenMPT/pluginBridge/Bridge.h 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/pluginBridge/Bridge.h 2014-09-11 23:33:32 UTC (rev 4277) @@ -19,6 +19,7 @@ { public: static Event sigQuit; + static bool fullMemDump; protected: static LONG instanceCount; Modified: trunk/OpenMPT/pluginBridge/BridgeCommon.h =================================================================== --- trunk/OpenMPT/pluginBridge/BridgeCommon.h 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/pluginBridge/BridgeCommon.h 2014-09-11 23:33:32 UTC (rev 4277) @@ -276,6 +276,7 @@ int32_t version; // Protocol version used by host int32_t hostPtrSize; // Size of VstIntPtr in host uint32_t mixBufSize; // Interal mix buffer size (for shared memory audio buffers) + uint32_t fullMemDump; // When crashing, create full memory dumps instead of stack dumps wchar_t str[_MAX_PATH]; // Plugin file to load. Out: Error message if result != 0. }; @@ -333,13 +334,14 @@ wcsncpy(newInstance.memName, memName, CountOf(newInstance.memName) - 1); } - void Init(const wchar_t *pluginPath, uint32_t mixBufSize) + void Init(const wchar_t *pluginPath, uint32_t mixBufSize, bool fullMemDump) { SetType(MsgHeader::init, sizeof(InitMsg)); init.result = 0; init.hostPtrSize = sizeof(VstIntPtr); init.mixBufSize = mixBufSize; + init.fullMemDump = fullMemDump; wcsncpy(init.str, pluginPath, CountOf(init.str) - 1); } Modified: trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp =================================================================== --- trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp 2014-09-11 19:18:01 UTC (rev 4276) +++ trunk/OpenMPT/pluginBridge/BridgeWrapper.cpp 2014-09-11 23:33:32 UTC (rev 4277) @@ -15,6 +15,7 @@ #include "misc_util.h" #include "../mptrack/Mptrack.h" #include "../mptrack/Vstplug.h" +#include "../mptrack/ExceptionHandler.h" #include "../common/mptFstream.h" #include "../common/thread.h" #include "../common/StringFixer.h" @@ -211,7 +212,7 @@ otherThread = mpt::thread_member<BridgeWrapper, &BridgeWrapper::MessageThread>(this); BridgeMessage initMsg; - initMsg.Init(pluginPath.ToWide().c_str(), MIXBUFFERSIZE); + initMsg.Init(pluginPath.ToWide().c_str(), MIXBUFFERSIZE, ExceptionHandler::fullMemDump); if(!SendToBridge(initMsg)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |