aboutsummaryrefslogtreecommitdiff
path: root/primedev/logging/crashhandler.h
blob: 992dd7d2e74f9b492110eda2d47bb3b5e4732231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <mutex>

//-----------------------------------------------------------------------------
// Purpose: Exception handling
//-----------------------------------------------------------------------------
class CCrashHandler
{
public:
	CCrashHandler();
	~CCrashHandler();

	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();

	const CHAR* GetExceptionString() const;
	const CHAR* GetExceptionString(DWORD dwExceptionCode) const;

	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;