Skip to content

Commit

Permalink
Lazily activate the debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Apr 8, 2024
1 parent 0b77e82 commit 5666b14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
30 changes: 24 additions & 6 deletions lib/debug.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
# frozen_string_literal: true

if ENV['RUBY_DEBUG_LAZY']
require_relative 'debug/prelude'
else
require_relative 'debug/session'
return unless defined?(DEBUGGER__)
DEBUGGER__::start no_sigint_hook: true, nonstop: true
require_relative 'debug/prelude'

module DEBUGGER__
def self.step_in(&block)
require "debug/session"

# If session.rb doesn't early return, we can then call the method it defines.
if defined?(Session)
start no_sigint_hook: true, nonstop: true
step_in(&block)
# Otherwise, we call the block without stepping in.
else
yield
end
end

def self.start(**kw)
require "debug/session"

# If session.rb doesn't early return, we can then call the method it defines.
if defined?(Session)
start(**kw)
end
end
end
9 changes: 0 additions & 9 deletions test/console/debugger_method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,6 @@ def test_prelude_defines_debugger_statements
end
end

def test_prelude_doesnt_override_debugger
run_ruby(program, options: "-Ilib -rdebug") do
assert_line_num(5)
type "debugger_source"
assert_line_text(/debug\/session\.rb/)
type "c"
end
end

def test_require_config_doesnt_cancel_prelude
run_ruby(program, options: "-Ilib -rdebug/config") do
assert_line_num(5)
Expand Down

0 comments on commit 5666b14

Please sign in to comment.