[前][次][番号順一覧][スレッド一覧]

ruby-changes:52306

From: ko1 <ko1@a...>
Date: Thu, 23 Aug 2018 13:12:23 +0900 (JST)
Subject: [ruby-changes:52306] ko1:r64514 (trunk): check trace flags at loading [Bug #14702]

ko1	2018-08-23 13:12:14 +0900 (Thu, 23 Aug 2018)

  New Revision: 64514

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64514

  Log:
    check trace flags at loading [Bug #14702]
    
    * iseq.c (iseq_init_trace): at ISeq loading time, we need to check
      `ruby_vm_event_enabled_flags` to turn on trace instructions.
      Seprate this checking code from `finish_iseq_build()` and make
      new function. `iseq_ibf_load()` calls this funcation after loading.
    
    * test/ruby/test_iseq.rb: add a test for this fix.

  Modified files:
    trunk/compile.c
    trunk/iseq.c
    trunk/iseq.h
    trunk/test/ruby/test_iseq.rb
Index: iseq.c
===================================================================
--- iseq.c	(revision 64513)
+++ iseq.c	(revision 64514)
@@ -504,6 +504,15 @@ rb_iseq_insns_info_decode_positions(cons https://github.com/ruby/ruby/blob/trunk/iseq.c#L504
 }
 #endif
 
+void
+iseq_init_trace(rb_iseq_t *iseq)
+{
+    iseq->aux.trace_events = 0;
+    if (ruby_vm_event_enabled_flags & ISEQ_TRACE_EVENTS) {
+        rb_iseq_trace_set(iseq, ruby_vm_event_enabled_flags & ISEQ_TRACE_EVENTS);
+    }
+}
+
 static VALUE
 finish_iseq_build(rb_iseq_t *iseq)
 {
@@ -531,10 +540,7 @@ finish_iseq_build(rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L540
 	rb_exc_raise(err);
     }
 
-    iseq->aux.trace_events = 0;
-    if (ruby_vm_event_enabled_flags & ISEQ_TRACE_EVENTS) {
-	rb_iseq_trace_set(iseq, ruby_vm_event_enabled_flags & ISEQ_TRACE_EVENTS);
-    }
+    iseq_init_trace(iseq);
     return Qtrue;
 }
 
Index: iseq.h
===================================================================
--- iseq.h	(revision 64513)
+++ iseq.h	(revision 64514)
@@ -144,6 +144,8 @@ VALUE iseq_ibf_dump(const rb_iseq_t *ise https://github.com/ruby/ruby/blob/trunk/iseq.h#L144
 void ibf_load_iseq_complete(rb_iseq_t *iseq);
 const rb_iseq_t *iseq_ibf_load(VALUE str);
 VALUE iseq_ibf_load_extra_data(VALUE str);
+void iseq_init_trace(rb_iseq_t *iseq);
+
 #if VM_INSN_INFO_TABLE_IMPL == 2
 unsigned int *rb_iseq_insns_info_decode_positions(const struct rb_iseq_constant_body *body);
 #endif
Index: compile.c
===================================================================
--- compile.c	(revision 64513)
+++ compile.c	(revision 64514)
@@ -10010,6 +10010,8 @@ iseq_ibf_load(VALUE str) https://github.com/ruby/ruby/blob/trunk/compile.c#L10010
     ibf_load_setup(load, loader_obj, str);
     iseq = ibf_load_iseq(load, 0);
 
+    iseq_init_trace(iseq);
+
     RB_GC_GUARD(loader_obj);
     return iseq;
 }
Index: test/ruby/test_iseq.rb
===================================================================
--- test/ruby/test_iseq.rb	(revision 64513)
+++ test/ruby/test_iseq.rb	(revision 64514)
@@ -438,4 +438,18 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L438
       end
     end;
   end
+
+  def test_to_binary_tracepoint
+    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
+    iseq = RubyVM::InstructionSequence.compile("x = 1\n y = 2", filename)
+    iseq_bin = iseq.to_binary
+    ary = []
+    TracePoint.new(:line){|tp|
+      next unless tp.path == filename
+      ary << [tp.path, tp.lineno]
+    }.enable{
+      ISeq.load_from_binary(iseq_bin).eval
+    }
+    assert_equal [[filename, 1], [filename, 2]], ary, '[Bug #14702]'
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]