diff options
author | Stan Lo <[email protected]> | 2022-12-09 23:39:12 +0000 |
---|---|---|
committer | git <[email protected]> | 2022-12-09 23:39:17 +0000 |
commit | 381e128c135e491689714cb69353d11e782f5994 (patch) | |
tree | bdb129826f9b1bf8f1f2ebf013883664f2006861 | |
parent | daa893db412c6ae814d0291b4ac6fc62a466d394 (diff) |
[ruby/irb] Fix step command (https://github.com/ruby/irb/pull/477)
The current `next` pre-command workaround on IRB source stepping
moves the location by 1 extra line. A better way is to make `debug`
skip IRB frames completely, which is what this commit does.
It also fixes the step command's test. The `|` in regexp was not escaped
so it was always incorrectly matched.
-rw-r--r-- | lib/irb/cmd/debug.rb | 9 | ||||
-rw-r--r-- | lib/irb/cmd/step.rb | 3 | ||||
-rw-r--r-- | test/irb/test_debug_cmd.rb | 4 |
3 files changed, 13 insertions, 3 deletions
diff --git a/lib/irb/cmd/debug.rb b/lib/irb/cmd/debug.rb index 76f17e3c2f..e6e812e075 100644 --- a/lib/irb/cmd/debug.rb +++ b/lib/irb/cmd/debug.rb @@ -55,6 +55,13 @@ module IRB end end + module SkipPathHelperForIRB + def skip_internal_path?(path) + # The latter can be removed once https://github.com/ruby/debug/issues/866 is resolved + super || path.match?(IRB_DIR) || path.match?('<internal:prelude>') + end + end + def setup_debugger unless defined?(DEBUGGER__::SESSION) begin @@ -75,6 +82,8 @@ module IRB end frames end + + DEBUGGER__::ThreadClient.prepend(SkipPathHelperForIRB) end true diff --git a/lib/irb/cmd/step.rb b/lib/irb/cmd/step.rb index d3d0f16291..2bc74a9d79 100644 --- a/lib/irb/cmd/step.rb +++ b/lib/irb/cmd/step.rb @@ -8,8 +8,7 @@ module IRB module ExtendCommand class Step < DebugCommand def execute(*args) - # Run `next` first to move out of binding.irb - super(pre_cmds: "next", do_cmds: ["step", *args].join(" ")) + super(do_cmds: ["step", *args].join(" ")) end end end diff --git a/test/irb/test_debug_cmd.rb b/test/irb/test_debug_cmd.rb index 3ba8742304..9aafbec7f0 100644 --- a/test/irb/test_debug_cmd.rb +++ b/test/irb/test_debug_cmd.rb @@ -119,11 +119,13 @@ module TestIRB output = run_ruby_file do type "step" + type "step" type "continue" end assert_match(/\(rdbg:irb\) step/, output) - assert_match(/=> 2| puts "Hello"/, output) + assert_match(/=> 5\| foo/, output) + assert_match(/=> 2\| puts "Hello"/, output) end def test_continue |