orx  1.10
Portable Game Engine
orxDebug.h
Go to the documentation of this file.
1 /* Orx - Portable Game Engine
2  *
3  * Copyright (c) 2008-2019 Orx-Project
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  *
18  * 2. Altered source versions must be plainly marked as such, and must not be
19  * misrepresented as being the original software.
20  *
21  * 3. This notice may not be removed or altered from any source
22  * distribution.
23  */
24 
45 #ifndef _orxDEBUG_H_
46 #define _orxDEBUG_H_
47 
48 #include "orxInclude.h"
49 
50 
51 /* *** orxDEBUG flags *** */
52 
53 #define orxDEBUG_KU32_STATIC_FLAG_NONE 0x00000000
54 
55 #define orxDEBUG_KU32_STATIC_FLAG_TIMESTAMP 0x00000001
56 #define orxDEBUG_KU32_STATIC_FLAG_FULL_TIMESTAMP 0x00000002
57 #define orxDEBUG_KU32_STATIC_FLAG_TYPE 0x00000004
58 #define orxDEBUG_KU32_STATIC_FLAG_TAGGED 0x00000008
59 
60 #define orxDEBUG_KU32_STATIC_FLAG_FILE 0x00000010
61 #define orxDEBUG_KU32_STATIC_FLAG_TERMINAL 0x00000020
62 #define orxDEBUG_KU32_STATIC_FLAG_CONSOLE 0x00000040
63 #define orxDEBUG_KU32_STATIC_FLAG_CALLBACK 0x00000080
64 
65 #define orxDEBUG_KU32_STATIC_MASK_DEFAULT 0x000000F5
66 
67 #define orxDEBUG_KU32_STATIC_MASK_DEBUG 0x000000BD
68 
69 #define orxDEBUG_KU32_STATIC_MASK_USER_ALL 0x0FFFFFFF
70 
71 
72 /* *** Misc *** */
73 
74 #define orxDEBUG_KZ_DEFAULT_DEBUG_FILE "orx-debug.log"
75 #define orxDEBUG_KZ_DEFAULT_LOG_FILE "orx.log"
76 #define orxDEBUG_KZ_DEFAULT_LOG_SUFFIX ".log"
77 #define orxDEBUG_KZ_DEFAULT_DEBUG_SUFFIX "-debug.log"
78 
79 
80 /* Debug levels */
81 typedef enum __orxDEBUG_LEVEL_t
82 {
111 
113 
114  orxDEBUG_LEVEL_ALL = 0xFFFFFFFE,
116  orxDEBUG_LEVEL_NONE = orxENUM_NONE
117 
119 
120 
121 /* Log callback function */
122 typedef orxSTATUS (orxFASTCALL *orxDEBUG_CALLBACK_FUNCTION)(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zLog);
123 
124 
125 /* *** Debug Macros *** */
126 
127 /* Log message, compiler specific */
128 #if defined(__orxGCC__) || defined(__orxLLVM__)
129 
130  #define orxLOG(STRING, ...) \
131  do \
132  { \
133  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
134  } while(orxFALSE)
135 
136  #define orxLOG_TERMINAL(STRING, ...) \
137  do \
138  { \
139  orxU32 u32DebugFlags; \
140  u32DebugFlags = _orxDebug_GetFlags(); \
141  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_TERMINAL, \
142  orxDEBUG_KU32_STATIC_FLAG_FILE \
143  |orxDEBUG_KU32_STATIC_FLAG_CONSOLE); \
144  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
145  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
146  } while(orxFALSE)
147 
148  #define orxLOG_FILE(STRING, ...) \
149  do \
150  { \
151  orxU32 u32DebugFlags; \
152  u32DebugFlags = _orxDebug_GetFlags(); \
153  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_FILE, \
154  orxDEBUG_KU32_STATIC_FLAG_CONSOLE \
155  |orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
156  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
157  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
158  } while(orxFALSE)
159 
160  #define orxLOG_CONSOLE(STRING, ...) \
161  do \
162  { \
163  orxU32 u32DebugFlags; \
164  u32DebugFlags = _orxDebug_GetFlags(); \
165  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_CONSOLE, \
166  orxDEBUG_KU32_STATIC_FLAG_FILE \
167  orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
168  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
169  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
170  } while(orxFALSE)
171 
172 #else /* __orxGCC__ || __orxLLVM__ */
173  #ifdef __orxMSVC__
174 
175  #define orxLOG(STRING, ...) \
176  do \
177  { \
178  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
179  } while(orxFALSE)
180 
181  #define orxLOG_TERMINAL(STRING, ...) \
182  do \
183  { \
184  orxU32 u32DebugFlags; \
185  u32DebugFlags = _orxDebug_GetFlags(); \
186  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_TERMINAL, \
187  orxDEBUG_KU32_STATIC_FLAG_FILE \
188  |orxDEBUG_KU32_STATIC_FLAG_CONSOLE); \
189  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
190  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
191  } while(orxFALSE)
192 
193  #define orxLOG_FILE(STRING, ...) \
194  do \
195  { \
196  orxU32 u32DebugFlags; \
197  u32DebugFlags = _orxDebug_GetFlags(); \
198  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_FILE, \
199  orxDEBUG_KU32_STATIC_FLAG_CONSOLE \
200  |orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
201  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
202  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
203  } while(orxFALSE)
204 
205  #define orxLOG_CONSOLE(STRING, ...) \
206  do \
207  { \
208  orxU32 u32DebugFlags; \
209  u32DebugFlags = _orxDebug_GetFlags(); \
210  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_FLAG_CONSOLE, \
211  orxDEBUG_KU32_STATIC_FLAG_FILE \
212  orxDEBUG_KU32_STATIC_FLAG_TERMINAL); \
213  _orxDebug_Log(orxDEBUG_LEVEL_LOG, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
214  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
215  } while(orxFALSE)
216 
217  #endif /* __orxMSVC__ */
218 #endif /* __orcGCC__ || __orxLLVM__ */
219 
220 #define orxDEBUG_INIT() \
221 do \
222 { \
223  orxU32 u32DebugFlags; \
224  _orxDebug_Init(); \
225  u32DebugFlags = _orxDebug_GetFlags(); \
226  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_MASK_DEBUG, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
227  if(orxSystem_GetVersionNumeric() < __orxVERSION__) \
228  { \
229  orxLOG("The version of the runtime library [" orxANSI_KZ_COLOR_FG_GREEN "%s" \
230  orxANSI_KZ_COLOR_FG_DEFAULT "] is " orxANSI_KZ_COLOR_FG_RED orxANSI_KZ_COLOR_BLINK_ON "older" \
231  orxANSI_KZ_COLOR_FG_DEFAULT orxANSI_KZ_COLOR_BLINK_OFF " than the version used when compiling this program [" \
232  orxANSI_KZ_COLOR_FG_GREEN "%s" orxANSI_KZ_COLOR_FG_DEFAULT "]." \
233  orxANSI_KZ_COLOR_FG_RED orxANSI_KZ_COLOR_BLINK_ON " Problems will likely ensue!", \
234  orxSystem_GetVersionFullString(), __orxVERSION_FULL_STRING__); \
235  } \
236  else if(orxSystem_GetVersionNumeric() > __orxVERSION__) \
237  { \
238  orxLOG("The version of the runtime library [" orxANSI_KZ_COLOR_FG_GREEN "%s" \
239  orxANSI_KZ_COLOR_FG_DEFAULT "] is " orxANSI_KZ_COLOR_FG_YELLOW orxANSI_KZ_COLOR_BLINK_ON "more recent" \
240  orxANSI_KZ_COLOR_FG_DEFAULT orxANSI_KZ_COLOR_BLINK_OFF " than the version used when compiling this program [" \
241  orxANSI_KZ_COLOR_FG_GREEN "%s" orxANSI_KZ_COLOR_FG_DEFAULT "]." \
242  orxANSI_KZ_COLOR_FG_YELLOW orxANSI_KZ_COLOR_BLINK_ON " Problems may arise due to possible incompatibilities!",\
243  orxSystem_GetVersionFullString(), __orxVERSION_FULL_STRING__); \
244  } \
245  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
246 } \
247 while(orxFALSE)
248 #define orxDEBUG_EXIT() _orxDebug_Exit()
249 
250 #ifdef __orxDEBUG__
251 
252  /* Debug print, compiler specific */
253  #if defined(__orxGCC__) || defined(__orxLLVM__)
254  #define orxDEBUG_PRINT(LEVEL, STRING, ...) \
255  do \
256  { \
257  orxU32 u32DebugFlags; \
258  u32DebugFlags = _orxDebug_GetFlags(); \
259  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_MASK_DEBUG, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
260  _orxDebug_Log(LEVEL, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, ##__VA_ARGS__); \
261  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
262  } while(orxFALSE)
263  #else /* __orxGCC__ || __orxLLVM__ */
264  #ifdef __orxMSVC__
265  #define orxDEBUG_PRINT(LEVEL, STRING, ...) \
266  do \
267  { \
268  orxU32 u32DebugFlags; \
269  u32DebugFlags = _orxDebug_GetFlags(); \
270  _orxDebug_SetFlags(orxDEBUG_KU32_STATIC_MASK_DEBUG, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
271  _orxDebug_Log(LEVEL, (const orxSTRING)__FUNCTION__, __FILE__, __LINE__, STRING, __VA_ARGS__); \
272  _orxDebug_SetFlags(u32DebugFlags, orxDEBUG_KU32_STATIC_MASK_USER_ALL); \
273  } while(orxFALSE)
274  #endif /* __orxMSVC__ */
275  #endif /* __orcGCC__ || __orxLLVM__ */
276 
277  /* End platform specific */
278 
279  #define orxDEBUG_ENABLE_LEVEL(LEVEL, ENABLE)_orxDebug_EnableLevel(LEVEL, ENABLE)
280  #define orxDEBUG_IS_LEVEL_ENABLED(LEVEL) _orxDebug_IsLevelEnabled(LEVEL)
281 
282  #define orxDEBUG_SET_FLAGS(SET, UNSET) _orxDebug_SetFlags(SET, UNSET)
283  #define orxDEBUG_GET_FLAGS() _orxDebug_GetFlags()
284 
285  #define orxDEBUG_SET_LOG_CALLBACK(CALLBACK) _orxDebug_SetLogCallback(CALLBACK)
286 
287  /* Break */
288  #define orxBREAK() _orxDebug_Break()
289 
290  /* Files */
291  #define orxDEBUG_SETDEBUGFILE(FILE) _orxDebug_SetDebugFile(FILE)
292  #define orxDEBUG_SETLOGFILE(FILE) _orxDebug_SetLogFile(FILE)
293  #define orxDEBUG_SETBASEFILENAME(FILE) \
294  do \
295  { \
296  orxCHAR zBuffer[256]; \
297  zBuffer[255] = orxCHAR_NULL; \
298  strncpy(zBuffer, FILE, 255); \
299  strncat(zBuffer, orxDEBUG_KZ_DEFAULT_DEBUG_SUFFIX, 255);\
300  _orxDebug_SetDebugFile(zBuffer); \
301  strncpy(zBuffer, FILE, 255); \
302  strncat(zBuffer, orxDEBUG_KZ_DEFAULT_LOG_SUFFIX, 255); \
303  _orxDebug_SetLogFile(zBuffer); \
304  } while(orxFALSE)
305 
306  /* Assert */
307  #if defined(__orxGCC__) || defined(__orxLLVM__)
308  #define orxASSERT(TEST, ...) \
309  if(!(TEST)) \
310  { \
311  orxDEBUG_PRINT(orxDEBUG_LEVEL_ASSERT, orxANSI_KZ_COLOR_BG_RED orxANSI_KZ_COLOR_FG_WHITE orxANSI_KZ_COLOR_BLINK_ON "FAILED ASSERTION [" #TEST "]", ##__VA_ARGS__); \
312  orxBREAK(); \
313  }
314  #else /* __orxGCC__ || __orxLLVM__ */
315  #ifdef __orxMSVC__
316  #define orxASSERT(TEST, ...) \
317  if(!(TEST)) \
318  { \
319  orxDEBUG_PRINT(orxDEBUG_LEVEL_ASSERT, orxANSI_KZ_COLOR_BG_RED orxANSI_KZ_COLOR_FG_WHITE orxANSI_KZ_COLOR_BLINK_ON "FAILED ASSERTION [" #TEST "]", __VA_ARGS__); \
320  orxBREAK(); \
321  }
322  #endif /* __orxMSVC__ */
323  #endif /* __orcGCC__ || __orxLLVM__ */
324 
325 #else /* __orxDEBUG__ */
326 
327  #define orxDEBUG_PRINT(LEVEL, STRING, ...)
328 
329  #define orxDEBUG_ENABLE_LEVEL(LEVEL, ENABLE)_orxDebug_EnableLevel(LEVEL, ENABLE)
330  #define orxDEBUG_IS_LEVEL_ENABLED(LEVEL) _orxDebug_IsLevelEnabled(LEVEL)
331 
332  #define orxDEBUG_SET_FLAGS(SET, UNSET) _orxDebug_SetFlags(SET, UNSET)
333  #define orxDEBUG_GET_FLAGS() _orxDebug_GetFlags()
334 
335  #define orxDEBUG_SET_LOG_CALLBACK(CALLBACK) _orxDebug_SetLogCallback(CALLBACK)
336 
337  /* Break */
338  #define orxBREAK()
339 
340  /* File */
341  #define orxDEBUG_SETDEBUGFILE(FILE)
342  #define orxDEBUG_SETLOGFILE(FILE) _orxDebug_SetLogFile(FILE)
343  #define orxDEBUG_SETBASEFILENAME(FILE) \
344  do \
345  { \
346  orxCHAR zBuffer[256]; \
347  zBuffer[255] = orxCHAR_NULL; \
348  strncpy(zBuffer, FILE, 255); \
349  strncat(zBuffer, orxDEBUG_KZ_DEFAULT_LOG_SUFFIX, 255); \
350  _orxDebug_SetLogFile(zBuffer); \
351  } while(orxFALSE)
352 
353  #define orxASSERT(TEST, ...)
354 
355 #endif /* __orxDEBUG__ */
356 
357 
358 
359 /*****************************************************************************/
360 
361 /* *** Debug defines. *** */
362 
363 #define orxDEBUG_KS32_BUFFER_OUTPUT_SIZE 2048
364 
365 #define orxDEBUG_KZ_DATE_FORMAT orxANSI_KZ_COLOR_FG_CYAN "[%H:%M:%S]" orxANSI_KZ_COLOR_RESET
366 #define orxDEBUG_KZ_DATE_FULL_FORMAT orxANSI_KZ_COLOR_FG_CYAN "[%Y-%m-%d %H:%M:%S]" orxANSI_KZ_COLOR_RESET
367 
368 #define orxDEBUG_KZ_TYPE_LOG_FORMAT orxANSI_KZ_COLOR_FG_GREEN "[%s]" orxANSI_KZ_COLOR_RESET
369 #define orxDEBUG_KZ_TYPE_WARNING_FORMAT orxANSI_KZ_COLOR_FG_YELLOW "[%s]" orxANSI_KZ_COLOR_RESET
370 #define orxDEBUG_KZ_TYPE_ERROR_FORMAT orxANSI_KZ_COLOR_FG_RED "[%s]" orxANSI_KZ_COLOR_RESET
371 
372 #define orxDEBUG_KZ_FILE_FORMAT orxANSI_KZ_COLOR_FG_MAGENTA "[%s:%s(%u)]" orxANSI_KZ_COLOR_RESET
373 
374 
375 /*****************************************************************************/
376 
377 /* *** Functions *** */
378 
382 extern orxDLLAPI orxSTATUS orxFASTCALL _orxDebug_Init();
383 
385 extern orxDLLAPI void orxFASTCALL _orxDebug_Exit();
386 
394 extern orxDLLAPI void orxCDECL _orxDebug_Log(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zFormat, ...);
395 
400 extern orxDLLAPI void orxFASTCALL _orxDebug_EnableLevel(orxDEBUG_LEVEL _eLevel, orxBOOL _bEnable);
401 
405 extern orxDLLAPI orxBOOL orxFASTCALL _orxDebug_IsLevelEnabled(orxDEBUG_LEVEL _eLevel);
406 
411 extern orxDLLAPI void orxFASTCALL _orxDebug_SetFlags(orxU32 _u32Add, orxU32 _u32Remove);
412 
416 extern orxDLLAPI orxU32 orxFASTCALL _orxDebug_GetFlags();
417 
419 extern orxDLLAPI void orxFASTCALL _orxDebug_Break();
420 
424 extern orxDLLAPI void orxFASTCALL _orxDebug_SetDebugFile(const orxSTRING _zFileName);
425 
429 extern orxDLLAPI void orxFASTCALL _orxDebug_SetLogFile(const orxSTRING _zFileName);
430 
434 extern orxDLLAPI void orxFASTCALL _orxDebug_SetLogCallback(const orxDEBUG_CALLBACK_FUNCTION _pfnLogCallback);
435 
436 #endif /* __orxDEBUG_H_ */
437 
orxDLLAPI void orxFASTCALL _orxDebug_SetDebugFile(const orxSTRING _zFileName)
orxSTATUS(orxFASTCALL * orxDEBUG_CALLBACK_FUNCTION)(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zLog)
Definition: orxDebug.h:122
orxDLLAPI void orxFASTCALL _orxDebug_EnableLevel(orxDEBUG_LEVEL _eLevel, orxBOOL _bEnable)
orxDLLAPI void orxFASTCALL _orxDebug_SetLogCallback(const orxDEBUG_CALLBACK_FUNCTION _pfnLogCallback)
orxDLLAPI void orxFASTCALL _orxDebug_SetLogFile(const orxSTRING _zFileName)
orxDLLAPI void orxCDECL _orxDebug_Log(orxDEBUG_LEVEL _eLevel, const orxSTRING _zFunction, const orxSTRING _zFile, orxU32 _u32Line, const orxSTRING _zFormat,...)
orxDLLAPI void orxFASTCALL _orxDebug_Break()
orxDLLAPI orxBOOL orxFASTCALL _orxDebug_IsLevelEnabled(orxDEBUG_LEVEL _eLevel)
orxDLLAPI void orxFASTCALL _orxDebug_Exit()
orxSTATUS
Definition: orxType.h:246
orxDLLAPI orxSTATUS orxFASTCALL _orxDebug_Init()
orxDLLAPI orxU32 orxFASTCALL _orxDebug_GetFlags()
#define orxDLLAPI
Definition: orxDecl.h:381
orxDLLAPI void orxFASTCALL _orxDebug_SetFlags(orxU32 _u32Add, orxU32 _u32Remove)
orxDEBUG_LEVEL
Definition: orxDebug.h:81

Generated for orx by doxygen 1.8.11