Skip to content

Use dc depth #831

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 2 commits into from
Nov 25, 2022
Merged
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
33 changes: 9 additions & 24 deletions ext/debug/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ di_body(const rb_debug_inspector_t *dc, void *ptr)
rb_debug_inspector_frame_binding_get(dc, i),
iseq,
rb_debug_inspector_frame_class_get(dc, i),
INT2FIX(len - i));
#ifdef RB_DEBUG_INSPECTOR_FRAME_DEPTH
rb_debug_inspector_frame_depth(dc, i)
#else
INT2FIX(len - i)
#endif
);
rb_ary_push(ary, e);
}

Expand All @@ -89,32 +94,11 @@ capture_frames(VALUE self, VALUE skip_path_prefix)
return rb_debug_inspector_open(di_body, (void *)skip_path_prefix);
}

#ifdef RB_PROFILE_FRAMES_HAS_C_FRAMES
#define BUFF_SIZE 4096

#ifdef RB_DEBUG_INSPECTOR_FRAME_DEPTH
static VALUE
frame_depth(VALUE self)
{
static VALUE buff[BUFF_SIZE];
static int lines[BUFF_SIZE];

int size = rb_profile_frames(0, BUFF_SIZE, buff, lines);

// If the buffer is full, there might be more frames.
// Fall back to rb_make_backtrace to get them all.
if (size >= BUFF_SIZE) {
VALUE bt = rb_make_backtrace();
size = RARRAY_LEN(bt);
return INT2FIX(size);
}

// rb_profile_frames will return one extra frame
// https://bugs.ruby-lang.org/issues/18907
#ifdef RB_PROFILE_FRAMES_HAS_EXTRA_FRAME
return INT2FIX(size - 1);
#else
return INT2FIX(size);
#endif
return rb_debug_inspector_current_depth();
}
#else
static VALUE
Expand All @@ -126,6 +110,7 @@ frame_depth(VALUE self)
}
#endif


// iseq

const struct rb_iseq *rb_iseqw_to_iseq(VALUE iseqw);
Expand Down
8 changes: 0 additions & 8 deletions ext/debug/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
$defs << '-DHAVE_RB_ISEQ_PARAMETERS'
$defs << '-DHAVE_RB_ISEQ_CODE_LOCATION'

if RUBY_VERSION >= '3.0.0'
$defs << '-DRB_PROFILE_FRAMES_HAS_C_FRAMES'

if RUBY_VERSION < '3.2.0'
$defs << '-DRB_PROFILE_FRAMES_HAS_EXTRA_FRAME'
end
end

if RUBY_VERSION >= '3.1.0'
$defs << '-DHAVE_RB_ISEQ_TYPE'
end
Expand Down