BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / udf / UdfDebug.h
blob2af84c9f8ab6987b294d6bf8ab6a1c057960c38f
1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
4 //
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 //----------------------------------------------------------------------
9 #ifndef _UDF_DEBUG_H
10 #define _UDF_DEBUG_H
12 /*! \file Debug.h
14 Handy debugging macros.
17 #include <KernelExport.h>
19 #include <OS.h>
20 #ifdef DEBUG
21 //# include <string.h>
22 #endif
23 #include <unistd.h>
26 #define DEBUG_TO_FILE 0
28 # include <stdio.h>
29 #if DEBUG_TO_FILE
30 //# include <stdio.h>
31 # include <stdarg.h>
32 extern "C" int vsprintf(char *s, const char *format, va_list arg);
33 # include <fcntl.h>
34 # define __out dbg_printf
35 void dbg_printf(const char *format,...);
36 void initialize_debugger(const char *filename);
37 #else
38 # if !_KERNEL_MODE
39 //# include <stdio.h>
40 # define __out printf
41 # else
42 //# include <null.h>
43 # define __out dprintf
44 # endif
45 # include <stdio.h>
46 # include <malloc.h>
47 //# define __out printf
48 #endif
50 class DebugHelper;
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
58 decreases it.
60 class DebugHelper
62 public:
63 DebugHelper(const char *className = NULL, uint8 tabCount = 1);
64 ~DebugHelper();
66 uint8 TabCount() const { return fTabCount; }
67 const char* ClassName() const { return fClassName; }
69 private:
70 uint8 fTabCount;
71 char *fClassName;
74 //----------------------------------------------------------------------
75 // NOTE: See Debug.cpp for complete descriptions of the following
76 // debug macros.
77 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
81 // DEBUG-independent macros
82 //----------------------------------------------------------------------
83 #define INFORM(x) { __out("udf: "); __out x; }
84 #if !_KERNEL_MODE
85 # define DIE(x) debugger x
86 #else
87 # define DIE(x) kernel_debugger x
88 #endif
90 //----------------------------------------------------------------------
91 // DEBUG-dependent macros
92 //----------------------------------------------------------------------
93 #ifdef DEBUG
94 #if DEBUG_TO_FILE
95 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) initialize_debugger(filename);
96 #else
97 #define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
98 #endif
100 #define DEBUG_INIT_SILENT(className) \
101 DebugHelper _debugHelper(className, 2);
103 #define DEBUG_INIT(className) \
104 DEBUG_INIT_SILENT(className); \
105 PRINT(("\n"));
107 #define DEBUG_INIT_ETC(className, arguments) \
108 DEBUG_INIT_SILENT(className) \
110 PRINT_INDENT(); \
111 if (_debugHelper.ClassName()) { \
112 __out("udf: %s::%s(", \
113 _debugHelper.ClassName(), __FUNCTION__); \
114 } else { \
115 __out("udf: %s(", __FUNCTION__); \
117 __out arguments; \
118 __out("):\n"); \
121 #define DUMP_INIT(className) \
122 DEBUG_INIT_SILENT(className);
124 #define PRINT(x) { \
126 PRINT_INDENT(); \
127 if (_debugHelper.ClassName()) { \
128 __out("udf: %s::%s(): ", \
129 _debugHelper.ClassName(), __FUNCTION__); \
130 } else { \
131 __out("udf: %s(): ", __FUNCTION__); \
133 __out x; \
137 #define LPRINT(x) { \
139 PRINT_INDENT(); \
140 if (_debugHelper.ClassName()) { \
141 __out("udf: %s::%s(): line %d: ", \
142 _debugHelper.ClassName(), __FUNCTION__, __LINE__); \
143 } else { \
144 __out("udf: %s(): line %d: ", \
145 __FUNCTION__, __LINE__); \
147 __out x; \
151 #define SIMPLE_PRINT(x) { \
153 __out x; \
157 #define PRINT_INDENT() { \
159 int32 _level = _get_debug_indent_level(); \
160 for (int32 i = 0; i < _level-_debugHelper.TabCount(); i++) { \
161 __out(" "); \
166 #define PRINT_DIVIDER() \
167 PRINT_INDENT(); \
168 SIMPLE_PRINT(("------------------------------------------------------------\n"));
170 #define DUMP(object) \
172 (object).dump(); \
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); \
188 return _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")); \
197 } else { \
198 LPRINT(("returning 0x%lx = %ld\n", _status, _status)); \
200 return _status; \
203 #define FATAL(x) { \
204 PRINT(("fatal error: ")); SIMPLE_PRINT(x); \
207 #define DBG(x) x ;
209 #else // ifdef DEBUG
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) ;
215 #define PRINT(x) ;
216 #define LPRINT(x) ;
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; }
226 #define DBG(x) ;
227 #endif // ifdef DEBUG else
229 #define TRACE(x) /*dprintf x*/
231 #ifdef TEST_HAIKU
232 #define TRACE_ERROR(x) printf x
233 #else
234 #define TRACE_ERROR(x) dprintf x
235 #endif
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)
240 //#define WARN(x)
241 #define WARN(x) DBG(dprintf x)
243 #endif // _UDF_DEBUG_H