TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
debugAssert.h
Go to the documentation of this file.
1 
26 #ifndef G3D_DEBUGASSERT_H
27 #define G3D_DEBUGASSERT_H
28 
29 #include <string>
30 #include "G3D/platform.h"
31 
32 #include <cstdlib>
33 
34 #ifdef _MSC_VER
35 // conditional expression is constant
36 # pragma warning (disable : 4127)
37 #endif
38 
39 #ifdef G3D_LINUX
40  // Needed so we can define a global display
41  // pointer for debugAssert.
42 #if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
43  #include <X11/Xlib.h>
44  #include <X11/Xutil.h>
45  #include <X11/Xatom.h>
46 #endif
47 #endif
48 
49 
80 namespace G3D {
81 typedef bool (*AssertionHook)(
82  const char* _expression,
83  const std::string& message,
84  const char* filename,
85  int lineNumber,
86  bool useGuiPrompt);
87 
94 
96 
102 void setFailureHook(AssertionHook hook);
104 
105 namespace _internal {
106  extern AssertionHook _debugHook;
108 } // internal
109 } // G3D
110 
116 #ifdef G3D_DEBUG
117 
118 # if defined(_MSC_VER)
119 # define rawBreak() ::DebugBreak();
120 # elif defined(__i386__)
121  // gcc on intel
122 # define rawBreak() __asm__ __volatile__ ( "int $3" );
123 # else
124  // some other gcc
125 # define rawBreak() ::abort()
126 # endif
127 
128 
129 # define debugBreak() G3D::_internal::_releaseInputGrab_(); rawBreak(); G3D::_internal::_restoreInputGrab_();
130 # define debugAssert(exp) debugAssertM(exp, "Debug assertion failure")
131 
132  #ifdef G3D_DEBUG_NOGUI
133  #define __debugPromptShowDialog__ false
134  #else
135  #define __debugPromptShowDialog__ true
136  #endif
137 
138  #define debugAssertM(exp, message) do { \
139  if (!(exp)) { \
140  G3D::_internal::_releaseInputGrab_(); \
141  if ((G3D::_internal::_debugHook != NULL) && \
142  G3D::_internal::_debugHook((const char*)(#exp), message, __FILE__, __LINE__, __debugPromptShowDialog__)) { \
143  rawBreak(); \
144  } \
145  G3D::_internal::_restoreInputGrab_(); \
146  } \
147  } while (0)
148 
149  #define alwaysAssertM debugAssertM
150 
151 #else // Release
152  #ifdef G3D_DEBUG_NOGUI
153  #define __debugPromptShowDialog__ false
154  #else
155  #define __debugPromptShowDialog__ true
156  #endif
157 
158  // In the release build, just define away assertions.
159  #define rawBreak() do {} while (0)
160  #define debugAssert(exp) do {} while (0)
161  #define debugAssertM(exp, message) do {} while (0)
162  #define debugBreak() do {} while (0)
163 
164  // But keep the 'always' assertions
165  #define alwaysAssertM(exp, message) { \
166  if (!(exp)) { \
167  G3D::_internal::_releaseInputGrab_(); \
168  if ((G3D::_internal::_failureHook != NULL) && \
169  G3D::_internal::_failureHook(#exp, message, __FILE__, __LINE__, __debugPromptShowDialog__)) { \
170  ::exit(-1); \
171  } \
172  G3D::_internal::_restoreInputGrab_(); \
173  } \
174  }
175 
176 #endif // if debug
177 
178 
179 
180 namespace G3D { namespace _internal {
181 
182 #ifdef G3D_LINUX
183 #if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
184 
190  extern Display* x11Display;
191 
198  extern Window x11Window;
199 #endif
200 #endif
201 
209  const char* expression,
210  const std::string& message,
211  const char* filename,
212  int lineNumber,
213  bool useGuiPrompt);
214 
215 bool _handleErrorCheck_(
216  const char* expression,
217  const std::string& message,
218  const char* filename,
219  int lineNumber,
220  bool useGuiPrompt);
221 
225 void _releaseInputGrab_();
226 
229 void _restoreInputGrab_();
230 
231 }; }; // namespace
232 
233 #endif
bool _handleErrorCheck_(const char *expression, const std::string &message, const char *filename, int lineNumber, bool useGuiPrompt)
Definition: debugAssert.cpp:191
Definition: AABox.h:25
AssertionHook _failureHook
Definition: debugAssert.cpp:37
void setFailureHook(AssertionHook hook)
Definition: debugAssert.cpp:315
void setAssertionHook(AssertionHook hook)
Definition: debugAssert.cpp:307
#define bool
Definition: CascPort.h:16
AssertionHook _debugHook
Definition: debugAssert.cpp:36
void _restoreInputGrab_()
Definition: debugAssert.cpp:279
void _releaseInputGrab_()
Definition: debugAssert.cpp:233
AssertionHook failureHook()
Definition: debugAssert.cpp:319
bool(* AssertionHook)(const char *_expression, const std::string &message, const char *filename, int lineNumber, bool useGuiPrompt)
Definition: debugAssert.h:81
AssertionHook assertionHook()
Definition: debugAssert.cpp:311
bool _handleDebugAssert_(const char *expression, const std::string &message, const char *filename, int lineNumber, bool useGuiPrompt)
Definition: debugAssert.cpp:136