summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 01:55:30 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-14 01:55:30 +0000
commitd1b290d5ba8ef97beb1707dcf30665cb6bc43c16 (patch)
tree6c5844012dc4f566806730e5678c60386e2d4352 /thread.c
parenta4eedafb132deefd25fe8dc62b2305213b0bbed7 (diff)
Add a new instruction `trace2` for hooking with custom data
This is needed for passing to the hook function the measuring target type (line/branch/method) and the site of coverage event fired. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59871 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/thread.c b/thread.c
index d706ee469b..fc9687bef0 100644
--- a/thread.c
+++ b/thread.c
@@ -69,6 +69,7 @@
#include "ruby/io.h"
#include "ruby/thread.h"
#include "ruby/thread_native.h"
+#include "ruby/debug.h"
#include "internal.h"
#ifndef USE_NATIVE_THREAD_PRIORITY
@@ -4970,24 +4971,29 @@ rb_check_deadlock(rb_vm_t *vm)
}
static void
-update_coverage(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
+update_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
{
VALUE coverage = rb_iseq_coverage(GET_THREAD()->ec.cfp->iseq);
if (RB_TYPE_P(coverage, T_ARRAY) && !RBASIC_CLASS(coverage)) {
- VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
- if (lines) {
- long line = rb_sourceline() - 1;
- long count;
- VALUE num;
- if (line >= RARRAY_LEN(lines)) { /* no longer tracked */
- return;
- }
- num = RARRAY_AREF(lines, line);
- if (!FIXNUM_P(num)) return;
- count = FIX2LONG(num) + 1;
- if (POSFIXABLE(count)) {
- RARRAY_ASET(lines, line, LONG2FIX(count));
+ switch (FIX2INT(trace_arg->data)) {
+ case COVERAGE_INDEX_LINES: {
+ VALUE lines = RARRAY_AREF(coverage, COVERAGE_INDEX_LINES);
+ if (lines) {
+ long line = rb_sourceline() - 1;
+ long count;
+ VALUE num;
+ if (line >= RARRAY_LEN(lines)) { /* no longer tracked */
+ return;
+ }
+ num = RARRAY_AREF(lines, line);
+ if (!FIXNUM_P(num)) return;
+ count = FIX2LONG(num) + 1;
+ if (POSFIXABLE(count)) {
+ RARRAY_ASET(lines, line, LONG2FIX(count));
+ }
}
+ break;
+ }
}
}
}
@@ -5003,7 +5009,7 @@ rb_set_coverages(VALUE coverages, int mode)
{
GET_VM()->coverages = coverages;
GET_VM()->coverage_mode = mode;
- rb_add_event_hook(update_coverage, RUBY_EVENT_COVERAGE, Qnil);
+ rb_add_event_hook2((rb_event_hook_func_t) update_coverage, RUBY_EVENT_COVERAGE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
}
/* Make coverage arrays empty so old covered files are no longer tracked. */
@@ -5022,7 +5028,7 @@ rb_reset_coverages(void)
VALUE coverages = rb_get_coverages();
st_foreach(rb_hash_tbl_raw(coverages), reset_coverage_i, 0);
GET_VM()->coverages = Qfalse;
- rb_remove_event_hook(update_coverage);
+ rb_remove_event_hook((rb_event_hook_func_t) update_coverage);
}
VALUE