diff options
Diffstat (limited to 'src/common/Debugging')
| -rw-r--r-- | src/common/Debugging/WheatyExceptionReport.cpp | 65 | ||||
| -rw-r--r-- | src/common/Debugging/WheatyExceptionReport.h | 6 | 
2 files changed, 9 insertions, 62 deletions
diff --git a/src/common/Debugging/WheatyExceptionReport.cpp b/src/common/Debugging/WheatyExceptionReport.cpp index b18e6c3f104..cbfc1fd3beb 100644 --- a/src/common/Debugging/WheatyExceptionReport.cpp +++ b/src/common/Debugging/WheatyExceptionReport.cpp @@ -10,7 +10,6 @@  #include <algorithm>  #include <ehdata.h>  #include <rttidata.h> -#include <cstdio>  #include <tlhelp32.h>  #include <tchar.h> @@ -48,12 +47,11 @@ TCHAR WheatyExceptionReport::m_szLogFileName[MAX_PATH];  TCHAR WheatyExceptionReport::m_szDumpFileName[MAX_PATH];  LPTOP_LEVEL_EXCEPTION_FILTER WheatyExceptionReport::m_previousFilter;  _invalid_parameter_handler WheatyExceptionReport::m_previousCrtHandler; -HANDLE WheatyExceptionReport::m_hReportFile; +FILE* WheatyExceptionReport::m_hReportFile;  HANDLE WheatyExceptionReport::m_hDumpFile;  HANDLE WheatyExceptionReport::m_hProcess;  SymbolPairs WheatyExceptionReport::symbols;  std::stack<SymbolDetail> WheatyExceptionReport::symbolDetails; -bool WheatyExceptionReport::stackOverflowException;  bool WheatyExceptionReport::alreadyCrashed;  std::mutex WheatyExceptionReport::alreadyCrashedLock;  WheatyExceptionReport::pRtlGetVersion WheatyExceptionReport::RtlGetVersion; @@ -70,7 +68,6 @@ WheatyExceptionReport::WheatyExceptionReport()             // Constructor      m_previousFilter = SetUnhandledExceptionFilter(WheatyUnhandledExceptionFilter);      m_previousCrtHandler = _set_invalid_parameter_handler(WheatyCrtHandler);      m_hProcess = GetCurrentProcess(); -    stackOverflowException = false;      alreadyCrashed = false;      RtlGetVersion = (pRtlGetVersion)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "RtlGetVersion");      if (!IsDebuggerPresent()) @@ -107,9 +104,6 @@ PEXCEPTION_POINTERS pExceptionInfo)      alreadyCrashed = true; -    if (pExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW) -        stackOverflowException = true; -      TCHAR module_folder_name[MAX_PATH];      GetModuleFileName(nullptr, module_folder_name, MAX_PATH);      TCHAR* pos = _tcsrchr(module_folder_name, '\\'); @@ -131,7 +125,7 @@ PEXCEPTION_POINTERS pExceptionInfo)      sprintf(m_szDumpFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].dmp",          crash_folder_path, GitRevision::GetHash(), pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond); -    sprintf(m_szLogFileName, "%s\\%s_%s_[%u-%u_%u-%u-%u].txt", +    _stprintf(m_szLogFileName, _T("%s\\%s_%s_[%u-%u_%u-%u-%u].txt"),          crash_folder_path, GitRevision::GetHash(), pos, systime.wDay, systime.wMonth, systime.wHour, systime.wMinute, systime.wSecond);      m_hDumpFile = CreateFile(m_szDumpFileName, @@ -142,14 +136,6 @@ PEXCEPTION_POINTERS pExceptionInfo)          FILE_FLAG_WRITE_THROUGH,          nullptr); -    m_hReportFile = CreateFile(m_szLogFileName, -        GENERIC_WRITE, -        0, -        nullptr, -        OPEN_ALWAYS, -        FILE_FLAG_WRITE_THROUGH, -        nullptr); -      if (m_hDumpFile)      {          MINIDUMP_EXCEPTION_INFORMATION info; @@ -176,13 +162,13 @@ PEXCEPTION_POINTERS pExceptionInfo)          CloseHandle(m_hDumpFile);      } +    m_hReportFile = _tfopen(m_szLogFileName, _T("wb")); +      if (m_hReportFile)      { -        SetFilePointer(m_hReportFile, 0, nullptr, FILE_END); -          GenerateExceptionReport(pExceptionInfo); -        CloseHandle(m_hReportFile); +        fclose(m_hReportFile);          m_hReportFile = nullptr;      } @@ -1465,47 +1451,10 @@ DWORD_PTR WheatyExceptionReport::DereferenceUnsafePointer(DWORD_PTR address)  //============================================================================  int __cdecl WheatyExceptionReport::Log(const TCHAR * format, ...)  { -    int retValue;      va_list argptr;      va_start(argptr, format); -    if (stackOverflowException) -    { -        retValue = HeapLog(format, argptr); -        va_end(argptr); -    } -    else -    { -        retValue = StackLog(format, argptr); -        va_end(argptr); -    } - -    return retValue; -} - -int __cdecl WheatyExceptionReport::StackLog(const TCHAR * format, va_list argptr) -{ -    int retValue; -    DWORD cbWritten; - -    TCHAR szBuff[WER_LARGE_BUFFER_SIZE]; -    retValue = vsprintf(szBuff, format, argptr); -    WriteFile(m_hReportFile, szBuff, retValue * sizeof(TCHAR), &cbWritten, nullptr); - -    return retValue; -} - -int __cdecl WheatyExceptionReport::HeapLog(const TCHAR * format, va_list argptr) -{ -    int retValue = 0; -    DWORD cbWritten; -    TCHAR* szBuff = (TCHAR*)malloc(sizeof(TCHAR) * WER_LARGE_BUFFER_SIZE); -    if (szBuff != nullptr) -    { -        retValue = vsprintf(szBuff, format, argptr); -        WriteFile(m_hReportFile, szBuff, retValue * sizeof(TCHAR), &cbWritten, nullptr); -        free(szBuff); -    } - +    int retValue = _vftprintf(m_hReportFile, format, argptr); +    va_end(argptr);      return retValue;  } diff --git a/src/common/Debugging/WheatyExceptionReport.h b/src/common/Debugging/WheatyExceptionReport.h index 912a98c198a..87493b52516 100644 --- a/src/common/Debugging/WheatyExceptionReport.h +++ b/src/common/Debugging/WheatyExceptionReport.h @@ -9,6 +9,7 @@  #include <dbghelp.h>  #include <set>  #include <cstdlib> +#include <cstdio>  #include <stack>  #include <mutex> @@ -171,8 +172,6 @@ class WheatyExceptionReport          static DWORD_PTR DereferenceUnsafePointer(DWORD_PTR address);          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(); @@ -182,12 +181,11 @@ class WheatyExceptionReport          static TCHAR m_szDumpFileName[MAX_PATH];          static LPTOP_LEVEL_EXCEPTION_FILTER m_previousFilter;          static _invalid_parameter_handler m_previousCrtHandler; -        static HANDLE m_hReportFile; +        static FILE* 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);  | 
