Skip to content

Commit 9affa45

Browse files
committed
reworking raise event hadling
1 parent 9b542a9 commit 9affa45

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

ext/ruby_debug/ruby_debug.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ inline static int
644644
c_call_new_frame_p(VALUE klass, ID mid)
645645
{
646646
klass = real_class(klass);
647+
// if ((klass == rb_mKernel) && (strcmp(rb_id2name(mid), "raise") == 0)) return 0;
648+
647649
if(rb_block_given_p()) return 1;
648650
if(klass == rb_cProc || klass == rb_mKernel || klass == rb_cModule /*|| klass == rb_cFixnum*/) return 1;
649651
return 0;
@@ -851,12 +853,6 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
851853
{
852854
case RUBY_EVENT_LINE:
853855
{
854-
if(debug_context->stack_size == 0 ||
855-
get_top_frame(debug_context)->info.runtime.block_iseq != thread->cfp->block_iseq ||
856-
get_top_frame(debug_context)->info.runtime.cfp->iseq != thread->cfp->iseq)
857-
save_call_frame(event, debug_context, self, file, line, mid);
858-
else
859-
set_frame_source(event, debug_context, self, file, line, mid);
860856
if (CTX_FL_TEST(debug_context, CTX_FL_CATCHING))
861857
{
862858
debug_frame_t *top_frame = get_top_frame(debug_context);
@@ -873,25 +869,26 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
873869
iseq->catch_table = debug_context->catch_table.old_catch_table;
874870
}
875871

876-
/* send catchpoint notification */
877-
if(debug == Qtrue)
878-
fprintf(stderr, "modname: %s\n", RSTRING_PTR(debug_context->catch_table.mod_name));
879-
// int c_hit_count = FIX2INT(rb_hash_aref(rdebug_catchpoints, debug_context->catch_table.mod_name)) + 1;
880-
// hit_count = INT2FIX(c_hit_count);
881-
// rb_hash_aset(rdebug_catchpoints, debug_context->catch_table.mod_name, hit_count);
872+
/* send catchpoint notification */
873+
int c_hit_count = FIX2INT(rb_hash_aref(rdebug_catchpoints, debug_context->catch_table.mod_name)) + 1;
874+
hit_count = INT2FIX(c_hit_count);
875+
rb_hash_aset(rdebug_catchpoints, debug_context->catch_table.mod_name, hit_count);
882876
debug_context->stop_reason = CTX_STOP_CATCHPOINT;
883877
rb_funcall(context, idAtCatchpoint, 1, debug_context->catch_table.errinfo);
884878
if(self && binding == Qnil)
885879
binding = create_binding(self);
886880
save_top_binding(debug_context, binding);
887-
call_at_line(context, debug_context, rb_str_new2(file), INT2FIX(line));
888-
rb_raise(rb_eRuntimeError, "rise up");
881+
call_at_line(context, debug_context, rb_str_new2(top_frame->file), INT2FIX(top_frame->line));
889882
}
890-
891-
/* now allow the next exception to be caught */
892-
CTX_FL_UNSET(debug_context, CTX_FL_CATCHING);
883+
893884
break;
894885
}
886+
if(debug_context->stack_size == 0 ||
887+
get_top_frame(debug_context)->info.runtime.block_iseq != thread->cfp->block_iseq ||
888+
get_top_frame(debug_context)->info.runtime.cfp->iseq != thread->cfp->iseq)
889+
save_call_frame(event, debug_context, self, file, line, mid);
890+
else
891+
set_frame_source(event, debug_context, self, file, line, mid);
895892

896893
if(RTEST(tracing) || CTX_FL_TEST(debug_context, CTX_FL_TRACING))
897894
rb_funcall(context, idAtTracing, 2, rb_str_new2(file), INT2FIX(line));
@@ -1002,6 +999,13 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
1002999
}
10031000
case RUBY_EVENT_RAISE:
10041001
{
1002+
if (CTX_FL_TEST(debug_context, CTX_FL_CATCHING)) {
1003+
/* we're re-raising exception after processing line event,
1004+
now allow the next exception to be caught, don't setup catchers */
1005+
CTX_FL_UNSET(debug_context, CTX_FL_CATCHING);
1006+
break;
1007+
}
1008+
10051009
VALUE ancestors;
10061010
VALUE expn_class, aclass;
10071011
int i;
@@ -1080,7 +1084,8 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
10801084
/* create a new catch table to catch this exception, and put it in the current iseq */
10811085
iseq->catch_table_size = 1;
10821086
iseq->catch_table =
1083-
create_catch_table(debug_context, top_frame->info.runtime.last_pc - cfp->iseq->iseq_encoded - insn_len(BIN(trace)));
1087+
create_catch_table(debug_context, top_frame->info.runtime.last_pc - cfp->iseq->iseq_encoded - insn_len(BIN(trace)));
1088+
break;
10841089
}
10851090
}
10861091
}

0 commit comments

Comments
 (0)