summaryrefslogtreecommitdiff
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-14 12:58:36 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-14 12:58:36 +0000
commit665ba24b446971fdf652a9c57c32b176d0018636 (patch)
tree31357897b60fbef63947d89ad7cd0f0ae95025bc /vm_insnhelper.c
parentfe3decb2017af2092d4b2181e27e4cd8f6bbf4fa (diff)
remove `trace` instruction. [Feature #14104]
* tool/instruction.rb: create `trace_` prefix instructions. * compile.c (ADD_TRACE): do not add `trace` instructions but add TRACE link elements. TRACE elements will be unified with a next instruction as instruction information. * vm_trace.c (update_global_event_hook): modify all ISeqs when hooks are enabled. * iseq.c (rb_iseq_trace_set): added to toggle `trace_` instructions. * vm_insnhelper.c (vm_trace): added. This function is a body of `trace_` prefix instructions. * vm_insnhelper.h (JUMP): save PC to a control frame. * insns.def (trace): removed. * vm_exec.h (INSN_ENTRY_SIG): add debug output (disabled). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 7625cdbcac..1a7000c964 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3723,3 +3723,58 @@ vm_opt_regexpmatch2(VALUE recv, VALUE obj)
return Qundef;
}
}
+
+rb_event_flag_t rb_iseq_event_flags(const rb_iseq_t *iseq, size_t pos);
+
+NOINLINE(static void vm_trace(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE *pc));
+
+static void
+vm_trace(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE *pc)
+{
+ const rb_iseq_t *iseq = reg_cfp->iseq;
+ size_t pos = pc - iseq->body->iseq_encoded;
+ rb_event_flag_t events = rb_iseq_event_flags(iseq, pos);
+ rb_event_flag_t event;
+
+ if (ec->trace_arg != NULL) return;
+
+ if (0) {
+ fprintf(stderr, "vm_trace>>%4d (%4x) - %s:%d %s\n",
+ (int)pos,
+ (int)events,
+ RSTRING_PTR(rb_iseq_path(iseq)),
+ (int)rb_iseq_line_no(iseq, pos),
+ RSTRING_PTR(rb_iseq_label(iseq)));
+ }
+
+ VM_ASSERT(reg_cfp->pc == pc);
+ VM_ASSERT(events != 0);
+
+ /* increment PC because source line is calculated with PC-1 */
+ if (events & ruby_vm_event_flags) {
+ if (event = (events & (RUBY_EVENT_CLASS | RUBY_EVENT_CALL | RUBY_EVENT_B_CALL))) {
+ VM_ASSERT(event == RUBY_EVENT_CLASS ||
+ event == RUBY_EVENT_CALL ||
+ event == RUBY_EVENT_B_CALL);
+ reg_cfp->pc++;
+ vm_dtrace(event, ec);
+ EXEC_EVENT_HOOK(ec, event, GET_SELF(), 0, 0, 0, Qundef);
+ reg_cfp->pc--;
+ }
+ if (events & RUBY_EVENT_LINE) {
+ reg_cfp->pc++;
+ vm_dtrace(RUBY_EVENT_LINE, ec);
+ EXEC_EVENT_HOOK(ec, RUBY_EVENT_LINE, GET_SELF(), 0, 0, 0, Qundef);
+ reg_cfp->pc--;
+ }
+ if (event = (events & (RUBY_EVENT_END | RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN))) {
+ VM_ASSERT(event == RUBY_EVENT_END ||
+ event == RUBY_EVENT_RETURN ||
+ event == RUBY_EVENT_B_RETURN);
+ reg_cfp->pc++;
+ vm_dtrace(RUBY_EVENT_LINE, ec);
+ EXEC_EVENT_HOOK(ec, event, GET_SELF(), 0, 0, 0, TOPN(0));
+ reg_cfp->pc--;
+ }
+ }
+}