diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-01 17:47:37 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-01 17:47:37 +0000 |
commit | 921385a6443338d6150e71acf0806108294c1c9a (patch) | |
tree | 8cb20b840cf75f6cbd8236de595efa7315924878 /vm_trace.c | |
parent | e78cf44a99b37c8f0f53844b0c0acbd073067bae (diff) | |
download | ruby-921385a6443338d6150e71acf0806108294c1c9a.tar.gz |
* 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
Diffstat (limited to 'vm_trace.c')
-rw-r--r-- | vm_trace.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vm_trace.c b/vm_trace.c index e2919ff79e..bedf41a9b6 100644 --- a/vm_trace.c +++ b/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); |