Skip to content

Commit 68f718d

Browse files
authored
Use correct binding in debug mode (#1007)
In debug command, IRB's context was using wrong binding. Some code colorization, command detection failed because binding.local_variable returned wrong value.
1 parent 04cd231 commit 68f718d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/irb/debug/ui.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def puts str = nil
5656
def readline _
5757
setup_interrupt do
5858
tc = DEBUGGER__::SESSION.instance_variable_get(:@tc)
59-
cmd = @irb.debug_readline(tc.current_frame.binding || TOPLEVEL_BINDING)
59+
cmd = @irb.debug_readline(tc.current_frame.eval_binding || TOPLEVEL_BINDING)
6060

6161
case cmd
6262
when nil # when user types C-d

test/irb/test_debugger_integration.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,23 @@ def bar
365365
assert_include(output, "InputMethod: RelineInputMethod")
366366
end
367367

368+
def test_irb_command_can_check_local_variables
369+
write_ruby <<~'ruby'
370+
binding.irb
371+
ruby
372+
373+
output = run_ruby_file do
374+
type "debug"
375+
type 'foobar = IRB'
376+
type "show_source foobar.start"
377+
type "show_source = 'Foo'"
378+
type "show_source + 'Bar'"
379+
type "continue"
380+
end
381+
assert_include(output, "def start(ap_path = nil)")
382+
assert_include(output, '"FooBar"')
383+
end
384+
368385
def test_help_command_is_delegated_to_the_debugger
369386
write_ruby <<~'ruby'
370387
binding.irb

0 commit comments

Comments
 (0)