Add hb_trace_t

This commit is contained in:
Behdad Esfahbod 2010-05-05 00:19:46 -04:00
parent 20e3dd5d29
commit dfc8cbe854

View File

@ -113,22 +113,28 @@ ASSERT_STATIC (sizeof (Type) + 1 <= sizeof (_Null##Type))
/* /*
* Debug * Trace
*/ */
/* Helper object to increment debug_depth and decrement
* when returning from the object. */ template <int max_depth>
template <int debug_level> struct hb_trace_t {
struct hb_auto_debug_depth_t { explicit hb_trace_t (unsigned int *pdepth) : pdepth(pdepth) { if (max_depth) ++*pdepth; }
explicit hb_auto_debug_depth_t (unsigned int *p) : p(p) { ++*p; } ~hb_trace_t (void) { if (max_depth) --*pdepth; }
~hb_auto_debug_depth_t (void) { --*p; }
inline void log (const char *what, const char *function, const void *obj)
{
if (*pdepth < max_depth)
fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, *pdepth, *pdepth, function);
}
private: private:
unsigned int *p; unsigned int *pdepth;
}; };
template <> /* Optimize when debugging is disabled */ template <> /* Optimize when tracing is disabled */
struct hb_auto_debug_depth_t<0> { struct hb_trace_t<0> {
explicit hb_auto_debug_depth_t (unsigned int *p) {} explicit hb_trace_t (unsigned int *p) {}
inline void log (const char *what, const char *function, const void *obj) {};
}; };
@ -143,9 +149,8 @@ struct hb_auto_debug_depth_t<0> {
#define TRACE_SANITIZE() \ #define TRACE_SANITIZE() \
hb_auto_debug_depth_t<HB_DEBUG_SANITIZE> auto_debug_depth (&context->debug_depth); \ hb_trace_t<HB_DEBUG_SANITIZE> trace (&context->debug_depth); \
if (HB_DEBUG_SANITIZE) \ trace.log ("SANITIZE", HB_FUNC, this);
_hb_trace ("SANITIZE", HB_FUNC, this, context->debug_depth, HB_DEBUG_SANITIZE); \
#define SANITIZE_ARG_DEF \ #define SANITIZE_ARG_DEF \