Skip to content

Commit 9d2292e

Browse files
committed
Use rb_debug_inspector_frame_loc_get if any
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`.
1 parent bead098 commit 9d2292e

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

ext/debug/debug.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,23 @@ static VALUE
5656
di_body(const rb_debug_inspector_t *dc, void *ptr)
5757
{
5858
VALUE skip_path_prefix = (VALUE)ptr;
59+
#if defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_COUNT) && defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_LOC_GET)
60+
long len = rb_debug_inspector_frame_count(dc);
61+
#else
5962
VALUE locs = rb_debug_inspector_backtrace_locations(dc);
60-
VALUE ary = rb_ary_new();
6163
long len = RARRAY_LEN(locs);
64+
#endif
65+
VALUE ary = rb_ary_new();
6266
long i;
6367

6468
for (i=1; i<len; i++) {
6569
VALUE e;
6670
VALUE iseq = rb_debug_inspector_frame_iseq_get(dc, i);
71+
#if defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_COUNT) && defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_LOC_GET)
72+
VALUE loc = rb_debug_inspector_frame_loc_get(dc, i);
73+
#else
6774
VALUE loc = RARRAY_AREF(locs, i);
75+
#endif
6876
VALUE path;
6977

7078
if (!NIL_P(iseq)) {

ext/debug/extconf.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
$defs << '-DHAVE_RB_ISEQ'
88
$defs << '-DHAVE_RB_ISEQ_PARAMETERS'
99
$defs << '-DHAVE_RB_ISEQ_CODE_LOCATION'
10+
$defs << '-DHAVE_RB_DEBUG_INSPECTOR_FRAME_COUNT'
11+
$defs << '-DHAVE_RB_DEBUG_INSPECTOR_FRAME_LOC_GET'
1012

1113
if RUBY_VERSION >= '3.1.0'
1214
$defs << '-DHAVE_RB_ISEQ_TYPE'
@@ -22,6 +24,11 @@
2224
# from Ruby 3.1
2325
have_func "rb_iseq_type(NULL)",
2426
[["VALUE rb_iseq_type(void *);"]]
27+
# from Ruby 3.5
28+
have_func "rb_debug_inspector_frame_count(NULL)",
29+
[["VALUE rb_debug_inspector_frame_count(void *);"]]
30+
have_func "rb_debug_inspector_frame_loc_get(NULL, 0)",
31+
[["VALUE rb_debug_inspector_frame_loc_get(void *, int index);"]]
2532
end
2633

2734
create_makefile 'debug/debug'

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(/\#11\s+<main>/) # TODO: can be changed
8787

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

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)