xref: /haiku/src/add-ons/kernel/file_systems/bfs/Debug.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /* Debug - debug stuff
2  *
3  * Copyright 2001-2005, Axel Dörfler, axeld@pinc-software.de.
4  * This file may be used under the terms of the MIT License.
5  */
6 #ifndef DEBUG_H
7 #define DEBUG_H
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 		__out("bfs: %s:%d: %s\n", __FUNCTION__, __LINE__, strerror(status));
74 	#define RETURN_ERROR(err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); return _status;}
75 	#define FATAL(x) { __out("bfs: "); __out x; sync(); panic("BFS!\n"); }
76 	#define INFORM(x) { __out("bfs: "); __out x; }
77 	#define FUNCTION() ;
78 	#define FUNCTION_START(x) ;
79 	#define D(x) ;
80 	#define ASSERT(x) ;
81 #endif
82 
83 #ifdef DEBUG
84 	struct block_run;
85 	struct bplustree_header;
86 	struct bplustree_node;
87 	struct data_stream;
88 	struct bfs_inode;
89 	struct disk_super_block;
90 	class Inode;
91 	class Volume;
92 
93 	// some structure dump functions
94 	extern void dump_block_run(const char *prefix, block_run &run);
95 	extern void dump_inode(Inode &inode);
96 	extern void dump_super_block(const disk_super_block *superBlock);
97 	extern void dump_data_stream(const data_stream *stream);
98 	extern void dump_inode(const bfs_inode *inode);
99 	extern void dump_bplustree_header(const bplustree_header *header);
100 	extern void dump_bplustree_node(const bplustree_node *node,
101 					const bplustree_header *header = NULL, Volume *volume = NULL);
102 	extern void dump_block(const char *buffer, int size);
103 
104 	extern void remove_debugger_commands();
105 	extern void add_debugger_commands();
106 #endif
107 
108 #endif	/* DEBUG_H */
109