Skip to content

Commit

Permalink
Merge pull request MacRuby#54 from msabramo/issue_1446
Browse files Browse the repository at this point in the history
Add more information when assertion fails in `RoxorVM::pop_current_exception`
  • Loading branch information
jballanc committed Apr 2, 2012
2 parents 35ca688 + 7dadabb commit ca3efd0
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4653,6 +4653,9 @@ RoxorCompiler::compile_node0(NODE *node)
// one from the VM stack and rethrow.
bb = new_rescue_invoke_bb;
compile_landing_pad_header();
#if ROXOR_COMPILER_DEBUG
printf("%s (%s:%d): Calling compile_pop_exception(1)...\n", __FUNCTION__, __FILE__, __LINE__);
#endif
compile_pop_exception(1);
compile_rethrow_exception();
rescue_invoke_bb = old_rescue_invoke_bb;
Expand Down
76 changes: 75 additions & 1 deletion vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,10 @@ RoxorVM::debug_exceptions(void)
for (std::vector<VALUE>::iterator i = current_exceptions.begin();
i != current_exceptions.end();
++i) {
printf("%p ", (void *)*i);
printf("current_exceptions[%d] = (%p) \"%s\"",
(int)(i - current_exceptions.begin()),
(void *)*i,
RSTRING_PTR(rb_inspect(*i)));
}
printf("\n");
}
Expand Down Expand Up @@ -3560,6 +3563,10 @@ static inline void
__vm_raise(void)
{
VALUE rb_exc = GET_VM()->current_exception();
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): rb_exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(rb_exc)));
#endif

// DTrace probe: raise
if (MACRUBY_RAISE_ENABLED()) {
Expand All @@ -3586,6 +3593,10 @@ RoxorVM::push_current_exception(VALUE exc)
assert(!NIL_P(exc));
GC_RETAIN(exc);
current_exceptions.push_back(exc);
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exc)));
#endif
//printf("PUSH %p %s\n", (void *)exc, RSTRING_PTR(rb_inspect(exc)));
}

Expand All @@ -3597,6 +3608,17 @@ RoxorVM::pop_current_exception(int pos)
return;
}

#if ROXOR_VM_DEBUG
if (!((size_t)pos < current_exceptions.size()))
{
printf("RoxorVM::%s (%s:%d) - "
"Warning: Assertion about to fail: "
"((size_t)pos < current_exceptions.size()); pos = %d; "
"current_exceptions.size() = %d\n",
__FUNCTION__, __FILE__, __LINE__, pos, (int)current_exceptions.size());
debug_exceptions();
}
#endif
assert((size_t)pos < current_exceptions.size());

std::vector<VALUE>::iterator iter = current_exceptions.end() - (pos + 1);
Expand All @@ -3613,6 +3635,10 @@ void
rb_rb2oc_exc_handler(void)
{
VALUE exc = GET_VM()->current_exception();
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exc)));
#endif
if (exc != Qnil) {
id ocexc = rb_rb2oc_exception(exc);
objc_exception_throw(ocexc);
Expand All @@ -3639,6 +3665,10 @@ void
rb_vm_raise_current_exception(void)
{
VALUE exception = GET_VM()->current_exception();
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exception = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exception)));
#endif
assert(exception != Qnil);
prepare_exception_bt(exception);
__vm_raise();
Expand All @@ -3649,6 +3679,10 @@ void
rb_vm_raise(VALUE exception)
{
prepare_exception_bt(exception);
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exception = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exception)));
#endif
GET_VM()->push_current_exception(exception);
__vm_raise();
}
Expand All @@ -3664,6 +3698,10 @@ rb_rescue2(VALUE (*b_proc) (ANYARGS), VALUE data1,
catch (...) {
RoxorVM *vm = GET_VM();
VALUE exc = vm->current_exception();
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exc)));
#endif
if (exc != Qnil) {
va_list ar;
VALUE eclass;
Expand All @@ -3679,6 +3717,10 @@ rb_rescue2(VALUE (*b_proc) (ANYARGS), VALUE data1,
va_end(ar);

if (handled) {
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): Calling pop_current_exception...\n",
__FUNCTION__, __FILE__, __LINE__);
#endif
vm->pop_current_exception();
if (r_proc != NULL) {
return (*r_proc)(data2, exc);
Expand Down Expand Up @@ -3890,6 +3932,10 @@ rb_vm_is_eh_active(int argc, ...)
assert(argc > 0);

VALUE current_exception = GET_VM()->current_exception();
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): current_exception = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(current_exception)));
#endif
if (current_exception == Qnil) {
// Not a Ruby exception...
return 0;
Expand Down Expand Up @@ -3925,6 +3971,10 @@ extern "C"
void
rb_vm_pop_exception(int pos)
{
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): Calling pop_current_exception(%d)...\n",
__FUNCTION__, __FILE__, __LINE__, pos);
#endif
GET_VM()->pop_current_exception(pos);
}

Expand All @@ -3941,7 +3991,15 @@ rb_vm_set_current_exception(VALUE exception)
{
assert(!NIL_P(exception));

#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exception = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exception)));
#endif
VALUE current = GET_VM()->current_exception();
#if ROXOR_VM_DEBUG
printf("%s: (%s:%d) current = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(current)));
#endif
assert(exception != current);
if (!NIL_P(current)) {
GET_VM()->pop_current_exception();
Expand Down Expand Up @@ -4535,6 +4593,10 @@ RoxorVM::increase_nesting_for_tag(VALUE tag)
{
std::map<VALUE, rb_vm_catch_t *>::iterator iter = this->catch_nesting.find(tag);
VALUE exc = current_exception();
#if ROXOR_VM_DEBUG
printf("%s: (%s:%d) exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exc)));
#endif
if (iter == catch_nesting.end()) {
rb_vm_catch_t *catch_ptr = new rb_vm_catch_t;
catch_ptr->nested = 1;
Expand Down Expand Up @@ -4617,6 +4679,10 @@ RoxorVM::ruby_throw(VALUE tag, VALUE value)
// since we are going to unwind the stack.
rb_vm_catch_t *catch_ptr = iter->second;
while (catch_ptr->current_exceptions.back() != current_exception()) {
#if ROXOR_VM_DEBUG
printf("RoxorVM::%s (%s:%d): Calling pop_current_exception...\n",
__FUNCTION__, __FILE__, __LINE__);
#endif
pop_current_exception();
}

Expand Down Expand Up @@ -4882,6 +4948,10 @@ rb_vm_thread_run(VALUE thread)
else {
exc = rb_vm_current_exception();
}
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exc)));
#endif
if (exc != Qnil) {
GC_WB(&t->exception, exc);
}
Expand Down Expand Up @@ -5110,6 +5180,10 @@ rb_vm_thread_raise(rb_vm_thread_t *t, VALUE exc)
{
// XXX we should lock here
RoxorVM *vm = (RoxorVM *)t->vm;
#if ROXOR_VM_DEBUG
printf("%s (%s:%d): exc = \"%s\"\n",
__FUNCTION__, __FILE__, __LINE__, RSTRING_PTR(rb_inspect(exc)));
#endif
vm->push_current_exception(exc);

rb_vm_thread_cancel(t);
Expand Down

0 comments on commit ca3efd0

Please sign in to comment.