1 /****************************************************************************** 2 / 3 / File: Debug.h 4 / 5 / Description: Compile time and runtime switchable debug macros. 6 / 7 / Copyright 1993-98, Be Incorporated 8 / 9 ******************************************************************************/ 10 11 #ifndef _DEBUG_H 12 #define _DEBUG_H 13 14 #include <BeBuild.h> 15 #include <SupportDefs.h> 16 #include <stdarg.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <OS.h> 20 21 /*------------------------------*/ 22 /*----- Private... -------------*/ 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 extern _IMPEXP_ROOT bool _rtDebugFlag; 27 28 _IMPEXP_ROOT bool _debugFlag(void); 29 _IMPEXP_ROOT bool _setDebugFlag(bool); 30 31 _IMPEXP_ROOT int _debugPrintf(const char *, ...); 32 _IMPEXP_ROOT int _sPrintf(const char *, ...); 33 _IMPEXP_ROOT int _xdebugPrintf(const char *, ...); 34 _IMPEXP_ROOT int _debuggerAssert(const char *, int, char *); 35 #ifdef __cplusplus 36 } 37 #endif 38 /*-------- ...to here ----------*/ 39 40 41 /*-------------------------------------------------------------*/ 42 /*----- Debug macros ------------------------------------------*/ 43 44 45 #if DEBUG 46 #define SET_DEBUG_ENABLED(FLAG) _setDebugFlag(FLAG) 47 #define IS_DEBUG_ENABLED() _debugFlag() 48 49 #define SERIAL_PRINT(ARGS) _sPrintf ARGS 50 #define PRINT(ARGS) _debugPrintf ARGS 51 #define PRINT_OBJECT(OBJ) if (_rtDebugFlag) { \ 52 PRINT(("%s\t", #OBJ)); \ 53 (OBJ).PrintToStream(); \ 54 } ((void) 0) 55 #define TRACE() _debugPrintf("File: %s, Line: %d, Thread: %d\n", \ 56 __FILE__, __LINE__, find_thread(NULL)) 57 58 #define SERIAL_TRACE() _sPrintf("File: %s, Line: %d, Thread: %d\n", \ 59 __FILE__, __LINE__, find_thread(NULL)) 60 61 #define DEBUGGER(MSG) if (_rtDebugFlag) debugger(MSG) 62 #if !defined(ASSERT) 63 #define ASSERT(E) (!(E) ? _debuggerAssert(__FILE__,__LINE__, #E) \ 64 : (int)0) 65 #endif 66 67 #define ASSERT_WITH_MESSAGE(expr, msg) \ 68 (!(expr) ? _debuggerAssert( __FILE__,__LINE__, msg) \ 69 : (int)0) 70 71 #define TRESPASS() DEBUGGER("Should not be here"); 72 73 #define DEBUG_ONLY(arg) arg 74 75 #else /* DEBUG == 0 */ 76 #define SET_DEBUG_ENABLED(FLAG) (void)0 77 #define IS_DEBUG_ENABLED() (void)0 78 79 #define SERIAL_PRINT(ARGS) (void)0 80 #define PRINT(ARGS) (void)0 81 #define PRINT_OBJECT(OBJ) (void)0 82 #define TRACE() (void)0 83 #define SERIAL_TRACE() (void)0 84 85 #define DEBUGGER(MSG) (void)0 86 #if !defined(ASSERT) 87 #define ASSERT(E) (void)0 88 #endif 89 #define ASSERT_WITH_MESSAGE(expr, msg) \ 90 (void)0 91 #define TRESPASS() (void)0 92 #define DEBUG_ONLY(x) 93 #endif 94 95 96 #if !__MWERKS__ 97 // STATIC_ASSERT is a compile-time check that can be used to 98 // verify static expressions such as: STATIC_ASSERT(sizeof(int64) == 8); 99 #define STATIC_ASSERT(x) \ 100 do { \ 101 struct __staticAssertStruct__ { \ 102 char __static_assert_failed__[2*(x) - 1]; \ 103 }; \ 104 } while (false) 105 #else 106 #define STATIC_ASSERT(x) 107 // the STATIC_ASSERT above doesn't work too well with mwcc because 108 // of scoping bugs; for now make it do nothing 109 #endif 110 111 /*-------------------------------------------------------------*/ 112 /*-------------------------------------------------------------*/ 113 114 #endif /* _DEBUG_H */ 115