From 6cbf5bf3799cadbd5967d24da4f24ce12daa3ca5 Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Wed, 21 May 2003 07:08:31 +0000 Subject: [PATCH] - Added option to include class name with DEBUG_INIT() to so it's clearer which dump() or init_check() or what have you function is printing out debug info. - Added DUMP_INIT() for dump() functions - Added tabCount option for class DebugHelper. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3279 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/udf/UdfDebug.cpp | 32 +++-- .../kernel/file_systems/udf/UdfDebug.h | 112 +++++++++++++----- 2 files changed, 105 insertions(+), 39 deletions(-) diff --git a/src/add-ons/kernel/file_systems/udf/UdfDebug.cpp b/src/add-ons/kernel/file_systems/udf/UdfDebug.cpp index cad560b38b..1cdf2509c1 100644 --- a/src/add-ons/kernel/file_systems/udf/UdfDebug.cpp +++ b/src/add-ons/kernel/file_systems/udf/UdfDebug.cpp @@ -21,7 +21,7 @@ //---------------------------------------------------------------------- /*! \def DEBUG_INIT(categoryFilter) \brief Increases the indentation level, prints out the enclosing function's - name, and creates a \c _DebugHelper object on the stack to automatically + name, and creates a \c DebugHelper object on the stack to automatically decrease the indentation level upon function exit. This macro should be called at the very beginning of any function in @@ -182,8 +182,8 @@ // declarations //---------------------------------------------------------------------- -static void indent(); -static void unindent(); +static void indent(uint8 tabCount); +static void unindent(uint8 tabCount); #ifdef USER static int32 get_tls_handle(); #endif @@ -228,10 +228,10 @@ _get_debug_indent_level() the current thread by 1. */ void -indent() +indent(uint8 tabCount) { #ifdef USER - tls_set(get_tls_handle(), (void*)(_get_debug_indent_level()+1)); + tls_set(get_tls_handle(), (void*)(_get_debug_indent_level()+tabCount)); #endif } @@ -239,10 +239,10 @@ indent() the current thread by 1. */ void -unindent() +unindent(uint8 tabCount) { #ifdef USER - tls_set(get_tls_handle(), (void*)(_get_debug_indent_level()-1)); + tls_set(get_tls_handle(), (void*)(_get_debug_indent_level()-tabCount)); #endif } @@ -273,23 +273,31 @@ get_tls_handle() #endif //---------------------------------------------------------------------- -// _DebugHelper +// DebugHelper //---------------------------------------------------------------------- /*! \brief Increases the current indentation level. */ -_DebugHelper::_DebugHelper(uint32 categoryFlags) +DebugHelper::DebugHelper(uint32 categoryFlags, const char *className, uint8 tabCount) : fCategoryFlags(categoryFlags) + , fTabCount(tabCount) + , fClassName(NULL) { if ((CategoryFlags() & CATEGORY_FILTER) == CategoryFlags()) - indent(); + indent(fTabCount); + if (className) { + fClassName = (char*)malloc(strlen(className)+1); + if (fClassName) + strcpy(fClassName, className); + } } /*! \brief Decreases the current indentation level. */ -_DebugHelper::~_DebugHelper() +DebugHelper::~DebugHelper() { if ((CategoryFlags() & CATEGORY_FILTER) == CategoryFlags()) - unindent(); + unindent(fTabCount); + free(fClassName); } diff --git a/src/add-ons/kernel/file_systems/udf/UdfDebug.h b/src/add-ons/kernel/file_systems/udf/UdfDebug.h index 4fcad88a6f..a5454fbce4 100644 --- a/src/add-ons/kernel/file_systems/udf/UdfDebug.h +++ b/src/add-ons/kernel/file_systems/udf/UdfDebug.h @@ -28,6 +28,10 @@ # define __out dprintf #endif +#include "cpp.h" + +class DebugHelper; + int32 _get_debug_indent_level(); /*! \brief Categories specifiable via the categoryFlags parameter to DEBUG_INIT() @@ -48,20 +52,25 @@ enum _DebugCategoryFlags { // Misc categories CF_HIGH_VOLUME = 0x00000200, //!< often-called functions + CF_DEBUGGING = 0x00000400, //!< internal debugging functions + CF_DUMP = 0x00000800, //!< dump() functions //------------------------------- // Handy combinations CF_ALL = 0xffffffff, - CF_ALL_VISIBILITIES = 0x00000007, - CF_ALL_OPS = 0x000001f8, CF_ALL_LOW_VOLUME = ~CF_HIGH_VOLUME, + + CF_ANY_VISIBILITY = 0x00000007, + CF_ANY_OP = 0x000001f8, + CF_ALL_STANDARD = CF_ANY_VISIBILITY | CF_ANY_OP, }; /*! \def CATEGORY_FILTER \brief Bitmask of currently enabled debugging categories. */ #define CATEGORY_FILTER CF_ALL +//#define CATEGORY_FILTER CF_ALL_STANDARD //#define CATEGORY_FILTER CF_ENTRY //#define CATEGORY_FILTER (CF_ENTRY | CF_PUBLIC) //#define CATEGORY_FILTER (CF_ENTRY | CF_PUBLIC | CF_PRIVATE) @@ -72,19 +81,21 @@ enum _DebugCategoryFlags { current indentation level by 1; on destruction, it decreases it by 1. */ -class _DebugHelper +class DebugHelper { public: - _DebugHelper(uint32 categoryFlags); - ~_DebugHelper(); + DebugHelper(uint32 categoryFlags, const char *className = NULL, uint8 tabCount = 1); + ~DebugHelper(); - uint32 CategoryFlags() { return fCategoryFlags; } + uint32 CategoryFlags() const { return fCategoryFlags; } + const char* ClassName() const { return fClassName; } private: uint32 fCategoryFlags; + uint8 fTabCount; + char *fClassName; }; - //---------------------------------------------------------------------- // NOTE: See UdfDebug.cpp for complete descriptions of the following // debug macros. @@ -105,41 +116,83 @@ private: // DEBUG-dependent macros //---------------------------------------------------------------------- #ifdef DEBUG - #define DEBUG_INIT(categoryFlags) \ - _DebugHelper _debug_helper((categoryFlags)); \ - PRINT(("\n")); + #define DEBUG_INIT_SILENT(categoryFlags, className) \ + DebugHelper _debugHelper((categoryFlags), className, 2); - #define PRINT(x) { \ - if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \ - == _debug_helper.CategoryFlags()) \ + #define DEBUG_INIT(categoryFlags, className) \ + DEBUG_INIT_SILENT(categoryFlags, className); \ + PRINT(("\n")); + + #define DEBUG_INIT_ETC(categoryFlags, className, arguments) \ + DEBUG_INIT_SILENT(categoryFlags, className) \ + if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \ + == _debugHelper.CategoryFlags()) \ + { \ + PRINT_INDENT(); \ + if (_debugHelper.ClassName()) { \ + __out("udf(%ld): %s::%s(", find_thread(NULL), \ + _debugHelper.ClassName(), __FUNCTION__); \ + } else { \ + __out("udf(%ld): %s(", find_thread(NULL), __FUNCTION__); \ + } \ + __out arguments; \ + __out("):\n"); \ + } + + #define DUMP_INIT(categoryFlags, className) \ + DEBUG_INIT_SILENT(categoryFlags, className); + + #define DUMP_PRINT(x) { \ + if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \ + == _debugHelper.CategoryFlags()) \ { \ PRINT_INDENT(); \ - __out("udf(%ld): %s(): ", find_thread(NULL), __FUNCTION__); \ __out x; \ } \ + } + + #define PRINT(x) { \ + if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \ + == _debugHelper.CategoryFlags()) \ + { \ + PRINT_INDENT(); \ + if (_debugHelper.ClassName()) { \ + __out("udf(%ld): %s::%s(): ", find_thread(NULL), \ + _debugHelper.ClassName(), __FUNCTION__); \ + } else { \ + __out("udf(%ld): %s(): ", find_thread(NULL), __FUNCTION__); \ + } \ + __out x; \ + } \ } - #define LPRINT(x) { \ - if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \ - == _debug_helper.CategoryFlags()) \ - { \ - PRINT_INDENT(); \ - __out("udf(%ld): %s(): line %d: ", find_thread(NULL), __FUNCTION__, __LINE__); \ - __out x; \ - } \ + #define LPRINT(x) { \ + if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \ + == _debugHelper.CategoryFlags()) \ + { \ + PRINT_INDENT(); \ + if (_debugHelper.ClassName()) { \ + __out("udf(%ld): %s::%s(): line %d: ", find_thread(NULL), \ + _debugHelper.ClassName(), __FUNCTION__, __LINE__); \ + } else { \ + __out("udf(%ld): %s(): line %d: ", find_thread(NULL), \ + __FUNCTION__, __LINE__); \ + } \ + __out x; \ + } \ } #define SIMPLE_PRINT(x) { \ - if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \ - == _debug_helper.CategoryFlags()) \ + if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \ + == _debugHelper.CategoryFlags()) \ { \ __out x; \ } \ } #define PRINT_INDENT() { \ - if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \ - == _debug_helper.CategoryFlags()) \ + if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \ + == _debugHelper.CategoryFlags()) \ { \ int32 _level = _get_debug_indent_level(); \ for (int32 i = 0; i < _level-1; i++) { \ @@ -148,6 +201,10 @@ private: } \ } + #define PRINT_DIVIDER() \ + PRINT_INDENT(); \ + SIMPLE_PRINT(("------------------------------------------------------------\n")); + #define REPORT_ERROR(err) { \ LPRINT(("returning error 0x%lx, `%s'\n", err, strerror(err))); \ } @@ -175,7 +232,7 @@ private: PRINT(("fatal error: ")); SIMPLE_PRINT(x); \ } - #define DBG(x) x ; + #define DBG(x) x ; #else // ifdef DEBUG #define DEBUG_INIT(x) ; @@ -188,6 +245,7 @@ private: #define RETURN(status) return status; #define FATAL(x) { __out("udf: fatal error: "); __out x; } #define DBG(x) ; + #define DUMP(x) ; #endif // ifdef DEBUG else #endif // DEBUG_H