Skip to content

Commit

Permalink
Stop Byebug after continue command
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Oct 28, 2015
1 parent 0aab7d7 commit 940aa89
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ext/byebug/byebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static VALUE tracepoints = Qnil;
static VALUE raised_exception = Qnil;

static ID idPuts;
static ID idEmpty;

/* Hash table with active threads and their associated contexts */
VALUE threads = Qnil;
Expand Down Expand Up @@ -584,6 +585,36 @@ Stop(VALUE self)
return Qtrue;
}

static VALUE
Stoppable(VALUE self)
{
VALUE context;
debug_context_t *dc;

if (!IS_STARTED)
return Qfalse;

if (breakpoints != Qnil && rb_funcall(breakpoints, idEmpty, 0) == Qfalse)
return Qfalse;

if (catchpoints != Qnil && rb_funcall(catchpoints, idEmpty, 0) == Qfalse)
return Qfalse;

if (post_mortem == Qtrue)
return Qfalse;

context = Current_context(self);
if (context != Qnil)
{
Data_Get_Struct(context, debug_context_t, dc);

if (dc->steps > 0)
return Qfalse;
}

return Qtrue;
}

/*
* call-seq:
* Byebug.start -> bool
Expand Down Expand Up @@ -747,6 +778,7 @@ Init_byebug()
rb_define_module_function(mByebug, "start", Start, 0);
rb_define_module_function(mByebug, "started?", Started, 0);
rb_define_module_function(mByebug, "stop", Stop, 0);
rb_define_module_function(mByebug, "stoppable?", Stoppable, 0);
rb_define_module_function(mByebug, "thread_context", Thread_context, 1);
rb_define_module_function(mByebug, "tracing?", Tracing, 0);
rb_define_module_function(mByebug, "tracing=", Set_tracing, 1);
Expand All @@ -762,4 +794,5 @@ Init_byebug()
rb_global_variable(&threads);

idPuts = rb_intern("puts");
idEmpty = rb_intern("empty?");
}
2 changes: 2 additions & 0 deletions lib/byebug/commands/continue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def execute
end

processor.proceed!

Byebug.stop if Byebug.stoppable?
end
end
end
6 changes: 6 additions & 0 deletions test/commands/continue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def test_continues_until_the_end_if_no_line_specified_and_no_breakpoints
debug_code(program) { assert_program_finished }
end

def test_stops_byebug_after_continue
enter 'continue'

debug_code(program) { assert_equal false, Byebug.started? }
end

def test_continues_up_to_breakpoint_if_no_line_specified
enter 'break 14', 'continue'

Expand Down

0 comments on commit 940aa89

Please sign in to comment.