Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/util/SignalHandler.h @ 7452

Last change on this file since 7452 was 7452, checked in by landauf, 14 years ago

changed to non-deprecated functions (xxxx64)
fixed a few errors that were copy-pasted from other sources
demangling function names on mingw

  • Property svn:eol-style set to native
File size: 4.0 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Christoph Renner
24 *   Co-authors:
25 *      ...
26 *
27 */
[682]28
[1505]29/**
[2030]30    @file
[7401]31    @ingroup Util
[1755]32    @brief Declaration of the SignalHandler class.
[1505]33*/
34
[497]35#ifndef _SignalHandler_H__
36#define _SignalHandler_H__
37
[2030]38#include "UtilPrereqs.h"
[1062]39
[2662]40#include <cassert>
[497]41#include <string>
[3370]42#include "Singleton.h"
[7449]43#include "SpecialConfig.h"
[497]44
[2171]45namespace orxonox
46{
47    typedef int (*SignalCallback)( void * someData );
48}
[497]49
[7449]50#if defined(ORXONOX_PLATFORM_LINUX)
51
52#include <list>
[497]53#include <signal.h>
54
[2171]55namespace orxonox
[497]56{
[2171]57    struct SignalRec
58    {
59        int signal;
60        sig_t handler;
61    };
[497]62
[2171]63    struct SignalCallbackRec
64    {
65        SignalCallback cb;
66        void * someData;
67    };
[497]68
69
[2171]70    typedef std::list<SignalRec> SignalRecList;
71    typedef std::list<SignalCallbackRec> SignalCallbackList;
[497]72
[7401]73    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile.
[3370]74    class SignalHandler : public Singleton<SignalHandler>
[2171]75    {
[3370]76        friend class Singleton<SignalHandler>;
[2171]77    public:
[3370]78        SignalHandler()  { }
79        ~SignalHandler() { }
[497]80
[2171]81        void registerCallback( SignalCallback cb, void * someData );
[497]82
[2171]83        void doCatch( const std::string & appName, const std::string & filename );
84        void dontCatch();
[497]85
[2171]86    private:
87        static void sigHandler( int sig );
[497]88
[2171]89        void catchSignal( int sig );
90        SignalRecList sigRecList;
[497]91
[2171]92        SignalCallbackList callbackList;
[497]93
[3370]94        static SignalHandler* singletonPtr_s;
[497]95
[2171]96        std::string appName;
97        std::string filename;
98    };
99}
[497]100
[7449]101#elif defined(ORXONOX_PLATFORM_WINDOWS) && defined(DBGHELP_FOUND)
[682]102
[7449]103#include <windows.h>
104
[2171]105namespace orxonox
[497]106{
[7449]107    /// The SignalHandler is used to catch unhandled exceptions like access violations and write a backtrace to the logfile.
[3370]108    class _UtilExport SignalHandler : public Singleton<SignalHandler>
[2171]109    {
[3370]110        friend class Singleton<SignalHandler>;
[2171]111    public:
[7449]112        SignalHandler();
113        ~SignalHandler();
114
115        void doCatch( const std::string & appName, const std::string & filename );
116
[7452]117        static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = NULL);
118        static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);
119
[7449]120    private:
121        static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);
122
123        static std::string getModuleName(const std::string& path);
124        static DWORD getModuleBase(DWORD dwAddress);
125
126        template <typename T>
127        static std::string pointerToString(T pointer);
128        template <typename T>
129        static std::string pointerToString(T* pointer);
130
131        static SignalHandler* singletonPtr_s;
132
133        std::string filename_;
134        LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_;
135    };
136}
137
138#else
139
140namespace orxonox
141{
142    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on systems except Linux and Windows.
143    class _UtilExport SignalHandler : public Singleton<SignalHandler>
144    {
145        friend class Singleton<SignalHandler>;
146    public:
[2662]147        void doCatch( const std::string & appName, const std::string & filename ) {}
[497]148
[2171]149    private:
[3370]150        static SignalHandler* singletonPtr_s;
[2171]151    };
152}
[497]153
[7449]154#endif
[1607]155
[497]156#endif /* _SignalHandler_H__ */
Note: See TracBrowser for help on using the repository browser.