mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_trace.c: add two methods:
(1) TracePoint#return_value which returns return value on the :return and :c_return event. (2) TracePoint#raised_exception which returns raised exception value on the :raise event. Eeach methods raise RuntimeError if it is called at unsupported event. Please review and give us feedback until next preview release (Dec/2012) of Ruby 2.0.0. * insns.def, vm.c, vm_eval.c, vm_insnhelper.c, eval.c, thread.c: ditto. * vm_trace.c, vm_core.h: move definition of rb_trace_arg_t from vm_trace.c to vm_core.h. Caller fills rb_trace_arg_t and pass the pointer of this variable. * test/ruby/test_settracefunc.rb: fix tests to test this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b1fa559039
commit
553931962a
10 changed files with 182 additions and 89 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
Tue Nov 20 18:35:05 2012 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_trace.c: add two methods:
|
||||
(1) TracePoint#return_value which returns return
|
||||
value on the :return and :c_return event.
|
||||
(2) TracePoint#raised_exception which returns raised exception
|
||||
value on the :raise event.
|
||||
Eeach methods raise RuntimeError if it is called at unsupported
|
||||
event.
|
||||
Please review and give us feedback until next preview
|
||||
release (Dec/2012) of Ruby 2.0.0.
|
||||
|
||||
* insns.def, vm.c, vm_eval.c, vm_insnhelper.c, eval.c, thread.c:
|
||||
ditto.
|
||||
|
||||
* vm_trace.c, vm_core.h: move definition of rb_trace_arg_t from
|
||||
vm_trace.c to vm_core.h.
|
||||
Caller fills rb_trace_arg_t and pass the pointer of this variable.
|
||||
|
||||
* test/ruby/test_settracefunc.rb: fix tests to test this change.
|
||||
|
||||
Tue Nov 20 17:31:12 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* configure.in: fix dtrace didn't work on darwin.
|
||||
|
|
4
eval.c
4
eval.c
|
@ -505,7 +505,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
|
|||
rb_sourcefile(),
|
||||
rb_sourceline());
|
||||
}
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0, mesg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -654,7 +654,7 @@ rb_raise_jump(VALUE mesg)
|
|||
|
||||
setup_exception(th, TAG_RAISE, mesg);
|
||||
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, mid, klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, mid, klass, Qnil);
|
||||
rb_thread_raised_clear(th);
|
||||
JUMP_TAG(TAG_RAISE);
|
||||
}
|
||||
|
|
|
@ -871,7 +871,8 @@ trace
|
|||
rb_sourceline());
|
||||
}
|
||||
}
|
||||
EXEC_EVENT_HOOK(th, flag, GET_SELF(), 0, 0 /* TODO: id, klass */);
|
||||
EXEC_EVENT_HOOK(th, flag, GET_SELF(), 0, 0 /* id and klass are resolved at callee */,
|
||||
flag & RUBY_EVENT_RETURN ? TOPN(0) : Qundef);
|
||||
}
|
||||
|
||||
/**********************************************************/
|
||||
|
|
|
@ -403,11 +403,22 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
trace = nil
|
||||
xyzzy = nil
|
||||
local_var = :outer
|
||||
raised_exc = nil
|
||||
method = :trace_by_tracepoint
|
||||
get_data = lambda{|tp|
|
||||
case tp.event
|
||||
when :return, :c_return
|
||||
tp.return_value
|
||||
when :raise
|
||||
tp.raised_exception
|
||||
else
|
||||
:nothing
|
||||
end
|
||||
}
|
||||
|
||||
eval <<-EOF.gsub(/^.*?: /, ""), nil, 'xyzzy'
|
||||
1: trace = TracePoint.trace(*trace_events){|tp|
|
||||
2: events << [tp.event, tp.line, tp.file, tp.klass, tp.id, tp.self, tp.binding.eval("local_var")]
|
||||
2: events << [tp.event, tp.line, tp.file, tp.klass, tp.id, tp.self, tp.binding.eval("local_var"), get_data.(tp)]
|
||||
3: }
|
||||
4: 1.times{|;local_var| local_var = :inner
|
||||
5: tap{}
|
||||
|
@ -425,50 +436,64 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
17: end
|
||||
18: xyzzy = XYZZY.new
|
||||
19: xyzzy.foo
|
||||
20: trace.untrace
|
||||
20: begin; raise RuntimeError; rescue RuntimeError => raised_exc; end
|
||||
21: trace.untrace
|
||||
EOF
|
||||
self.class.class_eval{remove_const(:XYZZY)}
|
||||
|
||||
answer_events = [
|
||||
#
|
||||
[:c_return, 1, "xyzzy", TracePoint, :trace, TracePoint, :outer],
|
||||
[:line, 4, 'xyzzy', self.class, method, self, :outer],
|
||||
[:c_call, 4, 'xyzzy', Integer, :times, 1, :outer],
|
||||
[:line, 4, 'xyzzy', self.class, method, self, nil],
|
||||
[:line, 5, 'xyzzy', self.class, method, self, :inner],
|
||||
[:c_call, 5, 'xyzzy', Kernel, :tap, self, :inner],
|
||||
[:c_return, 5, "xyzzy", Kernel, :tap, self, :inner],
|
||||
[:c_return, 4, "xyzzy", Integer, :times, 1, :outer],
|
||||
[:line, 7, 'xyzzy', self.class, method, self, :outer],
|
||||
[:c_call, 7, "xyzzy", Class, :inherited, Object, :outer],
|
||||
[:c_return, 7, "xyzzy", Class, :inherited, Object, :outer],
|
||||
[:class, 7, "xyzzy", nil, nil, xyzzy.class, nil],
|
||||
[:line, 8, "xyzzy", nil, nil, xyzzy.class, nil],
|
||||
[:line, 9, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer],
|
||||
[:c_call, 9, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer],
|
||||
[:c_return, 9, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer],
|
||||
[:line, 13, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer],
|
||||
[:c_call, 13, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer],
|
||||
[:c_return,13, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer],
|
||||
[:end, 17, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer],
|
||||
[:line, 18, "xyzzy", TestSetTraceFunc, method, self, :outer],
|
||||
[:c_call, 18, "xyzzy", Class, :new, xyzzy.class, :outer],
|
||||
[:c_call, 18, "xyzzy", BasicObject, :initialize, xyzzy, :outer],
|
||||
[:c_return,18, "xyzzy", BasicObject, :initialize, xyzzy, :outer],
|
||||
[:c_return,18, "xyzzy", Class, :new, xyzzy.class, :outer],
|
||||
[:line, 19, "xyzzy", TestSetTraceFunc, method, self, :outer],
|
||||
[:call, 9, "xyzzy", xyzzy.class, :foo, xyzzy, nil],
|
||||
[:line, 10, "xyzzy", xyzzy.class, :foo, xyzzy, nil],
|
||||
[:line, 11, "xyzzy", xyzzy.class, :foo, xyzzy, :XYZZY_foo],
|
||||
[:call, 13, "xyzzy", xyzzy.class, :bar, xyzzy, nil],
|
||||
[:line, 14, "xyzzy", xyzzy.class, :bar, xyzzy, nil],
|
||||
[:line, 15, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar],
|
||||
[:c_call, 15, "xyzzy", Kernel, :tap, xyzzy, :XYZZY_bar],
|
||||
[:c_return,15, "xyzzy", Kernel, :tap, xyzzy, :XYZZY_bar],
|
||||
[:return, 16, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar],
|
||||
[:return, 12, "xyzzy", xyzzy.class, :foo, xyzzy, :XYZZY_foo],
|
||||
[:line, 20, "xyzzy", TestSetTraceFunc, method, self, :outer],
|
||||
[:c_call, 20, "xyzzy", TracePoint, :untrace, trace, :outer],
|
||||
[:c_return, 1, "xyzzy", TracePoint, :trace, TracePoint, :outer, trace],
|
||||
[:line, 4, 'xyzzy', self.class, method, self, :outer, :nothing],
|
||||
[:c_call, 4, 'xyzzy', Integer, :times, 1, :outer, :nothing],
|
||||
[:line, 4, 'xyzzy', self.class, method, self, nil, :nothing],
|
||||
[:line, 5, 'xyzzy', self.class, method, self, :inner, :nothing],
|
||||
[:c_call, 5, 'xyzzy', Kernel, :tap, self, :inner, :nothing],
|
||||
[:c_return, 5, "xyzzy", Kernel, :tap, self, :inner, self],
|
||||
[:c_return, 4, "xyzzy", Integer, :times, 1, :outer, 1],
|
||||
[:line, 7, 'xyzzy', self.class, method, self, :outer, :nothing],
|
||||
[:c_call, 7, "xyzzy", Class, :inherited, Object, :outer, :nothing],
|
||||
[:c_return, 7, "xyzzy", Class, :inherited, Object, :outer, nil],
|
||||
[:class, 7, "xyzzy", nil, nil, xyzzy.class, nil, :nothing],
|
||||
[:line, 8, "xyzzy", nil, nil, xyzzy.class, nil, :nothing],
|
||||
[:line, 9, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer, :nothing],
|
||||
[:c_call, 9, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer, :nothing],
|
||||
[:c_return, 9, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer, nil],
|
||||
[:line, 13, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer, :nothing],
|
||||
[:c_call, 13, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer, :nothing],
|
||||
[:c_return,13, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer, nil],
|
||||
[:end, 17, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer, :nothing],
|
||||
[:line, 18, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing],
|
||||
[:c_call, 18, "xyzzy", Class, :new, xyzzy.class, :outer, :nothing],
|
||||
[:c_call, 18, "xyzzy", BasicObject, :initialize, xyzzy, :outer, :nothing],
|
||||
[:c_return,18, "xyzzy", BasicObject, :initialize, xyzzy, :outer, nil],
|
||||
[:c_return,18, "xyzzy", Class, :new, xyzzy.class, :outer, xyzzy],
|
||||
[:line, 19, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing],
|
||||
[:call, 9, "xyzzy", xyzzy.class, :foo, xyzzy, nil, :nothing],
|
||||
[:line, 10, "xyzzy", xyzzy.class, :foo, xyzzy, nil, :nothing],
|
||||
[:line, 11, "xyzzy", xyzzy.class, :foo, xyzzy, :XYZZY_foo, :nothing],
|
||||
[:call, 13, "xyzzy", xyzzy.class, :bar, xyzzy, nil, :nothing],
|
||||
[:line, 14, "xyzzy", xyzzy.class, :bar, xyzzy, nil, :nothing],
|
||||
[:line, 15, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar, :nothing],
|
||||
[:c_call, 15, "xyzzy", Kernel, :tap, xyzzy, :XYZZY_bar, :nothing],
|
||||
[:c_return,15, "xyzzy", Kernel, :tap, xyzzy, :XYZZY_bar, xyzzy],
|
||||
[:return, 16, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar, xyzzy],
|
||||
[:return, 12, "xyzzy", xyzzy.class, :foo, xyzzy, :XYZZY_foo, xyzzy],
|
||||
[:line, 20, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing],
|
||||
[:line, 20, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing],
|
||||
[:c_call, 20, "xyzzy", Kernel, :raise, self, :outer, :nothing],
|
||||
[:c_call, 20, "xyzzy", Exception, :exception, RuntimeError, :outer, :nothing],
|
||||
[:c_call, 20, "xyzzy", Exception, :initialize, raised_exc, :outer, :nothing],
|
||||
[:c_return,20, "xyzzy", Exception, :initialize, raised_exc, :outer, raised_exc],
|
||||
[:c_return,20, "xyzzy", Exception, :exception, RuntimeError, :outer, raised_exc],
|
||||
[:c_call, 20, "xyzzy", Exception, :backtrace, raised_exc, :outer, :nothing],
|
||||
[:c_return,20, "xyzzy", Exception, :backtrace, raised_exc, :outer, nil],
|
||||
[:raise, 20, "xyzzy", TestSetTraceFunc, :trace_by_tracepoint, self, :outer, raised_exc],
|
||||
[:c_return,20, "xyzzy", Kernel, :raise, self, :outer, nil],
|
||||
[:c_call, 20, "xyzzy", Module, :===, RuntimeError,:outer, :nothing],
|
||||
[:c_return,20, "xyzzy", Module, :===, RuntimeError,:outer, true],
|
||||
[:line, 21, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing],
|
||||
[:c_call, 21, "xyzzy", TracePoint, :untrace, trace, :outer, :nothing],
|
||||
]
|
||||
|
||||
return events, answer_events
|
||||
|
@ -499,7 +524,8 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
17: end
|
||||
18: xyzzy = XYZZY.new
|
||||
19: xyzzy.foo
|
||||
20: set_trace_func(nil)
|
||||
20: begin; raise RuntimeError; rescue RuntimeError => raised_exc; end
|
||||
21: set_trace_func(nil)
|
||||
EOF
|
||||
self.class.class_eval{remove_const(:XYZZY)}
|
||||
return events
|
||||
|
@ -507,8 +533,11 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
|
||||
def test_tracepoint
|
||||
events1, answer_events = *trace_by_tracepoint()
|
||||
mesg = events1.map{|e|
|
||||
"#{e[0]} - #{e[2]}:#{e[1]} id: #{e[4]}"
|
||||
}.join("\n")
|
||||
answer_events.zip(events1){|answer, event|
|
||||
assert_equal answer, event
|
||||
assert_equal answer, event, mesg
|
||||
}
|
||||
|
||||
events2 = trace_by_set_trace_func
|
||||
|
@ -561,5 +590,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
assert_raise(RuntimeError){tp_store.klass}
|
||||
assert_raise(RuntimeError){tp_store.binding}
|
||||
assert_raise(RuntimeError){tp_store.self}
|
||||
assert_raise(RuntimeError){tp_store.return_value}
|
||||
assert_raise(RuntimeError){tp_store.raised_exception}
|
||||
end
|
||||
end
|
||||
|
|
2
thread.c
2
thread.c
|
@ -1757,7 +1757,7 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
|
|||
if (status == THREAD_RUNNABLE || status == THREAD_TO_KILL)
|
||||
th->running_time_us += TIME_QUANTUM_USEC;
|
||||
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0, Qundef);
|
||||
|
||||
rb_thread_schedule_limits(limits_us);
|
||||
}
|
||||
|
|
6
vm.c
6
vm.c
|
@ -1181,7 +1181,7 @@ vm_exec(rb_thread_t *th)
|
|||
while (th->cfp->pc == 0 || th->cfp->iseq == 0) {
|
||||
if (UNLIKELY(VM_FRAME_TYPE(th->cfp) == VM_FRAME_MAGIC_CFUNC)) {
|
||||
const rb_method_entry_t *me = th->cfp->me;
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass, Qnil);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(me->klass, me->called_id);
|
||||
}
|
||||
th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
|
||||
|
@ -1355,10 +1355,10 @@ vm_exec(rb_thread_t *th)
|
|||
|
||||
switch (VM_FRAME_TYPE(th->cfp)) {
|
||||
case VM_FRAME_MAGIC_METHOD:
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
case VM_FRAME_MAGIC_CLASS:
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_END, th->cfp->self, 0, 0);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
29
vm_core.h
29
vm_core.h
|
@ -887,13 +887,30 @@ void rb_thread_lock_destroy(rb_thread_lock_t *);
|
|||
} while (0)
|
||||
|
||||
/* tracer */
|
||||
void
|
||||
rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass);
|
||||
typedef struct rb_trace_arg_struct {
|
||||
rb_event_flag_t event;
|
||||
rb_thread_t *th;
|
||||
rb_control_frame_t *cfp;
|
||||
VALUE self;
|
||||
ID id;
|
||||
VALUE klass;
|
||||
VALUE data;
|
||||
} rb_trace_arg_t;
|
||||
|
||||
#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
|
||||
if (UNLIKELY(ruby_vm_event_flags & (flag))) { \
|
||||
if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag)) { \
|
||||
rb_threadptr_exec_event_hooks((th), (flag), (self), (id), (klass)); \
|
||||
void rb_threadptr_exec_event_hooks(rb_trace_arg_t *trace_arg);
|
||||
|
||||
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) do { \
|
||||
if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
|
||||
if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
|
||||
rb_trace_arg_t trace_arg; \
|
||||
trace_arg.event = (flag_); \
|
||||
trace_arg.th = (th_); \
|
||||
trace_arg.cfp = (trace_arg.th)->cfp; \
|
||||
trace_arg.self = (self_); \
|
||||
trace_arg.id = (id_); \
|
||||
trace_arg.klass = (klass_); \
|
||||
trace_arg.data = (data_); \
|
||||
rb_threadptr_exec_event_hooks(&trace_arg); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
|
10
vm_eval.c
10
vm_eval.c
|
@ -56,7 +56,7 @@ vm_call0_cfunc(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv)
|
|||
VALUE val;
|
||||
|
||||
RUBY_DTRACE_FUNC_ENTRY_HOOK(ci->defined_class, ci->mid);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, ci->recv, ci->mid, ci->defined_class);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, ci->recv, ci->mid, ci->defined_class, Qnil);
|
||||
{
|
||||
rb_control_frame_t *reg_cfp = th->cfp;
|
||||
const rb_method_entry_t *me = ci->me;
|
||||
|
@ -84,7 +84,7 @@ vm_call0_cfunc(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv)
|
|||
vm_pop_frame(th);
|
||||
}
|
||||
}
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, ci->recv, ci->mid, ci->defined_class);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, ci->recv, ci->mid, ci->defined_class, val);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(ci->defined_class, ci->mid);
|
||||
|
||||
return val;
|
||||
|
@ -104,7 +104,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv
|
|||
rb_block_t *blockptr = ci->blockptr;
|
||||
|
||||
RUBY_DTRACE_FUNC_ENTRY_HOOK(defined_class, mid);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, mid, defined_class);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, mid, defined_class, Qnil);
|
||||
{
|
||||
rb_control_frame_t *reg_cfp = th->cfp;
|
||||
|
||||
|
@ -122,7 +122,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv
|
|||
VM_PROFILE_UP(3);
|
||||
vm_pop_frame(th);
|
||||
}
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, mid, defined_class);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, mid, defined_class, val);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(defined_class, mid);
|
||||
|
||||
return val;
|
||||
|
@ -1014,7 +1014,7 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
|
|||
#endif
|
||||
if (UNLIKELY(VM_FRAME_TYPE(th->cfp) == VM_FRAME_MAGIC_CFUNC)) {
|
||||
const rb_method_entry_t *me = th->cfp->me;
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass, Qnil);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(me->klass, me->called_id);
|
||||
}
|
||||
|
||||
|
|
|
@ -1450,7 +1450,7 @@ vm_call_cfunc_with_frame(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_i
|
|||
int argc = ci->argc;
|
||||
|
||||
RUBY_DTRACE_FUNC_ENTRY_HOOK(me->klass, me->called_id);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->klass, Qundef);
|
||||
|
||||
vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, defined_class,
|
||||
VM_ENVVAL_BLOCK_PTR(blockptr), 0, th->cfp->sp, 1, me);
|
||||
|
@ -1467,7 +1467,7 @@ vm_call_cfunc_with_frame(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_i
|
|||
|
||||
vm_pop_frame(th);
|
||||
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->klass, val);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(me->klass, me->called_id);
|
||||
|
||||
return val;
|
||||
|
@ -1517,7 +1517,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci)
|
|||
if (len >= 0) rb_check_arity(ci->argc, len, len);
|
||||
|
||||
RUBY_DTRACE_FUNC_ENTRY_HOOK(me->klass, me->called_id);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->called_id, me->klass, Qnil);
|
||||
|
||||
if (!(ci->me->flag & NOEX_PROTECTED) &&
|
||||
!(ci->flag & VM_CALL_ARGS_SPLAT)) {
|
||||
|
@ -1525,7 +1525,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci)
|
|||
}
|
||||
val = vm_call_cfunc_latter(th, reg_cfp, ci);
|
||||
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->klass, val);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(me->klass, me->called_id);
|
||||
|
||||
return val;
|
||||
|
@ -1576,14 +1576,14 @@ vm_call_bmethod_body(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
|
|||
VALUE val;
|
||||
|
||||
RUBY_DTRACE_FUNC_ENTRY_HOOK(ci->me->klass, ci->me->called_id);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, ci->recv, ci->me->called_id, ci->me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, ci->recv, ci->me->called_id, ci->me->klass, Qnil);
|
||||
|
||||
/* control block frame */
|
||||
th->passed_me = ci->me;
|
||||
GetProcPtr(ci->me->def->body.proc, proc);
|
||||
val = vm_invoke_proc(th, proc, ci->recv, ci->defined_class, ci->argc, argv, ci->blockptr);
|
||||
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, ci->recv, ci->me->called_id, ci->me->klass);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, ci->recv, ci->me->called_id, ci->me->klass, val);
|
||||
RUBY_DTRACE_FUNC_RETURN_HOOK(ci->me->klass, ci->me->called_id);
|
||||
|
||||
return val;
|
||||
|
|
69
vm_trace.c
69
vm_trace.c
|
@ -44,15 +44,6 @@ typedef struct rb_event_hook_struct {
|
|||
struct rb_event_hook_struct *next;
|
||||
} rb_event_hook_t;
|
||||
|
||||
typedef struct rb_trace_arg_struct {
|
||||
rb_event_flag_t event;
|
||||
rb_thread_t *th;
|
||||
rb_control_frame_t *cfp;
|
||||
VALUE self;
|
||||
ID id;
|
||||
VALUE klass;
|
||||
} rb_trace_arg_t;
|
||||
|
||||
typedef void (*rb_event_hook_raw_arg_func_t)(VALUE data, const rb_trace_arg_t *arg);
|
||||
|
||||
#define MAX_EVENT_NUM 32
|
||||
|
@ -306,10 +297,11 @@ exec_hooks(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_ar
|
|||
}
|
||||
|
||||
void
|
||||
rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t event, VALUE self, ID id, VALUE klass)
|
||||
rb_threadptr_exec_event_hooks(rb_trace_arg_t *targ)
|
||||
{
|
||||
rb_thread_t *th = targ->th;
|
||||
if (th->trace_running == 0 &&
|
||||
self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) {
|
||||
targ->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) {
|
||||
const int vm_tracing = th->vm->trace_running;
|
||||
int state = 0;
|
||||
int outer_state = th->state;
|
||||
|
@ -320,26 +312,18 @@ rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t event, VALUE self
|
|||
{
|
||||
const VALUE errinfo = th->errinfo;
|
||||
rb_hook_list_t *list;
|
||||
rb_trace_arg_t ta;
|
||||
|
||||
ta.event = event;
|
||||
ta.th = th;
|
||||
ta.cfp = th->cfp;
|
||||
ta.self = self;
|
||||
ta.id = id;
|
||||
ta.klass = klass;
|
||||
|
||||
/* thread local traces */
|
||||
list = &th->event_hooks;
|
||||
if (list->events & event) {
|
||||
state = exec_hooks(th, list, &ta, TRUE);
|
||||
if (list->events & targ->event) {
|
||||
state = exec_hooks(th, list, targ, TRUE);
|
||||
if (state) goto terminate;
|
||||
}
|
||||
|
||||
/* vm global traces */
|
||||
list = &th->vm->event_hooks;
|
||||
if (list->events & event) {
|
||||
state = exec_hooks(th, list, &ta, !vm_tracing);
|
||||
if (list->events & targ->event) {
|
||||
state = exec_hooks(th, list, targ, !vm_tracing);
|
||||
if (state) goto terminate;
|
||||
}
|
||||
th->errinfo = errinfo;
|
||||
|
@ -774,6 +758,43 @@ tp_attr_self_m(VALUE tpval)
|
|||
return tp->trace_arg->self;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
tp_attr_return_value_m(VALUE tpval)
|
||||
{
|
||||
rb_tp_t *tp = tpptr(tpval);
|
||||
tp_attr_check_active(tp);
|
||||
|
||||
if (tp->trace_arg->data == Qundef) {
|
||||
rb_bug("tp_attr_return_value_m: unreachable");
|
||||
}
|
||||
if (tp->trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN)) {
|
||||
/* ok */
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eRuntimeError, "not supported by this event");
|
||||
}
|
||||
return tp->trace_arg->data;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
tp_attr_raised_exception_m(VALUE tpval)
|
||||
{
|
||||
rb_tp_t *tp = tpptr(tpval);
|
||||
tp_attr_check_active(tp);
|
||||
|
||||
if (tp->trace_arg->data == Qundef) {
|
||||
rb_bug("tp_attr_raised_exception_m: unreachable");
|
||||
}
|
||||
if (tp->trace_arg->event & (RUBY_EVENT_RAISE)) {
|
||||
/* ok */
|
||||
}
|
||||
else {
|
||||
rb_raise(rb_eRuntimeError, "not supported by this event");
|
||||
}
|
||||
return tp->trace_arg->data;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
tp_call_trace(VALUE tpval, rb_trace_arg_t *trace_arg)
|
||||
{
|
||||
|
@ -902,4 +923,6 @@ Init_vm_trace(void)
|
|||
rb_define_method(rb_cTracePoint, "klass", tp_attr_klass_m, 0);
|
||||
rb_define_method(rb_cTracePoint, "binding", tp_attr_binding_m, 0);
|
||||
rb_define_method(rb_cTracePoint, "self", tp_attr_self_m, 0);
|
||||
rb_define_method(rb_cTracePoint, "return_value", tp_attr_return_value_m, 0);
|
||||
rb_define_method(rb_cTracePoint, "raised_exception", tp_attr_raised_exception_m, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue