Better trace message support infrastructure
We have varargs in the trace interface now. To be used soon...
This commit is contained in:
parent
02b2922fbf
commit
208109703c
|
@ -153,7 +153,7 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
|
|||
|
||||
|
||||
#define TRACE_SANITIZE() \
|
||||
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&c->debug_depth, "SANITIZE", this, NULL, HB_FUNC);
|
||||
hb_auto_trace_t<HB_DEBUG_SANITIZE, unsigned int> trace (&c->debug_depth, "SANITIZE", this, NULL, "%s", HB_FUNC);
|
||||
|
||||
|
||||
struct hb_sanitize_context_t
|
||||
|
@ -195,9 +195,8 @@ struct hb_sanitize_context_t
|
|||
p <= this->end &&
|
||||
(unsigned int) (this->end - p) >= len;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth,
|
||||
"%-*d-> range [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
this->debug_depth, this->debug_depth,
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth + 1,
|
||||
"range [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
p, p + len, len,
|
||||
this->start, this->end,
|
||||
ret ? "pass" : "FAIL");
|
||||
|
@ -210,9 +209,8 @@ struct hb_sanitize_context_t
|
|||
const char *p = (const char *) base;
|
||||
bool overflows = _hb_unsigned_int_mul_overflows (len, record_size);
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth,
|
||||
"%-*d-> array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s",
|
||||
this->debug_depth, this->debug_depth,
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth + 1,
|
||||
"array [%p..%p] (%d*%d=%ld bytes) in [%p..%p] -> %s",
|
||||
p, p + (record_size * len), record_size, len, (unsigned long) record_size * len,
|
||||
this->start, this->end,
|
||||
!overflows ? "does not overflow" : "OVERFLOWS FAIL");
|
||||
|
@ -231,9 +229,8 @@ struct hb_sanitize_context_t
|
|||
const char *p = (const char *) base;
|
||||
this->edit_count++;
|
||||
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth,
|
||||
"%-*d-> edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
this->debug_depth, this->debug_depth,
|
||||
DEBUG_MSG_LEVEL (SANITIZE, this->blob, this->debug_depth + 1,
|
||||
"edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
|
||||
this->edit_count,
|
||||
p, p + len, len,
|
||||
this->start, this->end,
|
||||
|
|
|
@ -69,7 +69,7 @@ static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) {
|
|||
#endif
|
||||
|
||||
#define TRACE_CLOSURE() \
|
||||
hb_auto_trace_t<HB_DEBUG_CLOSURE> trace (&c->debug_depth, "CLOSURE", this, NULL, HB_FUNC);
|
||||
hb_auto_trace_t<HB_DEBUG_CLOSURE, unsigned int> trace (&c->debug_depth, "CLOSURE", this, NULL, "%s", HB_FUNC);
|
||||
|
||||
|
||||
|
||||
|
@ -96,7 +96,7 @@ struct hb_closure_context_t
|
|||
#endif
|
||||
|
||||
#define TRACE_APPLY() \
|
||||
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", this, NULL, HB_FUNC);
|
||||
hb_auto_trace_t<HB_DEBUG_APPLY, unsigned int> trace (&c->debug_depth, "APPLY", this, NULL, "%s", HB_FUNC);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -501,6 +501,38 @@ _hb_debug (unsigned int level,
|
|||
#define DEBUG_LEVEL(WHAT, LEVEL) (_hb_debug ((LEVEL), HB_DEBUG_##WHAT))
|
||||
#define DEBUG(WHAT) (DEBUG_LEVEL (WHAT, 0))
|
||||
|
||||
template <int max_level> inline bool /* always returns TRUE */
|
||||
_hb_debug_msg_va (const char *what,
|
||||
const void *obj,
|
||||
const char *func,
|
||||
bool indented,
|
||||
int level,
|
||||
const char *message,
|
||||
va_list ap)
|
||||
{
|
||||
(void) (_hb_debug (level, max_level) &&
|
||||
fprintf (stderr, "%s", what) &&
|
||||
(obj && fprintf (stderr, "(%p)", obj), TRUE) &&
|
||||
fprintf (stderr, ": ") &&
|
||||
(func && fprintf (stderr, "%s: ", func), TRUE) &&
|
||||
(indented && fprintf (stderr, "%-*d-> ", level + 1, level), TRUE) &&
|
||||
vfprintf (stderr, message, ap) &&
|
||||
fprintf (stderr, "\n"));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
template <> inline bool /* always returns TRUE */
|
||||
_hb_debug_msg_va<0> (const char *what,
|
||||
const void *obj,
|
||||
const char *func,
|
||||
bool indented,
|
||||
int level,
|
||||
const char *message,
|
||||
va_list ap)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
template <int max_level> inline bool /* always returns TRUE */
|
||||
_hb_debug_msg (const char *what,
|
||||
const void *obj,
|
||||
|
@ -521,18 +553,11 @@ _hb_debug_msg (const char *what,
|
|||
va_list ap;
|
||||
va_start (ap, message);
|
||||
|
||||
(void) (_hb_debug (level, max_level) &&
|
||||
fprintf (stderr, "%s", what) &&
|
||||
(obj && fprintf (stderr, "(%p)", obj), TRUE) &&
|
||||
fprintf (stderr, ": ") &&
|
||||
(func && fprintf (stderr, "%s: ", func), TRUE) &&
|
||||
(indented && fprintf (stderr, "%-*d-> ", level + 1, level), TRUE) &&
|
||||
vfprintf (stderr, message, ap) &&
|
||||
fprintf (stderr, "\n"));
|
||||
bool ret = _hb_debug_msg_va<max_level> (what, obj, func, indented, level, message, ap);
|
||||
|
||||
va_end (ap);
|
||||
|
||||
return TRUE;
|
||||
return ret;
|
||||
}
|
||||
template <> inline bool /* always returns TRUE */
|
||||
_hb_debug_msg<0> (const char *what,
|
||||
|
@ -554,7 +579,7 @@ _hb_debug_msg<0> (const char *what,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, FALSE, (LEVEL), __VA_ARGS__)
|
||||
#define DEBUG_MSG_LEVEL(WHAT, OBJ, LEVEL, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), NULL, TRUE, (LEVEL), __VA_ARGS__)
|
||||
#define DEBUG_MSG(WHAT, OBJ, ...) DEBUG_MSG_LEVEL (WHAT, OBJ, 0, __VA_ARGS__)
|
||||
#define DEBUG_MSG_FUNC(WHAT, OBJ, ...) _hb_debug_msg<HB_DEBUG_##WHAT> (#WHAT, (OBJ), HB_FUNC, FALSE, 0, __VA_ARGS__)
|
||||
|
||||
|
@ -563,30 +588,35 @@ _hb_debug_msg<0> (const char *what,
|
|||
* Trace
|
||||
*/
|
||||
|
||||
template <int max_level>
|
||||
template <int max_level, typename T>
|
||||
struct hb_auto_trace_t {
|
||||
explicit inline hb_auto_trace_t (unsigned int *plevel_,
|
||||
const char *what,
|
||||
const void *obj,
|
||||
const char *func,
|
||||
const char *message) : plevel(plevel_)
|
||||
const char *message,
|
||||
...) : plevel(plevel_)
|
||||
{
|
||||
if (max_level) ++*plevel;
|
||||
/* TODO support variadic args here */
|
||||
_hb_debug_msg<max_level> (what, obj, func, TRUE, *plevel, "%s", message);
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, message);
|
||||
_hb_debug_msg_va<max_level> (what, obj, func, TRUE, *plevel, message, ap);
|
||||
va_end (ap);
|
||||
}
|
||||
~hb_auto_trace_t (void) { if (max_level) --*plevel; }
|
||||
|
||||
private:
|
||||
unsigned int *plevel;
|
||||
};
|
||||
template <> /* Optimize when tracing is disabled */
|
||||
struct hb_auto_trace_t<0> {
|
||||
template <typename T> /* Optimize when tracing is disabled */
|
||||
struct hb_auto_trace_t<0, T> {
|
||||
explicit inline hb_auto_trace_t (unsigned int *plevel_,
|
||||
const char *what,
|
||||
const void *obj,
|
||||
const char *func,
|
||||
const char *message) {}
|
||||
const char *message,
|
||||
...) {}
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue