}
}
+inline void factor_vm::verify_callstack(context *ctx, cell pc)
+{
+ if (pc == 0)
+ {
+ std::cout << "null return address" << std::endl;
+ return;
+ }
+
+ unsigned char *frame_top = (unsigned char*)ctx->callstack_top;
+ cell addr = pc;
+
+ while(frame_top < (unsigned char*)ctx->callstack_bottom)
+ {
+ std::cout << std::endl;
+ std::cout << "address " << (void*)addr << std::endl;
+ code_block *owner = code->code_block_for_address(addr);
+ std::cout << "owner " << (void*)owner->entry_point() << " ";
+ print_obj(owner->owner);
+ std::cout << std::endl;
+ cell frame_size = owner->stack_frame_size_for_address(addr);
+ std::cout << "frame size " << (void*)frame_size << std::endl;
+ frame_top += frame_size;
+ stack_frame *frame = (stack_frame*)frame_top - 1;
+ if (owner->entry_point() != frame->entry_point)
+ {
+ std::cout << "unexpected frame owner " << (void*)frame->entry_point << " ";
+ print_obj(((code_block*)frame->entry_point - 1)->owner);
+ std::cout << std::endl;
+ }
+ if (frame_size != frame->size)
+ std::cout << "unexpected frame size " << frame->size << std::endl;
+ // XXX x86
+ addr = *(cell*)frame_top;
+ }
+}
+
+inline void factor_vm::verify_callstack(context *ctx)
+{
+ /*
+ std::cout << std::endl << std::endl
+ << "callstack " << (void*)ctx->callstack_top
+ << " to " << (void*)ctx->callstack_bottom << std::endl;
+
+ // XXX x86-centric
+ cell return_address = *((cell*)ctx->callstack_top);
+ verify_callstack(ctx, return_address);
+ */
+}
+
template<typename Iterator> void factor_vm::iterate_callstack(context *ctx, Iterator &iterator)
{
stack_frame *frame = ctx->callstack_bottom - 1;
{
std::set<context *>::const_iterator begin = active_contexts.begin();
std::set<context *>::const_iterator end = active_contexts.end();
- while(begin != end) iterate_callstack(*begin++,iter);
+ while(begin != end)
+ {
+ verify_callstack(*begin);
+ iterate_callstack(*begin++,iter);
+ }
}
// run
void primitive_innermost_stack_frame_scan();
void primitive_set_innermost_stack_frame_quot();
void primitive_callstack_bounds();
+ void verify_callstack(context *ctx);
+ void verify_callstack(context *ctx, cell pc);
template<typename Iterator> void iterate_callstack(context *ctx, Iterator &iterator);
// cpu-*