xref: /haiku/src/add-ons/kernel/file_systems/bfs/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 
9 
10 #include <KernelExport.h>
11 
12 #ifdef DEBUG
13 #	include <string.h>
14 #endif
15 
16 #ifdef USER
17 #	include <stdio.h>
18 #	define __out printf
19 #else
20 #	include <null.h>
21 #	define __out dprintf
22 #endif
23 
24 // Which debugger should be used when?
25 // The DEBUGGER() macro actually has no effect if DEBUG is not defined,
26 // use the DIE() macro if you really want to die.
27 #ifdef DEBUG
28 #	ifdef USER
29 #		define DEBUGGER(x) debugger x
30 #	else
31 #		define DEBUGGER(x) kernel_debugger x
32 #	endif
33 #else
34 #	define DEBUGGER(x) ;
35 #endif
36 
37 #ifdef USER
38 #	define DIE(x) debugger x
39 #else
40 #	define DIE(x) kernel_debugger x
41 #endif
42 
43 // Short overview over the debug output macros:
44 //	PRINT()
45 //		is for general messages that very unlikely should appear in a release build
46 //	FATAL()
47 //		this is for fatal messages, when something has really gone wrong
48 //	INFORM()
49 //		general information, as disk size, etc.
50 //	REPORT_ERROR(status_t)
51 //		prints out error information
52 //	RETURN_ERROR(status_t)
53 //		calls REPORT_ERROR() and return the value
54 //	D()
55 //		the statements in D() are only included if DEBUG is defined
56 
57 #ifdef DEBUG
58 	#define PRINT(x) { __out("bfs: "); __out x; }
59 	#define REPORT_ERROR(status) \
60 		__out("bfs: %s:%d: %s\n", __FUNCTION__, __LINE__, strerror(status));
61 	#define RETURN_ERROR(err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); return _status;}
62 	#define FATAL(x) { __out("bfs: "); __out x; }
63 	#define INFORM(x) { __out("bfs: "); __out x; }
64 //	#define FUNCTION() __out("bfs: %s()\n",__FUNCTION__);
65 	#define FUNCTION_START(x) { __out("bfs: %s() ",__FUNCTION__); __out x; }
66 	#define FUNCTION() ;
67 //	#define FUNCTION_START(x) ;
68 	#define D(x) {x;};
69 	#define ASSERT(x) { if (!(x)) DEBUGGER(("bfs: assert failed: " #x "\n")); }
70 #else
71 	#define PRINT(x) ;
72 	#define REPORT_ERROR(status) ;
73 	#define RETURN_ERROR(status) return status;
74 	#define FATAL(x) { __out("bfs: "); __out x; }
75 	#define INFORM(x) { __out("bfs: "); __out x; }
76 	#define FUNCTION() ;
77 	#define FUNCTION_START(x) ;
78 	#define D(x) ;
79 	#define ASSERT(x) ;
80 #endif
81 
82 #ifdef DEBUG
83 	struct block_run;
84 	struct bplustree_header;
85 	struct bplustree_node;
86 	struct data_stream;
87 	struct bfs_inode;
88 	struct disk_super_block;
89 	class Volume;
90 
91 	// some structure dump functions
92 	extern void dump_block_run(const char *prefix, block_run &run);
93 	extern void dump_super_block(disk_super_block *superBlock);
94 	extern void dump_data_stream(data_stream *stream);
95 	extern void dump_inode(bfs_inode *inode);
96 	extern void dump_bplustree_header(bplustree_header *header);
97 	extern void dump_bplustree_node(bplustree_node *node,bplustree_header *header = NULL,Volume *volume = NULL);
98 	extern void dump_block(const char *buffer, int size);
99 #endif
100 
101 #endif	/* DEBUG_H */
102