2 * Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 200?, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
6 #ifndef DEBUG_SUPPORT_H
7 #define DEBUG_SUPPORT_H
14 # include <KernelExport.h>
17 #include <SupportDefs.h>
20 // define all macros we work with -- undefined macros are set to defaults
29 # define DEBUG_PRINT 0
32 # define DEBUG_PRINT 0
35 # define DEBUG_APP "bindfs"
37 #ifndef DEBUG_PRINT_FILE
38 # define DEBUG_PRINT_FILE "/var/log/" DEBUG_APP ".log"
42 // define the debug output function
46 # define __out dbg_printf
51 # include <KernelExport.h>
54 # define __out dbg_printf
56 # define __out dprintf
61 // define the PANIC() macro
64 # define PANIC(str) debugger(str)
66 # define PANIC(str) panic(str)
71 // functions exported by this module
72 status_t
init_debugging();
73 status_t
exit_debugging();
74 void dbg_printf_begin();
75 void dbg_printf_end();
77 void dbg_printf(const char *format
,...);
79 static inline void dbg_printf(const char *,...) {}
83 // Short overview over the debug output macros:
85 // is for general messages that very unlikely should appear in a release
88 // this is for fatal messages, when something has really gone wrong
90 // general information, as disk size, etc.
91 // REPORT_ERROR(status_t)
92 // prints out error information
93 // RETURN_ERROR(status_t)
94 // calls REPORT_ERROR() and return the value
96 // the statements in D() are only included if DEBUG is defined
99 #define DEBUG_THREAD find_thread(NULL)
100 #define DEBUG_CONTEXT(x) \
102 dbg_printf_begin(); \
103 __out(DEBUG_APP " [%Ld: %5ld] ", system_time(), DEBUG_THREAD); \
107 #define DEBUG_CONTEXT_FUNCTION(prefix, x) \
109 dbg_printf_begin(); \
110 __out(DEBUG_APP " [%Ld: %5ld] %s" prefix, system_time(), DEBUG_THREAD, \
111 __PRETTY_FUNCTION__); \
115 #define DEBUG_CONTEXT_LINE(x) \
117 dbg_printf_begin(); \
118 __out(DEBUG_APP " [%Ld: %5ld] %s:%d: ", system_time(), DEBUG_THREAD, \
119 __PRETTY_FUNCTION__, __LINE__); \
124 #define TPRINT(x...) DEBUG_CONTEXT( __out(x) )
125 #define TREPORT_ERROR(status) \
126 DEBUG_CONTEXT_LINE( __out("%s\n", strerror(status)) )
127 #define TRETURN_ERROR(err) \
129 status_t _status = err; \
130 if (_status < B_OK) \
131 TREPORT_ERROR(_status); \
134 #define TSET_ERROR(var, err) \
136 status_t _status = err; \
137 if (_status < B_OK) \
138 TREPORT_ERROR(_status); \
141 #define TFUNCTION(x...) DEBUG_CONTEXT_FUNCTION( ": ", __out(x) )
142 #define TFUNCTION_START() DEBUG_CONTEXT_FUNCTION( "\n", )
143 #define TFUNCTION_END() DEBUG_CONTEXT_FUNCTION( " done\n", )
146 #define PRINT(x...) TPRINT(x)
147 #define REPORT_ERROR(status) TREPORT_ERROR(status)
148 #define RETURN_ERROR(err) TRETURN_ERROR(err)
149 #define SET_ERROR(var, err) TSET_ERROR(var, err)
150 #define FATAL(x...) DEBUG_CONTEXT( __out(x) )
151 #define ERROR(x...) DEBUG_CONTEXT( __out(x) )
152 #define WARN(x...) DEBUG_CONTEXT( __out(x) )
153 #define INFORM(x...) DEBUG_CONTEXT( __out(x) )
154 #define FUNCTION(x...) TFUNCTION(x)
155 #define FUNCTION_START() TFUNCTION_START()
156 #define FUNCTION_END() TFUNCTION_END()
160 #define PRINT(x...) ;
161 #define REPORT_ERROR(status) ;
162 #define RETURN_ERROR(status) return status;
163 #define SET_ERROR(var, err) var = err;
164 #define FATAL(x...) DEBUG_CONTEXT( __out(x) )
165 #define ERROR(x...) DEBUG_CONTEXT( __out(x) )
166 #define WARN(x...) DEBUG_CONTEXT( __out(x) )
167 #define INFORM(x...) DEBUG_CONTEXT( __out(x) )
168 #define FUNCTION(x...) ;
169 #define FUNCTION_START() ;
170 #define FUNCTION_END() ;
176 #define TOUCH(var) (void)var
180 #endif // DEBUG_SUPPORT_H