diff --git a/lib/byebug/attacher.rb b/lib/byebug/attacher.rb index 002a69a90..5834a0ed2 100644 --- a/lib/byebug/attacher.rb +++ b/lib/byebug/attacher.rb @@ -6,13 +6,15 @@ module Byebug # Enters byebug right before (or right after if _before_ is false) return # events occur. Before entering byebug the init script is read. # - def self.attach(steps_out, before) + def self.attach + return errmsg('Byebug already started. Ignoring `byebug` call.') if started? + setup_cmd_line_args start run_init_script - current_context.step_out(steps_out, before) + current_context.step_out(2, true) end end @@ -22,8 +24,8 @@ def self.attach(steps_out, before) # Dropping a `byebug` call anywhere in your code, you get a debug prompt. # module Kernel - def byebug(steps_out = 1, before = true) - Byebug.attach(steps_out + 1, before) + def byebug + Byebug.attach end alias_method :debugger, :byebug diff --git a/lib/byebug/commands/tracevar.rb b/lib/byebug/commands/tracevar.rb index 920e24f70..98d6a8ede 100644 --- a/lib/byebug/commands/tracevar.rb +++ b/lib/byebug/commands/tracevar.rb @@ -32,7 +32,8 @@ def execute def on_change(name, value, stop) puts pr('trace.messages.on_change', name: name, value: value) - byebug(1, false) if stop + + @state.context.step_out(1, false) if stop end class << self diff --git a/test/commands/eval_test.rb b/test/commands/eval_test.rb index 3bfcbbfe1..ea5ef221c 100644 --- a/test/commands/eval_test.rb +++ b/test/commands/eval_test.rb @@ -111,8 +111,10 @@ module Byebug # Toy class to test evaluation in Byebug's prompt # class #{example_class} + attr_accessor :thread + def initialize - Thread.new do + @thread = Thread.new do loop do sleep 0.01 next if numbers.empty? @@ -144,7 +146,7 @@ def calc(number) byebug - 'Processed: ' + worker.squares.join(' ') + worker.thread.kill end EOC end diff --git a/test/support/test_case.rb b/test/support/test_case.rb index 439631283..4ab38206b 100644 --- a/test/support/test_case.rb +++ b/test/support/test_case.rb @@ -50,6 +50,7 @@ def setup def teardown cleanup_namespace clear_example_file + Byebug.stop end #