Orxonox  0.0.5 Codename: Arcturus
SignalHandler.h
Go to the documentation of this file.
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 (Linux implementation)
24  * Fabian 'x3n' Landau (Windows implementation)
25  * Co-authors:
26  * ...
27  *
28  */
29 
36 #ifndef _SignalHandler_H__
37 #define _SignalHandler_H__
38 
39 #include "UtilPrereqs.h"
40 
41 #include <cassert>
42 #include <string>
43 
44 #include "Singleton.h"
45 #include "SpecialConfig.h"
46 
47 #if defined(ORXONOX_PLATFORM_LINUX)
48 
49 #include <list>
50 #include <signal.h>
51 
52 namespace orxonox
53 {
54  typedef int (*SignalCallback)( void * someData );
55 
56  struct SignalRec
57  {
58  int signal;
59  sig_t handler;
60  };
61 
63  {
65  void * someData;
66  };
67 
68 
69  typedef std::list<SignalRec> SignalRecList;
70  typedef std::list<SignalCallbackRec> SignalCallbackList;
71 
73  class _UtilExport SignalHandler : public Singleton<SignalHandler>
74  {
75  friend class Singleton<SignalHandler>;
76 
77  public:
78  void registerCallback( SignalCallback cb, void * someData );
79 
80  void doCatch( const std::string & appName, const std::string & filename );
81  void dontCatch();
82 
83  private:
84  static void sigHandler( int sig );
85 
86  void catchSignal( int sig );
87  SignalRecList sigRecList;
88 
89  SignalCallbackList callbackList;
90 
92 
95  };
96 }
97 
98 #elif defined(ORXONOX_PLATFORM_WINDOWS) && defined(DBGHELP_FOUND)
99 
100 #include <windows.h>
101 
102 namespace orxonox
103 {
105  class _UtilExport SignalHandler : public Singleton<SignalHandler>
106  {
107  friend class Singleton<SignalHandler>;
108 
109  public:
110  SignalHandler();
111  ~SignalHandler();
112 
113  void doCatch(const std::string& appName, const std::string& filename);
114 
115  static std::string getStackTrace(PEXCEPTION_POINTERS pExceptionInfo = nullptr);
116  static std::string getExceptionType(PEXCEPTION_POINTERS pExceptionInfo);
117 
118  private:
119  static LONG WINAPI exceptionFilter(PEXCEPTION_POINTERS pExceptionInfo);
120 
121  static std::string getModuleName(const std::string& path);
122  static PVOID getModuleBase(LPCVOID dwAddress);
123 
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);
128 
129  static SignalHandler* singletonPtr_s;
130 
131  std::string filename_;
132  LPTOP_LEVEL_EXCEPTION_FILTER prevExceptionFilter_;
133  };
134 }
135 
136 #else
137 
138 namespace orxonox
139 {
141  class _UtilExport SignalHandler : public Singleton<SignalHandler>
142  {
143  friend class Singleton<SignalHandler>;
144 
145  public:
146  void doCatch(const std::string& appName, const std::string& filename) {}
147 
148  private:
149  static SignalHandler* singletonPtr_s;
150  };
151 }
152 
153 #endif
154 
155 #endif /* _SignalHandler_H__ */
basic_path< std::string, path_traits > path
Definition: CorePrereqs.h:316
std::list< SignalCallbackRec > SignalCallbackList
Definition: SignalHandler.h:70
#define _UtilExport
Definition: UtilPrereqs.h:60
::std::string string
Definition: gtest-port.h:756
The SignalHandler is used to catch signals like SIGSEGV and write a backtrace to the logfile...
Definition: SignalHandler.h:73
Various constants and options that only affect very little code.
sig_t handler
Definition: SignalHandler.h:59
std::string filename
Definition: SignalHandler.h:94
std::list< SignalRec > SignalRecList
Definition: SignalHandler.h:69
Definition: SignalHandler.h:62
Base for singleton classes.
Definition: Singleton.h:114
std::string appName
Definition: SignalHandler.h:93
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
SignalCallbackList callbackList
Definition: SignalHandler.h:89
static SignalHandler * singletonPtr_s
Definition: SignalHandler.h:91
Shared library macros, enums, constants and forward declarations for the util library ...
Definition: InputPrereqs.h:78
int signal
Definition: SignalHandler.h:58
void * someData
Definition: SignalHandler.h:65
SignalRecList sigRecList
Definition: SignalHandler.h:87
Definition of the Singleton template that is used as base class for classes that allow only one insta...
Definition: SignalHandler.h:56
SignalCallback cb
Definition: SignalHandler.h:64
int(* SignalCallback)(void *someData)
Definition: SignalHandler.h:54