Skip to content

Commit 8cef3d2

Browse files
authored
Treat frame.path as nilable in frame filtering (#1161)
1 parent 92773bc commit 8cef3d2

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

lib/irb/debug.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def setup(irb)
4949
def DEBUGGER__.capture_frames(*args)
5050
frames = capture_frames_without_irb(*args)
5151
frames.reject! do |frame|
52-
frame.realpath&.start_with?(IRB_DIR) || frame.path.start_with?("<internal:")
52+
frame.realpath&.start_with?(IRB_DIR) || frame.path&.start_with?("<internal:")
5353
end
5454
frames
5555
end
@@ -87,7 +87,7 @@ def configure_irb_for_debugger(irb)
8787
module SkipPathHelperForIRB
8888
def skip_internal_path?(path)
8989
# The latter can be removed once https://github.com/ruby/debug/issues/866 is resolved
90-
super || path.match?(IRB_DIR) || path.match?('<internal:prelude>')
90+
super || path&.match?(IRB_DIR) || path&.match?('<internal:prelude>')
9191
end
9292
end
9393

test/irb/helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,13 @@ def teardown
139139
end
140140
end
141141

142-
def run_ruby_file(timeout: TIMEOUT_SEC, &block)
143-
cmd = [EnvUtil.rubybin, "-I", LIB, @ruby_file.to_path]
142+
def run_ruby_file(timeout: TIMEOUT_SEC, via_irb: false, &block)
143+
if via_irb
144+
irb_path = File.expand_path("../../exe/irb", __dir__)
145+
cmd = [EnvUtil.rubybin, "-I", LIB, irb_path, @ruby_file.to_path]
146+
else
147+
cmd = [EnvUtil.rubybin, "-I", LIB, @ruby_file.to_path]
148+
end
144149
tmp_dir = Dir.mktmpdir
145150

146151
@commands = []

test/irb/test_debugger_integration.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ def test_next
123123
assert_match(/=> 2\| puts "hello"/, output)
124124
end
125125

126+
def test_next_with_irb_script
127+
# Regression test for https://github.com/ruby/irb/issues/1159
128+
# Running `irb file.rb` creates C frames with nil path that must be handled
129+
write_ruby <<~'ruby'
130+
binding.irb
131+
puts "hello"
132+
ruby
133+
134+
output = run_ruby_file(via_irb: true) do
135+
type "next"
136+
type "continue"
137+
end
138+
139+
assert_not_match(/NoMethodError/, output)
140+
assert_not_match(/undefined method.*start_with\?.*nil/, output)
141+
142+
assert_match(/irb\(main\):001>/, output)
143+
end
144+
126145
def test_break
127146
write_ruby <<~'RUBY'
128147
binding.irb

0 commit comments

Comments
 (0)