All pastes #500038 Raw Edit

Something

public text v1 · immutable
·published 2007-05-21 12:06 UTC
rendered paste body
Index: src/mangosd/Makefile.am
===================================================================
--- src/mangosd/Makefile.am	(revision 3680)
+++ src/mangosd/Makefile.am	(working copy)
@@ -39,7 +39,9 @@
 ## Additional files to include when running 'make dist'
 #  Include world daemon configuration
 EXTRA_DIST = \
-	mangosd.conf
+	mangosd.conf \
+	mdump.cpp \
+	mdump.h
 
 ## Additional files to install
 sysconf_DATA = \
Index: src/mangosd/Master.cpp
===================================================================
--- src/mangosd/Master.cpp	(revision 3680)
+++ src/mangosd/Master.cpp	(working copy)
@@ -42,6 +42,10 @@
 #include "Network/Parse.h"
 #include "Network/Socket.h"
 
+#ifdef WIN32
+#include "mdump.h"  
+#endif  
+
 /// \todo Warning disabling not useful under VC++2005. Can somebody say on which compiler it is useful?
 #pragma warning(disable:4305)
 
@@ -80,6 +84,9 @@
 /// Main function
 void Master::Run()
 {
+    #ifdef WIN32
+        MiniDumper("mangosd.exe");
+    #endif    
     sLog.outString( "MaNGOS daemon %s", _FULLVERSION );
     sLog.outString( "<Ctrl-C> to stop.\n\n" );
 
Index: src/mangosd/mdump.cpp
===================================================================
--- src/mangosd/mdump.cpp	(revision 0)
+++ src/mangosd/mdump.cpp	(revision 0)
@@ -0,0 +1,59 @@
+
+#include "mdump.h"
+
+LPCSTR MiniDumper::m_szAppName;
+
+MiniDumper::MiniDumper( LPCSTR szAppName )
+{
+	m_szAppName = szAppName ? _strdup(szAppName) : "Application";
+	::SetUnhandledExceptionFilter( TopLevelFilter );
+}
+
+LONG MiniDumper::TopLevelFilter( struct _EXCEPTION_POINTERS *pExceptionInfo )
+{
+	LONG retval = EXCEPTION_CONTINUE_SEARCH;
+	HWND hParent = NULL;
+	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 (hDll==NULL)
+		hDll = ::LoadLibrary( "DBGHELP.DLL" );
+
+	LPCTSTR szResult = NULL;
+	if (hDll)
+	{
+		MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
+		if (pDump)
+		{
+			char szDumpPath[_MAX_PATH];
+			SYSTEMTIME systime;
+			GetSystemTime(&systime);
+			sprintf_s(szDumpPath, "/Crash/%d-%d-%d-%d-%d-crash.dmp", systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);
+
+			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 = pExceptionInfo;
+				ExInfo.ClientPointers = NULL;
+				// write the dump
+				BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
+				if (bOK)
+					retval = EXCEPTION_EXECUTE_HANDLER;
+				::CloseHandle(hFile);
+			}
+		}
+	}
+	return retval;
+}
Index: src/mangosd/mdump.h
===================================================================
--- src/mangosd/mdump.h	(revision 0)
+++ src/mangosd/mdump.h	(revision 0)
@@ -0,0 +1,26 @@
+#ifndef _MDUMP_H_
+#define _MDUMP_H_
+
+#include <windows.h>
+#include <stdio.h>
+#include <tchar.h>
+#include "dbghelp.h"
+
+
+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
+									);
+
+class MiniDumper
+{
+private:
+	static LPCSTR m_szAppName;
+
+	static LONG WINAPI TopLevelFilter( struct _EXCEPTION_POINTERS *pExceptionInfo );
+
+public:
+	MiniDumper( LPCSTR szAppName );
+};
+#endif //_MDUMP_H_
Index: win/VC80/mangosd.vcproj
===================================================================
--- win/VC80/mangosd.vcproj	(revision 3680)
+++ win/VC80/mangosd.vcproj	(working copy)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="Windows-1252"?>
+<?xml version="1.0" encoding="windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="8.00"
+	Version="8,00"
 	Name="mangosd"
 	ProjectGUID="{A3A04E47-43A2-4C08-90B3-029CEF558594}"
 	RootNamespace="mangosd"
@@ -56,6 +56,7 @@
 				WarningLevel="3"
 				SuppressStartupBanner="true"
 				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
 				CompileAs="0"
 			/>
 			<Tool
@@ -77,7 +78,9 @@
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
 				AdditionalLibraryDirectories="..\..\dep\lib\release"
+				GenerateDebugInformation="true"
 				ProgramDatabaseFile=".\..\..\bin\Release/mangosd.pdb"
+				GenerateMapFile="true"
 				SubSystem="1"
 				ImportLibrary="$(OutDir)/mangosd.lib"
 			/>
@@ -260,6 +263,14 @@
 			>
 		</File>
 		<File
+			RelativePath="..\..\src\mangosd\mdump.cpp"
+			>
+		</File>
+		<File
+			RelativePath="..\..\src\mangosd\mdump.h"
+			>
+		</File>
+		<File
 			RelativePath="..\..\src\mangosd\RASocket.cpp"
 			>
 		</File>