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 0 10 #endif 11 12 #include <stdio.h> 13 14 #include <OS.h> 15 16 #ifdef DEBUG_PRINTF 17 #define __out DEBUG_PRINTF 18 #else 19 #define __out printf 20 #endif 21 22 // Short overview over the debug output macros: 23 // PRINT() 24 // is for general messages that very unlikely should appear in a release build 25 // FATAL() 26 // this is for fatal messages, when something has really gone wrong 27 // INFORM() 28 // general information, as disk size, etc. 29 // REPORT_ERROR(status_t) 30 // prints out error information 31 // RETURN_ERROR(status_t) 32 // calls REPORT_ERROR() and return the value 33 // D() 34 // the statements in D() are only included if DEBUG is defined 35 36 #define DEBUG_APP "REG" 37 #if DEBUG 38 #define PRINT(x) { __out(DEBUG_APP ": "); __out x; } 39 #define REPORT_ERROR(status) __out(DEBUG_APP ": %s:%d: %s\n",__FUNCTION__,__LINE__,strerror(status)); 40 #define RETURN_ERROR(err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); return _status;} 41 #define SET_ERROR(var, err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); var = _status; } 42 #define FATAL(x) { __out(DEBUG_APP ": "); __out x; } 43 #define ERROR(x) { __out(DEBUG_APP ": "); __out x; } 44 #define WARNING(x) { __out(DEBUG_APP ": "); __out x; } 45 #define INFORM(x) { __out(DEBUG_APP ": "); __out x; } 46 #define FUNCTION(x) { __out(DEBUG_APP ": %s() ",__FUNCTION__); __out x; } 47 #define FUNCTION_START() { __out(DEBUG_APP ": %s()\n",__FUNCTION__); } 48 #define FUNCTION_END() { __out(DEBUG_APP ": %s() done\n",__FUNCTION__); } 49 #define D(x) {x;}; 50 #else 51 #define PRINT(x) ; 52 #define REPORT_ERROR(status) ; 53 #define RETURN_ERROR(status) return status; 54 #define SET_ERROR(var, err) var = err; 55 #define FATAL(x) { __out(DEBUG_APP ": "); __out x; } 56 #define ERROR(x) { __out(DEBUG_APP ": "); __out x; } 57 #define WARNING(x) { __out(DEBUG_APP ": "); __out x; } 58 #define INFORM(x) { __out(DEBUG_APP ": "); __out x; } 59 #define FUNCTION(x) ; 60 #define FUNCTION_START() ; 61 #define FUNCTION_END() ; 62 #define D(x) ; 63 #endif 64 65 66 #endif /* DEBUG_H */ 67