From 1aa630e4a99af07aac165121b21814e15c20224e Mon Sep 17 00:00:00 2001 From: Koncord Date: Fri, 27 Oct 2017 05:27:00 +0800 Subject: [PATCH] [Server] Add StackWalker for Windows --- apps/openmw-mp/CMakeLists.txt | 4 + apps/openmw-mp/stacktrace.cpp | 23 ++- apps/openmw-mp/stackwalker/StackWalker.cpp | Bin 0 -> 84758 bytes apps/openmw-mp/stackwalker/StackWalker.h | 189 +++++++++++++++++++++ 4 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 apps/openmw-mp/stackwalker/StackWalker.cpp create mode 100644 apps/openmw-mp/stackwalker/StackWalker.h diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 2c521a529..93ad4768c 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -60,6 +60,10 @@ set(SERVER Script/CommandController.cpp Script/EventController.cpp Script/LuaState.cpp Script/luaUtils.cpp ) +if(WIN32) + list(APPEND SERVER stackwalker/StackWalker.cpp) +endif() + set(SERVER_HEADER ) diff --git a/apps/openmw-mp/stacktrace.cpp b/apps/openmw-mp/stacktrace.cpp index 858462a93..185f999a1 100644 --- a/apps/openmw-mp/stacktrace.cpp +++ b/apps/openmw-mp/stacktrace.cpp @@ -65,9 +65,30 @@ void stacktrace() #else -void stacktrace() +#include "stackwalker/StackWalker.h" + +class StackWalkerClr: public StackWalker { + std::string out; + virtual void OnOutput(LPCSTR szText) + { + out.append(szText); + } + +public: + std::string &getData() + { + ShowCallstack(); + return out; + } +}; + +void stacktrace() +{ + LOG_MESSAGE_SIMPLE(Log::LOG_FATAL, "Stacktrace:"); + StackWalkerClr swc; + LOG_APPEND(Log::LOG_FATAL, swc.getData().c_str()); } #endif \ No newline at end of file diff --git a/apps/openmw-mp/stackwalker/StackWalker.cpp b/apps/openmw-mp/stackwalker/StackWalker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c7787fd993104c87472cde32b2c6b58b91ccd149 GI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ScIPujC#qZzdYaapP4a0l)&OIi-@j88enRG8|jqvM3F z9&0g-LzM~+rRqgX&S&XaOwFMYLMjw*ttJaY@}LNUSx%f9K86$hEXJkPtK*UHtt#0- zaD4ua^SO!Z*uyUGLcGTe@F2|q`w>^x0j*uL{;o53^1V!f9A)P=W73e@xipj#?EVBg zmC>5GcbwGosF*i(_ou!*ah`;iOcG=SssqQ|8_ktufWgWb?B6SYwVqi1pMnx47FF}I31Ziu2m z#lBVs9eqAAMJkq)2CcNSWZc|nCB2XVT~QSg?pkr6 z6zRg|Xtj9D^j~`b+1btM7DRNsAr=Xtdh41|gH!d$oil%bVp8VkrRda(9gE4mzG7qc zNjEe8z)l`}-#&`x=%cK^;Hpf%F z$ZlS!dJPWIda6EPajC9BA2=~V&ko5g=NlfU?5h7CUw)B?F%8ojs(-ptu8iL=O= 1100)! +#pragma once + +#include + +// 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 = NULL, + 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 = NULL, + PReadProcessMemoryRoutine readMemoryFunction = NULL, + LPVOID pUserData = NULL // 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; + + 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 = NULL; \ + __try { \ + throw 0; \ + } __except( ( (pExp = GetExceptionInformation()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER)) {} \ + if (pExp != NULL) \ + 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