Skip to content

Commit cf469f2

Browse files
committed
The debug gem can abort when stepping into a rescue clause:
``` $ ruby -Ilib exe/rdbg rescue-test.rb [1, 7] in rescue-test.rb => 1| 1.times do 2| begin 3| raise 4| rescue 5| p 1 6| end 7| end =>#0 <main> at rescue-test.rb:1 (rdbg) s # step command [1, 7] in rescue-test.rb 1| 1.times do 2| begin => 3| raise 4| rescue 5| p 1 6| end 7| end =>#0 block in <main> at rescue-test.rb:3 ruby#1 Integer#times at <internal:numeric>:257 # and 1 frames (use `bt' command for all frames) (rdbg) s # step command /home/mame/work/debug/lib/debug/thread_client.rb:85:in 'DEBUGGER__::ThreadClient#default_frame_formatter': undefined method '+' for nil (NoMethodError) "#{colorize_blue("block")}#{args_str} in #{colorize_blue(block_loc + level)}" ^ from /home/mame/work/debug/lib/debug/thread_client.rb:755:in 'Method#call' from /home/mame/work/debug/lib/debug/thread_client.rb:755:in 'DEBUGGER__::ThreadClient#frame_str' from /home/mame/work/debug/lib/debug/thread_client.rb:742:in 'block in DEBUGGER__::ThreadClient#show_frames' from <internal:numeric>:257:in 'Integer#times' from /home/mame/work/debug/lib/debug/thread_client.rb:739:in 'DEBUGGER__::ThreadClient#show_frames' from /home/mame/work/debug/lib/debug/thread_client.rb:304:in 'DEBUGGER__::ThreadClient#suspend' from /home/mame/work/debug/lib/debug/thread_client.rb:358:in 'block in DEBUGGER__::ThreadClient#step_tp' from rescue-test.rb:5:in 'block in <main>' from <internal:numeric>:257:in 'Integer#times' from rescue-test.rb:1:in '<main>' rescue-test.rb:3:in 'block in <main>': unhandled exception from <internal:numeric>:257:in 'Integer#times' from rescue-test.rb:1:in '<main>' ``` This is because `rb_debug_inspector_backtrace_locations` returned a modified backtrace, which skips rescue/ensure frames, but `rb_debug_inspector_frame_XXX_get`'s index is considered for a raw backtrace, which includes rescue/ensure frames. The problem wil be fixed by ruby/ruby#13510. However, now the backtrace includes rescue/ensure frames, so some tests in debug gem fails. This fixes the test failures.
1 parent fb1cff5 commit cf469f2

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

test/console/frame_block_identifier_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def test_frame_block_identifier
4646
/ 15\| end/,
4747
/ 16\| end/,
4848
/=>\#0\tWhatever\#some_method at .*/,
49-
/ \#1\tblock in Kernel\#loop at <internal:kernel>:168/,
50-
/ \# and 2 frames \(use `bt' command for all frames\)/,
49+
/ \#1\t.*/,
50+
/ \# and (?:2|3) frames \(use `bt' command for all frames\)/,
5151
//,
5252
/Stop by \#0 BP \- Line .*/
5353
])

test/console/nested_break_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_multiple_nested_break
8383
assert_line_num 2
8484
type 'p foo(142)'
8585
type 'bt'
86-
assert_line_text(/\#7\s+<main>/) # TODO: can be changed
86+
assert_line_text(/\#\d+\s+<main>/)
8787

8888
type 'c'
8989
assert_line_text(/143/)

test/console/rescue_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/console_test_case'
4+
5+
module DEBUGGER__
6+
class RescueTest < ConsoleTestCase
7+
def program
8+
<<~RUBY
9+
1| 1.times do
10+
2| begin
11+
3| raise
12+
4| rescue
13+
5| p :ok
14+
6| end
15+
7| end
16+
RUBY
17+
end
18+
19+
def test_rescue
20+
debug_code program, remote: false do
21+
type 's'
22+
type 's'
23+
type 'c'
24+
end
25+
end
26+
end if RUBY_VERSION.to_f >= 3.5
27+
end
28+

test/console/trap_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_sigint
1616
debug_code program, remote: false do
1717
type 'b 3'
1818
type 'c'
19-
assert_line_num 2
2019
assert_line_text(/is registered as SIGINT handler/)
2120
type 'sigint'
2221
assert_line_num 3

0 commit comments

Comments
 (0)