summaryrefslogtreecommitdiff
path: root/vm_backtrace.c
diff options
context:
space:
mode:
authorJeremy Evans <[email protected]>2022-01-14 13:02:46 -0800
committerJeremy Evans <[email protected]>2022-02-17 08:54:07 -0800
commit4c366ec9775eb6acb3fcb3b88038d051512c75a2 ()
treeb36d45da1bdb3ccce9ca0d9d4a86852c23fa9299 /vm_backtrace.c
parent4113862c0068a8a95d752f5fdf14980f92cd41d7 (diff)
Add Thread.each_caller_location
This method takes a block and yields Thread::Backtrace::Location objects to the block. It does not take arguments, and always starts at the default frame that caller_locations would start at. Implements [Feature #16663]
Notes: Merged: https://.com/ruby/ruby/pull/5445
-rw-r--r--vm_backtrace.c42
1 files changed, 37 insertions, 5 deletions
@@ -572,8 +572,18 @@ bt_update_cfunc_loc(unsigned long cfunc_counter, rb_backtrace_location_t *cfunc_
}
}
static VALUE
-rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_frame, long num_frames, int* start_too_large, bool skip_internal)
{
const rb_control_frame_t *cfp = ec->cfp;
const rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
@@ -631,6 +641,9 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
loc->iseq = iseq;
loc->pc = pc;
bt_update_cfunc_loc(cfunc_counter, loc-1, iseq, pc);
cfunc_counter = 0;
}
}
@@ -654,6 +667,9 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
for (; cfp != end_cfp; cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)) {
if (cfp->iseq && cfp->pc && (!skip_internal || !is_internal_location(cfp))) {
bt_update_cfunc_loc(cfunc_counter, loc, cfp->iseq, cfp->pc);
break;
}
}
@@ -666,7 +682,7 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
MJIT_FUNC_EXPORTED VALUE
rb_ec_backtrace_object(const rb_execution_context_t *ec)
{
- return rb_ec_partial_backtrace_object(ec, BACKTRACE_START, ALL_BACKTRACE_LINES, NULL, FALSE);
}
static VALUE
@@ -841,13 +857,13 @@ backtrace_limit(VALUE self)
VALUE
rb_ec_backtrace_str_ary(const rb_execution_context_t *ec, long lev, long n)
{
- return backtrace_to_str_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, FALSE));
}
VALUE
rb_ec_backtrace_location_ary(const rb_execution_context_t *ec, long lev, long n, bool skip_internal)
{
- return backtrace_to_location_ary(rb_ec_partial_backtrace_object(ec, lev, n, NULL, skip_internal));
}
/* make old style backtrace directly */
@@ -1119,7 +1135,7 @@ ec_backtrace_to_ary(const rb_execution_context_t *ec, int argc, const VALUE *arg
return rb_ary_new();
}
- btval = rb_ec_partial_backtrace_object(ec, lev, n, &too_large, FALSE);
if (too_large) {
return Qnil;
@@ -1240,6 +1256,20 @@ rb_f_caller_locations(int argc, VALUE *argv, VALUE _)
return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 0);
}
/* called from Init_vm() in vm.c */
void
Init_vm_backtrace(void)
@@ -1315,6 +1345,8 @@ Init_vm_backtrace(void)
rb_define_global_function("caller", rb_f_caller, -1);
rb_define_global_function("caller_locations", rb_f_caller_locations, -1);
}
/* debugger API */