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>
21 //# include <string.h>
26 #define DEBUG_TO_FILE 0
32 extern "C" int vsprintf(char *s
, const char *format
, va_list arg
);
34 # define __out dbg_printf
35 void dbg_printf(const char *format
,...);
36 void initialize_debugger(const char *filename
);
43 # define __out dprintf
47 //# define __out printf
52 int32
_get_debug_indent_level();
54 /*! \brief Helper class that is allocated on the stack by
55 the \c DEBUG_INIT() macro. On creation, it increases the
56 current indentation level by the amount specified via its
57 constructor's \c tabCount parameter; on destruction, it
63 DebugHelper(const char *className
= NULL
, uint8 tabCount
= 1);
66 uint8
TabCount() const { return fTabCount
; }
67 const char* ClassName() const { return fClassName
; }
74 //----------------------------------------------------------------------
75 // NOTE: See Debug.cpp for complete descriptions of the following
77 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
81 // DEBUG-independent macros
82 //----------------------------------------------------------------------
83 #define INFORM(x) { __out("udf: "); __out x; }
85 # define DIE(x) debugger x
87 # define DIE(x) kernel_debugger x
90 //----------------------------------------------------------------------
91 // DEBUG-dependent macros
92 //----------------------------------------------------------------------
95 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) initialize_debugger(filename);
97 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
100 #define DEBUG_INIT_SILENT(className) \
101 DebugHelper _debugHelper(className, 2);
103 #define DEBUG_INIT(className) \
104 DEBUG_INIT_SILENT(className); \
107 #define DEBUG_INIT_ETC(className, arguments) \
108 DEBUG_INIT_SILENT(className) \
111 if (_debugHelper.ClassName()) { \
112 __out("udf: %s::%s(", \
113 _debugHelper.ClassName(), __FUNCTION__); \
115 __out("udf: %s(", __FUNCTION__); \
121 #define DUMP_INIT(className) \
122 DEBUG_INIT_SILENT(className);
127 if (_debugHelper.ClassName()) { \
128 __out("udf: %s::%s(): ", \
129 _debugHelper.ClassName(), __FUNCTION__); \
131 __out("udf: %s(): ", __FUNCTION__); \
137 #define LPRINT(x) { \
140 if (_debugHelper.ClassName()) { \
141 __out("udf: %s::%s(): line %d: ", \
142 _debugHelper.ClassName(), __FUNCTION__, __LINE__); \
144 __out("udf: %s(): line %d: ", \
145 __FUNCTION__, __LINE__); \
151 #define SIMPLE_PRINT(x) { \
157 #define PRINT_INDENT() { \
159 int32 _level = _get_debug_indent_level(); \
160 for (int32 i = 0; i < _level-_debugHelper.TabCount(); i++) { \
166 #define PRINT_DIVIDER() \
168 SIMPLE_PRINT(("------------------------------------------------------------\n"));
170 #define DUMP(object) \
175 #define PDUMP(objectPointer) \
177 (objectPointer)->dump(); \
180 #define REPORT_ERROR(error) { \
181 LPRINT(("returning error 0x%lx, `%s'\n", error, strerror(error))); \
184 #define RETURN_ERROR(error) { \
185 status_t _status = error; \
186 if (_status < (status_t)B_OK) \
187 REPORT_ERROR(_status); \
191 #define RETURN(error) { \
192 status_t _status = error; \
193 if (_status < (status_t)B_OK) { \
194 REPORT_ERROR(_status); \
195 } else if (_status == (status_t)B_OK) { \
196 LPRINT(("returning B_OK\n")); \
198 LPRINT(("returning 0x%lx = %ld\n", _status, _status)); \
204 PRINT(("fatal error: ")); SIMPLE_PRINT(x); \
210 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
211 #define DEBUG_INIT_SILENT(className) ;
212 #define DEBUG_INIT(className) ;
213 #define DEBUG_INIT_ETC(className, arguments) ;
214 #define DUMP_INIT(className) ;
217 #define SIMPLE_PRINT(x) ;
218 #define PRINT_INDENT(x) ;
219 #define PRINT_DIVIDER() ;
220 #define DUMP(object) ;
221 #define PDUMP(objectPointer) ;
222 #define REPORT_ERROR(status) ;
223 #define RETURN_ERROR(status) return status;
224 #define RETURN(status) return status;
225 #define FATAL(x) { __out("udf: fatal error: "); __out x; }
227 #endif // ifdef DEBUG else
229 #define TRACE(x) /*dprintf x*/
232 #define TRACE_ERROR(x) printf x
234 #define TRACE_ERROR(x) dprintf x
237 // These macros turn on or off extensive and generally unnecessary
238 // debugging output regarding table of contents parsing
239 //#define WARN(x) (dprintf x)
241 #define WARN(x) DBG(dprintf x)
243 #endif // _UDF_DEBUG_H