summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c13
-rw-r--r--include/ruby/ruby.h2
-rw-r--r--insns.def6
-rw-r--r--iseq.c12
-rw-r--r--thread.c4
-rw-r--r--vm_core.h3
6 files changed, 20 insertions, 20 deletions
diff --git a/compile.c b/compile.c
index 574a589dc8..4ca855b002 100644
--- a/compile.c
+++ b/compile.c
@@ -250,6 +250,16 @@ struct iseq_compile_data_ensure_node_stack {
#define ADD_TRACE(seq, event) \
ADD_ELEM((seq), (LINK_ELEMENT *)new_trace_body(iseq, (event)))
+#define ADD_TRACE_LINE_COVERAGE(seq, line) \
+ do { \
+ if (ISEQ_COVERAGE(iseq) && \
+ ISEQ_LINE_COVERAGE(iseq) && \
+ (line) > 0) { \
+ RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), (line) - 1, INT2FIX(0)); \
+ ADD_INSN2((seq), (line), tracecoverage, INT2FIX(RUBY_EVENT_COVERAGE_LINE), INT2FIX(line)); \
+ } \
+ } while (0)
+
#define DECL_BRANCH_BASE(branches, first_line, first_column, last_line, last_column, type) \
do { \
@@ -280,7 +290,7 @@ struct iseq_compile_data_ensure_node_stack {
rb_ary_push(branches, INT2FIX(last_line)); \
rb_ary_push(branches, INT2FIX(last_column)); \
rb_ary_push(branches, INT2FIX(counter_idx)); \
- ADD_INSN2((seq), (first_line), tracebranch, INT2FIX(RUBY_EVENT_COVERAGE_BRANCH), INT2FIX(counter_idx)); \
+ ADD_INSN2((seq), (first_line), tracecoverage, INT2FIX(RUBY_EVENT_COVERAGE_BRANCH), INT2FIX(counter_idx)); \
} \
} while (0)
@@ -5421,6 +5431,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
else {
if (node->flags & NODE_FL_NEWLINE) {
ISEQ_COMPILE_DATA(iseq)->last_line = line;
+ ADD_TRACE_LINE_COVERAGE(ret, line);
ADD_TRACE(ret, RUBY_EVENT_LINE);
}
}
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 3210103c64..0959413dac 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -2111,7 +2111,7 @@ int ruby_native_thread_p(void);
#define RUBY_INTERNAL_EVENT_GC_ENTER 0x2000000
#define RUBY_INTERNAL_EVENT_GC_EXIT 0x4000000
#define RUBY_INTERNAL_EVENT_OBJSPACE_MASK 0x7f00000
-#define RUBY_INTERNAL_EVENT_MASK 0xfffe0000
+#define RUBY_INTERNAL_EVENT_MASK 0xffff0000
typedef uint32_t rb_event_flag_t;
typedef void (*rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass);
diff --git a/insns.def b/insns.def
index 1c20573254..120040c034 100644
--- a/insns.def
+++ b/insns.def
@@ -778,11 +778,11 @@ checkkeyword
/**
@c setting
- @e trace a branch
- @j 分岐を trace する
+ @e fire a coverage event (currently, this is used for line coverage and branch coverage)
+ @j カバレッジイベントを trace する
*/
DEFINE_INSN
-tracebranch
+tracecoverage
(rb_num_t nf, VALUE data)
()
()
diff --git a/iseq.c b/iseq.c
index f0239ccde1..186f8622e7 100644
--- a/iseq.c
+++ b/iseq.c
@@ -350,21 +350,9 @@ finish_iseq_build(rb_iseq_t *iseq)
{
struct iseq_compile_data *data = ISEQ_COMPILE_DATA(iseq);
VALUE err = data->err_info;
- unsigned int i;
ISEQ_COMPILE_DATA_CLEAR(iseq);
compile_data_free(data);
- if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
- for (i = 0; i < iseq->body->insns_info_size; i++) {
- if (iseq->body->insns_info[i].events & RUBY_EVENT_LINE) {
- int line_no = iseq->body->insns_info[i].line_no - 1;
- if (0 <= line_no && line_no < RARRAY_LEN(ISEQ_LINE_COVERAGE(iseq))) {
- RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line_no, INT2FIX(0));
- }
- }
- }
- }
-
if (RTEST(err)) {
VALUE path = pathobj_path(iseq->body->location.pathobj);
if (err == Qtrue) err = rb_exc_new_cstr(rb_eSyntaxError, "compile error");
diff --git a/thread.c b/thread.c
index 2b0954e803..2460d7e3ac 100644
--- a/thread.c
+++ b/thread.c
@@ -5035,7 +5035,7 @@ update_line_coverage(VALUE data, const rb_trace_arg_t *trace_arg)
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 line = FIX2INT(trace_arg->data) - 1;
long count;
VALUE num;
if (line >= RARRAY_LEN(lines)) { /* no longer tracked */
@@ -5157,7 +5157,7 @@ rb_set_coverages(VALUE coverages, int mode, VALUE me2counter)
{
GET_VM()->coverages = coverages;
GET_VM()->coverage_mode = mode;
- rb_add_event_hook2((rb_event_hook_func_t) update_line_coverage, RUBY_EVENT_LINE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
+ rb_add_event_hook2((rb_event_hook_func_t) update_line_coverage, RUBY_EVENT_COVERAGE_LINE, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
if (mode & COVERAGE_TARGET_BRANCHES) {
rb_add_event_hook2((rb_event_hook_func_t) update_branch_coverage, RUBY_EVENT_COVERAGE_BRANCH, Qnil, RUBY_EVENT_HOOK_FLAG_SAFE | RUBY_EVENT_HOOK_FLAG_RAW_ARG);
}
diff --git a/vm_core.h b/vm_core.h
index 374fcff1b2..d1c6cd6574 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -1755,7 +1755,8 @@ RUBY_SYMBOL_EXPORT_BEGIN
int rb_thread_check_trap_pending(void);
/* #define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 */ /* from vm_core.h */
-#define RUBY_EVENT_COVERAGE_BRANCH 0x010000
+#define RUBY_EVENT_COVERAGE_LINE 0x010000
+#define RUBY_EVENT_COVERAGE_BRANCH 0x020000
extern VALUE rb_get_coverages(void);
extern void rb_set_coverages(VALUE, int, VALUE);