Skip to content

Commit

Permalink
Load history when starting a direct debug session
Browse files Browse the repository at this point in the history
When starting a debug session directly with RUBY_DEBUG_IRB_CONSOLE=1 and
`require 'debug'; debugger`, IRB's history wasn't loaded. This commit ensures
history is loaded in this case by calling `load_history` when configuring IRB
for the debugger.

Fixes ruby#975
  • Loading branch information
sunblaze committed Dec 12, 2024
1 parent 8241ec9 commit 6618e56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/irb/debug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def configure_irb_for_debugger(irb)
IRB.instance_variable_set(:@debugger_irb, irb)
irb.context.with_debugger = true
irb.context.irb_name += ":rdbg"
irb.context.io.load_history
end

module SkipPathHelperForIRB
Expand Down
22 changes: 22 additions & 0 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,28 @@ def foo
HISTORY
end

def test_direct_debug_session_loads_history
@envs['RUBY_DEBUG_IRB_CONSOLE'] = "1"
write_history <<~HISTORY
old_history_1
old_history_2
old_history_3
HISTORY

write_ruby <<~'RUBY'
require 'debug'
debugger
binding.irb # needed to satisfy run_ruby_file
RUBY

output = run_ruby_file do
type "history"
type "exit!"
end

assert_include(output, "old_history_3")
end

private

def write_history(history)
Expand Down

0 comments on commit 6618e56

Please sign in to comment.