1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
5 // This version copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 // Initial version copyright (c) 2002 Axel Dörfler, axeld@pinc-software.de
7 // dbg_printf() function copyright (c) 2003 Ingo Weinhold, bonefish@cs.tu-berlin.edu
8 //----------------------------------------------------------------------
14 Handy debugging macros.
17 #include <KernelExport.h>
25 #define DEBUG_TO_FILE 0
30 # define __out dbg_printf
31 void dbg_printf(const char *format
,...);
32 void initialize_debugger(const char *filename
);
39 # define __out dprintf
43 #include "util/kernel_cpp.h"
47 int32
_get_debug_indent_level();
49 /*! \brief Helper class that is allocated on the stack by
50 the \c DEBUG_INIT() macro. On creation, it increases the
51 current indentation level by the amount specified via its
52 constructor's \c tabCount parameter; on destruction, it
58 DebugHelper(const char *className
= NULL
, uint8 tabCount
= 1);
61 uint8
TabCount() const { return fTabCount
; }
62 const char* ClassName() const { return fClassName
; }
69 //----------------------------------------------------------------------
70 // NOTE: See Debug.cpp for complete descriptions of the following
72 //----------------------------------------------------------------------
75 //----------------------------------------------------------------------
76 // DEBUG-independent macros
77 //----------------------------------------------------------------------
78 #define INFORM(x) { __out("session: "); __out x; }
80 # define DIE(x) debugger x
82 # define DIE(x) kernel_debugger x
85 //----------------------------------------------------------------------
86 // DEBUG-dependent macros
87 //----------------------------------------------------------------------
90 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) initialize_debugger(filename);
92 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
95 #define DEBUG_INIT_SILENT(className) \
96 DebugHelper _debugHelper(className, 2);
98 #define DEBUG_INIT(className) \
99 DEBUG_INIT_SILENT(className); \
102 #define DEBUG_INIT_ETC(className, arguments) \
103 DEBUG_INIT_SILENT(className) \
106 if (_debugHelper.ClassName()) { \
107 __out("session: %s::%s(", \
108 _debugHelper.ClassName(), __FUNCTION__); \
110 __out("session: %s(", __FUNCTION__); \
116 #define DUMP_INIT(categoryFlags, className) \
117 DEBUG_INIT_SILENT(className);
122 if (_debugHelper.ClassName()) { \
123 __out("session: %s::%s(): ", \
124 _debugHelper.ClassName(), __FUNCTION__); \
126 __out("session: %s(): ", __FUNCTION__); \
132 #define LPRINT(x) { \
135 if (_debugHelper.ClassName()) { \
136 __out("session: %s::%s(): line %d: ", \
137 _debugHelper.ClassName(), __FUNCTION__, __LINE__); \
139 __out("session: %s(): line %d: ", \
140 __FUNCTION__, __LINE__); \
146 #define SIMPLE_PRINT(x) { \
152 #define PRINT_INDENT() { \
154 int32 _level = _get_debug_indent_level(); \
155 for (int32 i = 0; i < _level-_debugHelper.TabCount(); i++) { \
161 #define PRINT_DIVIDER() \
163 SIMPLE_PRINT(("------------------------------------------------------------\n"));
165 #define DUMP(object) \
170 #define PDUMP(objectPointer) \
172 (objectPointer)->dump(); \
175 #define REPORT_ERROR(error) { \
176 LPRINT(("returning error 0x%" B_PRIx32 ", `%s'\n", error, strerror(error))); \
179 #define RETURN_ERROR(error) { \
180 status_t _status = error; \
181 if (_status < (status_t)B_OK) \
182 REPORT_ERROR(_status); \
186 #define RETURN(error) { \
187 status_t _status = error; \
188 if (_status < (status_t)B_OK) { \
189 REPORT_ERROR(_status); \
190 } else if (_status == (status_t)B_OK) { \
191 LPRINT(("returning B_OK\n")); \
193 LPRINT(("returning 0x%" B_PRIx32 " = %" B_PRId32 "\n", _status, _status)); \
199 PRINT(("fatal error: ")); SIMPLE_PRINT(x); \
205 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
206 #define DEBUG_INIT_SILENT(className) ;
207 #define DEBUG_INIT(className) ;
208 #define DEBUG_INIT_ETC(className, arguments) ;
209 #define DUMP_INIT(className) ;
212 #define SIMPLE_PRINT(x) ;
213 #define PRINT_INDENT(x) ;
214 #define PRINT_DIVIDER() ;
215 #define PDUMP(objectPointer) ;
216 #define REPORT_ERROR(status) ;
217 #define RETURN_ERROR(status) return status;
218 #define RETURN(status) return status;
219 #define FATAL(x) { __out("session: fatal error: "); __out x; }
222 #endif // ifdef DEBUG else
224 #define TRACE(x) DBG(dprintf x)
226 // These macros turn on or off extensive and generally unnecessary
227 // debugging output regarding table of contents parsing
228 //#define WARN(x) (dprintf x)
230 #define WARN(x) DBG(dprintf x)