From ec88ceaa5bba7c6a198aea134409aad7ade36278 Mon Sep 17 00:00:00 2001 From: Kazuki Tsujimoto Date: Sat, 10 Sep 2016 12:42:32 +0900 Subject: [PATCH 2/2] Add TracePoint#callee_id --- cont.c | 4 ++-- eval.c | 4 ++-- gc.c | 2 +- include/ruby/intern.h | 2 +- insns.def | 2 +- thread.c | 6 +++--- vm.c | 31 +++++++++++++++++-------------- vm_backtrace.c | 2 +- vm_core.h | 20 +++++++++++--------- vm_eval.c | 8 ++++---- vm_insnhelper.c | 8 ++++---- vm_trace.c | 23 ++++++++++++++++++++--- 12 files changed, 67 insertions(+), 45 deletions(-) diff --git a/cont.c b/cont.c index 8119b5c..e1aead7 100644 --- a/cont.c +++ b/cont.c @@ -1280,7 +1280,7 @@ rb_fiber_start(void) th->root_svar = Qfalse; fib->status = RUNNING; - EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); cont->value = rb_vm_invoke_proc(th, proc, argc, argv, VM_BLOCK_HANDLER_NONE); } TH_POP_TAG(); @@ -1470,7 +1470,7 @@ fiber_switch(rb_fiber_t *fib, int argc, const VALUE *argv, int is_resume) value = fiber_store(fib, th); RUBY_VM_CHECK_INTS(th); - EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); return value; } diff --git a/eval.c b/eval.c index 4906a43..504c005 100644 --- a/eval.c +++ b/eval.c @@ -563,7 +563,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause) if (tag != TAG_FATAL) { RUBY_DTRACE_HOOK(RAISE, rb_obj_classname(th->errinfo)); - EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0, mesg); + EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0, 0, mesg); } } @@ -738,7 +738,7 @@ rb_raise_jump(VALUE mesg, VALUE cause) ID mid = me->called_id; rb_vm_pop_frame(th); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, me->def->original_id, klass, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, me->def->original_id, mid, klass, Qnil); setup_exception(th, TAG_RAISE, mesg, cause); diff --git a/gc.c b/gc.c index cf8170b..bf5b981 100644 --- a/gc.c +++ b/gc.c @@ -1751,7 +1751,7 @@ rb_objspace_set_event_hook(const rb_event_flag_t event) static void gc_event_hook_body(rb_thread_t *th, rb_objspace_t *objspace, const rb_event_flag_t event, VALUE data) { - EXEC_EVENT_HOOK(th, event, th->cfp->self, 0, 0, data); + EXEC_EVENT_HOOK(th, event, th->cfp->self, 0, 0, 0, data); } #define gc_event_hook_available_p(objspace) ((objspace)->flags.has_hook) diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 48608f3..6ef9d81 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -968,7 +968,7 @@ VALUE rb_mod_remove_cvar(VALUE, VALUE); ID rb_frame_callee(void); VALUE rb_str_succ(VALUE); VALUE rb_time_succ(VALUE); -int rb_frame_method_id_and_class(ID *idp, VALUE *klassp); +int rb_frame_method_id_and_class(ID *idp, ID *callee_idp, VALUE *klassp); VALUE rb_make_backtrace(void); VALUE rb_make_exception(int, const VALUE*); diff --git a/insns.def b/insns.def index f895af7..8345810 100644 --- a/insns.def +++ b/insns.def @@ -829,7 +829,7 @@ trace } } - EXEC_EVENT_HOOK(th, flag, GET_SELF(), 0, 0 /* id and klass are resolved at callee */, + EXEC_EVENT_HOOK(th, flag, GET_SELF(), 0, 0, 0 /* id and klass are resolved at callee */, (flag & (RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN)) ? TOPN(0) : Qundef); } diff --git a/thread.c b/thread.c index 6404bd2..b60d774 100644 --- a/thread.c +++ b/thread.c @@ -589,11 +589,11 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s th->errinfo = Qnil; th->root_lep = rb_vm_ep_local_ep(vm_proc_ep(th->first_proc)); th->root_svar = Qfalse; - EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, Qundef); + EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, 0, Qundef); th->value = rb_vm_invoke_proc(th, proc, (int)RARRAY_LEN(args), RARRAY_CONST_PTR(args), VM_BLOCK_HANDLER_NONE); - EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_END, th->self, 0, 0, Qundef); + EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_END, th->self, 0, 0, 0, Qundef); } else { th->value = (*th->first_func)((void *)args); @@ -2063,7 +2063,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing) if (th->status == THREAD_RUNNABLE) th->running_time_us += TIME_QUANTUM_USEC; - EXEC_EVENT_HOOK(th, RUBY_INTERNAL_EVENT_SWITCH, th->cfp->self, 0, 0, Qundef); + EXEC_EVENT_HOOK(th, RUBY_INTERNAL_EVENT_SWITCH, th->cfp->self, 0, 0, 0, Qundef); rb_thread_schedule_limits(limits_us); } diff --git a/vm.c b/vm.c index 2e9d767..06b51d2 100644 --- a/vm.c +++ b/vm.c @@ -330,7 +330,7 @@ ruby_th_dtrace_setup(rb_thread_t *th, VALUE klass, ID id, enum ruby_value_type type; if (!klass) { if (!th) th = GET_THREAD(); - if (!rb_thread_method_id_and_class(th, &id, &klass) || !klass) + if (!rb_thread_method_id_and_class(th, &id, 0, &klass) || !klass) return FALSE; } if (RB_TYPE_P(klass, T_ICLASS)) { @@ -522,8 +522,8 @@ rb_vm_pop_cfunc_frame(void) rb_control_frame_t *cfp = th->cfp; const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->owner, Qnil); /* TODO */ - RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->def->original_id); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, cfp->self, me->def->original_id, me->called_id, me->owner, Qnil); + RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->called_id); vm_pop_frame(th, cfp, cfp->ep); } @@ -984,9 +984,9 @@ invoke_bmethod(rb_thread_t *th, const rb_iseq_t *iseq, VALUE self, const struct iseq->body->stack_max); RUBY_DTRACE_METHOD_ENTRY_HOOK(th, me->owner, me->def->original_id); - EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, self, me->def->original_id, me->owner, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, self, me->def->original_id, me->called_id, me->owner, Qnil); ret = vm_exec(th); - EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, self, me->def->original_id, me->owner, ret); + EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, self, me->def->original_id, me->called_id, me->owner, ret); RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->owner, me->def->original_id); return ret; } @@ -1592,26 +1592,27 @@ hook_before_rewind(rb_thread_t *th, rb_control_frame_t *cfp, int will_finish_vm_ switch (VM_FRAME_TYPE(th->cfp)) { case VM_FRAME_MAGIC_METHOD: RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0); - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil); + EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, 0, Qnil); break; case VM_FRAME_MAGIC_BLOCK: case VM_FRAME_MAGIC_LAMBDA: if (VM_FRAME_BMETHOD_P(th->cfp)) { - EXEC_EVENT_HOOK(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, 0, Qnil); if (!will_finish_vm_exec) { /* kick RUBY_EVENT_RETURN at invoke_block_from_c() for bmethod */ EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, rb_vm_frame_method_entry(th->cfp)->def->original_id, + rb_vm_frame_method_entry(th->cfp)->called_id, rb_vm_frame_method_entry(th->cfp)->owner, Qnil); } } else { - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); + EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, 0, Qnil); } break; case VM_FRAME_MAGIC_CLASS: - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil); + EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, 0, Qnil); break; } } @@ -1735,6 +1736,7 @@ vm_exec(rb_thread_t *th) if (UNLIKELY(VM_FRAME_TYPE(th->cfp) == VM_FRAME_MAGIC_CFUNC)) { EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, rb_vm_frame_method_entry(th->cfp)->def->original_id, + rb_vm_frame_method_entry(th->cfp)->called_id, rb_vm_frame_method_entry(th->cfp)->owner, Qnil); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, rb_vm_frame_method_entry(th->cfp)->owner, @@ -1958,12 +1960,13 @@ rb_iseq_eval_main(const rb_iseq_t *iseq) } int -rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp) +rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp) { const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp); if (me) { if (idp) *idp = me->def->original_id; + if (called_idp) *called_idp = me->called_id; if (klassp) *klassp = me->owner; return TRUE; } @@ -1973,15 +1976,15 @@ rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE * } int -rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp) +rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, ID *called_idp, VALUE *klassp) { - return rb_vm_control_frame_id_and_class(th->cfp, idp, klassp); + return rb_vm_control_frame_id_and_class(th->cfp, idp, called_idp, klassp); } int -rb_frame_method_id_and_class(ID *idp, VALUE *klassp) +rb_frame_method_id_and_class(ID *idp, ID *called_idp, VALUE *klassp) { - return rb_thread_method_id_and_class(GET_THREAD(), idp, klassp); + return rb_thread_method_id_and_class(GET_THREAD(), idp, called_idp, klassp); } VALUE diff --git a/vm_backtrace.c b/vm_backtrace.c index cbde640..9e9d467 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -1088,7 +1088,7 @@ static VALUE get_klass(const rb_control_frame_t *cfp) { VALUE klass; - if (rb_vm_control_frame_id_and_class(cfp, 0, &klass)) { + if (rb_vm_control_frame_id_and_class(cfp, 0, 0, &klass)) { if (RB_TYPE_P(klass, T_ICLASS)) { return RBASIC(klass)->klass; } diff --git a/vm_core.h b/vm_core.h index ccba902..27678ef 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1420,7 +1420,7 @@ RUBY_SYMBOL_EXPORT_BEGIN VALUE rb_iseq_eval(const rb_iseq_t *iseq); VALUE rb_iseq_eval_main(const rb_iseq_t *iseq); RUBY_SYMBOL_EXPORT_END -int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp); +int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, ID *called_idp, VALUE *klassp); VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, int argc, const VALUE *argv, VALUE block_handler); VALUE rb_vm_make_proc_lambda(rb_thread_t *th, const struct rb_captured_block *captured, VALUE klass, int8_t is_lambda); @@ -1468,7 +1468,7 @@ int rb_vm_get_sourceline(const rb_control_frame_t *); VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method); void rb_vm_stack_to_heap(rb_thread_t *th); void ruby_thread_init_stack(rb_thread_t *th); -int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp); +int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp); void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp); void rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE exception_class, const char *mesg); @@ -1580,6 +1580,7 @@ struct rb_trace_arg_struct { rb_control_frame_t *cfp; VALUE self; ID id; + ID called_id; VALUE klass; VALUE data; @@ -1593,17 +1594,17 @@ struct rb_trace_arg_struct { void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg); void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg); -#define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \ +#define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, callee_id_, klass_, data_, pop_p_) do { \ const rb_event_flag_t flag_arg_ = (flag_); \ if (UNLIKELY(ruby_vm_event_flags & (flag_arg_))) { \ /* defer evaluating the other arguments */ \ - ruby_exec_event_hook_orig(th_, flag_arg_, self_, id_, klass_, data_, pop_p_); \ + ruby_exec_event_hook_orig(th_, flag_arg_, self_, id_, callee_id_, klass_, data_, pop_p_); \ } \ } while (0) static inline void ruby_exec_event_hook_orig(rb_thread_t *const th, const rb_event_flag_t flag, - VALUE self, ID id, VALUE klass, VALUE data, int pop_p) + VALUE self, ID id, ID called_id, VALUE klass, VALUE data, int pop_p) { if ((th->event_hooks.events | th->vm->event_hooks.events) & flag) { struct rb_trace_arg_struct trace_arg; @@ -1612,6 +1613,7 @@ ruby_exec_event_hook_orig(rb_thread_t *const th, const rb_event_flag_t flag, trace_arg.cfp = th->cfp; trace_arg.self = self; trace_arg.id = id; + trace_arg.called_id = called_id; trace_arg.klass = klass; trace_arg.data = data; trace_arg.path = Qundef; @@ -1621,11 +1623,11 @@ ruby_exec_event_hook_orig(rb_thread_t *const th, const rb_event_flag_t flag, } } -#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \ - EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0) +#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, callee_id_, klass_, data_) \ + EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, callee_id_, klass_, data_, 0) -#define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \ - EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1) +#define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, callee_id_, klass_, data_) \ + EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, callee_id_, klass_, data_, 1) RUBY_SYMBOL_EXPORT_BEGIN diff --git a/vm_eval.c b/vm_eval.c index a712e55..0f2f8aa 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -68,7 +68,7 @@ vm_call0_cfunc(rb_thread_t* th, struct rb_calling_info *calling, const struct rb VALUE val; RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, cc->me->owner, ci->mid); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, calling->recv, ci->mid, cc->me->owner, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, calling->recv, ci->mid, ci->mid, cc->me->owner, Qnil); { rb_control_frame_t *reg_cfp = th->cfp; const rb_callable_method_entry_t *me = cc->me; @@ -98,7 +98,7 @@ vm_call0_cfunc(rb_thread_t* th, struct rb_calling_info *calling, const struct rb rb_vm_pop_frame(th); } } - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, calling->recv, ci->mid, callnig->cc->me->owner, val); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, calling->recv, ci->mid, ci->mid, callnig->cc->me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, cc->me->owner, ci->mid); return val; @@ -117,7 +117,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, struct rb_calling_info *calling, cons VALUE block_handler = calling->block_handler; RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, me->owner, mid); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->def->original_id, me->owner, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->def->original_id, mid, me->owner, Qnil); { rb_control_frame_t *reg_cfp = th->cfp; @@ -136,7 +136,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, struct rb_calling_info *calling, cons VM_PROFILE_UP(C2C_POPF); rb_vm_pop_frame(th); } - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->def->original_id, me->owner, val); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->def->original_id, mid, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, mid); return val; diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 11aad2a..46595bc 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1724,7 +1724,7 @@ vm_call_cfunc_with_frame(rb_thread_t *th, rb_control_frame_t *reg_cfp, struct rb int argc = calling->argc; RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, me->owner, me->def->original_id); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->def->original_id, me->owner, Qundef); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->def->original_id, ci->mid, me->owner, Qundef); vm_push_frame(th, NULL, VM_FRAME_MAGIC_CFUNC | VM_FRAME_FLAG_CFRAME | VM_ENV_FLAG_LOCAL, recv, block_handler, (VALUE)me, @@ -1742,7 +1742,7 @@ vm_call_cfunc_with_frame(rb_thread_t *th, rb_control_frame_t *reg_cfp, struct rb rb_vm_pop_frame(th); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->def->original_id, me->owner, val); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->def->original_id, ci->mid, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->def->original_id); return val; @@ -1794,7 +1794,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, struct rb_calling_in if (len >= 0) rb_check_arity(calling->argc, len, len); RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, me->owner, me->called_id); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->owner, Qnil); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, ci->mid, me->owner, Qnil); if (!(cc->me->def->flag & METHOD_VISI_PROTECTED) && !(ci->flag & VM_CALL_ARGS_SPLAT) && @@ -1803,7 +1803,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, struct rb_calling_in } val = vm_call_cfunc_latter(th, reg_cfp, calling); - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->owner, val); + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, ci->mid, me->owner, val); RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, me->owner, me->called_id); return val; diff --git a/vm_trace.c b/vm_trace.c index fe14c64..aca6367 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -616,7 +616,7 @@ call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas rb_thread_t *th = GET_THREAD(); if (!klass) { - rb_thread_method_id_and_class(th, &id, &klass); + rb_thread_method_id_and_class(th, &id, 0, &klass); } if (klass) { @@ -781,7 +781,7 @@ fill_id_and_klass(rb_trace_arg_t *trace_arg) { if (!trace_arg->klass_solved) { if (!trace_arg->klass) { - rb_vm_control_frame_id_and_class(trace_arg->cfp, &trace_arg->id, &trace_arg->klass); + rb_vm_control_frame_id_and_class(trace_arg->cfp, &trace_arg->id, &trace_arg->called_id, &trace_arg->klass); } if (trace_arg->klass) { @@ -805,6 +805,13 @@ rb_tracearg_method_id(rb_trace_arg_t *trace_arg) } VALUE +rb_tracearg_callee_id(rb_trace_arg_t *trace_arg) +{ + fill_id_and_klass(trace_arg); + return trace_arg->called_id ? ID2SYM(trace_arg->called_id) : Qnil; +} + +VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg) { fill_id_and_klass(trace_arg); @@ -906,7 +913,7 @@ tracepoint_attr_path(VALUE tpval) } /* - * Return the name of the method being called + * Return the name at the definition of the method being called */ static VALUE tracepoint_attr_method_id(VALUE tpval) @@ -915,6 +922,15 @@ tracepoint_attr_method_id(VALUE tpval) } /* + * Return the called name of the method being called + */ +static VALUE +tracepoint_attr_callee_id(VALUE tpval) +{ + return rb_tracearg_callee_id(get_trace_arg()); +} + +/* * Return class or module of the method being called. * * class C; def foo; end; end @@ -1480,6 +1496,7 @@ Init_vm_trace(void) rb_define_method(rb_cTracePoint, "lineno", tracepoint_attr_lineno, 0); rb_define_method(rb_cTracePoint, "path", tracepoint_attr_path, 0); rb_define_method(rb_cTracePoint, "method_id", tracepoint_attr_method_id, 0); + rb_define_method(rb_cTracePoint, "callee_id", tracepoint_attr_callee_id, 0); rb_define_method(rb_cTracePoint, "defined_class", tracepoint_attr_defined_class, 0); rb_define_method(rb_cTracePoint, "binding", tracepoint_attr_binding, 0); rb_define_method(rb_cTracePoint, "self", tracepoint_attr_self, 0); -- 2.7.4