1 | #ifndef _WHEATYEXCEPTIONREPORT_ |
---|
2 | #define _WHEATYEXCEPTIONREPORT_ |
---|
3 | |
---|
4 | #include <dbghelp.h> |
---|
5 | |
---|
6 | #if _MSC_VER < 1400 |
---|
7 | # define countof(array) (sizeof(array) / sizeof(array[0])) |
---|
8 | #else |
---|
9 | # include <stdlib.h> |
---|
10 | # define countof _countof |
---|
11 | #endif // _MSC_VER < 1400 |
---|
12 | |
---|
13 | enum BasicType // Stolen from CVCONST.H in the DIA 2.0 SDK |
---|
14 | { |
---|
15 | btNoType = 0, |
---|
16 | btVoid = 1, |
---|
17 | btChar = 2, |
---|
18 | btWChar = 3, |
---|
19 | btInt = 6, |
---|
20 | btUInt = 7, |
---|
21 | btFloat = 8, |
---|
22 | btBCD = 9, |
---|
23 | btBool = 10, |
---|
24 | btLong = 13, |
---|
25 | btULong = 14, |
---|
26 | btCurrency = 25, |
---|
27 | btDate = 26, |
---|
28 | btVariant = 27, |
---|
29 | btComplex = 28, |
---|
30 | btBit = 29, |
---|
31 | btBSTR = 30, |
---|
32 | btHresult = 31 |
---|
33 | }; |
---|
34 | |
---|
35 | const char* const rgBaseType[] = |
---|
36 | { |
---|
37 | " <user defined> ", // btNoType = 0, |
---|
38 | " void ", // btVoid = 1, |
---|
39 | " char* ", // btChar = 2, |
---|
40 | " wchar_t* ", // btWChar = 3, |
---|
41 | " signed char ", |
---|
42 | " unsigned char ", |
---|
43 | " int ", // btInt = 6, |
---|
44 | " unsigned int ", // btUInt = 7, |
---|
45 | " float ", // btFloat = 8, |
---|
46 | " <BCD> ", // btBCD = 9, |
---|
47 | " bool ", // btBool = 10, |
---|
48 | " short ", |
---|
49 | " unsigned short ", |
---|
50 | " long ", // btLong = 13, |
---|
51 | " unsigned long ", // btULong = 14, |
---|
52 | " __int8 ", |
---|
53 | " __int16 ", |
---|
54 | " __int32 ", |
---|
55 | " __int64 ", |
---|
56 | " __int128 ", |
---|
57 | " unsigned __int8 ", |
---|
58 | " unsigned __int16 ", |
---|
59 | " unsigned __int32 ", |
---|
60 | " unsigned __int64 ", |
---|
61 | " unsigned __int128 ", |
---|
62 | " <currency> ", // btCurrency = 25, |
---|
63 | " <date> ", // btDate = 26, |
---|
64 | " VARIANT ", // btVariant = 27, |
---|
65 | " <complex> ", // btComplex = 28, |
---|
66 | " <bit> ", // btBit = 29, |
---|
67 | " BSTR ", // btBSTR = 30, |
---|
68 | " HRESULT " // btHresult = 31 |
---|
69 | }; |
---|
70 | |
---|
71 | class WheatyExceptionReport |
---|
72 | { |
---|
73 | public: |
---|
74 | |
---|
75 | WheatyExceptionReport( ); |
---|
76 | ~WheatyExceptionReport( ); |
---|
77 | |
---|
78 | // entry point where control comes on an unhandled exception |
---|
79 | static LONG WINAPI WheatyUnhandledExceptionFilter( |
---|
80 | PEXCEPTION_POINTERS pExceptionInfo ); |
---|
81 | |
---|
82 | private: |
---|
83 | |
---|
84 | // where report info is extracted and generated |
---|
85 | static void GenerateExceptionReport( PEXCEPTION_POINTERS pExceptionInfo ); |
---|
86 | static void PrintSystemInfo(); |
---|
87 | static BOOL _GetWindowsVersion(TCHAR* szVersion, DWORD cntMax); |
---|
88 | static BOOL _GetProcessorName(TCHAR* sProcessorName, DWORD maxcount); |
---|
89 | |
---|
90 | // Helper functions |
---|
91 | static LPTSTR GetExceptionString( DWORD dwCode ); |
---|
92 | static BOOL GetLogicalAddress( PVOID addr, PTSTR szModule, DWORD len, |
---|
93 | DWORD& section, DWORD_PTR& offset ); |
---|
94 | |
---|
95 | static void WriteStackDetails( PCONTEXT pContext, bool bWriteVariables ); |
---|
96 | |
---|
97 | static BOOL CALLBACK EnumerateSymbolsCallback(PSYMBOL_INFO,ULONG, PVOID); |
---|
98 | |
---|
99 | static bool FormatSymbolValue( PSYMBOL_INFO, STACKFRAME *, char * pszBuffer, unsigned cbBuffer ); |
---|
100 | |
---|
101 | static char * DumpTypeIndex( char *, DWORD64, DWORD, unsigned, DWORD_PTR, bool & , char*); |
---|
102 | |
---|
103 | static char * FormatOutputValue( char * pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress ); |
---|
104 | |
---|
105 | static BasicType GetBasicType( DWORD typeIndex, DWORD64 modBase ); |
---|
106 | |
---|
107 | static int __cdecl _tprintf(const TCHAR * format, ...); |
---|
108 | |
---|
109 | // Variables used by the class |
---|
110 | static TCHAR m_szLogFileName[MAX_PATH]; |
---|
111 | static LPTOP_LEVEL_EXCEPTION_FILTER m_previousFilter; |
---|
112 | static HANDLE m_hReportFile; |
---|
113 | static HANDLE m_hProcess; |
---|
114 | }; |
---|
115 | |
---|
116 | extern WheatyExceptionReport g_WheatyExceptionReport; // global instance of class |
---|
117 | #endif //WheatyExceptionReport |
---|