irb
irb copied to clipboard
Can't change workspace after entering `debug`
Description
After entering debug mode, all workspace functionality stops working. It's no longer possible to perform commands or statements under a different workspace after changing the workspace or pushing a workspace to the stack.
This happens because under debug mode, the current workspace is replaced and lines are always read with the context of the debug binding or the top level binding.
https://github.com/ruby/irb/blob/66318d0a343552715f214f07c57bc4a60552ccfd/lib/irb/debug/ui.rb#L59
Since it's not possible to exit debug mode, the workspace functionality is lost within irb for the remaining of the process.
irb(main):001> chws
Current workspace: main
=> nil
irb(main):002> chws foo
Current workspace: #<Foo:0x000000010a8ef250>
=> nil
irb(#<Foo:0x000000010a8ef250>):003> bar
=> "I'm a private method"
irb(#<Foo:0x000000010a8ef250>):004> chws
Current workspace: main
=> nil
irb(main):005> debug
irb:rdbg(main):006> chws foo
Current workspace: #<Foo:0x000000010a8ef250>
=> nil
irb:rdbg(#<Foo:0x000000010a8ef250>):007> bar
eval error: undefined local variable or method `bar' for main
(rdbg)/test.rb:1:in `<main>'
nil
irb:rdbg(main):008>
Result of irb_info
irb:rdbg(main):009> irb_info
Ruby version: 3.3.0
IRB version: irb 1.13.0 (2024-05-01)
InputMethod: RelineInputMethod with Reline 0.5.5
Completion: Autocomplete, RegexpCompletor
RUBY_PLATFORM: x86_64-darwin23
LANG env: en_CA.UTF-8
East Asian Ambiguous Width: 1
Terminal Emulator
kitty terminal
Setting Files
No settings file