Skip to content

Commit

Permalink
Merge pull request #160 from k0kubun/enable-disable-tracepoints
Browse files Browse the repository at this point in the history
Disable tracepoints after continue
  • Loading branch information
David Rodríguez committed Oct 31, 2015
2 parents 1bf2dd7 + a09a444 commit 1749e21
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
### Fixed
* [#177](https://github.com/deivid-rodriguez/byebug/issues/177). Some issues
with formatting results of evaluations.
* [#144](https://github.com/deivid-rodriguez/byebug/issues/144). Ruby process
after using byebug does no longer get slow.
* [#121](https://github.com/deivid-rodriguez/byebug/issues/121). `byebug`
commands inside code evaluated from debugger's prompt are now properly working.
* Another evaluation bug in autocommands.
Expand Down
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 @@ -585,6 +586,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 @@ -748,6 +779,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 @@ -763,4 +795,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: 4 additions & 2 deletions lib/byebug/interfaces/local_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Byebug
# Interface class for standard byebug use.
#
class LocalInterface < Interface
EOF_ALIAS = 'continue'

def initialize
super()
@input = STDIN
Expand All @@ -13,12 +15,12 @@ def initialize
#
# Reads a single line of input using Readline. If Ctrl-C is pressed in the
# middle of input, the line is reset to only the prompt and we ask for input
# again.
# again. If Ctrl-D is pressed, it returns "continue".
#
# @param prompt Prompt to be displayed.
#
def readline(prompt)
Readline.readline(prompt, false)
Readline.readline(prompt, false) || EOF_ALIAS
rescue Interrupt
puts('^C')
retry
Expand Down
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
17 changes: 17 additions & 0 deletions test/interfaces/local_interface_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'
require 'minitest/mock'

module Byebug
#
# Tests the local interface
#
class LocalInterfaceTest < TestCase
def test_continues_by_control_d
# `Readline.readline` returns nil for Control-D
Readline.stub(:readline, nil) do
interface = LocalInterface.new
assert_equal 'continue', interface.readline('(byebug)')
end
end
end
end

0 comments on commit 1749e21

Please sign in to comment.