]> gitweb.factorcode.org Git - factor.git/commitdiff
WIP verify_callstack function
authorJoe Groff <arcata@gmail.com>
Thu, 1 Dec 2011 01:56:24 +0000 (17:56 -0800)
committerJoe Groff <arcata@gmail.com>
Wed, 14 Dec 2011 17:56:47 +0000 (09:56 -0800)
dumps callstack in reverse order so i can visually inspect that it matches the old forward walking logic

vm/callstack.hpp
vm/debug.cpp
vm/gc.cpp
vm/slot_visitor.hpp
vm/vm.hpp

index a8e4407cd7bb1e7eb18b46e1dd122958e3e8373b..2c70936f8814dd5541705add90259c06a2df4146 100755 (executable)
@@ -21,6 +21,55 @@ template<typename Iterator> void factor_vm::iterate_callstack_object(callstack *
        }
 }
 
+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;
index 54a48897e5fca9e1ce6c8b554d81bdda2822f1f1..6d363a84cc76760676fdde13c31028ce3520a6e5 100755 (executable)
@@ -247,6 +247,7 @@ void factor_vm::print_callstack()
        if (ctx)
        {
                stack_frame_printer printer(this);
+               verify_callstack(ctx);
                iterate_callstack(ctx,printer);
        }
        else
index 177bb970afa91fad80393cc668fa71b13236187a..0a9dee2e4363c43ad0ba4a7e07ee3553d626aa69 100755 (executable)
--- a/vm/gc.cpp
+++ b/vm/gc.cpp
@@ -257,6 +257,7 @@ void factor_vm::scrub_context(context *ctx)
 {
        call_frame_scrubber scrubber(this,ctx);
        iterate_callstack(ctx,scrubber);
+       verify_callstack(ctx);
 }
 
 void factor_vm::scrub_contexts()
index 5e8cbe10d055d1356b3c9a9a9530738627a29629..5c0b3367f394fea7e0a74f30cb546f1b373ab395 100755 (executable)
@@ -378,6 +378,7 @@ template<typename Fixup>
 void slot_visitor<Fixup>::visit_callstack(context *ctx)
 {
        call_frame_slot_visitor<Fixup> call_frame_visitor(parent,this);
+       parent->verify_callstack(ctx);
        parent->iterate_callstack(ctx,call_frame_visitor);
 }
 
index ec9086ef19fdda08dbd703f2fbe385278820e247..54519d4d9ad66d04575abd12d3cb04736ac76b2f 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -182,7 +182,11 @@ struct factor_vm
        {
                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
@@ -639,6 +643,8 @@ struct factor_vm
        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-*