Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Don't emit stack trace for internal iseqs #13132

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

Closed
wants to merge 2 commits into from
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
2 changes: 1 addition & 1 deletion test/ruby/test_backtrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def test_thread_backtrace
th_backtrace = th.backtrace
th_locations = th.backtrace_locations

assert_equal(10, th_backtrace.count{|e| e =~ /th_rec/})
assert_equal(11, th_backtrace.count{|e| e =~ /th_rec/})
assert_equal(th_backtrace, th_locations.map{|e| e.to_s})
assert_equal(th_backtrace, th.backtrace(0))
assert_equal(th_locations.map{|e| e.to_s},
Expand Down
14 changes: 11 additions & 3 deletions vm_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ calculate_iseq_label(VALUE owner, const rb_iseq_t *iseq)
}
}

static bool is_internal_iseq(const rb_iseq_t *iseq);

// Return true if a given location is a C method or supposed to behave like one.
static inline bool
location_cfunc_p(rb_backtrace_location_t *loc)
Expand All @@ -272,7 +274,7 @@ location_cfunc_p(rb_backtrace_location_t *loc)
case VM_METHOD_TYPE_CFUNC:
return true;
case VM_METHOD_TYPE_ISEQ:
return rb_iseq_attr_p(loc->cme->def->body.iseq.iseqptr, BUILTIN_ATTR_C_TRACE);
return is_internal_iseq(loc->cme->def->body.iseq.iseqptr);
default:
return false;
}
Expand Down Expand Up @@ -606,10 +608,16 @@ backtrace_size(const rb_execution_context_t *ec)

static bool
is_internal_location(const rb_control_frame_t *cfp)
{
return is_internal_iseq(cfp->iseq);
}

static bool
is_internal_iseq(const rb_iseq_t *iseq)
{
static const char prefix[] = "<internal:";
const size_t prefix_len = sizeof(prefix) - 1;
VALUE file = rb_iseq_path(cfp->iseq);
VALUE file = rb_iseq_path(iseq);
return strncmp(prefix, RSTRING_PTR(file), prefix_len) == 0;
}

Expand Down Expand Up @@ -698,7 +706,7 @@ rb_ec_partial_backtrace_object(const rb_execution_context_t *ec, long start_fram
loc = &bt->backtrace[bt->backtrace_size++];
RB_OBJ_WRITE(btobj, &loc->cme, rb_vm_frame_method_entry(cfp));
// Ruby methods with `Primitive.attr! :c_trace` should behave like C methods
if (rb_iseq_attr_p(cfp->iseq, BUILTIN_ATTR_C_TRACE)) {
if (is_internal_location(cfp)) {
loc->iseq = NULL;
loc->pc = NULL;
cfunc_counter++;
Expand Down
Loading