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