Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ext/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,23 @@ static VALUE
di_body(const rb_debug_inspector_t *dc, void *ptr)
{
VALUE skip_path_prefix = (VALUE)ptr;
#if defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_COUNT) && defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_LOC_GET)
long len = rb_debug_inspector_frame_count(dc);
#else
VALUE locs = rb_debug_inspector_backtrace_locations(dc);
VALUE ary = rb_ary_new();
long len = RARRAY_LEN(locs);
#endif
VALUE ary = rb_ary_new();
long i;

for (i=1; i<len; i++) {
VALUE e;
VALUE iseq = rb_debug_inspector_frame_iseq_get(dc, i);
#if defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_COUNT) && defined(HAVE_RB_DEBUG_INSPECTOR_FRAME_LOC_GET)
VALUE loc = rb_debug_inspector_frame_loc_get(dc, i);
#else
VALUE loc = RARRAY_AREF(locs, i);
#endif
VALUE path;

if (!NIL_P(iseq)) {
Expand Down
7 changes: 7 additions & 0 deletions ext/debug/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
$defs << '-DHAVE_RB_ISEQ'
$defs << '-DHAVE_RB_ISEQ_PARAMETERS'
$defs << '-DHAVE_RB_ISEQ_CODE_LOCATION'
$defs << '-DHAVE_RB_DEBUG_INSPECTOR_FRAME_COUNT'
$defs << '-DHAVE_RB_DEBUG_INSPECTOR_FRAME_LOC_GET'

if RUBY_VERSION >= '3.1.0'
$defs << '-DHAVE_RB_ISEQ_TYPE'
Expand All @@ -22,6 +24,11 @@
# from Ruby 3.1
have_func "rb_iseq_type(NULL)",
[["VALUE rb_iseq_type(void *);"]]
# from Ruby 3.5
have_func "rb_debug_inspector_frame_count(NULL)",
[["VALUE rb_debug_inspector_frame_count(void *);"]]
have_func "rb_debug_inspector_frame_loc_get(NULL, 0)",
[["VALUE rb_debug_inspector_frame_loc_get(void *, int index);"]]
end

create_makefile 'debug/debug'
2 changes: 1 addition & 1 deletion test/console/nested_break_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_multiple_nested_break
assert_line_num 2
type 'p foo(142)'
type 'bt'
assert_line_text(/\#7\s+<main>/) # TODO: can be changed
assert_line_text(/\#11\s+<main>/) # TODO: can be changed

type 'c'
assert_line_text(/143/)
Expand Down
1 change: 0 additions & 1 deletion test/console/trap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_sigint
debug_code program, remote: false do
type 'b 3'
type 'c'
assert_line_num 2
Copy link
Member Author

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.

assert_line_text(/is registered as SIGINT handler/)
type 'sigint'
assert_line_num 3
Expand Down
Loading