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