00001
00002
00003
00004
00005
00006
00007 #ifndef M_SEHEXCEPTIONWATCHER_H
00008 #define M_SEHEXCEPTIONWATCHER_H
00009
00010
00011 #if defined(_MT) && !defined(_DLL)
00012
00013 extern "C"
00014 {
00017 struct _tiddata
00018 {
00019 unsigned long _tid;
00020
00021
00022 unsigned long _thandle;
00023
00024 int _terrno;
00025 unsigned long _tdoserrno;
00026 unsigned int _fpds;
00027 unsigned long _holdrand;
00028 char * _token;
00029 wchar_t * _wtoken;
00030 unsigned char * _mtoken;
00031
00032
00033 char * _errmsg;
00034
00035 #if _MSC_VER >= 1300
00036 wchar_t * _werrmsg;
00037
00038 #endif
00039 char * _namebuf0;
00040 wchar_t * _wnamebuf0;
00041 char * _namebuf1;
00042 wchar_t * _wnamebuf1;
00043 char * _asctimebuf;
00044 wchar_t * _wasctimebuf;
00045 void * _gmtimebuf;
00046 char * _cvtbuf;
00047
00048
00049 void * _initaddr;
00050 void * _initarg;
00051
00052
00053
00054
00055 void * _pxcptacttab;
00056 void * _tpxcptinfoptrs;
00057 int _tfpecode;
00058 #if _MSC_VER >= 1300
00059
00060
00061 void * ptmbcinfo;
00062
00063
00064
00065 void * ptlocinfo;
00066 #endif
00067
00068
00069
00070 unsigned long _NLG_dwCode;
00071
00072
00073
00074
00075 void * _terminate;
00076 void * _unexpected;
00077 void * _translator;
00078 void * _curexception;
00079 void * _curcontext;
00080 #if _MSC_VER >= 1300
00081 int _ProcessingThrow;
00082 #endif
00083 #if defined (_M_IA64)
00084 void * _pExitContext;
00085 void * _pUnwindContext;
00086 void * _pFrameInfoChain;
00087 unsigned __int64 _ImageBase;
00088 unsigned __int64 _TargetGp;
00089 unsigned __int64 _ThrowImageBase;
00090 #elif defined (_M_IX86)
00091 void * _pFrameInfoChain;
00092 #endif
00093 };
00094 typedef struct _tiddata * _ptiddata;
00095
00096 _ptiddata __cdecl _getptd();
00097 }
00098
00099 #endif //_MT
00100
00101
00103 class SEHExceptionWatcher
00104 {
00105 protected:
00106 #ifdef _MSC_VER
00108 const EXCEPTION_RECORD * GetCurrentExceptionRecord();
00110 const _CONTEXT * GetCurrentExceptionContext();
00111
00115 std::string AddressToString(HANDLE hModule, PVOID address );
00116
00117 typedef DWORD (__stdcall *SSO)(DWORD SymOptions);
00118 DWORD (__stdcall *SymSetOptions)(DWORD SymOptions);
00119 typedef BOOL (__stdcall *SI)( HANDLE hProcess, PCTSTR UserSearchPath, BOOL fInvadeProcess);
00120 BOOL (__stdcall *SymInitialize)( HANDLE hProcess, PCTSTR UserSearchPath, BOOL fInvadeProcess);
00121 typedef BOOL (__stdcall *SC)(HANDLE hProcess);
00122 BOOL (__stdcall *SymCleanup)(HANDLE hProcess);
00123 typedef BOOL (__stdcall *SGLFA64)( HANDLE hProcess, DWORD64 dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
00124 BOOL (__stdcall *SymGetLineFromAddr64)( HANDLE hProcess, DWORD64 dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
00125 typedef BOOL (__stdcall *SW64)(DWORD MachineType,HANDLE hProcess,HANDLE hThread,LPSTACKFRAME64 StackFrame,PVOID ContextRecord,PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
00126 BOOL (__stdcall *StackWalk64)(DWORD MachineType,HANDLE hProcess,HANDLE hThread,LPSTACKFRAME64 StackFrame,PVOID ContextRecord,PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
00127 typedef PVOID (__stdcall *SFTA64)(HANDLE hProcess,DWORD64 AddrBase);
00128 PVOID (__stdcall *SymFunctionTableAccess64)(HANDLE hProcess,DWORD64 AddrBase);
00129 typedef DWORD64 (__stdcall *SGMB64)(HANDLE hProcess,DWORD64 dwAddr);
00130 DWORD64 (__stdcall *SymGetModuleBase64)(HANDLE hProcess,DWORD64 dwAddr);
00131 #endif
00132 public:
00134 SEHExceptionWatcher();
00136 std::string Read();
00137
00138 };
00139
00140 #endif