mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d81b5a4ffb
commit
3f606b7063
3 changed files with 153 additions and 79 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
Thu Nov 29 15:38:14 2012 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Thu Nov 29 15:10:45 2012 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* test/minitest/test_minitest_unit.rb: restore orig_verbose only
|
* test/minitest/test_minitest_unit.rb: restore orig_verbose only
|
||||||
|
|
|
@ -26,13 +26,8 @@ extern "C" {
|
||||||
/* Note: This file contains experimental APIs. */
|
/* Note: This file contains experimental APIs. */
|
||||||
/* APIs can be replaced at Ruby 2.0.1 or later */
|
/* APIs can be replaced at Ruby 2.0.1 or later */
|
||||||
|
|
||||||
typedef enum {
|
/* Old style set_trace_func APIs */
|
||||||
RUBY_EVENT_HOOK_FLAG_SAFE = 0x01,
|
|
||||||
RUBY_EVENT_HOOK_FLAG_DELETED = 0x02,
|
|
||||||
RUBY_EVENT_HOOK_FLAG_RAW_ARG = 0x04
|
|
||||||
} rb_event_hook_flag_t;
|
|
||||||
|
|
||||||
/* 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);
|
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(rb_event_hook_func_t func);
|
||||||
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data);
|
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data);
|
||||||
|
@ -40,10 +35,6 @@ void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_f
|
||||||
int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func);
|
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);
|
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 */
|
/* TracePoint APIs */
|
||||||
|
|
||||||
VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data);
|
VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data);
|
||||||
|
@ -51,15 +42,29 @@ VALUE rb_tracepoint_enable(VALUE tpval);
|
||||||
VALUE rb_tracepoint_disable(VALUE tpval);
|
VALUE rb_tracepoint_disable(VALUE tpval);
|
||||||
VALUE rb_tracepoint_enabled_p(VALUE tpval);
|
VALUE rb_tracepoint_enabled_p(VALUE tpval);
|
||||||
|
|
||||||
VALUE rb_tracepoint_attr_event(VALUE tpval);
|
struct rb_trace_arg_struct;
|
||||||
VALUE rb_tracepoint_attr_lineno(VALUE tpval);
|
struct rb_trace_arg_struct *rb_tracearg_from_tracepoint(VALUE tpval);
|
||||||
VALUE rb_tracepoint_attr_path(VALUE tpval);
|
|
||||||
VALUE rb_tracepoint_attr_method_id(VALUE tpval);
|
VALUE rb_tracearg_event(struct rb_trace_arg_struct *trace_arg);
|
||||||
VALUE rb_tracepoint_attr_defined_class(VALUE tpval);
|
VALUE rb_tracearg_lineno(struct rb_trace_arg_struct *trace_arg);
|
||||||
VALUE rb_tracepoint_attr_binding(VALUE tpval);
|
VALUE rb_tracearg_path(struct rb_trace_arg_struct *trace_arg);
|
||||||
VALUE rb_tracepoint_attr_self(VALUE tpval);
|
VALUE rb_tracearg_method_id(struct rb_trace_arg_struct *trace_arg);
|
||||||
VALUE rb_tracepoint_attr_return_value(VALUE tpval);
|
VALUE rb_tracearg_defined_class(struct rb_trace_arg_struct *trace_arg);
|
||||||
VALUE rb_tracepoint_attr_raised_exception(VALUE tpval);
|
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
|
#if defined __GNUC__ && __GNUC__ >= 4
|
||||||
#pragma GCC visibility pop
|
#pragma GCC visibility pop
|
||||||
|
|
180
vm_trace.c
180
vm_trace.c
|
@ -630,12 +630,18 @@ tp_attr_check_active(rb_tp_t *tp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
struct rb_trace_arg_struct *
|
||||||
rb_tracepoint_attr_event(VALUE tpval)
|
rb_tracearg_from_tracepoint(VALUE tpval)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
rb_tp_t *tp = tpptr(tpval);
|
||||||
tp_attr_check_active(tp);
|
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);
|
rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
|
||||||
|
@ -660,21 +666,16 @@ fill_path_and_lineno(rb_trace_arg_t *trace_arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_lineno(VALUE tpval)
|
rb_tracearg_lineno(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
fill_path_and_lineno(trace_arg);
|
||||||
tp_attr_check_active(tp);
|
return INT2FIX(trace_arg->lineno);
|
||||||
fill_path_and_lineno(tp->trace_arg);
|
|
||||||
return INT2FIX(tp->trace_arg->lineno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_path(VALUE tpval)
|
rb_tracearg_path(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
fill_path_and_lineno(trace_arg);
|
||||||
tp_attr_check_active(tp);
|
return trace_arg->path;
|
||||||
fill_path_and_lineno(tp->trace_arg);
|
|
||||||
return tp->trace_arg->path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -702,33 +703,26 @@ fill_id_and_klass(rb_trace_arg_t *trace_arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_method_id(VALUE tpval)
|
rb_tracearg_method_id(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
fill_id_and_klass(trace_arg);
|
||||||
tp_attr_check_active(tp);
|
return trace_arg->id ? ID2SYM(trace_arg->id) : Qnil;
|
||||||
fill_id_and_klass(tp->trace_arg);
|
|
||||||
return tp->trace_arg->id ? ID2SYM(tp->trace_arg->id) : Qnil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_defined_class(VALUE tpval)
|
rb_tracearg_defined_class(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
fill_id_and_klass(trace_arg);
|
||||||
tp_attr_check_active(tp);
|
return trace_arg->klass;
|
||||||
fill_id_and_klass(tp->trace_arg);
|
|
||||||
return tp->trace_arg->klass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
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;
|
rb_control_frame_t *cfp;
|
||||||
tp_attr_check_active(tp);
|
cfp = rb_vm_get_ruby_level_next_cfp(trace_arg->th, trace_arg->cfp);
|
||||||
|
|
||||||
cfp = rb_vm_get_ruby_level_next_cfp(tp->trace_arg->th, tp->trace_arg->cfp);
|
|
||||||
if (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 {
|
else {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
@ -736,48 +730,111 @@ rb_tracepoint_attr_binding(VALUE tpval)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_self(VALUE tpval)
|
rb_tracearg_self(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
return trace_arg->self;
|
||||||
tp_attr_check_active(tp);
|
|
||||||
|
|
||||||
return tp->trace_arg->self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_return_value(VALUE tpval)
|
rb_tracearg_return_value(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
if (trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN)) {
|
||||||
tp_attr_check_active(tp);
|
|
||||||
|
|
||||||
if (tp->trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN)) {
|
|
||||||
/* ok */
|
/* ok */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_raise(rb_eRuntimeError, "not supported by this event");
|
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");
|
rb_bug("tp_attr_return_value_m: unreachable");
|
||||||
}
|
}
|
||||||
return tp->trace_arg->data;
|
return trace_arg->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_tracepoint_attr_raised_exception(VALUE tpval)
|
rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg)
|
||||||
{
|
{
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
if (trace_arg->event & (RUBY_EVENT_RAISE)) {
|
||||||
tp_attr_check_active(tp);
|
|
||||||
|
|
||||||
if (tp->trace_arg->event & (RUBY_EVENT_RAISE)) {
|
|
||||||
/* ok */
|
/* ok */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_raise(rb_eRuntimeError, "not supported by this event");
|
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");
|
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
|
static void
|
||||||
|
@ -813,10 +870,12 @@ rb_tracepoint_enable(VALUE tpval)
|
||||||
rb_tp_t *tp = tpptr(tpval);
|
rb_tp_t *tp = tpptr(tpval);
|
||||||
|
|
||||||
if (tp->target_th) {
|
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 {
|
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;
|
tp->tracing = 1;
|
||||||
return Qundef;
|
return Qundef;
|
||||||
|
@ -956,13 +1015,14 @@ Init_vm_trace(void)
|
||||||
rb_define_method(rb_cTracePoint, "disable", tracepoint_disable_m, 0);
|
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, "enabled?", rb_tracepoint_enabled_p, 0);
|
||||||
|
|
||||||
rb_define_method(rb_cTracePoint, "event", rb_tracepoint_attr_event, 0);
|
rb_define_method(rb_cTracePoint, "event", tracepoint_attr_event, 0);
|
||||||
rb_define_method(rb_cTracePoint, "lineno", rb_tracepoint_attr_lineno, 0);
|
rb_define_method(rb_cTracePoint, "lineno", tracepoint_attr_lineno, 0);
|
||||||
rb_define_method(rb_cTracePoint, "path", rb_tracepoint_attr_path, 0);
|
rb_define_method(rb_cTracePoint, "path", tracepoint_attr_path, 0);
|
||||||
rb_define_method(rb_cTracePoint, "method_id", rb_tracepoint_attr_method_id, 0);
|
rb_define_method(rb_cTracePoint, "method_id", tracepoint_attr_method_id, 0);
|
||||||
rb_define_method(rb_cTracePoint, "defined_class", rb_tracepoint_attr_defined_class, 0);
|
rb_define_method(rb_cTracePoint, "defined_class", tracepoint_attr_defined_class, 0);
|
||||||
rb_define_method(rb_cTracePoint, "binding", rb_tracepoint_attr_binding, 0);
|
rb_define_method(rb_cTracePoint, "binding", tracepoint_attr_binding, 0);
|
||||||
rb_define_method(rb_cTracePoint, "self", rb_tracepoint_attr_self, 0);
|
rb_define_method(rb_cTracePoint, "self", tracepoint_attr_self, 0);
|
||||||
rb_define_method(rb_cTracePoint, "return_value", rb_tracepoint_attr_return_value, 0);
|
rb_define_method(rb_cTracePoint, "return_value", tracepoint_attr_return_value, 0);
|
||||||
rb_define_method(rb_cTracePoint, "raised_exception", rb_tracepoint_attr_raised_exception, 0);
|
rb_define_method(rb_cTracePoint, "raised_exception", tracepoint_attr_raised_exception, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue