Skip to content

The debug gem can abort when stepping into a rescue clause: #1142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

mame
Copy link
Member

@mame mame commented Jun 4, 2025

$ 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
  #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.

```
$ 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.
Copy link

launchable-app bot commented Jun 4, 2025

Tests Failed

✖️no tests failed ✔️679 tests passed(1 flake)

@mame mame marked this pull request as ready for review June 4, 2025 08:23
@mame
Copy link
Member Author

mame commented Jun 4, 2025

Approved by @ko1

@mame mame merged commit cf469f2 into ruby:master Jun 4, 2025
28 of 32 checks passed
@mame mame deleted the fix-stepping-into-resue branch June 4, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant