xref: /haiku/src/servers/registrar/Debug.h (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 #ifndef DEBUG_H
2 #define DEBUG_H
3 /* Debug - debug stuff
4 **
5 ** Initial version by Axel Dörfler, axeld@pinc-software.de
6 ** This file may be used under the terms of the OpenBeOS License.
7 */
8 #ifndef DEBUG
9 #	define DEBUG 1
10 #endif
11 
12 #include <stdio.h>
13 #define __out printf
14 
15 // Short overview over the debug output macros:
16 //	PRINT()
17 //		is for general messages that very unlikely should appear in a release build
18 //	FATAL()
19 //		this is for fatal messages, when something has really gone wrong
20 //	INFORM()
21 //		general information, as disk size, etc.
22 //	REPORT_ERROR(status_t)
23 //		prints out error information
24 //	RETURN_ERROR(status_t)
25 //		calls REPORT_ERROR() and return the value
26 //	D()
27 //		the statements in D() are only included if DEBUG is defined
28 
29 #define DEBUG_APP "REG"
30 #ifdef DEBUG
31 	#define PRINT(x) { __out(DEBUG_APP ": "); __out x; }
32 	#define REPORT_ERROR(status) __out(DEBUG_APP ": %s:%d: %s\n",__FUNCTION__,__LINE__,strerror(status));
33 	#define RETURN_ERROR(err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); return _status;}
34 	#define SET_ERROR(var, err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); var = _status; }
35 	#define FATAL(x) { __out(DEBUG_APP ": "); __out x; }
36 	#define INFORM(x) { __out(DEBUG_APP ": "); __out x; }
37 	#define FUNCTION(x) { __out(DEBUG_APP ": %s() ",__FUNCTION__); __out x; }
38 	#define FUNCTION_START() { __out(DEBUG_APP ": %s()\n",__FUNCTION__); }
39 	#define FUNCTION_END() { __out(DEBUG_APP ": %s() done\n",__FUNCTION__); }
40 	#define D(x) {x;};
41 #else
42 	#define PRINT(x) ;
43 	#define REPORT_ERROR(status) ;
44 	#define RETURN_ERROR(status) return status;
45 	#define SET_ERROR(var, err) var = err;
46 	#define FATAL(x) { __out(DEBUG_APP ": "); __out x; }
47 	#define INFORM(x) { __out(DEBUG_APP ": "); __out x; }
48 	#define FUNCTION(x) ;
49 	#define FUNCTION_START() ;
50 	#define FUNCTION_END() ;
51 	#define D(x) ;
52 #endif
53 
54 
55 #endif	/* DEBUG_H */
56