Project

General

Profile

Feature #12747 » 0002-Add-TracePoint-callee_id.patch

ktsj (Kazuki Tsujimoto), 09/10/2016 06:30 AM

View differences:

cont.c
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();
......
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;
}
eval.c
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);
}
}
......
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);
gc.c
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)
include/ruby/intern.h
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*);
insns.def
}
}
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);
}
thread.c
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);
......
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);
}
vm.c
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)) {
......
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);
}
......
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;
}
......
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;
}
}
......
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,
......
}
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;
}
......
}
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
vm_backtrace.c
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;
}
vm_core.h
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);
......
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);
......
rb_control_frame_t *cfp;
VALUE self;
ID id;
ID called_id;
VALUE klass;
VALUE data;
......
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;
......
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;
......
}
}
#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
vm_eval.c
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;
......
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;
......
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;
......
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;
vm_insnhelper.c
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,
......
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;
......
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) &&
......
}
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;
vm_trace.c
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) {
......
{
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) {
......
}
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);
......
}
/*
* 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)
......
}
/*
* 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
......
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-2/2)