Browse Source

fix a set of multiline debug call sites

pull/7/head
Sami Vaarala 11 years ago
parent
commit
dd77a90d8b
  1. 102
      src/duk_debug_heap.c
  2. 34
      src/duk_heap_markandsweep.c
  3. 50
      src/duk_hobject_enum.c
  4. 4
      src/duk_hobject_finalizer.c
  5. 32
      src/duk_hobject_pc2line.c

102
src/duk_debug_heap.c

@ -41,20 +41,20 @@ static const char *duk__get_heap_type_string(duk_heaphdr *hdr) {
static void duk__dump_indented(duk_heaphdr *obj, int index) {
#ifdef DUK_USE_REFERENCE_COUNTING
DUK_DPRINT(" [%d]: %p %s (flags: 0x%08x, ref: %d) -> %!O",
index,
(void *) obj,
duk__get_heap_type_string(obj),
(int) DUK_HEAPHDR_GET_FLAGS(obj),
DUK_HEAPHDR_GET_REFCOUNT(obj),
obj);
DUK_D(DUK_DPRINT(" [%d]: %p %s (flags: 0x%08x, ref: %d) -> %!O",
index,
(void *) obj,
duk__get_heap_type_string(obj),
(int) DUK_HEAPHDR_GET_FLAGS(obj),
DUK_HEAPHDR_GET_REFCOUNT(obj),
obj));
#else
DUK_DPRINT(" [%d]: %p %s (flags: 0x%08x) -> %!O",
index,
(void *) obj,
duk__get_heap_type_string(obj),
(int) DUK_HEAPHDR_GET_FLAGS(obj),
obj);
DUK_D(DUK_DPRINT(" [%d]: %p %s (flags: 0x%08x) -> %!O",
index,
(void *) obj,
duk__get_heap_type_string(obj),
(int) DUK_HEAPHDR_GET_FLAGS(obj),
obj));
#endif
}
@ -86,11 +86,11 @@ static void duk__dump_stringtable(duk_heap *heap) {
duk_uint32_t i;
char buf[64+1];
DUK_DPRINT("stringtable %p, used %d, size %d, load %d%%",
(void *) heap->st,
(int) heap->st_used,
(int) heap->st_size,
(int) (((double) heap->st_used) / ((double) heap->st_size) * 100.0));
DUK_D(DUK_DPRINT("stringtable %p, used %d, size %d, load %d%%",
(void *) heap->st,
(int) heap->st_used,
(int) heap->st_size,
(int) (((double) heap->st_used) / ((double) heap->st_size) * 100.0)));
for (i = 0; i < heap->st_size; i++) {
duk_hstring *e = heap->st[i];
@ -103,36 +103,36 @@ static void duk__dump_stringtable(duk_heap *heap) {
duk__sanitize_snippet(buf, sizeof(buf), e);
#ifdef DUK_USE_REFERENCE_COUNTING
DUK_DPRINT(" [%d]: %p (flags: 0x%08x, ref: %d) '%s', strhash=0x%08x, blen=%d, clen=%d, "
"arridx=%d, internal=%d, reserved_word=%d, strict_reserved_word=%d, eval_or_arguments=%d",
i,
(void *) e,
(int) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) e),
(int) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) e),
buf,
(int) e->hash,
(int) e->blen,
(int) e->clen,
DUK_HSTRING_HAS_ARRIDX(e) ? 1 : 0,
DUK_HSTRING_HAS_INTERNAL(e) ? 1 : 0,
DUK_HSTRING_HAS_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_STRICT_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(e) ? 1 : 0);
DUK_D(DUK_DPRINT(" [%d]: %p (flags: 0x%08x, ref: %d) '%s', strhash=0x%08x, blen=%d, clen=%d, "
"arridx=%d, internal=%d, reserved_word=%d, strict_reserved_word=%d, eval_or_arguments=%d",
i,
(void *) e,
(int) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) e),
(int) DUK_HEAPHDR_GET_REFCOUNT((duk_heaphdr *) e),
buf,
(int) e->hash,
(int) e->blen,
(int) e->clen,
DUK_HSTRING_HAS_ARRIDX(e) ? 1 : 0,
DUK_HSTRING_HAS_INTERNAL(e) ? 1 : 0,
DUK_HSTRING_HAS_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_STRICT_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(e) ? 1 : 0));
#else
DUK_DPRINT(" [%d]: %p (flags: 0x%08x) '%s', strhash=0x%08x, blen=%d, clen=%d, "
"arridx=%d, internal=%d, reserved_word=%d, strict_reserved_word=%d, eval_or_arguments=%d",
i,
(void *) e,
(int) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) e),
buf,
(int) e->hash,
(int) e->blen,
(int) e->clen,
DUK_HSTRING_HAS_ARRIDX(e) ? 1 : 0,
DUK_HSTRING_HAS_INTERNAL(e) ? 1 : 0,
DUK_HSTRING_HAS_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_STRICT_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(e) ? 1 : 0);
DUK_D(DUK_DPRINT(" [%d]: %p (flags: 0x%08x) '%s', strhash=0x%08x, blen=%d, clen=%d, "
"arridx=%d, internal=%d, reserved_word=%d, strict_reserved_word=%d, eval_or_arguments=%d",
i,
(void *) e,
(int) DUK_HEAPHDR_GET_FLAGS((duk_heaphdr *) e),
buf,
(int) e->hash,
(int) e->blen,
(int) e->clen,
DUK_HSTRING_HAS_ARRIDX(e) ? 1 : 0,
DUK_HSTRING_HAS_INTERNAL(e) ? 1 : 0,
DUK_HSTRING_HAS_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_STRICT_RESERVED_WORD(e) ? 1 : 0,
DUK_HSTRING_HAS_EVAL_OR_ARGUMENTS(e) ? 1 : 0));
#endif
}
}
@ -147,12 +147,12 @@ static void duk__dump_strcache(duk_heap *heap) {
for (i = 0; i < DUK_HEAP_STRCACHE_SIZE; i++) {
duk_strcache *c = &heap->strcache[i];
if (!c->h) {
DUK_DPRINT(" [%d]: bidx=%d, cidx=%d, str=NULL",
i, c->bidx, c->cidx);
DUK_D(DUK_DPRINT(" [%d]: bidx=%d, cidx=%d, str=NULL",
i, c->bidx, c->cidx));
} else {
duk__sanitize_snippet(buf, sizeof(buf), c->h);
DUK_DPRINT(" [%d]: bidx=%d cidx=%d str=%s",
i, c->bidx, c->cidx, buf);
DUK_D(DUK_DPRINT(" [%d]: bidx=%d cidx=%d str=%s",
i, c->bidx, c->cidx, buf));
}
}
}

34
src/duk_heap_markandsweep.c

@ -133,9 +133,9 @@ static void duk__mark_hobject(duk_heap *heap, duk_hobject *h) {
/* recursion tracking happens here only */
static void duk__mark_heaphdr(duk_heap *heap, duk_heaphdr *h) {
DUK_DDDPRINT("duk__mark_heaphdr %p, type %d",
(void *) h,
h ? (int) DUK_HEAPHDR_GET_TYPE(h) : (int) -1);
DUK_DDD(DUK_DDDPRINT("duk__mark_heaphdr %p, type %d",
(void *) h,
h ? (int) DUK_HEAPHDR_GET_TYPE(h) : (int) -1));
if (!h) {
return;
}
@ -389,8 +389,8 @@ static void duk__finalize_refcounts(duk_heap *heap) {
thr = duk__get_temp_hthread(heap);
DUK_ASSERT(thr != NULL);
DUK_DDPRINT("duk__finalize_refcounts: heap=%p, hthread=%p",
(void *) heap, (void *) thr);
DUK_DD(DUK_DDPRINT("duk__finalize_refcounts: heap=%p, hthread=%p",
(void *) heap, (void *) thr));
hdr = heap->heap_allocated;
while (hdr) {
@ -492,8 +492,8 @@ static void duk__sweep_stringtable(duk_heap *heap, duk_size_t *out_count_keep) {
}
#ifdef DUK_USE_DEBUG
DUK_DPRINT("mark-and-sweep sweep stringtable: %d freed, %d kept",
(int) count_free, (int) count_keep);
DUK_D(DUK_DPRINT("mark-and-sweep sweep stringtable: %d freed, %d kept",
(int) count_free, (int) count_keep));
#endif
*out_count_keep = count_keep;
}
@ -644,8 +644,8 @@ static void duk__sweep_heap(duk_heap *heap, duk_int_t flags, duk_size_t *out_cou
}
#ifdef DUK_USE_DEBUG
DUK_DPRINT("mark-and-sweep sweep objects (non-string): %d freed, %d kept, %d rescued, %d queued for finalization",
(int) count_free, (int) count_keep, (int) count_rescue, (int) count_finalize);
DUK_D(DUK_DPRINT("mark-and-sweep sweep objects (non-string): %d freed, %d kept, %d rescued, %d queued for finalization",
(int) count_free, (int) count_keep, (int) count_rescue, (int) count_finalize));
#endif
*out_count_keep = count_keep;
}
@ -848,8 +848,8 @@ static void duk__assert_valid_refcounts(duk_heap *heap) {
*/
#if 0 /* this case can no longer occur because refcount is unsigned */
} else if (DUK_HEAPHDR_GET_REFCOUNT(hdr) < 0) {
DUK_DPRINT("invalid refcount: %d, %p -> %!O",
(hdr != NULL ? DUK_HEAPHDR_GET_REFCOUNT(hdr) : 0), (void *) hdr, hdr);
DUK_D(DUK_DPRINT("invalid refcount: %d, %p -> %!O",
(hdr != NULL ? DUK_HEAPHDR_GET_REFCOUNT(hdr) : 0), (void *) hdr, hdr));
DUK_ASSERT(DUK_HEAPHDR_GET_REFCOUNT(hdr) > 0);
#endif
}
@ -887,8 +887,8 @@ int duk_heap_mark_and_sweep(duk_heap *heap, int flags) {
return 0; /* OK */
}
DUK_DPRINT("garbage collect (mark-and-sweep) starting, requested flags: 0x%08x, effective flags: 0x%08x",
flags, flags | heap->mark_and_sweep_base_flags);
DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) starting, requested flags: 0x%08x, effective flags: 0x%08x",
flags, flags | heap->mark_and_sweep_base_flags));
flags |= heap->mark_and_sweep_base_flags;
@ -1068,11 +1068,11 @@ int duk_heap_mark_and_sweep(duk_heap *heap, int flags) {
heap->mark_and_sweep_trigger_counter =
(tmp * DUK_HEAP_MARK_AND_SWEEP_TRIGGER_MULT) +
DUK_HEAP_MARK_AND_SWEEP_TRIGGER_ADD;
DUK_DPRINT("garbage collect (mark-and-sweep) finished: %d objects kept, %d strings kept, trigger reset to %d",
(int) count_keep_obj, (int) count_keep_str, (int) heap->mark_and_sweep_trigger_counter);
DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %d objects kept, %d strings kept, trigger reset to %d",
(int) count_keep_obj, (int) count_keep_str, (int) heap->mark_and_sweep_trigger_counter));
#else
DUK_DPRINT("garbage collect (mark-and-sweep) finished: %d objects kept, %d strings kept, no voluntary trigger",
(int) count_keep_obj, (int) count_keep_str);
DUK_D(DUK_DPRINT("garbage collect (mark-and-sweep) finished: %d objects kept, %d strings kept, no voluntary trigger",
(int) count_keep_obj, (int) count_keep_str));
#endif
return 0; /* OK */
}

50
src/duk_hobject_enum.c

@ -64,17 +64,17 @@ static void duk__sort_array_indices(duk_hobject *h_obj) {
p_end = keys + h_obj->e_used;
keys += DUK__ENUM_START_INDEX;
DUK_DDDPRINT("keys=%p, p_end=%p (after skipping enum props)",
(void *) keys, (void *) p_end);
DUK_DDD(DUK_DDDPRINT("keys=%p, p_end=%p (after skipping enum props)",
(void *) keys, (void *) p_end));
#ifdef DUK_USE_DDDPRINT
{
duk_uint_fast32_t i;
for (i = 0; i < (duk_uint_fast32_t) h_obj->e_used; i++) {
DUK_DDDPRINT("initial: %d %p -> %!O",
(int) i,
(void *) DUK_HOBJECT_E_GET_KEY_PTR(h_obj, i),
(void *) DUK_HOBJECT_E_GET_KEY(h_obj, i));
DUK_DDD(DUK_DDDPRINT("initial: %d %p -> %!O",
(int) i,
(void *) DUK_HOBJECT_E_GET_KEY_PTR(h_obj, i),
(void *) DUK_HOBJECT_E_GET_KEY(h_obj, i)));
}
}
#endif
@ -85,16 +85,16 @@ static void duk__sort_array_indices(duk_hobject *h_obj) {
val_curr = DUK_HSTRING_GET_ARRIDX_SLOW(*p_curr);
if (val_curr >= val_highest) {
DUK_DDDPRINT("p_curr=%p, p_end=%p, val_highest=%d, val_curr=%d -> "
"already in correct order, next",
(void *) p_curr, (void *) p_end, (int) val_highest, (int) val_curr);
DUK_DDD(DUK_DDDPRINT("p_curr=%p, p_end=%p, val_highest=%d, val_curr=%d -> "
"already in correct order, next",
(void *) p_curr, (void *) p_end, (int) val_highest, (int) val_curr));
val_highest = val_curr;
continue;
}
DUK_DDDPRINT("p_curr=%p, p_end=%p, val_highest=%d, val_curr=%d -> "
"needs to be inserted",
(void *) p_curr, (void *) p_end, (int) val_highest, (int) val_curr);
DUK_DDD(DUK_DDDPRINT("p_curr=%p, p_end=%p, val_highest=%d, val_curr=%d -> "
"needs to be inserted",
(void *) p_curr, (void *) p_end, (int) val_highest, (int) val_curr));
/* Needs to be inserted; scan backwards, since we optimize
* for the case where elements are nearly in order.
@ -104,8 +104,8 @@ static void duk__sort_array_indices(duk_hobject *h_obj) {
for (;;) {
val_insert = DUK_HSTRING_GET_ARRIDX_SLOW(*p_insert);
if (val_insert < val_curr) {
DUK_DDDPRINT("p_insert=%p, val_insert=%d, val_curr=%d -> insert after this",
(void *) p_insert, (int) val_insert, (int) val_curr);
DUK_DDD(DUK_DDDPRINT("p_insert=%p, val_insert=%d, val_curr=%d -> insert after this",
(void *) p_insert, (int) val_insert, (int) val_curr));
p_insert++;
break;
}
@ -113,8 +113,8 @@ static void duk__sort_array_indices(duk_hobject *h_obj) {
DUK_DDD(DUK_DDDPRINT("p_insert=%p -> out of keys, insert to beginning"));
break;
}
DUK_DDDPRINT("p_insert=%p, val_insert=%d, val_curr=%d -> search backwards",
(void *) p_insert, (int) val_insert, (int) val_curr);
DUK_DDD(DUK_DDDPRINT("p_insert=%p, val_insert=%d, val_curr=%d -> search backwards",
(void *) p_insert, (int) val_insert, (int) val_curr));
p_insert--;
}
@ -126,9 +126,9 @@ static void duk__sort_array_indices(duk_hobject *h_obj) {
*/
h_curr = *p_curr;
DUK_DDDPRINT("memmove: dest=%p, src=%p, size=%d, h_curr=%p",
(void *) (p_insert + 1), (void *) p_insert,
(int) (p_curr - p_insert), (void *) h_curr);
DUK_DDD(DUK_DDDPRINT("memmove: dest=%p, src=%p, size=%d, h_curr=%p",
(void *) (p_insert + 1), (void *) p_insert,
(int) (p_curr - p_insert), (void *) h_curr));
DUK_MEMMOVE((void *) (p_insert + 1),
(void *) p_insert,
@ -141,10 +141,10 @@ static void duk__sort_array_indices(duk_hobject *h_obj) {
{
duk_uint_fast32_t i;
for (i = 0; i < (duk_uint_fast32_t) h_obj->e_used; i++) {
DUK_DDDPRINT("final: %d %p -> %!O",
(int) i,
(void *) DUK_HOBJECT_E_GET_KEY_PTR(h_obj, i),
(void *) DUK_HOBJECT_E_GET_KEY(h_obj, i));
DUK_DDD(DUK_DDDPRINT("final: %d %p -> %!O",
(int) i,
(void *) DUK_HOBJECT_E_GET_KEY_PTR(h_obj, i),
(void *) DUK_HOBJECT_E_GET_KEY(h_obj, i)));
}
}
#endif
@ -390,8 +390,8 @@ int duk_hobject_enumerator_next(duk_context *ctx, int get_value) {
DUK_ASSERT(target != NULL);
duk_pop(ctx); /* still reachable */
DUK_DDDPRINT("getting next enum value, target=%!iO, enumerator=%!iT",
target, duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("getting next enum value, target=%!iO, enumerator=%!iT",
target, duk_get_tval(ctx, -1)));
/* no array part */
for (;;) {

4
src/duk_hobject_finalizer.c

@ -76,8 +76,8 @@ void duk_hobject_run_finalizer(duk_hthread *thr, duk_hobject *obj) {
/* Note: we ask for one return value from duk_safe_call to get this
* error debugging here.
*/
DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T",
(void *) obj, duk_get_tval(ctx, -1));
DUK_D(DUK_DPRINT("wrapped finalizer call failed for object %p (ignored); error: %!T",
(void *) obj, duk_get_tval(ctx, -1)));
}
duk_pop_2(ctx); /* -> [...] */

32
src/duk_hobject_pc2line.c

@ -57,11 +57,11 @@ void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_
hdr[hdr_index + 1] = (duk_uint32_t) curr_offset;
#if 0
DUK_DDDPRINT("hdr[%d]: pc=%d line=%d offset=%d",
(int) (curr_pc / DUK_PC2LINE_SKIP),
(int) curr_pc,
(int) hdr[hdr_index + 0],
(int) hdr[hdr_index + 1]);
DUK_DDD(DUK_DDDPRINT("hdr[%d]: pc=%d line=%d offset=%d",
(int) (curr_pc / DUK_PC2LINE_SKIP),
(int) curr_pc,
(int) hdr[hdr_index + 0],
(int) hdr[hdr_index + 1]));
#endif
DUK_MEMZERO(be_ctx, sizeof(*be_ctx));
@ -79,8 +79,8 @@ void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_
diff_line = next_line - curr_line;
#if 0
DUK_DDDPRINT("curr_line=%d, next_line=%d -> diff_line=%d",
(int) curr_line, (int) next_line, (int) diff_line);
DUK_DDD(DUK_DDDPRINT("curr_line=%d, next_line=%d -> diff_line=%d",
(int) curr_line, (int) next_line, (int) diff_line));
#endif
if (diff_line == 0) {
@ -117,9 +117,9 @@ void duk_hobject_pc2line_pack(duk_hthread *thr, duk_compiler_instr *instrs, duk_
duk_to_fixed_buffer(ctx, -1);
DUK_DDDPRINT("final pc2line data: pc_limit=%d, length=%d, %lf bits/opcode --> %!ixT",
(int) length, (int) new_size, (double) new_size * 8.0 / (double) length,
duk_get_tval(ctx, -1));
DUK_DDD(DUK_DDDPRINT("final pc2line data: pc_limit=%d, length=%d, %lf bits/opcode --> %!ixT",
(int) length, (int) new_size, (double) new_size * 8.0 / (double) length,
duk_get_tval(ctx, -1)));
}
/* PC is unsigned. If caller does PC arithmetic and gets a negative result,
@ -153,16 +153,16 @@ duk_uint_fast32_t duk_hobject_pc2line_query(duk_hbuffer_fixed *buf, duk_uint_fas
pc_limit = hdr[0];
if (pc >= pc_limit) {
/* Note: pc is unsigned and cannot be negative */
DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%d, limit=%d)",
(int) pc, (int) pc_limit);
DUK_DD(DUK_DDPRINT("pc2line lookup failed: pc out of bounds (pc=%d, limit=%d)",
(int) pc, (int) pc_limit));
goto error;
}
curr_line = hdr[1 + hdr_index * 2];
start_offset = hdr[1 + hdr_index * 2 + 1];
if ((duk_size_t) start_offset > DUK_HBUFFER_FIXED_GET_SIZE(buf)) {
DUK_DDPRINT("pc2line lookup failed: start_offset out of bounds (start_offset=%d, buffer_size=%d)",
(int) start_offset, (int) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf));
DUK_DD(DUK_DDPRINT("pc2line lookup failed: start_offset out of bounds (start_offset=%d, buffer_size=%d)",
(int) start_offset, (int) DUK_HBUFFER_GET_SIZE((duk_hbuffer *) buf)));
goto error;
}
@ -171,8 +171,8 @@ duk_uint_fast32_t duk_hobject_pc2line_query(duk_hbuffer_fixed *buf, duk_uint_fas
bd_ctx->length = (duk_size_t) (DUK_HBUFFER_FIXED_GET_SIZE(buf) - start_offset);
#if 0
DUK_DDDPRINT("pc2line lookup: pc=%d -> hdr_index=%d, pc_base=%d, n=%d, start_offset=%d",
(int) pc, (int) hdr_index, (int) pc_base, (int) n, (int) start_offset);
DUK_DDD(DUK_DDDPRINT("pc2line lookup: pc=%d -> hdr_index=%d, pc_base=%d, n=%d, start_offset=%d",
(int) pc, (int) hdr_index, (int) pc_base, (int) n, (int) start_offset));
#endif
while (n > 0) {

Loading…
Cancel
Save