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
13 // define all macros we work with -- undefined macros are set to defaults
26 # define DEBUG_PRINT 0
29 # define DEBUG_PRINT 0
32 # define DEBUG_APP "package_daemon"
34 #ifndef DEBUG_PRINT_FILE
35 # define DEBUG_PRINT_FILE "/var/log/" DEBUG_APP ".log"
40 # include <KernelExport.h>
43 #include <SupportDefs.h>
46 // define the debug output function
50 # define __out dbg_printf
52 # define __out debug_printf
55 # include <KernelExport.h>
58 # define __out dbg_printf
60 # define __out dprintf
65 // define the PANIC() macro
68 # define PANIC(str) debugger(str)
70 # define PANIC(str) panic(str)
75 // functions exported by this module
76 status_t
init_debugging();
77 status_t
exit_debugging();
78 void dbg_printf_begin();
79 void dbg_printf_end();
81 void dbg_printf(const char *format
,...);
83 static inline void dbg_printf(const char *,...) {}
87 // Short overview over the debug output macros:
89 // is for general messages that very unlikely should appear in a release
92 // this is for fatal messages, when something has really gone wrong
94 // general information, as disk size, etc.
95 // REPORT_ERROR(status_t)
96 // prints out error information
97 // RETURN_ERROR(status_t)
98 // calls REPORT_ERROR() and return the value
100 // the statements in D() are only included if DEBUG is defined
103 #define DEBUG_THREAD find_thread(NULL)
104 #define DEBUG_CONTEXT(x) \
106 dbg_printf_begin(); \
107 __out(DEBUG_APP " [%" B_PRIdBIGTIME ": %5" B_PRId32 "] ", \
108 system_time(), DEBUG_THREAD); \
112 #define DEBUG_CONTEXT_FUNCTION(prefix, x) \
114 dbg_printf_begin(); \
115 __out(DEBUG_APP " [%" B_PRIdBIGTIME ": %5" B_PRId32 "] %s" prefix, \
116 system_time(), DEBUG_THREAD,__PRETTY_FUNCTION__); \
120 #define DEBUG_CONTEXT_LINE(x) \
122 dbg_printf_begin(); \
123 __out(DEBUG_APP " [%" B_PRIdBIGTIME ": %5" B_PRId32 "] %s:%d: ", \
124 system_time(), DEBUG_THREAD, __PRETTY_FUNCTION__, __LINE__); \
129 #define TPRINT(x...) DEBUG_CONTEXT( __out(x) )
130 #define TREPORT_ERROR(status) \
131 DEBUG_CONTEXT_LINE( __out("%s\n", strerror(status)) )
132 #define TRETURN_ERROR(err) \
134 status_t _status = err; \
135 if (_status < B_OK) \
136 TREPORT_ERROR(_status); \
139 #define TSET_ERROR(var, err) \
141 status_t _status = err; \
142 if (_status < B_OK) \
143 TREPORT_ERROR(_status); \
146 #define TFUNCTION(x...) DEBUG_CONTEXT_FUNCTION( ": ", __out(x) )
147 #define TFUNCTION_START() DEBUG_CONTEXT_FUNCTION( "\n", )
148 #define TFUNCTION_END() DEBUG_CONTEXT_FUNCTION( " done\n", )
151 #define PRINT(x...) TPRINT(x)
152 #define REPORT_ERROR(status) TREPORT_ERROR(status)
153 #define RETURN_ERROR(err) TRETURN_ERROR(err)
154 #define SET_ERROR(var, err) TSET_ERROR(var, err)
155 #define FATAL(x...) DEBUG_CONTEXT( __out(x) )
156 #define ERROR(x...) DEBUG_CONTEXT( __out(x) )
157 #define WARN(x...) DEBUG_CONTEXT( __out(x) )
158 #define INFORM(x...) DEBUG_CONTEXT( __out(x) )
159 #define FUNCTION(x...) TFUNCTION(x)
160 #define FUNCTION_START() TFUNCTION_START()
161 #define FUNCTION_END() TFUNCTION_END()
165 #define PRINT(x...) ;
166 #define REPORT_ERROR(status) ;
167 #define RETURN_ERROR(status) return status;
168 #define SET_ERROR(var, err) var = err;
169 #define FATAL(x...) DEBUG_CONTEXT( __out(x) )
170 #define ERROR(x...) DEBUG_CONTEXT( __out(x) )
171 #define WARN(x...) DEBUG_CONTEXT( __out(x) )
172 #define INFORM(x...) DEBUG_CONTEXT( __out(x) )
173 #define FUNCTION(x...) ;
174 #define FUNCTION_START() ;
175 #define FUNCTION_END() ;
181 #define TOUCH(var) (void)var
185 #endif // DEBUG_SUPPORT_H