From 32f74c39dd062b67cb326a81c2bf5099dc736708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Diego=20Piske?= Date: Sat, 26 Apr 2025 18:44:01 -0300 Subject: [PATCH] Fix FrameInfo#block_identifier Since ruby 3.4, not all cases match BLOCK_LABL_REGEXP anymore This fixes for those cases. --- lib/debug/frame_info.rb | 4 +- test/console/frame_block_identifier_test.rb | 58 +++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/console/frame_block_identifier_test.rb diff --git a/lib/debug/frame_info.rb b/lib/debug/frame_info.rb index 8eb041969..8fab332de 100644 --- a/lib/debug/frame_info.rb +++ b/lib/debug/frame_info.rb @@ -86,7 +86,9 @@ def frame_type def block_identifier return unless frame_type == :block - _, level, block_loc = location.label.match(BLOCK_LABL_REGEXP).to_a + re_match = location.label.match(BLOCK_LABL_REGEXP) + _, level, block_loc = re_match ? re_match.to_a : [nil, nil, location.label] + [level || "", block_loc] end diff --git a/test/console/frame_block_identifier_test.rb b/test/console/frame_block_identifier_test.rb new file mode 100644 index 000000000..a4349da19 --- /dev/null +++ b/test/console/frame_block_identifier_test.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require_relative '../support/console_test_case' + +module DEBUGGER__ + + class FrameBlockIdentifierTest < ConsoleTestCase + def program + <<~RUBY + 1| + 2| class Whatever + 3| def some_method + 4| will_exit = false + 5| loop do + 6| return if will_exit + 7| will_exit = true + 8| + 9| begin + 10| raise "foo" + 11| rescue => e + 12| puts "the end" + 13| end + 14| end + 15| end + 16| end + 17| + 18| Whatever.new.some_method + RUBY + end + + def test_frame_block_identifier + debug_code(program) do + type 'b 12' + type 'c' + assert_line_num 12 + assert_line_text([ + /\[7, 16\] in .*/, + / 7\| will_exit = true/, + / 8\| /, + / 9\| begin/, + / 10\| raise "foo"/, + / 11\| rescue => e/, + /=> 12\| puts "the end"/, + / 13\| end/, + / 14\| end/, + / 15\| end/, + / 16\| end/, + /=>\#0\tWhatever\#some_method at .*/, + / \#1\tblock in Kernel\#loop at :168/, + / \# and 2 frames \(use `bt' command for all frames\)/, + //, + /Stop by \#0 BP \- Line .*/ + ]) + type 'c' + end + end + end +end