BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / bindfs / DebugSupport.h
blob394e1ba69c3ca058a4bf927ced71476b8c3bd50d
1 /*
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.
5 */
6 #ifndef DEBUG_SUPPORT_H
7 #define DEBUG_SUPPORT_H
10 #include <string.h>
13 #if !USER
14 # include <KernelExport.h>
15 #endif
16 #include <OS.h>
17 #include <SupportDefs.h>
20 // define all macros we work with -- undefined macros are set to defaults
21 #ifndef USER
22 # define USER 0
23 #endif
24 #ifndef DEBUG
25 # define DEBUG 0
26 #endif
27 #if !DEBUG
28 # undef DEBUG_PRINT
29 # define DEBUG_PRINT 0
30 #endif
31 #ifndef DEBUG_PRINT
32 # define DEBUG_PRINT 0
33 #endif
34 #ifndef DEBUG_APP
35 # define DEBUG_APP "bindfs"
36 #endif
37 #ifndef DEBUG_PRINT_FILE
38 # define DEBUG_PRINT_FILE "/var/log/" DEBUG_APP ".log"
39 #endif
42 // define the debug output function
43 #if USER
44 # include <stdio.h>
45 # if DEBUG_PRINT
46 # define __out dbg_printf
47 # else
48 # define __out printf
49 # endif
50 #else
51 # include <KernelExport.h>
52 # include <null.h>
53 # if DEBUG_PRINT
54 # define __out dbg_printf
55 # else
56 # define __out dprintf
57 # endif
58 #endif
61 // define the PANIC() macro
62 #ifndef PANIC
63 # if USER
64 # define PANIC(str) debugger(str)
65 # else
66 # define PANIC(str) panic(str)
67 # endif
68 #endif
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();
76 #if DEBUG_PRINT
77 void dbg_printf(const char *format,...);
78 #else
79 static inline void dbg_printf(const char *,...) {}
80 #endif
83 // Short overview over the debug output macros:
84 // PRINT()
85 // is for general messages that very unlikely should appear in a release
86 // build
87 // FATAL()
88 // this is for fatal messages, when something has really gone wrong
89 // INFORM()
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
95 // D()
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); \
104 x; \
105 dbg_printf_end(); \
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__); \
112 x; \
113 dbg_printf_end(); \
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__); \
120 x; \
121 dbg_printf_end(); \
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); \
132 return _status; \
134 #define TSET_ERROR(var, err) \
136 status_t _status = err; \
137 if (_status < B_OK) \
138 TREPORT_ERROR(_status); \
139 var = _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", )
145 #if DEBUG
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()
157 #define DARG(x) x
158 #define D(x) {x;};
159 #else
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() ;
171 #define DARG(x)
172 #define D(x) ;
173 #endif
175 #ifndef TOUCH
176 #define TOUCH(var) (void)var
177 #endif
180 #endif // DEBUG_SUPPORT_H