Skip to content

Commit 9b542a9

Browse files
committed
reworking raise event hadling (wip, currently broken)
1 parent fde2982 commit 9b542a9

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

ext/ruby_debug/ruby_debug.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ c_call_new_frame_p(VALUE klass, ID mid)
645645
{
646646
klass = real_class(klass);
647647
if(rb_block_given_p()) return 1;
648-
if(klass == rb_cProc || klass == rb_mKernel || klass == rb_cModule) return 1;
648+
if(klass == rb_cProc || klass == rb_mKernel || klass == rb_cModule /*|| klass == rb_cFixnum*/) return 1;
649649
return 0;
650650
}
651651

@@ -865,21 +865,27 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
865865
{
866866
rb_control_frame_t *cfp = top_frame->info.runtime.cfp;
867867
VALUE hit_count;
868+
rb_iseq_t *iseq = cfp->iseq;
868869

869-
/* restore the proper catch table */
870-
cfp->iseq->catch_table_size = debug_context->catch_table.old_catch_table_size;
871-
cfp->iseq->catch_table = debug_context->catch_table.old_catch_table;
870+
if (iseq != NULL) {
871+
/* restore the proper catch table */
872+
iseq->catch_table_size = debug_context->catch_table.old_catch_table_size;
873+
iseq->catch_table = debug_context->catch_table.old_catch_table;
874+
}
872875

873876
/* send catchpoint notification */
874-
int c_hit_count = FIX2INT(rb_hash_aref(rdebug_catchpoints, debug_context->catch_table.mod_name)) + 1;
875-
hit_count = INT2FIX(c_hit_count);
876-
rb_hash_aset(rdebug_catchpoints, debug_context->catch_table.mod_name, hit_count);
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);
877882
debug_context->stop_reason = CTX_STOP_CATCHPOINT;
878883
rb_funcall(context, idAtCatchpoint, 1, debug_context->catch_table.errinfo);
879884
if(self && binding == Qnil)
880885
binding = create_binding(self);
881886
save_top_binding(debug_context, binding);
882887
call_at_line(context, debug_context, rb_str_new2(file), INT2FIX(line));
888+
rb_raise(rb_eRuntimeError, "rise up");
883889
}
884890

885891
/* now allow the next exception to be caught */
@@ -1000,7 +1006,12 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
10001006
VALUE expn_class, aclass;
10011007
int i;
10021008

1003-
set_frame_source(event, debug_context, self, file, line, mid);
1009+
if(debug == Qtrue) {
1010+
fprintf(stderr, "stack_size %d\n", debug_context->stack_size);
1011+
for (i = 0; i < debug_context->stack_size; i++) {
1012+
fprintf(stderr, "%s:%d, iseq: %p\n", FRAME_N(i)->file, FRAME_N(i)->line, FRAME_N(i)->info.runtime.cfp->iseq);
1013+
}
1014+
}
10041015

10051016
if(post_mortem == Qtrue && self)
10061017
{
@@ -1054,18 +1065,23 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
10541065
{
10551066
debug_frame_t *top_frame = get_top_frame(debug_context);
10561067
rb_control_frame_t *cfp = top_frame->info.runtime.cfp;
1057-
1058-
/* save the current catch table */
1059-
CTX_FL_SET(debug_context, CTX_FL_CATCHING);
1060-
debug_context->catch_table.old_catch_table_size = cfp->iseq->catch_table_size;
1061-
debug_context->catch_table.old_catch_table = cfp->iseq->catch_table;
1068+
rb_iseq_t *iseq = cfp->iseq;
1069+
10621070
debug_context->catch_table.mod_name = mod_name;
10631071
debug_context->catch_table.errinfo = rb_errinfo();
1064-
1065-
/* create a new catch table to catch this exception, and put it in the current iseq */
1066-
cfp->iseq->catch_table_size = 1;
1067-
cfp->iseq->catch_table =
1068-
create_catch_table(debug_context, top_frame->info.runtime.last_pc - cfp->iseq->iseq_encoded - insn_len(BIN(trace)));
1072+
CTX_FL_SET(debug_context, CTX_FL_CATCHING);
1073+
if (iseq != NULL) {
1074+
1075+
/* save the current catch table */
1076+
debug_context->catch_table.old_catch_table_size = iseq->catch_table_size;
1077+
debug_context->catch_table.old_catch_table = iseq->catch_table;
1078+
1079+
1080+
/* create a new catch table to catch this exception, and put it in the current iseq */
1081+
iseq->catch_table_size = 1;
1082+
iseq->catch_table =
1083+
create_catch_table(debug_context, top_frame->info.runtime.last_pc - cfp->iseq->iseq_encoded - insn_len(BIN(trace)));
1084+
}
10691085
}
10701086
}
10711087

0 commit comments

Comments
 (0)