Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11115 was 11115, checked in by landauf, 9 years ago

fixed code to compile in 64bit mode

  • Property svn:eol-style set to native
File size: 4.2 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:
[9550]23 *      Christoph Renner (Linux implementation)
24 *      Fabian 'x3n' Landau (Windows implementation)
[1505]25 *   Co-authors:
26 *      ...
27 *
28 */
[682]29
[1505]30/**
[2030]31    @file
[7401]32    @ingroup Util
[1755]33    @brief Declaration of the SignalHandler class.
[1505]34*/
35
[497]36#ifndef _SignalHandler_H__
37#define _SignalHandler_H__
38
[2030]39#include "UtilPrereqs.h"
[1062]40
[2662]41#include <cassert>
[497]42#include <string>
[7457]43
[3370]44#include "Singleton.h"
[7449]45#include "SpecialConfig.h"
[497]46
[7449]47#if defined(ORXONOX_PLATFORM_LINUX)
48
49#include <list>
[497]50#include <signal.h>
51
[2171]52namespace orxonox
[497]53{
[7455]54    typedef int (*SignalCallback)( void * someData );
55
[2171]56    struct SignalRec
57    {
58        int signal;
59        sig_t handler;
60    };
[497]61
[2171]62    struct SignalCallbackRec
63    {
64        SignalCallback cb;
65        void * someData;
66    };
[497]67
68
[2171]69    typedef std::list<SignalRec> SignalRecList;
70    typedef std::list<SignalCallbackRec> SignalCallbackList;
[497]71
[7401]72    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile.
[8351]73    class _UtilExport SignalHandler : public Singleton<SignalHandler>
[2171]74    {
[3370]75        friend class Singleton<SignalHandler>;
[497]76
[7457]77        public:
78            void registerCallback( SignalCallback cb, void * someData );
[497]79
[7457]80            void doCatch( const std::string & appName, const std::string & filename );
81            void dontCatch();
[497]82
[7457]83        private:
84            static void sigHandler( int sig );
[497]85
[7457]86            void catchSignal( int sig );
87            SignalRecList sigRecList;
[497]88
[7457]89            SignalCallbackList callbackList;
[497]90
[7457]91            static SignalHandler* singletonPtr_s;
[497]92
[7457]93            std::string appName;
94            std::string filename;
[2171]95    };
96}
[497]97
[7449]98#elif defined(ORXONOX_PLATFORM_WINDOWS) && defined(DBGHELP_FOUND)
[682]99
[7449]100#include <windows.h>
101
[2171]102namespace orxonox
[497]103{
[7449]104    /// The SignalHandler is used to catch unhandled exceptions like access violations and write a backtrace to the logfile.
[3370]105    class _UtilExport SignalHandler : public Singleton<SignalHandler>
[2171]106    {
[3370]107        friend class Singleton<SignalHandler>;
[7449]108
[7455]109        public:
110            SignalHandler();
111            ~SignalHandler();
[7449]112
[7455]113            void doCatch(const std::string& appName, const std::string& filename);
[7452]114
[11071]115            static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = nullptr);
[7455]116            static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);
[7449]117
[7455]118        private:
119            static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);
[7449]120
[7455]121            static std::string getModuleName(const std::string& path);
[11115]122            static PVOID getModuleBase(LPCVOID dwAddress);
[7449]123
[7455]124            template <typename T>
125            static std::string pointerToString(T pointer, bool bFillZeros = true);
126            template <typename T>
127            static std::string pointerToString(T* pointer);
[7449]128
[7455]129            static SignalHandler* singletonPtr_s;
130
131            std::string filename_;
132            LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_;
[7449]133    };
134}
135
136#else
137
138namespace orxonox
139{
140    /// The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile. Not implemented on systems except Linux and Windows.
141    class _UtilExport SignalHandler : public Singleton<SignalHandler>
142    {
143        friend class Singleton<SignalHandler>;
[497]144
[7455]145        public:
146            void doCatch(const std::string& appName, const std::string& filename) {}
147
148        private:
149            static SignalHandler* singletonPtr_s;
[2171]150    };
151}
[497]152
[7449]153#endif
[1607]154
[497]155#endif /* _SignalHandler_H__ */
Note: See TracBrowser for help on using the repository browser.