ext/byebug/byebug.c in byebug-2.7.0 vs ext/byebug/byebug.c in byebug-3.0.0

- old
+ new

@@ -8,10 +8,12 @@ static VALUE catchpoints = Qnil; static VALUE breakpoints = Qnil; static VALUE tracepoints = Qnil; +static VALUE raised_exception = Qnil; + /* Implements thread syncronization, we must stop threads when debugging */ VALUE locker = Qnil; /* Threads table */ VALUE threads = Qnil; @@ -156,13 +158,12 @@ } static VALUE call_at_return(VALUE context_obj, debug_context_t *dc, VALUE file, VALUE line) { - dc->stop_reason = CTX_STOP_BREAKPOINT; + CTX_FL_UNSET(dc, CTX_FL_STOP_ON_RET); return call_at(context_obj, dc, rb_intern("at_return"), 2, file, line); - } static void call_at_line_check(VALUE context_obj, debug_context_t *dc, VALUE breakpoint, VALUE file, VALUE line) @@ -238,10 +239,13 @@ EVENT_SETUP dc->calced_stack_size++; + if (CTX_FL_TEST(dc, CTX_FL_STOP_ON_RET)) + dc->steps_out = dc->steps_out <= 0 ? -1 : dc->steps_out + 1; + EVENT_COMMON breakpoint = Qnil; klass = rb_tracearg_defined_class(trace_arg); mid = SYM2ID(rb_tracearg_method_id(trace_arg)); @@ -267,25 +271,25 @@ if (dc->calced_stack_size > 0) dc->calced_stack_size--; EVENT_COMMON - if (dc->calced_stack_size + 1 == dc->before_frame) + if (dc->steps_out == 1) { + dc->steps = 1; + } + else if ((dc->steps_out == 0) && (CTX_FL_TEST(dc, CTX_FL_STOP_ON_RET))) + { VALUE file, line; reset_stepping_stop_points(dc); file = rb_tracearg_path(trace_arg); line = rb_tracearg_lineno(trace_arg); call_at_return(context, dc, file, line); } - if (dc->calced_stack_size + 1 == dc->after_frame) - { - reset_stepping_stop_points(dc); - dc->steps = 1; - } + dc->steps_out = dc->steps_out <= 0 ? -1 : dc->steps_out - 1; cleanup(dc); } static void @@ -313,64 +317,59 @@ } static void raise_event(VALUE trace_point, void *data) { - VALUE expn_class, aclass; - VALUE err; - VALUE ancestors; + VALUE expn_class, ancestors; + VALUE path, lineno, binding, post_mortem_context; int i; debug_context_t *new_dc; - VALUE binding, path, lineno; EVENT_SETUP - err = rb_errinfo(); - EVENT_COMMON - binding = rb_tracearg_binding(trace_arg); - path = rb_tracearg_path(trace_arg); - lineno = rb_tracearg_lineno(trace_arg); + path = rb_tracearg_path(trace_arg); + lineno = rb_tracearg_lineno(trace_arg); + binding = rb_tracearg_binding(trace_arg); + raised_exception = rb_tracearg_raised_exception(trace_arg); if (post_mortem == Qtrue) { - context = context_dup(dc); - rb_ivar_set(err, rb_intern("@__bb_file") , path); - rb_ivar_set(err, rb_intern("@__bb_line") , lineno); - rb_ivar_set(err, rb_intern("@__bb_binding"), binding); - rb_ivar_set(err, rb_intern("@__bb_context"), context); + post_mortem_context = context_dup(dc); + rb_ivar_set(raised_exception, rb_intern("@__bb_file") , path); + rb_ivar_set(raised_exception, rb_intern("@__bb_line") , lineno); + rb_ivar_set(raised_exception, rb_intern("@__bb_binding"), binding); + rb_ivar_set(raised_exception, rb_intern("@__bb_context"), post_mortem_context); - Data_Get_Struct(context, debug_context_t, new_dc); + Data_Get_Struct(post_mortem_context, debug_context_t, new_dc); rb_debug_inspector_open(context_backtrace_set, (void *)new_dc); } - expn_class = rb_obj_class(err); - - if (catchpoints == Qnil || dc->calced_stack_size == 0 || - CTX_FL_TEST(dc, CTX_FL_CATCHING) || + if (catchpoints == Qnil || + dc->calced_stack_size == 0 || RHASH_TBL(catchpoints)->num_entries == 0) { cleanup(dc); return; } + expn_class = rb_obj_class(raised_exception); ancestors = rb_mod_ancestors(expn_class); for (i = 0; i < RARRAY_LENINT(ancestors); i++) { - VALUE mod_name; - VALUE hit_count; + VALUE ancestor_class, module_name, hit_count; - aclass = rb_ary_entry(ancestors, i); - mod_name = rb_mod_name(aclass); - hit_count = rb_hash_aref(catchpoints, mod_name); + ancestor_class = rb_ary_entry(ancestors, i); + module_name = rb_mod_name(ancestor_class); + hit_count = rb_hash_aref(catchpoints, module_name); /* increment exception */ if (hit_count != Qnil) { - rb_hash_aset(catchpoints, mod_name, INT2FIX(FIX2INT(hit_count) + 1)); - call_at_catchpoint(context, dc, err); + rb_hash_aset(catchpoints, module_name, INT2FIX(FIX2INT(hit_count) + 1)); + call_at_catchpoint(context, dc, raised_exception); call_at_line(context, dc, path, lineno); break; } } @@ -676,11 +675,11 @@ /* * call-seq: * Byebug.post_mortem? -> bool * - * Returns +true+ if post-moterm debugging is enabled. + * Returns +true+ if post-mortem debugging is enabled. */ static VALUE bb_post_mortem(VALUE self) { return post_mortem; @@ -738,10 +737,22 @@ rb_hash_aset(catchpoints, rb_str_dup(value), INT2FIX(0)); return value; } /* + * call-seq: + * Byebug.raised_exception -> exception + * + * Returns raised exception when in post_mortem mode. + */ +static VALUE +bb_raised_exception(VALUE self) +{ + return raised_exception; +} + +/* * Document-class: Byebug * * == Summary * * This is a singleton class allows controlling byebug. Use it to start/stop @@ -750,32 +761,34 @@ void Init_byebug() { mByebug = rb_define_module("Byebug"); - rb_define_module_function(mByebug, "add_catchpoint" , bb_add_catchpoint , 1); - rb_define_module_function(mByebug, "breakpoints" , bb_breakpoints , 0); - rb_define_module_function(mByebug, "catchpoints" , bb_catchpoints , 0); - rb_define_module_function(mByebug, "contexts" , bb_contexts , 0); - rb_define_module_function(mByebug, "current_context", bb_current_context, 0); - rb_define_module_function(mByebug, "debug_load" , bb_load , -1); - rb_define_module_function(mByebug, "post_mortem?" , bb_post_mortem , 0); - rb_define_module_function(mByebug, "post_mortem=" , bb_set_post_mortem, 1); - rb_define_module_function(mByebug, "_start" , bb_start , 0); - rb_define_module_function(mByebug, "started?" , bb_started , 0); - rb_define_module_function(mByebug, "stop" , bb_stop , 0); - rb_define_module_function(mByebug, "thread_context" , bb_thread_context , 1); - rb_define_module_function(mByebug, "tracing?" , bb_tracing , 0); - rb_define_module_function(mByebug, "tracing=" , bb_set_tracing , 1); - rb_define_module_function(mByebug, "verbose" , bb_verbose , 0); - rb_define_module_function(mByebug, "verbose=" , bb_set_verbose , 1); + rb_define_module_function(mByebug, "add_catchpoint" , bb_add_catchpoint , 1); + rb_define_module_function(mByebug, "breakpoints" , bb_breakpoints , 0); + rb_define_module_function(mByebug, "catchpoints" , bb_catchpoints , 0); + rb_define_module_function(mByebug, "contexts" , bb_contexts , 0); + rb_define_module_function(mByebug, "current_context" , bb_current_context , 0); + rb_define_module_function(mByebug, "debug_load" , bb_load , -1); + rb_define_module_function(mByebug, "post_mortem?" , bb_post_mortem , 0); + rb_define_module_function(mByebug, "post_mortem=" , bb_set_post_mortem , 1); + rb_define_module_function(mByebug, "raised_exception" , bb_raised_exception, 0); + rb_define_module_function(mByebug, "_start" , bb_start , 0); + rb_define_module_function(mByebug, "started?" , bb_started , 0); + rb_define_module_function(mByebug, "stop" , bb_stop , 0); + rb_define_module_function(mByebug, "thread_context" , bb_thread_context , 1); + rb_define_module_function(mByebug, "tracing?" , bb_tracing , 0); + rb_define_module_function(mByebug, "tracing=" , bb_set_tracing , 1); + rb_define_module_function(mByebug, "verbose" , bb_verbose , 0); + rb_define_module_function(mByebug, "verbose=" , bb_set_verbose , 1); cThreadsTable = rb_define_class_under(mByebug, "ThreadsTable", rb_cObject); Init_context(mByebug); Init_breakpoint(mByebug); rb_global_variable(&breakpoints); rb_global_variable(&catchpoints); rb_global_variable(&tracepoints); + rb_global_variable(&raised_exception); rb_global_variable(&threads); }