ruby-changes:25918
From: ko1 <ko1@a...>
Date: Thu, 29 Nov 2012 15:43:44 +0900 (JST)
Subject: [ruby-changes:25918] ko1:r37975 (trunk): * include/ruby/debug.h: provide rb_tracearg_*() APIs,
ko1 2012-11-29 15:43:31 +0900 (Thu, 29 Nov 2012) New Revision: 37975 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37975 Log: * include/ruby/debug.h: provide rb_tracearg_*() APIs, instead of rb_tracepoint_attr_*(). These APIs are for debuggers/profilers. They will be explained in another docs somtime. * vm_trace.c: ditto. Modified files: trunk/ChangeLog trunk/include/ruby/debug.h trunk/vm_trace.c Index: include/ruby/debug.h =================================================================== --- include/ruby/debug.h (revision 37974) +++ include/ruby/debug.h (revision 37975) @@ -26,13 +26,8 @@ /* Note: This file contains experimental APIs. */ /* APIs can be replaced at Ruby 2.0.1 or later */ -typedef enum { - RUBY_EVENT_HOOK_FLAG_SAFE = 0x01, - RUBY_EVENT_HOOK_FLAG_DELETED = 0x02, - RUBY_EVENT_HOOK_FLAG_RAW_ARG = 0x04 -} rb_event_hook_flag_t; +/* Old style set_trace_func APIs */ -/* Safe API. Callback will be called under PUSH_TAG() */ void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data); int rb_remove_event_hook(rb_event_hook_func_t func); int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data); @@ -40,10 +35,6 @@ int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func); int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data); -/* advanced version */ -void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag); -void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag); - /* TracePoint APIs */ VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data); @@ -51,16 +42,30 @@ VALUE rb_tracepoint_disable(VALUE tpval); VALUE rb_tracepoint_enabled_p(VALUE tpval); -VALUE rb_tracepoint_attr_event(VALUE tpval); -VALUE rb_tracepoint_attr_lineno(VALUE tpval); -VALUE rb_tracepoint_attr_path(VALUE tpval); -VALUE rb_tracepoint_attr_method_id(VALUE tpval); -VALUE rb_tracepoint_attr_defined_class(VALUE tpval); -VALUE rb_tracepoint_attr_binding(VALUE tpval); -VALUE rb_tracepoint_attr_self(VALUE tpval); -VALUE rb_tracepoint_attr_return_value(VALUE tpval); -VALUE rb_tracepoint_attr_raised_exception(VALUE tpval); +struct rb_trace_arg_struct; +struct rb_trace_arg_struct *rb_tracearg_from_tracepoint(VALUE tpval); +VALUE rb_tracearg_event(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_lineno(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_path(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_method_id(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_defined_class(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_binding(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_self(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_return_value(struct rb_trace_arg_struct *trace_arg); +VALUE rb_tracearg_raised_exception(struct rb_trace_arg_struct *trace_arg); + +/* undocumented advanced APIs */ + +typedef enum { + RUBY_EVENT_HOOK_FLAG_SAFE = 0x01, + RUBY_EVENT_HOOK_FLAG_DELETED = 0x02, + RUBY_EVENT_HOOK_FLAG_RAW_ARG = 0x04 +} rb_event_hook_flag_t; + +void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag); +void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag); + #if defined __GNUC__ && __GNUC__ >= 4 #pragma GCC visibility pop #endif Index: ChangeLog =================================================================== --- ChangeLog (revision 37974) +++ ChangeLog (revision 37975) @@ -1,3 +1,12 @@ +Thu Nov 29 15:38:14 2012 Koichi Sasada <ko1@a...> + + * include/ruby/debug.h: provide rb_tracearg_*() APIs, + instead of rb_tracepoint_attr_*(). + These APIs are for debuggers/profilers. + They will be explained in another docs somtime. + + * vm_trace.c: ditto. + Thu Nov 29 15:10:45 2012 NARUSE, Yui <naruse@r...> * test/minitest/test_minitest_unit.rb: restore orig_verbose only Index: vm_trace.c =================================================================== --- vm_trace.c (revision 37974) +++ vm_trace.c (revision 37975) @@ -630,14 +630,20 @@ } } -VALUE -rb_tracepoint_attr_event(VALUE tpval) +struct rb_trace_arg_struct * +rb_tracearg_from_tracepoint(VALUE tpval) { rb_tp_t *tp = tpptr(tpval); tp_attr_check_active(tp); - return ID2SYM(get_event_id(tp->trace_arg->event)); + return tp->trace_arg; } +VALUE +rb_tracearg_event(rb_trace_arg_t *trace_arg) +{ + return ID2SYM(get_event_id(trace_arg->event)); +} + rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, rb_control_frame_t *cfp); int rb_vm_control_frame_id_and_class(rb_control_frame_t *cfp, ID *idp, VALUE *klassp); VALUE rb_binding_new_with_cfp(rb_thread_t *th, rb_control_frame_t *src_cfp); @@ -660,21 +666,16 @@ } VALUE -rb_tracepoint_attr_lineno(VALUE tpval) +rb_tracearg_lineno(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - fill_path_and_lineno(tp->trace_arg); - return INT2FIX(tp->trace_arg->lineno); + fill_path_and_lineno(trace_arg); + return INT2FIX(trace_arg->lineno); } - VALUE -rb_tracepoint_attr_path(VALUE tpval) +rb_tracearg_path(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - fill_path_and_lineno(tp->trace_arg); - return tp->trace_arg->path; + fill_path_and_lineno(trace_arg); + return trace_arg->path; } static void @@ -702,33 +703,26 @@ } VALUE -rb_tracepoint_attr_method_id(VALUE tpval) +rb_tracearg_method_id(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - fill_id_and_klass(tp->trace_arg); - return tp->trace_arg->id ? ID2SYM(tp->trace_arg->id) : Qnil; + fill_id_and_klass(trace_arg); + return trace_arg->id ? ID2SYM(trace_arg->id) : Qnil; } VALUE -rb_tracepoint_attr_defined_class(VALUE tpval) +rb_tracearg_defined_class(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - fill_id_and_klass(tp->trace_arg); - return tp->trace_arg->klass; + fill_id_and_klass(trace_arg); + return trace_arg->klass; } VALUE -rb_tracepoint_attr_binding(VALUE tpval) +rb_tracearg_binding(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); rb_control_frame_t *cfp; - tp_attr_check_active(tp); - - cfp = rb_vm_get_ruby_level_next_cfp(tp->trace_arg->th, tp->trace_arg->cfp); + cfp = rb_vm_get_ruby_level_next_cfp(trace_arg->th, trace_arg->cfp); if (cfp) { - return rb_binding_new_with_cfp(tp->trace_arg->th, cfp); + return rb_binding_new_with_cfp(trace_arg->th, cfp); } else { return Qnil; @@ -736,50 +730,113 @@ } VALUE -rb_tracepoint_attr_self(VALUE tpval) +rb_tracearg_self(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - - return tp->trace_arg->self; + return trace_arg->self; } VALUE -rb_tracepoint_attr_return_value(VALUE tpval) +rb_tracearg_return_value(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - - if (tp->trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN)) { + if (trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN)) { /* ok */ } else { rb_raise(rb_eRuntimeError, "not supported by this event"); } - if (tp->trace_arg->data == Qundef) { + if (trace_arg->data == Qundef) { rb_bug("tp_attr_return_value_m: unreachable"); } - return tp->trace_arg->data; + return trace_arg->data; } VALUE -rb_tracepoint_attr_raised_exception(VALUE tpval) +rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg) { - rb_tp_t *tp = tpptr(tpval); - tp_attr_check_active(tp); - - if (tp->trace_arg->event & (RUBY_EVENT_RAISE)) { + if (trace_arg->event & (RUBY_EVENT_RAISE)) { /* ok */ } else { rb_raise(rb_eRuntimeError, "not supported by this event"); } - if (tp->trace_arg->data == Qundef) { + if (trace_arg->data == Qundef) { rb_bug("tp_attr_raised_exception_m: unreachable"); } - return tp->trace_arg->data; + return trace_arg->data; } +static VALUE +tracepoint_attr_event(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_event(tp->trace_arg); +} + +static VALUE +tracepoint_attr_lineno(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_lineno(tp->trace_arg); +} + +static VALUE +tracepoint_attr_path(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_path(tp->trace_arg); +} + +static VALUE +tracepoint_attr_method_id(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_method_id(tp->trace_arg); +} + +static VALUE +tracepoint_attr_defined_class(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_defined_class(tp->trace_arg); +} + +static VALUE +tracepoint_attr_binding(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_binding(tp->trace_arg); +} + +static VALUE +tracepoint_attr_self(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_self(tp->trace_arg); +} + +static VALUE +tracepoint_attr_return_value(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_return_value(tp->trace_arg); +} + +static VALUE +tracepoint_attr_raised_exception(VALUE tpval) +{ + rb_tp_t *tp = tpptr(tpval); + tp_attr_check_active(tp); + return rb_tracearg_raised_exception(tp->trace_arg); +} + static void tp_call_trace(VALUE tpval, rb_trace_arg_t *trace_arg) { @@ -813,10 +870,12 @@ rb_tp_t *tp = tpptr(tpval); if (tp->target_th) { - rb_thread_add_event_hook2(tp->target_th->self, (rb_event_hook_func_t)tp_call_trace, tp->events, tpval, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); + rb_thread_add_event_hook2(tp->target_th->self, (rb_event_hook_func_t)tp_call_trace, tp->events, tpval, + RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); } else { - rb_add_event_hook2((rb_event_hook_func_t)tp_call_trace, tp->events, tpval, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); + rb_add_event_hook2((rb_event_hook_func_t)tp_call_trace, tp->events, tpval, + RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG); } tp->tracing = 1; return Qundef; @@ -956,13 +1015,14 @@ 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, "event", rb_tracepoint_attr_event, 0); - rb_define_method(rb_cTracePoint, "lineno", rb_tracepoint_attr_lineno, 0); - rb_define_method(rb_cTracePoint, "path", rb_tracepoint_attr_path, 0); - rb_define_method(rb_cTracePoint, "method_id", rb_tracepoint_attr_method_id, 0); - rb_define_method(rb_cTracePoint, "defined_class", rb_tracepoint_attr_defined_class, 0); - rb_define_method(rb_cTracePoint, "binding", rb_tracepoint_attr_binding, 0); - rb_define_method(rb_cTracePoint, "self", rb_tracepoint_attr_self, 0); - rb_define_method(rb_cTracePoint, "return_value", rb_tracepoint_attr_return_value, 0); - rb_define_method(rb_cTracePoint, "raised_exception", rb_tracepoint_attr_raised_exception, 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); + rb_define_method(rb_cTracePoint, "method_id", tracepoint_attr_method_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); + rb_define_method(rb_cTracePoint, "return_value", tracepoint_attr_return_value, 0); + rb_define_method(rb_cTracePoint, "raised_exception", tracepoint_attr_raised_exception, 0); } + -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/