[OTLayout] Start unbreaking tracing

This commit is contained in:
Behdad Esfahbod 2012-11-23 15:06:59 -05:00
parent dabe698fcb
commit 902cc8aca0
3 changed files with 68 additions and 36 deletions

View File

@ -167,7 +167,9 @@ ASSERT_STATIC (Type::min_size + 1 <= sizeof (_Null##Type))
#define TRACE_SANITIZE() \ #define TRACE_SANITIZE() \
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&c->debug_depth, "SANITIZE", this, HB_FUNC, ""); hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace \
(&c->debug_depth, "SANITIZE", this, HB_FUNC, \
"");
struct hb_sanitize_context_t struct hb_sanitize_context_t
@ -206,10 +208,11 @@ struct hb_sanitize_context_t
{ {
const char *p = (const char *) base; const char *p = (const char *) base;
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&this->debug_depth, "SANITIZE", this->blob, NULL, hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace
"check_range [%p..%p] (%d bytes) in [%p..%p]", (&this->debug_depth, "SANITIZE", this->blob, NULL,
p, p + len, len, "check_range [%p..%p] (%d bytes) in [%p..%p]",
this->start, this->end); p, p + len, len,
this->start, this->end);
return TRACE_RETURN (likely (this->start <= p && p <= this->end && (unsigned int) (this->end - p) >= len)); return TRACE_RETURN (likely (this->start <= p && p <= this->end && (unsigned int) (this->end - p) >= len));
} }
@ -219,10 +222,11 @@ struct hb_sanitize_context_t
const char *p = (const char *) base; const char *p = (const char *) base;
bool overflows = _hb_unsigned_int_mul_overflows (len, record_size); bool overflows = _hb_unsigned_int_mul_overflows (len, record_size);
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&this->debug_depth, "SANITIZE", this->blob, NULL, hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace
"check_array [%p..%p] (%d*%d=%ld bytes) in [%p..%p]", (&this->debug_depth, "SANITIZE", this->blob, NULL,
p, p + (record_size * len), record_size, len, (unsigned long) record_size * len, "check_array [%p..%p] (%d*%d=%ld bytes) in [%p..%p]",
this->start, this->end); p, p + (record_size * len), record_size, len, (unsigned long) record_size * len,
this->start, this->end);
return TRACE_RETURN (likely (!overflows && this->check_range (base, record_size * len))); return TRACE_RETURN (likely (!overflows && this->check_range (base, record_size * len)));
} }
@ -238,11 +242,12 @@ struct hb_sanitize_context_t
const char *p = (const char *) base; const char *p = (const char *) base;
this->edit_count++; this->edit_count++;
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&this->debug_depth, "SANITIZE", this->blob, NULL, hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace
"may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s", (&this->debug_depth, "SANITIZE", this->blob, NULL,
this->edit_count, "may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
p, p + len, len, this->edit_count,
this->start, this->end); p, p + len, len,
this->start, this->end);
return TRACE_RETURN (this->writable); return TRACE_RETURN (this->writable);
} }
@ -338,7 +343,9 @@ struct Sanitizer
#define TRACE_SERIALIZE() \ #define TRACE_SERIALIZE() \
hb_auto_trace_t<HB_DEBUG_SERIALIZE> trace (&c->debug_depth, "SERIALIZE", c, HB_FUNC, ""); hb_auto_trace_t<HB_DEBUG_SERIALIZE, bool> trace \
(&c->debug_depth, "SERIALIZE", c, HB_FUNC, \
"");
struct hb_serialize_context_t struct hb_serialize_context_t

View File

@ -37,12 +37,15 @@
namespace OT { namespace OT {
#ifndef HB_DEBUG_CLOSURE #ifndef HB_DEBUG_CLOSURE
#define HB_DEBUG_CLOSURE (HB_DEBUG+0) #define HB_DEBUG_CLOSURE (HB_DEBUG+0)
#endif #endif
#define TRACE_CLOSURE() \ #define TRACE_CLOSURE() \
hb_auto_trace_t<HB_DEBUG_CLOSURE> trace (&c->debug_depth, "CLOSURE", this, HB_FUNC, ""); hb_auto_trace_t<HB_DEBUG_CLOSURE, void_t> trace \
(&c->debug_depth, "CLOSURE", this, HB_FUNC, \
"");
struct hb_closure_context_t struct hb_closure_context_t
{ {
@ -87,8 +90,9 @@ struct hb_closure_context_t
#endif #endif
#define TRACE_WOULD_APPLY() \ #define TRACE_WOULD_APPLY() \
hb_auto_trace_t<HB_DEBUG_WOULD_APPLY> trace (&c->debug_depth, "WOULD_APPLY", this, HB_FUNC, "%d glyphs", c->len); hb_auto_trace_t<HB_DEBUG_WOULD_APPLY, bool> trace \
(&c->debug_depth, "WOULD_APPLY", this, HB_FUNC, \
"%d glyphs", c->len);
struct hb_would_apply_context_t struct hb_would_apply_context_t
{ {
@ -123,8 +127,9 @@ struct hb_would_apply_context_t
#endif #endif
#define TRACE_COLLECT_GLYPHS() \ #define TRACE_COLLECT_GLYPHS() \
hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS> trace (&c->debug_depth, "COLLECT_GLYPHS", this, HB_FUNC, ""); hb_auto_trace_t<HB_DEBUG_COLLECT_GLYPHS, void_t> trace \
(&c->debug_depth, "COLLECT_GLYPHS", this, HB_FUNC, \
"");
struct hb_collect_glyphs_context_t struct hb_collect_glyphs_context_t
{ {
@ -183,8 +188,9 @@ struct hb_get_coverage_context_t
#endif #endif
#define TRACE_APPLY() \ #define TRACE_APPLY() \
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", this, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace \
(&c->debug_depth, "APPLY", this, HB_FUNC, \
"idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
struct hb_apply_context_t struct hb_apply_context_t
{ {
@ -517,7 +523,9 @@ static inline bool match_input (hb_apply_context_t *c,
bool *p_is_mark_ligature = NULL, bool *p_is_mark_ligature = NULL,
unsigned int *p_total_component_count = NULL) unsigned int *p_total_component_count = NULL)
{ {
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace
(&c->debug_depth, "APPLY", NULL, HB_FUNC,
"idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1); hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx, count - 1);
if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false); if (skippy_iter.has_no_chance ()) return TRACE_RETURN (false);
@ -674,7 +682,9 @@ static inline bool match_backtrack (hb_apply_context_t *c,
match_func_t match_func, match_func_t match_func,
const void *match_data) const void *match_data)
{ {
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace
(&c->debug_depth, "APPLY", NULL, HB_FUNC,
"idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true); hb_apply_context_t::mark_skipping_backward_iterator_t skippy_iter (c, c->buffer->backtrack_len (), count, true);
if (skippy_iter.has_no_chance ()) if (skippy_iter.has_no_chance ())
@ -699,7 +709,9 @@ static inline bool match_lookahead (hb_apply_context_t *c,
const void *match_data, const void *match_data,
unsigned int offset) unsigned int offset)
{ {
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace
(&c->debug_depth, "APPLY", NULL, HB_FUNC,
"idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true); hb_apply_context_t::mark_skipping_forward_iterator_t skippy_iter (c, c->buffer->idx + offset - 1, count, true);
if (skippy_iter.has_no_chance ()) if (skippy_iter.has_no_chance ())
@ -748,7 +760,10 @@ static inline bool apply_lookup (hb_apply_context_t *c,
unsigned int lookupCount, unsigned int lookupCount,
const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */) const LookupRecord lookupRecord[] /* Array of LookupRecords--in design order */)
{ {
hb_auto_trace_t<HB_DEBUG_APPLY> trace (&c->debug_depth, "APPLY", NULL, HB_FUNC, "idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint); hb_auto_trace_t<HB_DEBUG_APPLY, bool> trace
(&c->debug_depth, "APPLY", NULL, HB_FUNC,
"idx %d codepoint %u", c->buffer->idx, c->buffer->cur().codepoint);
unsigned int end = c->buffer->len; unsigned int end = c->buffer->len;
if (unlikely (count == 0 || c->buffer->idx + count > end)) if (unlikely (count == 0 || c->buffer->idx + count > end))
return TRACE_RETURN (false); return TRACE_RETURN (false);

View File

@ -682,7 +682,18 @@ struct hb_printer_t<void_t> {
* Trace * Trace
*/ */
template <int max_level> template <typename T>
static inline void _hb_warn_no_return (bool returned)
{
if (unlikely (!returned)) {
fprintf (stderr, "OUCH, returned with no call to TRACE_RETURN. This is a bug, please report.\n");
}
}
template <>
inline void _hb_warn_no_return<void_t> (bool returned)
{}
template <int max_level, typename ret_t>
struct hb_auto_trace_t { struct hb_auto_trace_t {
explicit inline hb_auto_trace_t (unsigned int *plevel_, explicit inline hb_auto_trace_t (unsigned int *plevel_,
const char *what_, const char *what_,
@ -700,24 +711,23 @@ struct hb_auto_trace_t {
} }
inline ~hb_auto_trace_t (void) inline ~hb_auto_trace_t (void)
{ {
if (unlikely (!returned)) { _hb_warn_no_return<ret_t> (returned);
fprintf (stderr, "OUCH, returned with no call to TRACE_RETURN. This is a bug, please report. Level was %d.\n", plevel ? *plevel : -1); if (!returned) {
_hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, " "); _hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, " ");
return;
} }
if (plevel) --*plevel; if (plevel) --*plevel;
} }
template <typename T> inline ret_t ret (ret_t v, unsigned int line = 0)
inline T ret (T v, unsigned int line = 0)
{ {
if (unlikely (returned)) { if (unlikely (returned)) {
fprintf (stderr, "OUCH, double calls to TRACE_RETURN. This is a bug, please report.\n"); fprintf (stderr, "OUCH, double calls to TRACE_RETURN. This is a bug, please report.\n");
return v; return v;
} }
_hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1, "return %s (line %d)", hb_printer_t<bool>().print (v), line); _hb_debug_msg<max_level> (what, obj, NULL, true, plevel ? *plevel : 1, -1,
"return %s (line %d)",
hb_printer_t<ret_t>().print (v), line);
if (plevel) --*plevel; if (plevel) --*plevel;
plevel = NULL; plevel = NULL;
returned = true; returned = true;
@ -730,8 +740,8 @@ struct hb_auto_trace_t {
const void *obj; const void *obj;
bool returned; bool returned;
}; };
template <> /* Optimize when tracing is disabled */ template <typename ret_t> /* Optimize when tracing is disabled */
struct hb_auto_trace_t<0> { struct hb_auto_trace_t<0, ret_t> {
explicit inline hb_auto_trace_t (unsigned int *plevel_ HB_UNUSED, explicit inline hb_auto_trace_t (unsigned int *plevel_ HB_UNUSED,
const char *what HB_UNUSED, const char *what HB_UNUSED,
const void *obj HB_UNUSED, const void *obj HB_UNUSED,