Skip to content

Commit

Permalink
coro: more debug tracing. also track cont pc
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Oct 23, 2014
1 parent 90de1df commit e0ff4f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
17 changes: 16 additions & 1 deletion src/pmc/continuation.pmc
Expand Up @@ -40,6 +40,16 @@ more information.
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */

#ifdef NDEBUG
# define TRACE_CONT_1(s, arg)
# define TRACE_CONT_d(s, arg)
#else
# define TRACE_CONT_1(s, arg) \
if (Interp_trace_TEST(interp, PARROT_TRACE_CORO_STATE_FLAG)) \
fprintf(stderr, (s), (arg))
# define TRACE_CONT_d(s, arg) TRACE_CONT_1(s, arg)
#endif


/*
* A Continuation (and an ExceptionHandler) has in its context a pointer
Expand Down Expand Up @@ -225,7 +235,9 @@ for any returned values.

VTABLE void set_pointer(void *value) {
SET_ATTR_address(INTERP, SELF, (opcode_t *)value);
TRACE_CONT_d("# - cont: address %p - ", value);
SET_ATTR_runloop_id(INTERP, SELF, INTERP->current_runloop_id);
TRACE_CONT_d("%d\n", INTERP->current_runloop_id);
}


Expand Down Expand Up @@ -327,8 +339,11 @@ destination to continue execution.
Parrot_pcc_set_signature(INTERP, CURRENT_CONTEXT(INTERP), from_obj);

/* switch segment */
if (INTERP->code != seg)
if (INTERP->code != seg) {
TRACE_CONT_d("# - cont: switch from seg %p - ", INTERP->code);
TRACE_CONT_d("%p\n", seg);
Parrot_switch_to_cs(INTERP, seg, 1);
}

return pc;
}
Expand Down
29 changes: 18 additions & 11 deletions src/pmc/coroutine.pmc
Expand Up @@ -257,9 +257,10 @@ yields are exhausted and the coro is dead.
ctx = Parrot_pmc_new(INTERP, enum_class_CallContext);
TRACE_CORO("# - coro: first ctx\n");
Parrot_pcc_set_context(INTERP, ctx);
TRACE_CORO_d("# - coro: first ctx %p\n", caller_ctx);
TRACE_CORO_d("# - coro: to_ctx %p\n", ctx);
TRACE_CORO_d("# - coro: cont %p\n", ccont);
TRACE_CORO_d("# - coro: first ctx %p -> ", caller_ctx);
TRACE_CORO_d("%p\n", ctx);
TRACE_CORO_d("# - coro: cont %p pc ", ccont);
TRACE_CORO_d("%p\n", PARROT_CONTINUATION(ccont)->address);

GET_ATTR_n_regs_used(INTERP, SELF, n_regs_used);
Parrot_pcc_allocate_registers(INTERP, ctx, n_regs_used);
Expand All @@ -272,7 +273,6 @@ yields are exhausted and the coro is dead.

Parrot_pcc_set_sub(INTERP, ctx, SELF);
Parrot_pcc_set_continuation(INTERP, ctx, ccont);
TRACE_CORO_d("# - coro: cont %p\n", ccont);

INTERP->current_cont = PMCNULL;

Expand Down Expand Up @@ -305,9 +305,10 @@ yields are exhausted and the coro is dead.
ccont = Parrot_pcc_get_continuation(INTERP, ctx);
GET_ATTR_yield(INTERP, SELF, yield);
TRACE_CORO_1("# - coro: !ff (yield=%ld)\n", yield);
TRACE_CORO_d("# - coro: cont %p\n", ccont);
TRACE_CORO_d("# - coro: ctx %p\n", caller_ctx);
TRACE_CORO_d("# - coro: to_ctx %p\n", ctx);
TRACE_CORO_d("# - coro: ctx %p -> ", caller_ctx);
TRACE_CORO_d("%p\n", ctx);
TRACE_CORO_d("# - coro: cont %p pc ", ccont);
TRACE_CORO_d("%p\n", PARROT_CONTINUATION(ccont)->address);

if (yield == 2) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
Expand Down Expand Up @@ -342,9 +343,10 @@ yields are exhausted and the coro is dead.
ccont = Parrot_pcc_get_continuation(INTERP, ctx);

GETATTR_Continuation_to_ctx(INTERP, ccont, to_ctx);
TRACE_CORO_d("# - coro: cont %p\n", ccont);
TRACE_CORO_d("# - coro: ctx %p\n", ctx);
TRACE_CORO_d("# - coro: to_ctx %p\n", to_ctx);
TRACE_CORO_d("# - coro: ctx %p -> ", ctx);
TRACE_CORO_d("%p\n", to_ctx);
TRACE_CORO_d("# - coro: cont %p pc ", ccont);
TRACE_CORO_d("%p\n", PARROT_CONTINUATION(ccont)->address);
PObj_get_FLAGS(SELF) &= ~SUB_FLAG_CORO_FF;

GET_ATTR_caller_seg(INTERP, SELF, caller_seg);
Expand All @@ -357,10 +359,15 @@ yields are exhausted and the coro is dead.

/* toggle address */
GET_ATTR_address(INTERP, SELF, dest);
TRACE_CORO_d("# - coro: address %p -> ", dest);
SET_ATTR_address(INTERP, SELF, (opcode_t *)next);
TRACE_CORO_d("%p\n", next);

if (INTERP->code != wanted_seg)
if (INTERP->code != wanted_seg) {
TRACE_CORO_d("# - coro: switch from seg %p -> ", INTERP->code);
TRACE_CORO_d("%p\n", wanted_seg);
Parrot_switch_to_cs(INTERP, wanted_seg, 1);
}

return dest;
}
Expand Down

0 comments on commit e0ff4f2

Please sign in to comment.