Bug #15270 ยป 0001-Fix-TracePoint-for-nested-iseq-loaded-from-binary.patch
| compile.c | ||
|---|---|---|
| 
         ibf_load_iseq_each(load, iseq, offset); 
   | 
||
| 
         ISEQ_COMPILE_DATA_CLEAR(iseq); 
   | 
||
| 
         FL_UNSET(iseq, ISEQ_NOT_LOADED_YET); 
   | 
||
| 
         rb_iseq_init_trace(iseq); 
   | 
||
| 
         load->iseq = prev_src_iseq; 
   | 
||
| 
     } 
   | 
||
| ... | ... | |
| 
         ibf_load_setup(load, loader_obj, str); 
   | 
||
| 
         iseq = ibf_load_iseq(load, 0); 
   | 
||
| 
         rb_iseq_init_trace(iseq); 
   | 
||
| 
         RB_GC_GUARD(loader_obj); 
   | 
||
| 
         return iseq; 
   | 
||
| 
     } 
   | 
||
| test/ruby/test_iseq.rb | ||
|---|---|---|
| 
         end 
   | 
||
| 
       end 
   | 
||
| 
       def strip_lineno(source) 
   | 
||
| 
         source.gsub(/^.*?: /, "") 
   | 
||
| 
       end 
   | 
||
| 
       def sample_iseq 
   | 
||
| 
         ISeq.compile <<-EOS.gsub(/^.*?: /, "") 
   | 
||
| 
         ISeq.compile(strip_lineno(<<-EOS)) 
   | 
||
| 
          1: class C 
   | 
||
| 
          2:   def foo 
   | 
||
| 
          3:     begin 
   | 
||
| ... | ... | |
| 
         end; 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         iseq = RubyVM::InstructionSequence.compile("x = 1\n y = 2", filename) 
   | 
||
| 
       def collect_from_binary_tracepoint_lines(tracepoint_type, filename) 
   | 
||
| 
         iseq = RubyVM::InstructionSequence.compile(strip_lineno(<<-RUBY), filename) 
   | 
||
| 
           class A 
   | 
||
| 
             class B 
   | 
||
| 
               2.times { 
   | 
||
| 
                 def self.foo 
   | 
||
| 
                   a = 'good day' 
   | 
||
| 
                   raise 
   | 
||
| 
                 rescue 
   | 
||
| 
                   'dear reader' 
   | 
||
| 
                 end 
   | 
||
| 
               } 
   | 
||
| 
             end 
   | 
||
| 
             B.foo 
   | 
||
| 
           end 
   | 
||
| 
         RUBY 
   | 
||
| 
         iseq_bin = iseq.to_binary 
   | 
||
| 
         ary = [] 
   | 
||
| 
         TracePoint.new(:line){|tp| 
   | 
||
| 
         lines = [] 
   | 
||
| 
         TracePoint.new(tracepoint_type){|tp| 
   | 
||
| 
           next unless tp.path == filename 
   | 
||
| 
           ary << [tp.path, tp.lineno] 
   | 
||
| 
           lines << tp.lineno 
   | 
||
| 
         }.enable{ 
   | 
||
| 
           ISeq.load_from_binary(iseq_bin).eval 
   | 
||
| 
         } 
   | 
||
| 
         assert_equal [[filename, 1], [filename, 2]], ary, '[Bug #14702]' 
   | 
||
| 
         lines 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_line_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         lines = collect_from_binary_tracepoint_lines(:line, filename) 
   | 
||
| 
         assert_equal [1, 2, 3, 4, 4, 12, 5, 6, 8], lines, '[Bug #14702]' 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_class_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         lines = collect_from_binary_tracepoint_lines(:class, filename) 
   | 
||
| 
         assert_equal [1, 2], lines, '[Bug #14702]' 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_end_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         lines = collect_from_binary_tracepoint_lines(:end, filename) 
   | 
||
| 
         assert_equal [11, 13], lines, '[Bug #14702]' 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_return_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         lines = collect_from_binary_tracepoint_lines(:return, filename) 
   | 
||
| 
         assert_equal [9], lines, '[Bug #14702]' 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_b_call_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         lines = collect_from_binary_tracepoint_lines(:b_call, filename) 
   | 
||
| 
         assert_equal [3, 3], lines, '[Bug #14702]' 
   | 
||
| 
       end 
   | 
||
| 
       def test_to_binary_b_return_tracepoint 
   | 
||
| 
         filename = "#{File.basename(__FILE__)}_#{__LINE__}" 
   | 
||
| 
         lines = collect_from_binary_tracepoint_lines(:b_return, filename) 
   | 
||
| 
         assert_equal [10, 10], lines, '[Bug #14702]' 
   | 
||
| 
       end 
   | 
||
| 
     end 
   | 
||