diff --git a/ext/debug/debug.c b/ext/debug/debug.c index fc4b4bb5a..9eaac2bbd 100644 --- a/ext/debug/debug.c +++ b/ext/debug/debug.c @@ -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); } @@ -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 @@ -126,6 +110,7 @@ frame_depth(VALUE self) } #endif + // iseq const struct rb_iseq *rb_iseqw_to_iseq(VALUE iseqw); diff --git a/ext/debug/extconf.rb b/ext/debug/extconf.rb index c9d056b7e..b4e78fbe3 100644 --- a/ext/debug/extconf.rb +++ b/ext/debug/extconf.rb @@ -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