diff options
author | F1F7Y <64418963+F1F7Y@users.noreply.github.com> | 2023-10-08 22:11:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-08 22:11:55 +0200 |
commit | 70a0114caa21ab7417c3cc74c1cf8f46cfd197a1 (patch) | |
tree | 01d31bc052f7fbc44234ae6224bda57673199cc2 /NorthstarDLL/logging/crashhandler.h | |
parent | 024605399a4878f97fd789416d9ea4234241f039 (diff) | |
download | NorthstarLauncher-70a0114caa21ab7417c3cc74c1cf8f46cfd197a1.tar.gz NorthstarLauncher-70a0114caa21ab7417c3cc74c1cf8f46cfd197a1.zip |
Rewrite crash handler (#477)
The goal of this commit is to make the crash handler code more readable and fix some issues.
- Format registers
- Format Modules
- Format stacktrace
- Format mods
- Create minidump
Diffstat (limited to 'NorthstarDLL/logging/crashhandler.h')
-rw-r--r-- | NorthstarDLL/logging/crashhandler.h | 107 |
1 files changed, 89 insertions, 18 deletions
diff --git a/NorthstarDLL/logging/crashhandler.h b/NorthstarDLL/logging/crashhandler.h index 4d8a59ce..e18de948 100644 --- a/NorthstarDLL/logging/crashhandler.h +++ b/NorthstarDLL/logging/crashhandler.h @@ -1,26 +1,97 @@ #pragma once -void InitialiseCrashHandler(); -void RemoveCrashHandler(); +#include <mutex> -struct BacktraceModule +//----------------------------------------------------------------------------- +// Purpose: Exception handling +//----------------------------------------------------------------------------- +class CCrashHandler { - std::string name; - std::string relativeAddress; - std::string address; -}; + public: + CCrashHandler(); + ~CCrashHandler(); -struct ExceptionLog -{ - std::string cause; - HMODULE crashedModule; - EXCEPTION_RECORD exceptionRecord; - CONTEXT contextRecord; - std::vector<BacktraceModule> trace; - std::vector<std::string> registerDump; + void Init(); + void Shutdown(); + + void Lock() + { + m_Mutex.lock(); + } + + void Unlock() + { + m_Mutex.unlock(); + } + + void SetState(bool bState) + { + m_bState = bState; + } + + bool GetState() const + { + return m_bState; + } + + void SetAllFatal(bool bState) + { + m_bAllExceptionsFatal = bState; + } + + bool GetAllFatal() const + { + return m_bAllExceptionsFatal; + } + + //----------------------------------------------------------------------------- + // Exception helpers + //----------------------------------------------------------------------------- + void SetExceptionInfos(EXCEPTION_POINTERS* pExceptionPointers); + + void SetCrashedModule(); - std::string runtimeInfo; + const CHAR* GetExceptionString() const; + const CHAR* GetExceptionString(DWORD dwExceptionCode) const; - int longestModuleNameLength; - int longestRelativeAddressLength; + bool IsExceptionFatal() const; + bool IsExceptionFatal(DWORD dwExceptionCode) const; + + //----------------------------------------------------------------------------- + // Formatting + //----------------------------------------------------------------------------- + void ShowPopUpMessage(); + + void FormatException(); + void FormatCallstack(); + void FormatFlags(const CHAR* pszRegister, DWORD nValue); + void FormatIntReg(const CHAR* pszRegister, DWORD64 nValue); + void FormatFloatReg(const CHAR* pszRegister, M128A nValue); + void FormatRegisters(); + void FormatLoadedMods(); + void FormatLoadedPlugins(); + void FormatModules(); + + //----------------------------------------------------------------------------- + // Minidump + //----------------------------------------------------------------------------- + void WriteMinidump(); + + private: + PVOID m_hExceptionFilter; + EXCEPTION_POINTERS* m_pExceptionInfos; + + bool m_bHasSetConsolehandler; + bool m_bAllExceptionsFatal; + bool m_bHasShownCrashMsg; + bool m_bState; + + std::string m_svCrashedModule; + std::string m_svCrashedOffset; + + std::string m_svError; + + std::mutex m_Mutex; }; + +extern CCrashHandler* g_pCrashHandler; |