- 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
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
/*! \def DEBUG_INIT(categoryFilter)
|
/*! \def DEBUG_INIT(categoryFilter)
|
||||||
\brief Increases the indentation level, prints out the enclosing function's
|
\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.
|
decrease the indentation level upon function exit.
|
||||||
|
|
||||||
This macro should be called at the very beginning of any function in
|
This macro should be called at the very beginning of any function in
|
||||||
@@ -182,8 +182,8 @@
|
|||||||
// declarations
|
// declarations
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
static void indent();
|
static void indent(uint8 tabCount);
|
||||||
static void unindent();
|
static void unindent(uint8 tabCount);
|
||||||
#ifdef USER
|
#ifdef USER
|
||||||
static int32 get_tls_handle();
|
static int32 get_tls_handle();
|
||||||
#endif
|
#endif
|
||||||
@@ -228,10 +228,10 @@ _get_debug_indent_level()
|
|||||||
the current thread by 1.
|
the current thread by 1.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
indent()
|
indent(uint8 tabCount)
|
||||||
{
|
{
|
||||||
#ifdef USER
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,10 +239,10 @@ indent()
|
|||||||
the current thread by 1.
|
the current thread by 1.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
unindent()
|
unindent(uint8 tabCount)
|
||||||
{
|
{
|
||||||
#ifdef USER
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,23 +273,31 @@ get_tls_handle()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// _DebugHelper
|
// DebugHelper
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
/*! \brief Increases the current indentation level.
|
/*! \brief Increases the current indentation level.
|
||||||
*/
|
*/
|
||||||
_DebugHelper::_DebugHelper(uint32 categoryFlags)
|
DebugHelper::DebugHelper(uint32 categoryFlags, const char *className, uint8 tabCount)
|
||||||
: fCategoryFlags(categoryFlags)
|
: fCategoryFlags(categoryFlags)
|
||||||
|
, fTabCount(tabCount)
|
||||||
|
, fClassName(NULL)
|
||||||
{
|
{
|
||||||
if ((CategoryFlags() & CATEGORY_FILTER) == CategoryFlags())
|
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.
|
/*! \brief Decreases the current indentation level.
|
||||||
*/
|
*/
|
||||||
_DebugHelper::~_DebugHelper()
|
DebugHelper::~DebugHelper()
|
||||||
{
|
{
|
||||||
if ((CategoryFlags() & CATEGORY_FILTER) == CategoryFlags())
|
if ((CategoryFlags() & CATEGORY_FILTER) == CategoryFlags())
|
||||||
unindent();
|
unindent(fTabCount);
|
||||||
|
free(fClassName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@
|
|||||||
# define __out dprintf
|
# define __out dprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "cpp.h"
|
||||||
|
|
||||||
|
class DebugHelper;
|
||||||
|
|
||||||
int32 _get_debug_indent_level();
|
int32 _get_debug_indent_level();
|
||||||
|
|
||||||
/*! \brief Categories specifiable via the categoryFlags parameter to DEBUG_INIT()
|
/*! \brief Categories specifiable via the categoryFlags parameter to DEBUG_INIT()
|
||||||
@@ -48,20 +52,25 @@ enum _DebugCategoryFlags {
|
|||||||
|
|
||||||
// Misc categories
|
// Misc categories
|
||||||
CF_HIGH_VOLUME = 0x00000200, //!< often-called functions
|
CF_HIGH_VOLUME = 0x00000200, //!< often-called functions
|
||||||
|
CF_DEBUGGING = 0x00000400, //!< internal debugging functions
|
||||||
|
CF_DUMP = 0x00000800, //!< dump() functions
|
||||||
|
|
||||||
//-------------------------------
|
//-------------------------------
|
||||||
|
|
||||||
// Handy combinations
|
// Handy combinations
|
||||||
CF_ALL = 0xffffffff,
|
CF_ALL = 0xffffffff,
|
||||||
CF_ALL_VISIBILITIES = 0x00000007,
|
|
||||||
CF_ALL_OPS = 0x000001f8,
|
|
||||||
CF_ALL_LOW_VOLUME = ~CF_HIGH_VOLUME,
|
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
|
/*! \def CATEGORY_FILTER
|
||||||
\brief Bitmask of currently enabled debugging categories.
|
\brief Bitmask of currently enabled debugging categories.
|
||||||
*/
|
*/
|
||||||
#define CATEGORY_FILTER CF_ALL
|
#define CATEGORY_FILTER CF_ALL
|
||||||
|
//#define CATEGORY_FILTER CF_ALL_STANDARD
|
||||||
//#define CATEGORY_FILTER CF_ENTRY
|
//#define CATEGORY_FILTER CF_ENTRY
|
||||||
//#define CATEGORY_FILTER (CF_ENTRY | CF_PUBLIC)
|
//#define CATEGORY_FILTER (CF_ENTRY | CF_PUBLIC)
|
||||||
//#define CATEGORY_FILTER (CF_ENTRY | CF_PUBLIC | CF_PRIVATE)
|
//#define CATEGORY_FILTER (CF_ENTRY | CF_PUBLIC | CF_PRIVATE)
|
||||||
@@ -72,19 +81,21 @@ enum _DebugCategoryFlags {
|
|||||||
current indentation level by 1; on destruction, it decreases
|
current indentation level by 1; on destruction, it decreases
|
||||||
it by 1.
|
it by 1.
|
||||||
*/
|
*/
|
||||||
class _DebugHelper
|
class DebugHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
_DebugHelper(uint32 categoryFlags);
|
DebugHelper(uint32 categoryFlags, const char *className = NULL, uint8 tabCount = 1);
|
||||||
~_DebugHelper();
|
~DebugHelper();
|
||||||
|
|
||||||
uint32 CategoryFlags() { return fCategoryFlags; }
|
uint32 CategoryFlags() const { return fCategoryFlags; }
|
||||||
|
const char* ClassName() const { return fClassName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 fCategoryFlags;
|
uint32 fCategoryFlags;
|
||||||
|
uint8 fTabCount;
|
||||||
|
char *fClassName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// NOTE: See UdfDebug.cpp for complete descriptions of the following
|
// NOTE: See UdfDebug.cpp for complete descriptions of the following
|
||||||
// debug macros.
|
// debug macros.
|
||||||
@@ -105,41 +116,83 @@ private:
|
|||||||
// DEBUG-dependent macros
|
// DEBUG-dependent macros
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#define DEBUG_INIT(categoryFlags) \
|
#define DEBUG_INIT_SILENT(categoryFlags, className) \
|
||||||
_DebugHelper _debug_helper((categoryFlags)); \
|
DebugHelper _debugHelper((categoryFlags), className, 2);
|
||||||
|
|
||||||
|
#define DEBUG_INIT(categoryFlags, className) \
|
||||||
|
DEBUG_INIT_SILENT(categoryFlags, className); \
|
||||||
PRINT(("\n"));
|
PRINT(("\n"));
|
||||||
|
|
||||||
#define PRINT(x) { \
|
#define DEBUG_INIT_ETC(categoryFlags, className, arguments) \
|
||||||
if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \
|
DEBUG_INIT_SILENT(categoryFlags, className) \
|
||||||
== _debug_helper.CategoryFlags()) \
|
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(); \
|
PRINT_INDENT(); \
|
||||||
__out("udf(%ld): %s(): ", find_thread(NULL), __FUNCTION__); \
|
|
||||||
__out x; \
|
__out x; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LPRINT(x) { \
|
#define PRINT(x) { \
|
||||||
if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \
|
if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \
|
||||||
== _debug_helper.CategoryFlags()) \
|
== _debugHelper.CategoryFlags()) \
|
||||||
{ \
|
{ \
|
||||||
PRINT_INDENT(); \
|
PRINT_INDENT(); \
|
||||||
__out("udf(%ld): %s(): line %d: ", find_thread(NULL), __FUNCTION__, __LINE__); \
|
if (_debugHelper.ClassName()) { \
|
||||||
__out x; \
|
__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 ((_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) { \
|
#define SIMPLE_PRINT(x) { \
|
||||||
if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \
|
if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \
|
||||||
== _debug_helper.CategoryFlags()) \
|
== _debugHelper.CategoryFlags()) \
|
||||||
{ \
|
{ \
|
||||||
__out x; \
|
__out x; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PRINT_INDENT() { \
|
#define PRINT_INDENT() { \
|
||||||
if ((_debug_helper.CategoryFlags() & CATEGORY_FILTER) \
|
if ((_debugHelper.CategoryFlags() & CATEGORY_FILTER) \
|
||||||
== _debug_helper.CategoryFlags()) \
|
== _debugHelper.CategoryFlags()) \
|
||||||
{ \
|
{ \
|
||||||
int32 _level = _get_debug_indent_level(); \
|
int32 _level = _get_debug_indent_level(); \
|
||||||
for (int32 i = 0; i < _level-1; i++) { \
|
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) { \
|
#define REPORT_ERROR(err) { \
|
||||||
LPRINT(("returning error 0x%lx, `%s'\n", err, strerror(err))); \
|
LPRINT(("returning error 0x%lx, `%s'\n", err, strerror(err))); \
|
||||||
}
|
}
|
||||||
@@ -188,6 +245,7 @@ private:
|
|||||||
#define RETURN(status) return status;
|
#define RETURN(status) return status;
|
||||||
#define FATAL(x) { __out("udf: fatal error: "); __out x; }
|
#define FATAL(x) { __out("udf: fatal error: "); __out x; }
|
||||||
#define DBG(x) ;
|
#define DBG(x) ;
|
||||||
|
#define DUMP(x) ;
|
||||||
#endif // ifdef DEBUG else
|
#endif // ifdef DEBUG else
|
||||||
|
|
||||||
#endif // DEBUG_H
|
#endif // DEBUG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user