summaryrefslogtreecommitdiff
path: root/vm_trace.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-27 00:21:02 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-27 00:21:02 +0000
commit680f0b5ba4eb4ba4f542ebc8d1204da61b71eb92 (patch)
tree8b49f2f3f6fe57d5d5738402089c792ef4368bc2 /vm_trace.c
parentdc7522f835937152cd3f7a410886d6f8ed8a7ea0 (diff)
* include/ruby/ruby.h, gc.c, vm_trace.c: add internal events.
* RUBY_INTERNAL_EVENT_NEWOBJ: object created. * RUBY_INTERNAL_EVENT_FREE: object freeed. * RUBY_INTERNAL_EVENT_GC_START: GC started. And rename `RUBY_EVENT_SWITCH' to `RUBY_INTERNAL_EVENT_SWITCH'. Internal events can not invoke any Ruby program because the tracing timing may be critical (under huge restriction). These events can be hooked only by C-extensions. We recommend to use rb_potponed_job_register() API to call Ruby program safely. This change is mostly written by Aman Gupta (tmm1). https://bugs.ruby-lang.org/issues/8107#note-12 [Feature #8107] * include/ruby/debug.h, vm_trace.c: added two new APIs. * rb_tracearg_event_flag() returns rb_event_flag_t of this event. * rb_tracearg_object() returns created/freeed object. * ext/-test-/tracepoint/extconf.rb, ext/-test-/tracepoint/tracepoint.c, test/-ext-/tracepoint/test_tracepoint.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_trace.c')
-rw-r--r--vm_trace.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/vm_trace.c b/vm_trace.c
index 0c54426..9c77153 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -72,6 +72,8 @@ recalc_add_ruby_vm_event_flags(rb_event_flag_t events)
}
ruby_vm_event_flags |= ruby_event_flag_count[i] ? (1<<i) : 0;
}
+
+ rb_objspace_set_event_hook(ruby_vm_event_flags);
}
static void
@@ -86,6 +88,8 @@ recalc_remove_ruby_vm_event_flags(rb_event_flag_t events)
}
ruby_vm_event_flags |= ruby_event_flag_count[i] ? (1<<i) : 0;
}
+
+ rb_objspace_set_event_hook(ruby_vm_event_flags);
}
/* add/remove hooks */
@@ -260,7 +264,7 @@ exec_hooks(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_ar
rb_event_hook_t *hook;
for (hook = list->hooks; hook; hook = hook->next) {
- if (LIKELY(!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED)) && (trace_arg->event & hook->events)) {
+ if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) && (trace_arg->event & hook->events)) {
if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_RAW_ARG)) {
(*hook->func)(trace_arg->event, hook->data, trace_arg->self, trace_arg->id, trace_arg->klass);
}
@@ -692,6 +696,12 @@ rb_tracearg_from_tracepoint(VALUE tpval)
return get_trace_arg();
}
+rb_event_flag_t
+rb_tracearg_event_flag(rb_trace_arg_t *trace_arg)
+{
+ return trace_arg->event;
+}
+
VALUE
rb_tracearg_event(rb_trace_arg_t *trace_arg)
{
@@ -813,6 +823,21 @@ rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg)
return trace_arg->data;
}
+VALUE
+rb_tracearg_object(rb_trace_arg_t *trace_arg)
+{
+ if (trace_arg->event & (RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREE)) {
+ /* ok */
+ }
+ else {
+ rb_raise(rb_eRuntimeError, "not supported by this event");
+ }
+ if (trace_arg->data == Qundef) {
+ rb_bug("tp_attr_raised_exception_m: unreachable");
+ }
+ return trace_arg->data;
+}
+
/*
* Type of event
*