Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasimir666 <casimir666@users.sourceforge.net>2008-07-06 12:19:07 +0400
committerCasimir666 <casimir666@users.sourceforge.net>2008-07-06 12:19:07 +0400
commit8254e266efe92fb8fc83960813c031f4d3c88aeb (patch)
treee63688fa14781b013246c643f9c9f59d035b1b96 /src/apps/mplayerc/MiniDump.cpp
parent3cc1331eb308fe04b8ac57826f670924de52db61 (diff)
NEW : creation of minidump when mpc crash
FIXED : Crash with CoreAVC when changing "prefered decoder" setting during playback FIXED : Missing checkmarks on "tearing test" and "display stats" options (bug #2010857) git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@631 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/apps/mplayerc/MiniDump.cpp')
-rw-r--r--src/apps/mplayerc/MiniDump.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/src/apps/mplayerc/MiniDump.cpp b/src/apps/mplayerc/MiniDump.cpp
new file mode 100644
index 000000000..e5ebe9a77
--- /dev/null
+++ b/src/apps/mplayerc/MiniDump.cpp
@@ -0,0 +1,159 @@
+/*
+ * $Id$
+ *
+ * (C) 2006-2007 see AUTHORS
+ *
+ * This file is part of mplayerc.
+ *
+ * Mplayerc is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Mplayerc is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "StdAfx.h"
+#include "resource.h"
+#include "DbgHelp.h"
+
+class CMiniDump
+{
+public:
+ CMiniDump();
+
+private :
+ static LONG WINAPI UnhandledExceptionFilter(_EXCEPTION_POINTERS *lpTopLevelExceptionFilter);
+ static BOOL PreventSetUnhandledExceptionFilter();
+};
+
+CMiniDump _Singleton;
+
+
+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
+ );
+
+
+CMiniDump::CMiniDump ()
+{
+ SetUnhandledExceptionFilter (UnhandledExceptionFilter);
+
+#ifndef _WIN64
+ // Enable catching in CRT (http://blog.kalmbachnet.de/?postid=75)
+ PreventSetUnhandledExceptionFilter();
+#endif
+}
+
+LPTOP_LEVEL_EXCEPTION_FILTER WINAPI MyDummySetUnhandledExceptionFilter(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter)
+{
+ return NULL;
+}
+
+
+BOOL CMiniDump::PreventSetUnhandledExceptionFilter()
+{
+ HMODULE hKernel32 = LoadLibrary(_T("kernel32.dll"));
+ if (hKernel32 == NULL) return FALSE;
+ void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter");
+ if(pOrgEntry == NULL) return FALSE;
+ unsigned char newJump[ 100 ];
+ DWORD dwOrgEntryAddr = (DWORD) pOrgEntry;
+ dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far
+ void *pNewFunc = &MyDummySetUnhandledExceptionFilter;
+ DWORD dwNewEntryAddr = (DWORD) pNewFunc;
+ DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr;
+
+ newJump[ 0 ] = 0xE9; // JMP absolute
+ memcpy(&newJump[ 1 ], &dwRelativeAddr, sizeof(pNewFunc));
+ SIZE_T bytesWritten;
+ BOOL bRet = WriteProcessMemory(GetCurrentProcess(),
+ pOrgEntry, newJump, sizeof(pNewFunc) + 1, &bytesWritten);
+ return bRet;
+}
+
+
+LONG WINAPI CMiniDump::UnhandledExceptionFilter(_EXCEPTION_POINTERS *lpTopLevelExceptionFilter)
+{
+ LONG retval = EXCEPTION_CONTINUE_SEARCH;
+ HWND hParent = NULL;
+ HMODULE hDll = NULL;
+ TCHAR szResult[800];
+ TCHAR 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)
+
+ if (GetModuleFileName( NULL, szDbgHelpPath, _MAX_PATH ))
+ {
+ TCHAR *pSlash = _tcsrchr( szDbgHelpPath, _T('\\') );
+ if (pSlash)
+ {
+ _tcscpy_s( pSlash+1, _MAX_PATH+szDbgHelpPath-pSlash, _T("DBGHELP.DLL") );
+ hDll = ::LoadLibrary( szDbgHelpPath );
+ }
+ }
+
+ if (hDll==NULL)
+ {
+ // load any version we can
+ hDll = ::LoadLibrary(_T("DBGHELP.DLL"));
+ }
+
+ if (hDll)
+ {
+ MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
+ if (pDump)
+ {
+ TCHAR szDumpPath[_MAX_PATH];
+
+ GetModuleFileName (NULL, szDumpPath, _MAX_PATH);
+ _tcscat_s( szDumpPath, _MAX_PATH, _T(".dmp") );
+
+ // 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;
+
+ ExInfo.ThreadId = ::GetCurrentThreadId();
+ ExInfo.ExceptionPointers = lpTopLevelExceptionFilter;
+ ExInfo.ClientPointers = NULL;
+
+ // write the dump
+ BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
+ if (bOK)
+ {
+ _stprintf_s(szResult, countof(szResult), ResStr(IDS_MPC_CRASH), szDumpPath );
+ retval = EXCEPTION_EXECUTE_HANDLER;
+ }
+ else
+ {
+ _stprintf_s(szResult, countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), szDumpPath, GetLastError() );
+ }
+ ::CloseHandle(hFile);
+ }
+ else
+ {
+ _stprintf_s(szResult, countof(szResult), ResStr(IDS_MPC_MINIDUMP_FAIL), szDumpPath, GetLastError() );
+ }
+ }
+ }
+
+ if (szResult)
+ MessageBox (NULL, szResult, _T("MPC-HC Mini Dump"), MB_OK);
+
+ return retval;
+}