src/SEHExceptionWatcher.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006 by Kirill Kolodyazhniy.
00003 * See the file "license.terms" for information on usage and redistribution
00004 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
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;       /* thread ID */
00020 
00021 
00022         unsigned long   _thandle;   /* thread handle */
00023 
00024         int     _terrno;            /* errno value */
00025         unsigned long   _tdoserrno; /* _doserrno value */
00026         unsigned int    _fpds;      /* Floating Point data segment */
00027         unsigned long   _holdrand;  /* rand() seed value */
00028         char *      _token;         /* ptr to strtok() token */
00029         wchar_t *   _wtoken;        /* ptr to wcstok() token */
00030         unsigned char * _mtoken;    /* ptr to _mbstok() token */
00031 
00032         /* following pointers get malloc'd at runtime */
00033         char *      _errmsg;        /* ptr to strerror()/_strerror()
00034                                        buff */
00035 #if _MSC_VER >= 1300
00036         wchar_t *   _werrmsg;       /* ptr to _wcserror()/__wcserror()
00037                                        buff */
00038 #endif
00039         char *      _namebuf0;      /* ptr to tmpnam() buffer */
00040         wchar_t *   _wnamebuf0;     /* ptr to _wtmpnam() buffer */
00041         char *      _namebuf1;      /* ptr to tmpfile() buffer */
00042         wchar_t *   _wnamebuf1;     /* ptr to _wtmpfile() buffer */
00043         char *      _asctimebuf;    /* ptr to asctime() buffer */
00044         wchar_t *   _wasctimebuf;   /* ptr to _wasctime() buffer */
00045         void *      _gmtimebuf;     /* ptr to gmtime() structure */
00046         char *      _cvtbuf;        /* ptr to ecvt()/fcvt buffer */
00047 
00048         /* following fields are needed by _beginthread code */
00049         void *      _initaddr;      /* initial user thread address */
00050         void *      _initarg;       /* initial user thread argument */
00051 
00052         /* following three fields are needed to support
00053          * signal handling and
00054          * runtime errors */
00055         void *      _pxcptacttab;   /* ptr to exception-action table */
00056         void *      _tpxcptinfoptrs; /* ptr to exception info pointers*/
00057         int         _tfpecode;      /* float point exception code */
00058 #if _MSC_VER >= 1300
00059         /* pointer to the copy of the multibyte character
00060          * information used by the thread */
00061         /*pthreadmbcinfo*/ void *  ptmbcinfo;
00062 
00063         /* pointer to the copy of the locale informaton
00064          * used by the thead */
00065         /*pthreadlocinfo*/ void *  ptlocinfo;
00066 #endif
00067 
00068 
00069         /* following field is needed by NLG routines */
00070         unsigned long   _NLG_dwCode;
00071 
00072         /*
00073          * Per-Thread data needed by C++ Exception Handling
00074          */
00075         void *      _terminate;     /* terminate() routine */
00076         void *      _unexpected;    /* unexpected() routine */
00077         void *      _translator;    /* S.E. translator */
00078         void *      _curexception;  /* current exception */
00079         void *      _curcontext;    /* current exception context */
00080 #if _MSC_VER >= 1300
00081         int         _ProcessingThrow; /* for uncaught_exception */
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  /* defined (_M_IX86) */
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

Generated on Thu Oct 26 13:47:45 2006 for MWidgets by  doxygen 1.4.7