1
0

Removed the LeakFinder for Windows. (#3777)

This commit is contained in:
Mattes D 2017-06-19 11:05:19 +02:00 committed by GitHub
parent bb020bbe78
commit 7ac3b0fa0b
23 changed files with 1459 additions and 2916 deletions

View File

@ -49,6 +49,7 @@ set(SHARED_OSS_SRC
../../src/OSSupport/File.cpp
../../src/OSSupport/IsThread.cpp
../../src/OSSupport/StackTrace.cpp
../../src/OSSupport/WinStackWalker.cpp
)
set(SHARED_OSS_HDR
@ -57,12 +58,9 @@ set(SHARED_OSS_HDR
../../src/OSSupport/File.h
../../src/OSSupport/IsThread.h
../../src/OSSupport/StackTrace.h
../../src/OSSupport/WinStackWalker.h
)
if(WIN32)
list (APPEND SHARED_OSS_SRC ../../src/StackWalker.cpp)
list (APPEND SHARED_OSS_HDR ../../src/StackWalker.h)
endif()
flatten_files(SHARED_OSS_SRC)
flatten_files(SHARED_OSS_HDR)

View File

@ -51,6 +51,7 @@ set(SHARED_OSS_SRC
../../src/OSSupport/File.cpp
../../src/OSSupport/IsThread.cpp
../../src/OSSupport/StackTrace.cpp
../../src/OSSupport/WinStackWalker.cpp
)
set(SHARED_OSS_HDR
@ -59,12 +60,9 @@ set(SHARED_OSS_HDR
../../src/OSSupport/File.h
../../src/OSSupport/IsThread.h
../../src/OSSupport/StackTrace.h
../../src/OSSupport/WinStackWalker.h
)
if(WIN32)
list (APPEND SHARED_OSS_SRC ../../src/StackWalker.cpp)
list (APPEND SHARED_OSS_HDR ../../src/StackWalker.h)
endif()
flatten_files(SHARED_OSS_SRC)
flatten_files(SHARED_OSS_HDR)

View File

@ -18,9 +18,11 @@ set(SHARED_SRC
../../src/OSSupport/CriticalSection.cpp
../../src/OSSupport/File.cpp
../../src/OSSupport/StackTrace.cpp
../../src/OSSupport/WinStackWalker.cpp
../../src/Noise/Noise.cpp
../../src/StringUtils.cpp
)
set(SHARED_HDR
../../src/Noise/Noise.h
../../src/Noise/OctavedNoise.h
@ -28,13 +30,10 @@ set(SHARED_HDR
../../src/OSSupport/CriticalSection.h
../../src/OSSupport/File.h
../../src/OSSupport/StackTrace.h
../../src/OSSupport/WinStackWalker.h
../../src/StringUtils.h
)
if(WIN32)
list (APPEND SHARED_SRC ../../src/StackWalker.cpp)
list (APPEND SHARED_HDR ../../src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR})

View File

@ -54,20 +54,18 @@ set(SHARED_OSS_SRC
../../src/OSSupport/File.cpp
../../src/OSSupport/IsThread.cpp
../../src/OSSupport/StackTrace.cpp
../../src/OSSupport/WinStackWalker.cpp
)
set(SHARED_OSS_HDR
../../src/OSSupport/CriticalSection.h
../../src/OSSupport/Event.h
../../src/OSSupport/File.h
../../src/OSSupport/IsThread.h
../../src/OSSupport/StackTrace.h
../../src/OSSupport/WinStackWalker.h
)
if(WIN32)
list (APPEND SHARED_OSS_SRC ../../src/StackWalker.cpp)
list (APPEND SHARED_OSS_HDR ../../src/StackWalker.h)
endif()
flatten_files(SHARED_SRC)
flatten_files(SHARED_HDR)
flatten_files(SHARED_OSS_SRC)

View File

@ -202,10 +202,6 @@ if (NOT MSVC)
else ()
# MSVC-specific handling: Put all files into one project, separate by the folders:
# Add the MSVC-specific LeakFinder sources:
list (APPEND SRCS LeakFinder.cpp StackWalker.cpp)
list (APPEND HDRS LeakFinder.h StackWalker.h MemoryLeak.h)
source_group(Bindings FILES "Bindings/Bindings.cpp" "Bindings/Bindings.h")
# Add all subfolders as solution-folders:
@ -258,9 +254,6 @@ else ()
SET_SOURCE_FILES_PROPERTIES(
Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS "/Yc\"string.h\" /Fp\"$(IntDir)/Bindings.pch\""
)
SET_SOURCE_FILES_PROPERTIES(
"StackWalker.cpp LeakFinder.cpp" PROPERTIES COMPILE_FLAGS "/Yc\"Globals.h\""
)
list(APPEND SOURCE "Resources/Cuberite.rc")
# Make MSVC generate the PDB files even for the release build:

File diff suppressed because it is too large Load Diff

View File

@ -1,156 +0,0 @@
/**********************************************************************
*
* LEAKFINDER.H
*
*
*
* LICENSE (http://www.opensource.org/licenses/bsd-license.php)
*
* Copyright (c) 2005-2010, Jochen Kalmbach
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of Jochen Kalmbach nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
**********************************************************************/
// #pragma once is supported starting with _MCS_VER 1000,
// so we need not to check the version (because we only support _MSC_VER >= 1100)!
#pragma once
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
HRESULT InitLeakFinder();
void DeinitLeakFinder();
#ifdef __cplusplus
}
#endif
// The following is only available if the file is CPP
#ifdef __cplusplus
#include "StackWalker.h"
// Interface for output...
class LeakFinderOutput : public StackWalker
{
public:
typedef enum LeakFinderOptions
{
// No addition info will be retrived
// (only the address is available)
LeakFinderNone = 0,
LeakFinderShowCompleteCallstack = 0x1000
} LeakFinderOptions;
LeakFinderOutput(int options = OptionsAll, LPCSTR szSymPath = nullptr);
virtual void OnLeakSearchStart(LPCSTR sszLeakFinderName);
virtual void OnLeakStartEntry(LPCSTR szKeyName, SIZE_T nDataSize);
protected:
virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry);
virtual void OnOutput(LPCSTR szText)
{
printf(szText);
StackWalker::OnOutput(szText);
}
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr)
{
if (strcmp(szFuncName, "SymGetLineFromAddr64") == 0) return;
StackWalker::OnDbgHelpErr(szFuncName, gle, addr);
}
};
class LeakFinderXmlOutput : public LeakFinderOutput
{
public:
LeakFinderXmlOutput();
virtual ~LeakFinderXmlOutput();
LeakFinderXmlOutput(LPCTSTR szFileName);
virtual void OnLeakSearchStart(LPCSTR sszLeakFinderName);
virtual void OnLeakStartEntry(LPCSTR szKeyName, SIZE_T nDataSize);
protected:
virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry);
virtual void OnOutput(LPCSTR szText) { }
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr) { }
FILE * m_fXmlFile;
int m_Progress;
};
// C++ interface:
void DeinitLeakFinder(LeakFinderOutput *output);
class ZZZ_LeakFinder
{
public:
ZZZ_LeakFinder()
{
m_pXml = nullptr;
#ifdef XML_LEAK_FINDER
m_pXml = new LeakFinderXmlOutput();
#endif
InitLeakFinder();
}
~ZZZ_LeakFinder()
{
DeinitLeakFinder(m_pXml);
if (m_pXml != nullptr) delete m_pXml;
}
protected:
LeakFinderXmlOutput *m_pXml;
};
#if defined(INIT_LEAK_FINDER)
#if _MSC_VER >= 1200
#pragma warning(push)
#endif
#pragma warning (disable:4074)
// WARNING: If you enable this option, the code might run without the CRT being initialized or after the CRT was deinitialized!!!
// Currently the code is not designed to bypass the CRT...
//#pragma init_seg (compiler)
ZZZ_LeakFinder zzz_LeakFinder;
#if _MSC_VER >= 1200
#pragma warning(pop)
#else
#pragma warning(default:4074)
#endif
#endif
#endif // __cplusplus
extern void DumpUsedMemory(LeakFinderOutput * output = nullptr);

View File

@ -1,19 +0,0 @@
#pragma once
#ifdef _WIN32
#ifdef _DEBUG
// Enable the CRT debugging features:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
// This works only in MSVC 2010+:
#if _MSC_VER >= 1600
// Map the new operator
#ifndef DEBUG_NEW
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif // _CRTDBG_MAP_ALLOC
#endif // _MSC_VER
#endif // _DEBUG
#endif // _WIN32

View File

@ -18,6 +18,7 @@ SET (SRCS
StackTrace.cpp
TCPLinkImpl.cpp
UDPEndpointImpl.cpp
WinStackWalker.cpp
)
SET (HDRS
@ -38,6 +39,7 @@ SET (HDRS
StackTrace.h
TCPLinkImpl.h
UDPEndpointImpl.h
WinStackWalker.h
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

View File

@ -6,7 +6,7 @@
#include "Globals.h"
#include "StackTrace.h"
#ifdef _WIN32
#include "../StackWalker.h"
#include "WinStackWalker.h"
#elif !defined(ANDROID) // The Android NDK has no execinfo header
#ifdef __GLIBC__
#include <execinfo.h>
@ -21,10 +21,8 @@
void PrintStackTrace(void)
{
#ifdef _WIN32
// Reuse the StackWalker from the LeakFinder project already bound to MCS
// Define a subclass of the StackWalker that outputs everything to stdout
class PrintingStackWalker :
public StackWalker
class PrintingStackWalker:
public WinStackWalker
{
virtual void OnOutput(LPCSTR szText) override
{

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,173 @@
// WinStackWalker.h
// Declares the stack walking for Windows binaries
/*
LICENSE (http://www.opensource.org/licenses/bsd-license.php)
Copyright (c) 2005-2010, Jochen Kalmbach
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution.
Neither the name of Jochen Kalmbach nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#ifdef _WIN32 // This is Windows-only code
class StackWalkerInternal; // forward
class WinStackWalker
{
public:
enum StackWalkOptions
{
// No addition info will be retrived
// (only the address is available)
RetrieveNone = 0,
// Try to get the symbol-name
RetrieveSymbol = 1,
// Try to get the line for this symbol
RetrieveLine = 2,
// Try to retrieve the module-infos
RetrieveModuleInfo = 4,
// Also retrieve the version for the DLL / EXE
RetrieveFileVersion = 8,
// Contains all the abouve
RetrieveVerbose = 0xF,
// Generate a "good" symbol-search-path
SymBuildPath = 0x10,
// Also use the public Microsoft-Symbol-Server
SymUseSymSrv = 0x20,
// Contains all the abouve "Sym"-options
SymAll = 0x30,
// Contains all options (default)
OptionsAll = 0x3F
};
WinStackWalker(
int options = OptionsAll,
LPCSTR szSymPath = nullptr,
DWORD dwProcessId = GetCurrentProcessId(),
HANDLE hProcess = GetCurrentProcess()
);
WinStackWalker(DWORD dwProcessId, HANDLE hProcess);
virtual ~WinStackWalker();
typedef BOOL(__stdcall *PReadProcessMemoryRoutine)(
HANDLE hProcess,
DWORD64 qwBaseAddress,
PVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesRead,
LPVOID pUserData // optional data, which was passed in "ShowCallstack"
);
BOOL LoadModules();
BOOL ShowCallstack(
HANDLE hThread = GetCurrentThread(),
const CONTEXT *context = nullptr,
PReadProcessMemoryRoutine readMemoryFunction = nullptr,
LPVOID pUserData = nullptr // optional to identify some data in the 'readMemoryFunction'-callback
);
protected:
enum
{
STACKWALK_MAX_NAMELEN = 1024, ///< Max name length for found symbols
};
protected:
// Entry for each Callstack-Entry
struct CallstackEntry
{
DWORD64 offset; // if 0, we have no valid entry
CHAR name[STACKWALK_MAX_NAMELEN];
CHAR undName[STACKWALK_MAX_NAMELEN];
CHAR undFullName[STACKWALK_MAX_NAMELEN];
DWORD64 offsetFromSmybol;
DWORD offsetFromLine;
DWORD lineNumber;
CHAR lineFileName[STACKWALK_MAX_NAMELEN];
DWORD symType;
LPCSTR symTypeString;
CHAR moduleName[STACKWALK_MAX_NAMELEN];
DWORD64 baseOfImage;
CHAR loadedImageName[STACKWALK_MAX_NAMELEN];
};
enum CallstackEntryType { firstEntry, nextEntry, lastEntry };
virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName);
virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion);
virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry);
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr);
virtual void OnOutput(LPCSTR szText);
StackWalkerInternal *m_sw;
HANDLE m_hProcess;
DWORD m_dwProcessId;
BOOL m_modulesLoaded;
LPSTR m_szSymPath;
int m_options;
int m_MaxRecursionCount;
static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
friend StackWalkerInternal;
};
#define GET_CURRENT_CONTEXT(c, contextFlags) \
do \
{ \
memset(&c, 0, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
RtlCaptureContext(&c); \
} while (false);
#endif // _WIN32

View File

@ -34,22 +34,6 @@ extern "C"
/** Enable the memory leak finder - needed for the "dumpmem" server command:
Synchronize this with main.cpp - the leak finder needs initialization before it can be used to dump memory
_X 2014_02_20: Disabled for canon repo, it makes the debug version too slow in MSVC2013
and we haven't had a memory leak for over a year anyway. */
// #define ENABLE_LEAK_FINDER
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
#pragma warning(push)
#pragma warning(disable:4100)
#include "LeakFinder.h"
#pragma warning(pop)
#endif
typedef std::list< cClientHandle* > ClientList;
@ -535,23 +519,6 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
a_Output.Finished();
return;
}
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
else if (split[0].compare("dumpmem") == 0)
{
LeakFinderXmlOutput Output("memdump.xml");
DumpUsedMemory(&Output);
return;
}
else if (split[0].compare("killmem") == 0)
{
for (;;)
{
new char[100 * 1024 * 1024]; // Allocate and leak 100 MiB in a loop -> fill memory and kill MCS
}
}
#endif
else if (cPluginManager::Get()->ExecuteConsoleCommand(split, a_Output, a_Cmd))
{
a_Output.Finished();
@ -637,10 +604,6 @@ void cServer::BindBuiltInConsoleCommands(void)
PlgMgr->BindConsoleCommand("load", nullptr, handler, "Adds and enables the specified plugin");
PlgMgr->BindConsoleCommand("unload", nullptr, handler, "Disables the specified plugin");
PlgMgr->BindConsoleCommand("destroyentities", nullptr, handler, "Destroys all entities in all worlds");
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
PlgMgr->BindConsoleCommand("dumpmem", nullptr, handler, " - Dumps all used memory blocks together with their callstacks into memdump.xml");
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -1,214 +0,0 @@
/**********************************************************************
*
* StackWalker.h
*
*
*
* LICENSE (http://www.opensource.org/licenses/bsd-license.php)
*
* Copyright (c) 2005-2010, Jochen Kalmbach
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of Jochen Kalmbach nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* **********************************************************************/
// #pragma once is supported starting with _MCS_VER 1000,
// so we need not to check the version (because we only support _MSC_VER >= 1100)!
#pragma once
#include <windows.h>
// special defines for VC5/6 (if no actual PSDK is installed):
#if _MSC_VER < 1300
typedef unsigned __int64 DWORD64, *PDWORD64;
#if defined(_WIN64)
typedef unsigned __int64 SIZE_T, *PSIZE_T;
#else
typedef unsigned long SIZE_T, *PSIZE_T;
#endif
#endif // _MSC_VER < 1300
class StackWalkerInternal; // forward
class StackWalker
{
public:
typedef enum StackWalkOptions
{
// No addition info will be retrived
// (only the address is available)
RetrieveNone = 0,
// Try to get the symbol-name
RetrieveSymbol = 1,
// Try to get the line for this symbol
RetrieveLine = 2,
// Try to retrieve the module-infos
RetrieveModuleInfo = 4,
// Also retrieve the version for the DLL/EXE
RetrieveFileVersion = 8,
// Contains all the abouve
RetrieveVerbose = 0xF,
// Generate a "good" symbol-search-path
SymBuildPath = 0x10,
// Also use the public Microsoft-Symbol-Server
SymUseSymSrv = 0x20,
// Contains all the abouve "Sym"-options
SymAll = 0x30,
// Contains all options (default)
OptionsAll = 0x3F
} StackWalkOptions;
StackWalker(
int options = OptionsAll, // 'int' is by design, to combine the enum-flags
LPCSTR szSymPath = nullptr,
DWORD dwProcessId = GetCurrentProcessId(),
HANDLE hProcess = GetCurrentProcess()
);
StackWalker(DWORD dwProcessId, HANDLE hProcess);
virtual ~StackWalker();
typedef BOOL (__stdcall *PReadProcessMemoryRoutine)(
HANDLE hProcess,
DWORD64 qwBaseAddress,
PVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesRead,
LPVOID pUserData // optional data, which was passed in "ShowCallstack"
);
BOOL LoadModules();
BOOL ShowCallstack(
HANDLE hThread = GetCurrentThread(),
const CONTEXT *context = nullptr,
PReadProcessMemoryRoutine readMemoryFunction = nullptr,
LPVOID pUserData = nullptr // optional to identify some data in the 'readMemoryFunction'-callback
);
#if _MSC_VER >= 1300
// due to some reasons, the "STACKWALK_MAX_NAMELEN" must be declared as "public"
// in older compilers in order to use it... starting with VC7 we can declare it as "protected"
protected:
#endif
enum { STACKWALK_MAX_NAMELEN = 1024 }; // max name length for found symbols
protected:
// Entry for each Callstack-Entry
typedef struct CallstackEntry
{
DWORD64 offset; // if 0, we have no valid entry
CHAR name[STACKWALK_MAX_NAMELEN];
CHAR undName[STACKWALK_MAX_NAMELEN];
CHAR undFullName[STACKWALK_MAX_NAMELEN];
DWORD64 offsetFromSmybol;
DWORD offsetFromLine;
DWORD lineNumber;
CHAR lineFileName[STACKWALK_MAX_NAMELEN];
DWORD symType;
LPCSTR symTypeString;
CHAR moduleName[STACKWALK_MAX_NAMELEN];
DWORD64 baseOfImage;
CHAR loadedImageName[STACKWALK_MAX_NAMELEN];
} CallstackEntry;
typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry};
virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName);
virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion);
virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry);
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr);
virtual void OnOutput(LPCSTR szText);
StackWalkerInternal *m_sw;
HANDLE m_hProcess;
DWORD m_dwProcessId;
BOOL m_modulesLoaded;
LPSTR m_szSymPath;
int m_options;
int m_MaxRecursionCount;
static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
friend StackWalkerInternal;
};
// The "ugly" assembler-implementation is needed for systems before XP
// If you have a new PSDK and you only compile for XP and later, then you can use
// the "RtlCaptureContext"
// Currently there is no define which determines the PSDK-Version...
// So we just use the compiler-version (and assumes that the PSDK is
// the one which was installed by the VS-IDE)
// INFO: If you want, you can use the RtlCaptureContext if you only target XP and later...
// But I currently use it in x64/IA64 environments...
//#if defined(_M_IX86) && (_WIN32_WINNT <= 0x0500) && (_MSC_VER < 1400)
#if defined(_M_IX86)
#ifdef CURRENT_THREAD_VIA_EXCEPTION
// TODO: The following is not a "good" implementation,
// because the callstack is only valid in the "__except" block...
#define GET_CURRENT_CONTEXT(c, contextFlags) \
do { \
memset(&c, 0, sizeof(CONTEXT)); \
EXCEPTION_POINTERS *pExp = nullptr; \
__try { \
throw 0; \
} __except( ( (pExp = GetExceptionInformation()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER)) {} \
if (pExp != nullptr) \
memcpy(&c, pExp->ContextRecord, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
} while(0);
#else
// The following should be enough for walking the callstack...
#define GET_CURRENT_CONTEXT(c, contextFlags) \
do { \
memset(&c, 0, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
__asm call x \
__asm x: pop eax \
__asm mov c.Eip, eax \
__asm mov c.Ebp, ebp \
__asm mov c.Esp, esp \
} while(0);
#endif
#else
// The following is defined for x86 (XP and higher), x64 and IA64:
#define GET_CURRENT_CONTEXT(c, contextFlags) \
do { \
memset(&c, 0, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
RtlCaptureContext(&c); \
} while(0);
#endif

View File

@ -71,27 +71,6 @@ bool cRoot::m_RunAsService = false;
/** If defined, a thorough leak finder will be used (debug MSVC only); leaks will be output to the Output window
_X 2014_02_20: Disabled for canon repo, it makes the debug version too slow in MSVC2013
and we haven't had a memory leak for over a year anyway.
Synchronize this with Server.cpp to enable the "dumpmem" console command. */
// #define ENABLE_LEAK_FINDER
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
#pragma warning(push)
#pragma warning(disable:4100)
#include "LeakFinder.h"
#pragma warning(pop)
#endif
#ifndef _DEBUG
static void NonCtrlHandler(int a_Signal)
{
@ -470,10 +449,6 @@ static std::unique_ptr<cMemorySettingsRepository> ParseArguments(int argc, char
int main(int argc, char ** argv)
{
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
InitLeakFinder();
#endif
// Magic code to produce dump-files on Windows if the server crashes:
#if defined(_WIN32) && !defined(_WIN64) && defined(_MSC_VER) // 32-bit Windows app compiled in MSVC
HINSTANCE hDbgHelp = LoadLibrary(L"DBGHELP.DLL");
@ -571,10 +546,5 @@ int main(int argc, char ** argv)
UniversalMain(ParseArguments(argc, argv));
}
}
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
DeinitLeakFinder();
#endif
return EXIT_SUCCESS;
}

View File

@ -8,22 +8,19 @@ add_definitions(-DTEST_GLOBALS=1)
set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/BoundingBox.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
)
set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/BoundingBox.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h
)
set (SRCS
BoundingBoxTest.cpp
)
if (MSVC)
# Add the MSVC-specific LeakFinder / StackTracer sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS})

View File

@ -8,23 +8,19 @@ add_definitions(-DTEST_GLOBALS=1)
set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/ByteBuffer.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
)
set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/ByteBuffer.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h
)
set (SRCS
ByteBufferTest.cpp
)
if (MSVC)
# Add the MSVC-specific LeakFinder / StackTracer sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS})
add_executable(ByteBuffer-exe ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS})

View File

@ -10,11 +10,13 @@ add_definitions(-DTEST_GLOBALS=1)
set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/CompositeChat.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
)
set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/CompositeChat.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
)
set (SRCS
@ -22,11 +24,6 @@ set (SRCS
ClientHandle.cpp
)
if (MSVC)
# Add the MSVC-specific LeakFinder / StackTracer sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS})

View File

@ -8,22 +8,19 @@ add_definitions(-DTEST_GLOBALS=1)
set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/FastRandom.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
)
set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/FastRandom.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h
)
set (SRCS
FastRandomTest.cpp
)
if (MSVC)
# Add the MSVC-specific LeakFinder / StackTracer sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS})

View File

@ -30,6 +30,7 @@ set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/OSSupport/File.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.cpp
${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.cpp
@ -60,6 +61,7 @@ set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/OSSupport/File.h
${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h
${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.h
${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.h
@ -79,11 +81,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()
if (MSVC)
# Add the MSVC-specific LeakFinder sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
add_library(GeneratorTestingSupport STATIC ${SHARED_SRCS} ${SHARED_HDRS} ${STUBS})
target_link_libraries(GeneratorTestingSupport tolualib zlib)

View File

@ -30,6 +30,7 @@ set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/OSSupport/File.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.cpp
${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.cpp
@ -60,6 +61,7 @@ set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/OSSupport/File.h
${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h
${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.h
${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.h
@ -74,11 +76,6 @@ set (SRCS
)
if (MSVC)
# Add the MSVC-specific LeakFinder sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS})

View File

@ -21,6 +21,7 @@ set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/OSSupport/File.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp
${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.cpp
${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.cpp
@ -51,6 +52,7 @@ set (SHARED_HDRS
${CMAKE_SOURCE_DIR}/src/OSSupport/File.h
${CMAKE_SOURCE_DIR}/src/OSSupport/GZipFile.h
${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h
${CMAKE_SOURCE_DIR}/src/WorldStorage/FastNBT.h
${CMAKE_SOURCE_DIR}/src/WorldStorage/SchematicFileSerializer.h
@ -67,11 +69,6 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()
if (MSVC)
# Add the MSVC-specific LeakFinder sources:
list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
endif()
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS})