diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-29 05:32:19 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-29 05:32:19 +0000 |
commit | bf91b74a321daa428b2e68fd2c556b0f66d3ead1 (patch) | |
tree | d112dcdc0f34898811f8a1db6be9cc83390d092e /vm.c | |
parent | d9da8f44d17a69f65f354980aca48f18c1b91f6f (diff) | |
download | ruby-bf91b74a321daa428b2e68fd2c556b0f66d3ead1.tar.gz |
vm.c: ruby_th_dtrace_setup
* vm.c (ruby_th_dtrace_setup): extract setup for calling dtrace
hook from RUBY_DTRACE_HOOK macro.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -179,6 +179,46 @@ rb_vm_inc_const_missing_count(void) ruby_vm_const_missing_count +=1; } +VALUE rb_class_path_no_cache(VALUE _klass); + +int +ruby_th_dtrace_setup(rb_thread_t *th, VALUE klass, ID id, + struct ruby_dtrace_method_hook_args *args) +{ + enum ruby_value_type type; + if (!klass) { + if (!th) th = GET_THREAD(); + if (!rb_thread_method_id_and_class(th, &id, &klass) || !klass) + return FALSE; + } + if (RB_TYPE_P(klass, T_ICLASS)) { + klass = RBASIC(klass)->klass; + } + else if (FL_TEST(klass, FL_SINGLETON)) { + klass = rb_attr_get(klass, id__attached__); + if (NIL_P(klass)) return FALSE; + } + type = BUILTIN_TYPE(klass); + if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) { + VALUE name = rb_class_path_no_cache(klass); + const char *classname; + const char *methodname = rb_id2name(id); + const char *filename = rb_sourcefile(); + if (methodname && filename) { + if (NIL_P(name) || !(classname = StringValuePtr(name))) + classname = "<unknown>"; + args->classname = classname; + args->methodname = methodname; + args->filename = filename; + args->line_no = rb_sourceline(); + args->klass = klass; + args->name = name; + return TRUE; + } + } + return FALSE; +} + /* * call-seq: * RubyVM.stat -> Hash |