diff --git a/lib/irb/cmd/debug.rb b/lib/irb/cmd/debug.rb index 01bbf49d5..9eca96421 100644 --- a/lib/irb/cmd/debug.rb +++ b/lib/irb/cmd/debug.rb @@ -35,6 +35,11 @@ def execute(pre_cmds: nil, do_cmds: nil) return end + if IRB.respond_to?(:JobManager) + warn "Can't start the debugger when IRB is running in a multi-IRB session." + return + end + unless IRB::Debug.setup(irb_context.irb) puts <<~MSG You need to install the debug gem before using this command. diff --git a/lib/irb/cmd/subirb.rb b/lib/irb/cmd/subirb.rb index 5f3e02c98..777ebf150 100644 --- a/lib/irb/cmd/subirb.rb +++ b/lib/irb/cmd/subirb.rb @@ -11,8 +11,7 @@ module IRB module ExtendCommand class MultiIRBCommand < Nop - def initialize(conf) - super + def execute(*args) extend_irb_context end @@ -29,6 +28,12 @@ class IrbCommand < MultiIRBCommand description "Start a child IRB." def execute(*obj) + if irb_context.with_debugger + warn "Multi-IRB commands are not available when the debugger is enabled." + return + end + + super IRB.irb(nil, *obj) end end @@ -38,6 +43,12 @@ class Jobs < MultiIRBCommand description "List of current sessions." def execute + if irb_context.with_debugger + warn "Multi-IRB commands are not available when the debugger is enabled." + return + end + + super IRB.JobManager end end @@ -47,6 +58,12 @@ class Foreground < MultiIRBCommand description "Switches to the session of the given number." def execute(key = nil) + if irb_context.with_debugger + warn "Multi-IRB commands are not available when the debugger is enabled." + return + end + + super raise CommandArgumentError.new("Please specify the id of target IRB job (listed in the `jobs` command).") unless key IRB.JobManager.switch(key) end @@ -57,6 +74,12 @@ class Kill < MultiIRBCommand description "Kills the session with the given number." def execute(*keys) + if irb_context.with_debugger + warn "Multi-IRB commands are not available when the debugger is enabled." + return + end + + super IRB.JobManager.kill(*keys) end end diff --git a/test/irb/test_debug_cmd.rb b/test/irb/test_debug_cmd.rb index c8b92bec1..cbc1f864b 100644 --- a/test/irb/test_debug_cmd.rb +++ b/test/irb/test_debug_cmd.rb @@ -365,6 +365,38 @@ def bar assert_include(output, "show_source Show the source code of a given method or constant.") end + def test_debugger_cant_be_activated_while_multi_irb_is_active + write_ruby <<~'ruby' + binding.irb + a = 1 + ruby + + output = run_ruby_file do + type "jobs" + type "next" + type "exit" + end + + assert_match(/irb\(main\):001:0> jobs/, output) + assert_include(output, "Can't start the debugger when IRB is running in a multi-IRB session.") + end + + def test_multi_irb_commands_are_not_available_after_activating_the_debugger + write_ruby <<~'ruby' + binding.irb + a = 1 + ruby + + output = run_ruby_file do + type "next" + type "jobs" + type "continue" + end + + assert_match(/irb\(main\):001:0> next/, output) + assert_include(output, "Multi-IRB commands are not available when the debugger is enabled.") + end + private TIMEOUT_SEC = 3