From 939a25346b5744b4fa3e55e79e0d0ab5efc11962 Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sun, 19 Jan 2014 13:57:49 +0100 Subject: Core/CrashHandler: Fix issues on Windows crash handler Fix few issues on WheatyExceptionReport: - fix NULL dereference exception in GetLogicalAddress() when TC assert in triggered ( *((volatile int*)NULL) = 0; ) - fix infinite loop in DumpTypeIndex() when dumping std types like std::string - fix FormatSymbolValue() pointing to wrong address when accessing local variable values - use portable types instead of x86 specific types, this fixes some wrong address issues on x86 platform - use bigger buffers to format symbols to avoid buffer overflows --- .../shared/Debugging/WheatyExceptionReport.cpp | 25 ++++++++++++++++------ .../shared/Debugging/WheatyExceptionReport.h | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/server/shared/Debugging') diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp index f4da4093dfa..33f1492bb7f 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.cpp +++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp @@ -566,6 +566,9 @@ PVOID addr, PTSTR szModule, DWORD len, DWORD& section, DWORD_PTR& offset) DWORD_PTR hMod = (DWORD_PTR)mbi.AllocationBase; + if (!hMod) + return FALSE; + if (!GetModuleFileName((HMODULE)hMod, szModule, len)) return FALSE; @@ -708,7 +711,7 @@ bool bWriteVariables, HANDLE pThreadHandle) } // Get the source line for this stack frame entry - IMAGEHLP_LINE64 lineInfo = { sizeof(IMAGEHLP_LINE) }; + IMAGEHLP_LINE64 lineInfo = { sizeof(IMAGEHLP_LINE64) }; DWORD dwLineDisplacement; if (SymGetLineFromAddr64(m_hProcess, sf.AddrPC.Offset, &dwLineDisplacement, &lineInfo)) @@ -746,11 +749,11 @@ ULONG /*SymbolSize*/, PVOID UserContext) { - char szBuffer[2048]; + char szBuffer[4092]; __try { - if (FormatSymbolValue(pSymInfo, (STACKFRAME*)UserContext, + if (FormatSymbolValue(pSymInfo, (STACKFRAME64*)UserContext, szBuffer, sizeof(szBuffer))) _tprintf(_T("\t%s\r\n"), szBuffer); } @@ -769,7 +772,7 @@ PVOID UserContext) ////////////////////////////////////////////////////////////////////////////// bool WheatyExceptionReport::FormatSymbolValue( PSYMBOL_INFO pSym, -STACKFRAME * sf, +STACKFRAME64 * sf, char * pszBuffer, unsigned /*cbBuffer*/) { @@ -782,7 +785,7 @@ unsigned /*cbBuffer*/) pszCurrBuffer += sprintf(pszCurrBuffer, "Local "); // If it's a function, don't do anything. - if (pSym->Tag == 5) // SymTagFunction from CVCONST.H from the DIA SDK + if (pSym->Tag == SymTagFunction) // SymTagFunction from CVCONST.H from the DIA SDK return false; DWORD_PTR pVariable = 0; // Will point to the variable's data in memory @@ -791,7 +794,11 @@ unsigned /*cbBuffer*/) { // if (pSym->Register == 8) // EBP is the value 8 (in DBGHELP 5.1) { // This may change!!! +#ifdef _M_IX86 pVariable = sf->AddrFrame.Offset; +#elif _M_X64 + pVariable = sf->AddrStack.Offset; +#endif pVariable += (DWORD_PTR)pSym->Address; } // else @@ -889,6 +896,12 @@ char* /*Name*/) // Iterate through each of the children for (unsigned i = 0; i < dwChildrenCount; i++) { + DWORD symTag; + SymGetTypeInfo(m_hProcess, modBase, children.ChildId[i], TI_GET_SYMTAG, &symTag); + + if (symTag == SymTagFunction || symTag == SymTagTypedef) + continue; + // Add appropriate indentation level (since this routine is recursive) for (unsigned j = 0; j <= nestingLevel+1; j++) pszCurrBuffer += sprintf(pszCurrBuffer, "\t"); @@ -1017,7 +1030,7 @@ WheatyExceptionReport::GetBasicType(DWORD typeIndex, DWORD64 modBase) //============================================================================ int __cdecl WheatyExceptionReport::_tprintf(const TCHAR * format, ...) { - TCHAR szBuff[1024]; + TCHAR szBuff[4092]; int retValue; DWORD cbWritten; va_list argptr; diff --git a/src/server/shared/Debugging/WheatyExceptionReport.h b/src/server/shared/Debugging/WheatyExceptionReport.h index 582f1f157b8..a4ba69d3ff3 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.h +++ b/src/server/shared/Debugging/WheatyExceptionReport.h @@ -98,7 +98,7 @@ class WheatyExceptionReport static BOOL CALLBACK EnumerateSymbolsCallback(PSYMBOL_INFO, ULONG, PVOID); - static bool FormatSymbolValue(PSYMBOL_INFO, STACKFRAME *, char * pszBuffer, unsigned cbBuffer); + static bool FormatSymbolValue(PSYMBOL_INFO, STACKFRAME64 *, char * pszBuffer, unsigned cbBuffer); static char * DumpTypeIndex(char *, DWORD64, DWORD, unsigned, DWORD_PTR, bool &, char*); -- cgit v1.2.3 From 138a3363846abe27bab7838978235f7860b5a52b Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sun, 19 Jan 2014 17:54:31 +0100 Subject: CoreCore/CrashHandler: Handle CRT asserts in Windows build Handle CRT asserts in Windows crash handler instead of popping up a Abort/Retry/Ignore window --- src/server/shared/Debugging/WheatyExceptionReport.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/server/shared/Debugging') diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp index 33f1492bb7f..b4d57f065b0 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.cpp +++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp @@ -62,6 +62,13 @@ WheatyExceptionReport::WheatyExceptionReport() // Constructor // Install the unhandled exception filter function m_previousFilter = SetUnhandledExceptionFilter(WheatyUnhandledExceptionFilter); m_hProcess = GetCurrentProcess(); + if (!IsDebuggerPresent()) + { + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + } } //============ -- cgit v1.2.3