зеркало из https://github.com/github/ruby.git
* vm_trace.c: add TracePoint#inspect.
* test/ruby/test_settracefunc.rb: add a test for this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e78cf44a99
Коммит
921385a644
|
@ -1,3 +1,9 @@
|
|||
Sun Dec 2 02:46:04 2012 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_trace.c: add TracePoint#inspect.
|
||||
|
||||
* test/ruby/test_settracefunc.rb: add a test for this change.
|
||||
|
||||
Sat Dec 1 21:18:19 2012 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* test/ruby/test_backtrace.rb: add a test for
|
||||
|
|
|
@ -746,4 +746,29 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
assert_equal([created_thread, :thread_end, 0, nil, nil, nil, Thread], events[1])
|
||||
assert_equal(2, events.size)
|
||||
end
|
||||
|
||||
def test_tracepoint_inspect
|
||||
events = []
|
||||
trace = TracePoint.new{|tp| events << [tp.event, tp.inspect]}
|
||||
assert_equal("#<TracePoint:disabled>", trace.inspect)
|
||||
trace.enable{
|
||||
assert_equal("#<TracePoint:enabled>", trace.inspect)
|
||||
Thread.new{}.join
|
||||
}
|
||||
assert_equal("#<TracePoint:disabled>", trace.inspect)
|
||||
events.each{|(ev, str)|
|
||||
case ev
|
||||
when :line
|
||||
assert_match(/ in /, str)
|
||||
when :call, :c_call
|
||||
assert_match(/call \`/, str) # #<TracePoint:c_call `inherited'@../trunk/test.rb:11>
|
||||
when :return, :c_return
|
||||
assert_match(/return \`/, str) # #<TracePoint:return `m'@../trunk/test.rb:3>
|
||||
when /thread/
|
||||
assert_match(/\#<Thread:/, str) # #<TracePoint:thread_end of #<Thread:0x87076c0>>
|
||||
else
|
||||
assert_match(/\#<TracePoint:/, str)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
56
vm_trace.c
56
vm_trace.c
|
@ -1169,6 +1169,60 @@ tracepoint_trace_s(int argc, VALUE *argv, VALUE self)
|
|||
return trace;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* trace.inspect -> string
|
||||
*
|
||||
* Return a string containing a human-readable TracePoint
|
||||
* status.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
tracepoint_inspect(VALUE self)
|
||||
{
|
||||
rb_tp_t *tp = tpptr(self);
|
||||
|
||||
if (tp->trace_arg) {
|
||||
switch (tp->trace_arg->event) {
|
||||
case RUBY_EVENT_LINE:
|
||||
case RUBY_EVENT_SPECIFIED_LINE:
|
||||
{
|
||||
VALUE sym = rb_tracearg_method_id(tp->trace_arg);
|
||||
if (NIL_P(sym))
|
||||
goto default_inspect;
|
||||
return rb_sprintf("#<TracePoint:%"PRIsVALUE"@%"PRIsVALUE":%d in `%"PRIsVALUE"'>",
|
||||
rb_tracearg_event(tp->trace_arg),
|
||||
rb_tracearg_path(tp->trace_arg),
|
||||
FIX2INT(rb_tracearg_lineno(tp->trace_arg)),
|
||||
sym);
|
||||
}
|
||||
case RUBY_EVENT_CALL:
|
||||
case RUBY_EVENT_C_CALL:
|
||||
case RUBY_EVENT_RETURN:
|
||||
case RUBY_EVENT_C_RETURN:
|
||||
return rb_sprintf("#<TracePoint:%"PRIsVALUE" `%"PRIsVALUE"'@%"PRIsVALUE":%d>",
|
||||
rb_tracearg_event(tp->trace_arg),
|
||||
rb_tracearg_method_id(tp->trace_arg),
|
||||
rb_tracearg_path(tp->trace_arg),
|
||||
FIX2INT(rb_tracearg_lineno(tp->trace_arg)));
|
||||
case RUBY_EVENT_THREAD_BEGIN:
|
||||
case RUBY_EVENT_THREAD_END:
|
||||
return rb_sprintf("#<TracePoint:%"PRIsVALUE" %"PRIsVALUE">",
|
||||
rb_tracearg_event(tp->trace_arg),
|
||||
rb_tracearg_self(tp->trace_arg));
|
||||
default:
|
||||
default_inspect:
|
||||
return rb_sprintf("#<TracePoint:%"PRIsVALUE"@%"PRIsVALUE":%d>",
|
||||
rb_tracearg_event(tp->trace_arg),
|
||||
rb_tracearg_path(tp->trace_arg),
|
||||
FIX2INT(rb_tracearg_lineno(tp->trace_arg)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return rb_sprintf("#<TracePoint:%s>", tp->tracing ? "enabled" : "disabled");
|
||||
}
|
||||
}
|
||||
|
||||
/* This function is called from inits.c */
|
||||
void
|
||||
Init_vm_trace(void)
|
||||
|
@ -1226,6 +1280,8 @@ Init_vm_trace(void)
|
|||
rb_define_method(rb_cTracePoint, "disable", tracepoint_disable_m, 0);
|
||||
rb_define_method(rb_cTracePoint, "enabled?", rb_tracepoint_enabled_p, 0);
|
||||
|
||||
rb_define_method(rb_cTracePoint, "inspect", tracepoint_inspect, 0);
|
||||
|
||||
rb_define_method(rb_cTracePoint, "event", tracepoint_attr_event, 0);
|
||||
rb_define_method(rb_cTracePoint, "lineno", tracepoint_attr_lineno, 0);
|
||||
rb_define_method(rb_cTracePoint, "path", tracepoint_attr_path, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче