Skip to content

Commit f4a2e2c

Browse files
committed
fixed hanging on exceptional breakpoints
1 parent 74c55a8 commit f4a2e2c

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

ext/ruby_debug/ruby_debug.c

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <insns_info.inc>
1010
#include "ruby_debug.h"
1111

12-
#define DEBUG_VERSION "0.11.30.pre"
12+
#define DEBUG_VERSION "0.11.30.pre2"
1313

1414
#define FRAME_N(n) (&debug_context->frames[debug_context->stack_size-(n)-1])
1515
#define GET_FRAME (FRAME_N(check_frame_number(debug_context, frame)))
@@ -857,6 +857,35 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
857857
save_call_frame(event, debug_context, self, file, line, mid);
858858
else
859859
set_frame_source(event, debug_context, self, file, line, mid);
860+
if (CTX_FL_TEST(debug_context, CTX_FL_CATCHING))
861+
{
862+
debug_frame_t *top_frame = get_top_frame(debug_context);
863+
864+
if (top_frame != NULL)
865+
{
866+
rb_control_frame_t *cfp = top_frame->info.runtime.cfp;
867+
VALUE hit_count;
868+
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;
872+
873+
/* 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+
debug_context->stop_reason = CTX_STOP_CATCHPOINT;
878+
rb_funcall(context, idAtCatchpoint, 1, debug_context->catch_table.errinfo);
879+
if(self && binding == Qnil)
880+
binding = create_binding(self);
881+
save_top_binding(debug_context, binding);
882+
call_at_line(context, debug_context, rb_str_new2(file), INT2FIX(line));
883+
}
884+
885+
/* now allow the next exception to be caught */
886+
CTX_FL_UNSET(debug_context, CTX_FL_CATCHING);
887+
break;
888+
}
860889

861890
if(RTEST(tracing) || CTX_FL_TEST(debug_context, CTX_FL_TRACING))
862891
rb_funcall(context, idAtTracing, 2, rb_str_new2(file), INT2FIX(line));
@@ -971,7 +1000,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
9711000
VALUE expn_class, aclass;
9721001
int i;
9731002

974-
// set_frame_source(event, debug_context, self, file, line, mid);
1003+
set_frame_source(event, debug_context, self, file, line, mid);
9751004

9761005
if(post_mortem == Qtrue && self)
9771006
{
@@ -1026,18 +1055,17 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
10261055
debug_frame_t *top_frame = get_top_frame(debug_context);
10271056
rb_control_frame_t *cfp = top_frame->info.runtime.cfp;
10281057

1029-
/* send catchpoint notification */
1030-
int c_hit_count = FIX2INT(rb_hash_aref(rdebug_catchpoints, mod_name)) + 1;
1031-
hit_count = INT2FIX(c_hit_count);
1032-
rb_hash_aset(rdebug_catchpoints, mod_name, hit_count);
1033-
debug_context->stop_reason = CTX_STOP_CATCHPOINT;
1034-
rb_funcall(context, idAtCatchpoint, 1, rb_errinfo());
1035-
1036-
if(self && binding == Qnil)
1037-
binding = create_binding(self);
1038-
save_top_binding(debug_context, binding);
1039-
call_at_line(context, debug_context, rb_str_new2(file), INT2FIX(line));
1040-
break;
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;
1062+
debug_context->catch_table.mod_name = mod_name;
1063+
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)));
10411069
}
10421070
}
10431071

0 commit comments

Comments
 (0)