-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Make rb_debug_inspector_backtrace_locations
return a raw backtrace
#13510
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
mame
merged 3 commits into
ruby:master
from
mame:fix-rb_debug_inspector_backtrace_locations
Jun 4, 2025
Merged
Make rb_debug_inspector_backtrace_locations
return a raw backtrace
#13510
mame
merged 3 commits into
ruby:master
from
mame:fix-rb_debug_inspector_backtrace_locations
Jun 4, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, a user of the debug inspector API was supposed to use `rb_debug_inspector_backtrace_locations` to get an array of `Thread::Backtrace::Location`, and then used its index to get more information from `rb_debug_inspector _frame_binding_get(index)`, etc. However, `rb_debug_inspector_backtrace_locations` returned an array of backtraces excluding rescue/ensure frames. On the other hand, `rb_debug_inspector_frame_binding_get(index)` interprets index with rescue/ensure frames. This led to inconsistency of the index, and it was very difficult to correctly use the debug inspector API. This is a minimal fix for the issue by making `rb_debug_inspector_backtrace_locations` return a raw backtrace including rescue/ensure frames.
mame
added a commit
to mame/debug
that referenced
this pull request
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 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.
mame
added a commit
to ruby/debug
that referenced
this pull request
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.
Approved by @ko1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, a user of the debug inspector API was supposed to use
rb_debug_inspector_backtrace_locations
to get an array ofThread::Backtrace::Location
, and then used its index to get more information fromrb_debug_inspector _frame_binding_get(index)
, etc.However,
rb_debug_inspector_backtrace_locations
returned an array of backtraces excluding rescue/ensure frames. On the other hand,rb_debug_inspector_frame_binding_get(index)
interprets index with rescue/ensure frames. This led to inconsistency of the index, and it was very difficult to correctly use the debug inspector API.This is a minimal fix for the issue by making
rb_debug_inspector_backtrace_locations
return a raw backtrace including rescue/ensure frames.