[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() \
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
@ -206,10 +208,11 @@ struct hb_sanitize_context_t
{
const char *p = (const char *) base;
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&this->debug_depth, "SANITIZE", this->blob, NULL,
"check_range [%p..%p] (%d bytes) in [%p..%p]",
p, p + len, len,
this->start, this->end);
hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace
(&this->debug_depth, "SANITIZE", this->blob, NULL,
"check_range [%p..%p] (%d bytes) in [%p..%p]",
p, p + len, len,
this->start, this->end);
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;
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,
"check_array [%p..%p] (%d*%d=%ld bytes) in [%p..%p]",
p, p + (record_size * len), record_size, len, (unsigned long) record_size * len,
this->start, this->end);
hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace
(&this->debug_depth, "SANITIZE", this->blob, NULL,
"check_array [%p..%p] (%d*%d=%ld bytes) in [%p..%p]",
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)));
}
@ -238,11 +242,12 @@ struct hb_sanitize_context_t
const char *p = (const char *) base;
this->edit_count++;
hb_auto_trace_t<HB_DEBUG_SANITIZE> trace (&this->debug_depth, "SANITIZE", this->blob, NULL,
"may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
this->edit_count,
p, p + len, len,
this->start, this->end);
hb_auto_trace_t<HB_DEBUG_SANITIZE, bool> trace
(&this->debug_depth, "SANITIZE", this->blob, NULL,
"may_edit(%u) [%p..%p] (%d bytes) in [%p..%p] -> %s",
this->edit_count,
p, p + len, len,
this->start, this->end);
return TRACE_RETURN (this->writable);
}
@ -338,7 +343,9 @@ struct Sanitizer
#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

View File

@ -37,12 +37,15 @@
namespace OT {
#ifndef HB_DEBUG_CLOSURE
#define HB_DEBUG_CLOSURE (HB_DEBUG+0)
#endif
#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
{
@ -87,8 +90,9 @@ struct hb_closure_context_t
#endif
#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
{
@ -123,8 +127,9 @@ struct hb_would_apply_context_t
#endif
#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
{
@ -183,8 +188,9 @@ struct hb_get_coverage_context_t
#endif
#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
{
@ -517,7 +523,9 @@ static inline bool match_input (hb_apply_context_t *c,
bool *p_is_mark_ligature = 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);
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,
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);
if (skippy_iter.has_no_chance ())
@ -699,7 +709,9 @@ static inline bool match_lookahead (hb_apply_context_t *c,
const void *match_data,
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);
if (skippy_iter.has_no_chance ())
@ -748,7 +760,10 @@ static inline bool apply_lookup (hb_apply_context_t *c,
unsigned int lookupCount,
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;
if (unlikely (count == 0 || c->buffer->idx + count > end))
return TRACE_RETURN (false);

View File

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