From 29b07e64e27a0a31899d4e3ce01e7528a75ee438 Mon Sep 17 00:00:00 2001 From: Aditya <152765789+adityawrk@users.noreply.github.com> Date: Sun, 29 Nov 2026 09:07:11 +0530 Subject: [PATCH] Show the source path for a breakpoint in eval'd code LineBreakpoint#activate stored iseq.absolute_path, which is nil for code compiled by eval, including ERB. The breakpoint still stopped, but its label was only the line number. Use the iseq path when there is no absolute path. A file loaded from disk still uses its absolute path. --- lib/debug/breakpoint.rb | 3 +- test/console/erb_breakpoint_test.rb | 43 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/console/erb_breakpoint_test.rb diff --git a/lib/debug/breakpoint.rb b/lib/debug/breakpoint.rb index 78c4d2174..d7dcd8967 100644 --- a/lib/debug/breakpoint.rb +++ b/lib/debug/breakpoint.rb @@ -189,7 +189,8 @@ def activate iseq, event, line @iseq = iseq @type = event @line = line - @path = iseq.absolute_path + # eval'd sources such as ERB have a path but no absolute path (debug#1129) + @path = iseq.absolute_path || iseq.path @key = [@path, @line].freeze SESSION.rehash_bps diff --git a/test/console/erb_breakpoint_test.rb b/test/console/erb_breakpoint_test.rb new file mode 100644 index 000000000..d90b43f7c --- /dev/null +++ b/test/console/erb_breakpoint_test.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require_relative '../support/console_test_case' + +module DEBUGGER__ + class ErbBreakpointTest < ConsoleTestCase + ERB_PATH = File.expand_path("../../tmp-erb-view/index.html.erb", __dir__) + + def write_temp_file(program) + FileUtils.mkdir_p(File.dirname(ERB_PATH)) + File.write(ERB_PATH, "placeholder") + super + end + + def remove_temp_file + super + FileUtils.rm_f(ERB_PATH) + Dir.rmdir(File.dirname(ERB_PATH)) rescue nil + end + + def program + <<~RUBY + 1| eval(<<~'SRC', binding, #{ERB_PATH.inspect}) + 2| def render + 3| a = 1 + 4| b = a + 1 + 5| b + 6| end + 7| SRC + 8| render + RUBY + end + + def test_breakpoint_on_eval_source_keeps_its_path + debug_code program do + type "b #{ERB_PATH}:3" + type 'c' + assert_line_text(/BP - Line #{Regexp.escape(ERB_PATH)}:3/) + type 'c' + end + end + end +end