summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 17:55:54 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-29 17:55:54 +0000
commit970944847455dae54072ade11b4f4247e4707681 (patch)
treed2f0a8f6abb5dab608b60426768b7c6886ee529c
parent4556a9ec654406c1be43a0b0b3bff99e4d0ed3c1 (diff)
* vm.c: add a return hook when a method raises an exception.
* probes_helper.h: look up klass and method if none are provided. * eval.c: update macro usage. * vm_eval.c: ditto. * vm_insnhelper.c: ditto. * test/dtrace/test_function_entry.rb: test for change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog14
-rw-r--r--eval.c2
-rw-r--r--probes_helper.h16
-rw-r--r--test/dtrace/test_function_entry.rb29
-rw-r--r--vm.c3
-rw-r--r--vm_eval.c6
-rw-r--r--vm_insnhelper.c6
7 files changed, 64 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 7dd24e1b810..7a957fae7ae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Fri Nov 30 02:53:47 2012 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * vm.c: add a return hook when a method raises an exception.
+
+ * probes_helper.h: look up klass and method if none are provided.
+
+ * eval.c: update macro usage.
+
+ * vm_eval.c: ditto.
+
+ * vm_insnhelper.c: ditto.
+
+ * test/dtrace/test_function_entry.rb: test for change.
+
Fri Nov 30 02:27:12 2012 NARUSE, Yui <naruse@ruby-lang.org>
* compile.c (compile_array_): refix r37991 remove assertion:
diff --git a/eval.c b/eval.c
index d45e8720069..d4df41c18ee 100644
--- a/eval.c
+++ b/eval.c
@@ -18,7 +18,7 @@
#include "ruby/encoding.h"
#include "internal.h"
#include "vm_core.h"
-#include "probes.h"
+#include "probes_helper.h"
#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
diff --git a/probes_helper.h b/probes_helper.h
index c8d8c9840b6..7f4beb944f3 100644
--- a/probes_helper.h
+++ b/probes_helper.h
@@ -18,11 +18,19 @@
} \
} \
-#define RUBY_DTRACE_METHOD_RETURN_HOOK(klass, id) \
+#define RUBY_DTRACE_METHOD_RETURN_HOOK(th, klass, id) \
if (RUBY_DTRACE_METHOD_RETURN_ENABLED()) { \
- const char * classname = rb_class2name((klass)); \
- const char * methodname = rb_id2name((id)); \
- const char * filename = rb_sourcefile(); \
+ VALUE _klass = (klass); \
+ VALUE _id = (id); \
+ const char * classname; \
+ const char * methodname; \
+ const char * filename; \
+ if (!_klass) { \
+ rb_thread_method_id_and_class((th), &_id, &_klass); \
+ } \
+ classname = rb_class2name(_klass); \
+ methodname = rb_id2name(_id); \
+ filename = rb_sourcefile(); \
if (classname && methodname && filename) { \
RUBY_DTRACE_METHOD_RETURN( \
classname, \
diff --git a/test/dtrace/test_function_entry.rb b/test/dtrace/test_function_entry.rb
index 7a5f685f163..c7bf4786437 100644
--- a/test/dtrace/test_function_entry.rb
+++ b/test/dtrace/test_function_entry.rb
@@ -44,6 +44,35 @@ ruby$target:::method-return
}
end
+ def test_return_from_raise
+ program = <<-eoruby
+ class Foo
+ def bar; raise; end
+ def baz
+ bar
+ rescue
+ end
+ end
+
+ Foo.new.baz
+ eoruby
+
+ probe = <<-eoprobe
+ruby$target:::method-return
+/arg0 && arg1 && arg2/
+{
+ printf("%s %s %s %d\\n", copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3);
+}
+ eoprobe
+
+ trap_probe(probe, program) { |d_file, rb_file, probes|
+ foo_calls = probes.map { |line| line.split }.find_all { |row|
+ row.first == 'Foo' && row[1] == 'bar'
+ }
+ assert foo_calls.any?
+ }
+ end
+
private
def ruby_program
<<-eoruby
diff --git a/vm.c b/vm.c
index 44fbd26e19d..ab86569bec3 100644
--- a/vm.c
+++ b/vm.c
@@ -1177,7 +1177,7 @@ vm_exec(rb_thread_t *th)
if (UNLIKELY(VM_FRAME_TYPE(th->cfp) == VM_FRAME_MAGIC_CFUNC)) {
const rb_method_entry_t *me = th->cfp->me;
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass, Qnil);
- RUBY_DTRACE_METHOD_RETURN_HOOK(me->klass, me->called_id);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->klass, me->called_id);
}
th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
}
@@ -1350,6 +1350,7 @@ vm_exec(rb_thread_t *th)
switch (VM_FRAME_TYPE(th->cfp)) {
case VM_FRAME_MAGIC_METHOD:
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0)
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
break;
case VM_FRAME_MAGIC_CLASS:
diff --git a/vm_eval.c b/vm_eval.c
index 29fae2238d4..5959e933a55 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -85,7 +85,7 @@ vm_call0_cfunc(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv)
}
}
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, ci->recv, ci->mid, ci->defined_class, val);
- RUBY_DTRACE_METHOD_RETURN_HOOK(ci->defined_class, ci->mid);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, ci->defined_class, ci->mid);
return val;
}
@@ -123,7 +123,7 @@ vm_call0_cfunc_with_frame(rb_thread_t* th, rb_call_info_t *ci, const VALUE *argv
vm_pop_frame(th);
}
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, mid, defined_class, val);
- RUBY_DTRACE_METHOD_RETURN_HOOK(defined_class, mid);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, defined_class, mid);
return val;
}
@@ -1036,7 +1036,7 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
if (UNLIKELY(VM_FRAME_TYPE(th->cfp) == VM_FRAME_MAGIC_CFUNC)) {
const rb_method_entry_t *me = th->cfp->me;
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, th->cfp->self, me->called_id, me->klass, Qnil);
- RUBY_DTRACE_METHOD_RETURN_HOOK(me->klass, me->called_id);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->klass, me->called_id);
}
th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 241313a3015..d242097771c 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1468,7 +1468,7 @@ vm_call_cfunc_with_frame(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_i
vm_pop_frame(th);
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->klass, val);
- RUBY_DTRACE_METHOD_RETURN_HOOK(me->klass, me->called_id);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->klass, me->called_id);
return val;
}
@@ -1526,7 +1526,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci)
val = vm_call_cfunc_latter(th, reg_cfp, ci);
EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->called_id, me->klass, val);
- RUBY_DTRACE_METHOD_RETURN_HOOK(me->klass, me->called_id);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->klass, me->called_id);
return val;
}
@@ -1584,7 +1584,7 @@ vm_call_bmethod_body(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
val = vm_invoke_proc(th, proc, ci->recv, ci->defined_class, ci->argc, argv, ci->blockptr);
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, ci->recv, ci->me->called_id, ci->me->klass, val);
- RUBY_DTRACE_METHOD_RETURN_HOOK(ci->me->klass, ci->me->called_id);
+ RUBY_DTRACE_METHOD_RETURN_HOOK(th, ci->me->klass, ci->me->called_id);
return val;
}