Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 13, 2010, 11:12:21 PM (15 years ago)
Author:
landauf
Message:

added windows implementation of SignalHandler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/util/SignalHandler.h

    r7401 r7449  
    3939
    4040#include <cassert>
    41 #include <list>
    4241#include <string>
    4342#include "Singleton.h"
     43#include "SpecialConfig.h"
    4444
    4545namespace orxonox
     
    4848}
    4949
    50 #ifdef ORXONOX_PLATFORM_LINUX
     50#if defined(ORXONOX_PLATFORM_LINUX)
     51
     52#include <list>
    5153#include <signal.h>
    5254
     
    9799}
    98100
    99 #else /* ORXONOX_PLATFORM_LINUX */
     101#elif defined(ORXONOX_PLATFORM_WINDOWS) && defined(DBGHELP_FOUND)
     102
     103#include <windows.h>
    100104
    101105namespace orxonox
    102106{
    103     /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on Windows.
     107    /// The SignalHandler is used to catch unhandled exceptions like access violations and write a backtrace to the logfile.
    104108    class _UtilExport SignalHandler : public Singleton<SignalHandler>
    105109    {
    106110        friend class Singleton<SignalHandler>;
    107111    public:
    108         SignalHandler()  { }
    109         ~SignalHandler() { }
     112        SignalHandler();
     113        ~SignalHandler();
     114
     115        void doCatch( const std::string & appName, const std::string & filename );
     116
     117    private:
     118        static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);
     119
     120        static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL);
     121        static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);
     122        static std::string getModuleName(const std::string& path);
     123        static DWORD getModuleBase(DWORD dwAddress);
     124
     125        template <typename T>
     126        static std::string pointerToString(T pointer);
     127        template <typename T>
     128        static std::string pointerToString(T* pointer);
     129
     130        static SignalHandler* singletonPtr_s;
     131
     132        std::string filename_;
     133        LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_;
     134    };
     135}
     136
     137#else
     138
     139namespace orxonox
     140{
     141    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on systems except Linux and Windows.
     142    class _UtilExport SignalHandler : public Singleton<SignalHandler>
     143    {
     144        friend class Singleton<SignalHandler>;
     145    public:
    110146        void doCatch( const std::string & appName, const std::string & filename ) {}
    111         void dontCatch() {}
    112         void registerCallback( SignalCallback cb, void * someData ) {}
    113147
    114148    private:
     
    117151}
    118152
    119 #endif /* ORXONOX_PLATFORM_LINUX */
     153#endif
    120154
    121155#endif /* _SignalHandler_H__ */
Note: See TracChangeset for help on using the changeset viewer.