From 6618e56f14b85d386f5ad4ca7ca03f72861d68ae Mon Sep 17 00:00:00 2001 From: James Reid-Smith Date: Thu, 12 Dec 2024 11:22:47 -0500 Subject: [PATCH 1/3] Load history when starting a direct debug session 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/irb#975 --- lib/irb/debug.rb | 1 + test/irb/test_history.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/irb/debug.rb b/lib/irb/debug.rb index cd64b77ad..130058569 100644 --- a/lib/irb/debug.rb +++ b/lib/irb/debug.rb @@ -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 diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index 15c16ed89..e82c046ca 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -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) From 72205fe8e47736bc3b7f7f432018de5d12a1f60f Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 12 Dec 2024 16:52:46 +0000 Subject: [PATCH 2/3] Update test/irb/test_history.rb --- test/irb/test_history.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/irb/test_history.rb b/test/irb/test_history.rb index e82c046ca..021bb682c 100644 --- a/test/irb/test_history.rb +++ b/test/irb/test_history.rb @@ -503,11 +503,19 @@ def test_direct_debug_session_loads_history RUBY output = run_ruby_file do + type "history" + type "puts 'foo'" type "history" type "exit!" end - assert_include(output, "old_history_3") + assert_include(output, "irb:rdbg(main):002") # assert that we're in an irb:rdbg session + assert_include(output, "5: history") + assert_include(output, "4: puts 'foo'") + assert_include(output, "3: history") + assert_include(output, "2: old_history_3") + assert_include(output, "1: old_history_2") + assert_include(output, "0: old_history_1") end private From 4a29c386c0e03a6e9f4c0b9b5c4d70bb53d462b1 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 12 Dec 2024 17:19:20 +0000 Subject: [PATCH 3/3] Update lib/irb/debug.rb --- lib/irb/debug.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/irb/debug.rb b/lib/irb/debug.rb index 130058569..59be1365b 100644 --- a/lib/irb/debug.rb +++ b/lib/irb/debug.rb @@ -81,7 +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 + irb.context.io.load_history if irb.context.io.class < HistorySavingAbility end module SkipPathHelperForIRB