diff --git a/ext/context.c b/ext/context.c index 76e3f3d..5c9bda6 100644 --- a/ext/context.c +++ b/ext/context.c @@ -147,6 +147,7 @@ context_create(VALUE thread, VALUE cDebugThread) { context->stack_size = 0; locations = rb_funcall(thread, rb_intern("backtrace_locations"), 1, INT2FIX(1)); context->calced_stack_size = locations != Qnil ? RARRAY_LENINT(locations) : 0; + context->init_stack_size = -1; context->stack = NULL; context->thnum = ++thnum_current; @@ -154,6 +155,8 @@ context_create(VALUE thread, VALUE cDebugThread) { context->flags = 0; context->last_file = NULL; context->last_line = -1; + context->hit_user_code = 0; + context->script_finished = 0; context->stop_frame = -1; context->thread_pause = 0; context->stop_reason = CTX_STOP_NONE; diff --git a/ext/debase_internals.c b/ext/debase_internals.c index 896e63b..856b203 100644 --- a/ext/debase_internals.c +++ b/ext/debase_internals.c @@ -303,6 +303,8 @@ remove_pause_flag(VALUE thread, VALUE context_object, VALUE ignored) static void call_at_line(debug_context_t *context, char *file, int line, VALUE context_object) { + context->hit_user_code = 1; + rb_hash_foreach(contexts, remove_pause_flag, 0); CTX_FL_UNSET(context, CTX_FL_STEPPED); CTX_FL_UNSET(context, CTX_FL_FORCE_MOVE); @@ -331,6 +333,13 @@ process_line_event(VALUE trace_point, void *data) tp = TRACE_POINT; path = rb_tracearg_path(tp); + if(context->stack_size <= context->init_stack_size && context->hit_user_code) { + context->script_finished = 1; + } + if(context->script_finished) { + return; + } + if (is_path_accepted(path)) { lineno = rb_tracearg_lineno(tp); @@ -340,6 +349,10 @@ process_line_event(VALUE trace_point, void *data) update_stack_size(context); print_event(tp, context); + if(context->init_stack_size == -1) { + context->init_stack_size = context->stack_size; + } + if (context->thread_pause) { context->stop_next = 1; context->dest_frame = -1; diff --git a/ext/debase_internals.h b/ext/debase_internals.h index dcb2abe..559ce53 100644 --- a/ext/debase_internals.h +++ b/ext/debase_internals.h @@ -60,6 +60,9 @@ typedef struct debug_context { char *last_file; int last_line; + int init_stack_size; + int script_finished; + int hit_user_code; } debug_context_t; typedef struct