Skip to content

Use rb_debug_inspector_frame_loc_get if any - #1139

Closed
mame wants to merge 1 commit into
ruby:masterfrom
mame:use-rb_debug_inspector_frame_loc_get
Closed

Use rb_debug_inspector_frame_loc_get if any#1139
mame wants to merge 1 commit into
ruby:masterfrom
mame:use-rb_debug_inspector_frame_loc_get

Conversation

@mame

@mamemame commented Jun 4, 2025

Copy link
Copy Markdown
Member

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
#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 caused by the design issue of the debug inspector API. See ruby/ruby#13508

This changeset fixes the issue by using a newly-introduced debug inspector API, namely rb_debug_inspector_frame_loc_get.

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 caused by the design issue of the debug inspector API.
See ruby/ruby#13508
This changeset fixes the issue by using a newly-introduced debug
inspector API, namely `rb_debug_inspector_frame_loc_get`.
@cloudbees-smart-tests

cloudbees-smart-testsBot commented Jun 4, 2025

Copy link
Copy Markdown

Tests Failed

✖️369 tests failed ✔️8 tests passed

23/27 test sessions failed

❌ Test session #4414554 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414556 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414559 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414561 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414562 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414563 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414564 failedos:ubuntu-latesttest_task:test_testdetails on CI
🔔 no issues ✖️11 tests failed ✔️1 test passed

❌ Test session #4414565 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414566 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414567 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414568 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414569 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414570 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414571 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414576 failedos:ubuntu-latesttest_task:test_protocoldetails on CI
🔔 no issues ✖️64 tests failed ✔️no tests passed

❌ Test session #4414577 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414578 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414581 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414583 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414584 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414585 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414586 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

❌ Test session #4414609 failedos:ubuntu-latesttest_task:test_consoledetails on CI
🔔 no issues ✖️294 tests failed ✔️7 tests passed

debug_code program, remote: false do
type 'b 3'
type 'c'
assert_line_num 2

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby spoofs the location of the C frame to the location of the caller. But rb_debug_inspector_frame_loc_get does not do this spoofing, so the location of Process#kill is not sigint-test.rb:2 but #<none>:0.

$ ruby -Ilib exe/rdbg sigint-test.rb
[1, 3] in sigint-test.rb
=> 1| trap('SIGINT'){ puts "SIGINT" }
2| Process.kill('SIGINT', Process.pid)
3| p :ok
=>#0 <main> at sigint-test.rb:1
(rdbg) c # continue command
# No sourcefile available for
=>#0 [C] Process.kill at #<none>:0
#1 <main> at sigint-test.rb:2
Stop by SIGINT
#<Proc:0x00007950068cd4b0 sigint-test.rb:1> is registered as SIGINT handler.
`sigint` command execute it.
(rdbg)

This change reflects that.

@mame

mame commented Jun 4, 2025

Copy link
Copy Markdown
MemberAuthor

superseded by #1142

@mamemame closed this Jun 4, 2025
Sign up for freeto 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

@mame