mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 10:00:28 +00:00
feat(Core/Debugging): improve crash reports (#2365)
* Enabled crash reports for Windows
This commit is contained in:
@@ -3,14 +3,19 @@
|
||||
|
||||
#if PLATFORM == PLATFORM_WINDOWS && !defined(__MINGW32__)
|
||||
|
||||
#include <winnt.h>
|
||||
#include <winternl.h>
|
||||
#include <dbghelp.h>
|
||||
#include <set>
|
||||
#if _MSC_VER < 1400
|
||||
# define countof(array) (sizeof(array) / sizeof(array[0]))
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
# define countof _countof
|
||||
#endif // _MSC_VER < 1400
|
||||
#include <stdlib.h>
|
||||
#include <stack>
|
||||
#include <mutex>
|
||||
#define countof _countof
|
||||
|
||||
#define WER_MAX_ARRAY_ELEMENTS_COUNT 10
|
||||
#define WER_MAX_NESTING_LEVEL 4
|
||||
#define WER_SMALL_BUFFER_SIZE 1024
|
||||
#define WER_LARGE_BUFFER_SIZE WER_SMALL_BUFFER_SIZE * 16
|
||||
|
||||
enum BasicType // Stolen from CVCONST.H in the DIA 2.0 SDK
|
||||
{
|
||||
@@ -37,40 +42,54 @@ enum BasicType // Stolen from CVCON
|
||||
btStdString = 101
|
||||
};
|
||||
|
||||
const char* const rgBaseType[] =
|
||||
enum DataKind // Stolen from CVCONST.H in the DIA 2.0 SDK
|
||||
{
|
||||
" <user defined> ", // btNoType = 0,
|
||||
" void ", // btVoid = 1,
|
||||
" char* ", // btChar = 2,
|
||||
" wchar_t* ", // btWChar = 3,
|
||||
" signed char ",
|
||||
" unsigned char ",
|
||||
" int ", // btInt = 6,
|
||||
" unsigned int ", // btUInt = 7,
|
||||
" float ", // btFloat = 8,
|
||||
" <BCD> ", // btBCD = 9,
|
||||
" bool ", // btBool = 10,
|
||||
" short ",
|
||||
" unsigned short ",
|
||||
" long ", // btLong = 13,
|
||||
" unsigned long ", // btULong = 14,
|
||||
" __int8 ",
|
||||
" __int16 ",
|
||||
" __int32 ",
|
||||
" __int64 ",
|
||||
" __int128 ",
|
||||
" unsigned __int8 ",
|
||||
" unsigned __int16 ",
|
||||
" unsigned __int32 ",
|
||||
" unsigned __int64 ",
|
||||
" unsigned __int128 ",
|
||||
" <currency> ", // btCurrency = 25,
|
||||
" <date> ", // btDate = 26,
|
||||
" VARIANT ", // btVariant = 27,
|
||||
" <complex> ", // btComplex = 28,
|
||||
" <bit> ", // btBit = 29,
|
||||
" BSTR ", // btBSTR = 30,
|
||||
" HRESULT " // btHresult = 31
|
||||
DataIsUnknown,
|
||||
DataIsLocal,
|
||||
DataIsStaticLocal,
|
||||
DataIsParam,
|
||||
DataIsObjectPtr,
|
||||
DataIsFileStatic,
|
||||
DataIsGlobal,
|
||||
DataIsMember,
|
||||
DataIsStaticMember,
|
||||
DataIsConstant
|
||||
};
|
||||
|
||||
char const* const rgBaseType[] =
|
||||
{
|
||||
"<user defined>", // btNoType = 0,
|
||||
"void", // btVoid = 1,
|
||||
"char",//char* // btChar = 2,
|
||||
"wchar_t*", // btWChar = 3,
|
||||
"signed char",
|
||||
"unsigned char",
|
||||
"int", // btInt = 6,
|
||||
"unsigned int", // btUInt = 7,
|
||||
"float", // btFloat = 8,
|
||||
"<BCD>", // btBCD = 9,
|
||||
"bool", // btBool = 10,
|
||||
"short",
|
||||
"unsigned short",
|
||||
"long", // btLong = 13,
|
||||
"unsigned long", // btULong = 14,
|
||||
"int8",
|
||||
"int16",
|
||||
"int32",
|
||||
"int64",
|
||||
"int128",
|
||||
"uint8",
|
||||
"uint16",
|
||||
"uint32",
|
||||
"uint64",
|
||||
"uint128",
|
||||
"<currency>", // btCurrency = 25,
|
||||
"<date>", // btDate = 26,
|
||||
"VARIANT", // btVariant = 27,
|
||||
"<complex>", // btComplex = 28,
|
||||
"<bit>", // btBit = 29,
|
||||
"BSTR", // btBSTR = 30,
|
||||
"HRESULT" // btHresult = 31
|
||||
};
|
||||
|
||||
struct SymbolPair
|
||||
@@ -81,9 +100,9 @@ struct SymbolPair
|
||||
_offset = offset;
|
||||
}
|
||||
|
||||
bool operator<(const SymbolPair& other) const
|
||||
bool operator<(SymbolPair const& other) const
|
||||
{
|
||||
return _offset < other._offset ||
|
||||
return _offset < other._offset ||
|
||||
(_offset == other._offset && _type < other._type);
|
||||
}
|
||||
|
||||
@@ -92,6 +111,26 @@ struct SymbolPair
|
||||
};
|
||||
typedef std::set<SymbolPair> SymbolPairs;
|
||||
|
||||
struct SymbolDetail
|
||||
{
|
||||
SymbolDetail() : Prefix(), Type(), Suffix(), Name(), Value(), Logged(false), HasChildren(false) {}
|
||||
|
||||
std::string ToString();
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return Value.empty() && !HasChildren;
|
||||
}
|
||||
|
||||
std::string Prefix;
|
||||
std::string Type;
|
||||
std::string Suffix;
|
||||
std::string Name;
|
||||
std::string Value;
|
||||
bool Logged;
|
||||
bool HasChildren;
|
||||
};
|
||||
|
||||
class WheatyExceptionReport
|
||||
{
|
||||
public:
|
||||
@@ -103,6 +142,8 @@ class WheatyExceptionReport
|
||||
static LONG WINAPI WheatyUnhandledExceptionFilter(
|
||||
PEXCEPTION_POINTERS pExceptionInfo);
|
||||
|
||||
static void __cdecl WheatyCrtHandler(wchar_t const* expression, wchar_t const* function, wchar_t const* file, unsigned int line, uintptr_t pReserved);
|
||||
|
||||
static void printTracesForAllThreads(bool);
|
||||
private:
|
||||
// where report info is extracted and generated
|
||||
@@ -120,15 +161,18 @@ class WheatyExceptionReport
|
||||
|
||||
static BOOL CALLBACK EnumerateSymbolsCallback(PSYMBOL_INFO, ULONG, PVOID);
|
||||
|
||||
static bool FormatSymbolValue(PSYMBOL_INFO, STACKFRAME64 *, char * pszBuffer, unsigned cbBuffer);
|
||||
static bool FormatSymbolValue(PSYMBOL_INFO, STACKFRAME64 *);
|
||||
|
||||
static char * DumpTypeIndex(char *, DWORD64, DWORD, unsigned, DWORD_PTR, bool &, char*, char*);
|
||||
static void DumpTypeIndex(DWORD64, DWORD, DWORD_PTR, bool &, char const*, char*, bool, bool);
|
||||
|
||||
static char * FormatOutputValue(char * pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress);
|
||||
static void FormatOutputValue(char * pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress, size_t bufferSize, size_t countOverride = 0);
|
||||
|
||||
static BasicType GetBasicType(DWORD typeIndex, DWORD64 modBase);
|
||||
static DWORD_PTR DereferenceUnsafePointer(DWORD_PTR address);
|
||||
|
||||
static int __cdecl _tprintf(const TCHAR * format, ...);
|
||||
static int __cdecl Log(const TCHAR * format, ...);
|
||||
static int __cdecl StackLog(const TCHAR * format, va_list argptr);
|
||||
static int __cdecl HeapLog(const TCHAR * format, va_list argptr);
|
||||
|
||||
static bool StoreSymbol(DWORD type , DWORD_PTR offset);
|
||||
static void ClearSymbols();
|
||||
@@ -137,13 +181,24 @@ class WheatyExceptionReport
|
||||
static TCHAR m_szLogFileName[MAX_PATH];
|
||||
static TCHAR m_szDumpFileName[MAX_PATH];
|
||||
static LPTOP_LEVEL_EXCEPTION_FILTER m_previousFilter;
|
||||
static _invalid_parameter_handler m_previousCrtHandler;
|
||||
static HANDLE m_hReportFile;
|
||||
static HANDLE m_hDumpFile;
|
||||
static HANDLE m_hProcess;
|
||||
static SymbolPairs symbols;
|
||||
static std::stack<SymbolDetail> symbolDetails;
|
||||
static bool stackOverflowException;
|
||||
static bool alreadyCrashed;
|
||||
static std::mutex alreadyCrashedLock;
|
||||
typedef NTSTATUS(NTAPI* pRtlGetVersion)(PRTL_OSVERSIONINFOW lpVersionInformation);
|
||||
static pRtlGetVersion RtlGetVersion;
|
||||
|
||||
static void PushSymbolDetail();
|
||||
static void PopSymbolDetail();
|
||||
static void PrintSymbolDetail();
|
||||
|
||||
};
|
||||
|
||||
extern WheatyExceptionReport g_WheatyExceptionReport; // global instance of class
|
||||
#endif // _WIN32
|
||||
#endif // _WHEATYEXCEPTIONREPORT_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user