Project

General

Profile

Bug #15270 ยป 0001-Fix-TracePoint-for-nested-iseq-loaded-from-binary.patch

alanwu (Alan Wu), 10/30/2018 02:46 PM

View differences:

compile.c
9883 9883
    ibf_load_iseq_each(load, iseq, offset);
9884 9884
    ISEQ_COMPILE_DATA_CLEAR(iseq);
9885 9885
    FL_UNSET(iseq, ISEQ_NOT_LOADED_YET);
9886
    rb_iseq_init_trace(iseq);
9886 9887
    load->iseq = prev_src_iseq;
9887 9888
}
9888 9889

  
......
10031 10032
    ibf_load_setup(load, loader_obj, str);
10032 10033
    iseq = ibf_load_iseq(load, 0);
10033 10034

  
10034
    rb_iseq_init_trace(iseq);
10035

  
10036 10035
    RB_GC_GUARD(loader_obj);
10037 10036
    return iseq;
10038 10037
}
test/ruby/test_iseq.rb
286 286
    end
287 287
  end
288 288

  
289
  def strip_lineno(source)
290
    source.gsub(/^.*?: /, "")
291
  end
292

  
289 293
  def sample_iseq
290
    ISeq.compile <<-EOS.gsub(/^.*?: /, "")
294
    ISeq.compile(strip_lineno(<<-EOS))
291 295
     1: class C
292 296
     2:   def foo
293 297
     3:     begin
......
439 443
    end;
440 444
  end
441 445

  
442
  def test_to_binary_tracepoint
443
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
444
    iseq = RubyVM::InstructionSequence.compile("x = 1\n y = 2", filename)
446
  def collect_from_binary_tracepoint_lines(tracepoint_type, filename)
447
    iseq = RubyVM::InstructionSequence.compile(strip_lineno(<<-RUBY), filename)
448
      class A
449
        class B
450
          2.times {
451
            def self.foo
452
              a = 'good day'
453
              raise
454
            rescue
455
              'dear reader'
456
            end
457
          }
458
        end
459
        B.foo
460
      end
461
    RUBY
462

  
445 463
    iseq_bin = iseq.to_binary
446
    ary = []
447
    TracePoint.new(:line){|tp|
464
    lines = []
465
    TracePoint.new(tracepoint_type){|tp|
448 466
      next unless tp.path == filename
449
      ary << [tp.path, tp.lineno]
467
      lines << tp.lineno
450 468
    }.enable{
451 469
      ISeq.load_from_binary(iseq_bin).eval
452 470
    }
453
    assert_equal [[filename, 1], [filename, 2]], ary, '[Bug #14702]'
471

  
472
    lines
473
  end
474

  
475
  def test_to_binary_line_tracepoint
476
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
477
    lines = collect_from_binary_tracepoint_lines(:line, filename)
478

  
479
    assert_equal [1, 2, 3, 4, 4, 12, 5, 6, 8], lines, '[Bug #14702]'
480
  end
481

  
482
  def test_to_binary_class_tracepoint
483
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
484
    lines = collect_from_binary_tracepoint_lines(:class, filename)
485

  
486
    assert_equal [1, 2], lines, '[Bug #14702]'
487
  end
488

  
489
  def test_to_binary_end_tracepoint
490
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
491
    lines = collect_from_binary_tracepoint_lines(:end, filename)
492

  
493
    assert_equal [11, 13], lines, '[Bug #14702]'
494
  end
495

  
496
  def test_to_binary_return_tracepoint
497
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
498
    lines = collect_from_binary_tracepoint_lines(:return, filename)
499

  
500
    assert_equal [9], lines, '[Bug #14702]'
501
  end
502

  
503
  def test_to_binary_b_call_tracepoint
504
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
505
    lines = collect_from_binary_tracepoint_lines(:b_call, filename)
506

  
507
    assert_equal [3, 3], lines, '[Bug #14702]'
508
  end
509

  
510
  def test_to_binary_b_return_tracepoint
511
    filename = "#{File.basename(__FILE__)}_#{__LINE__}"
512
    lines = collect_from_binary_tracepoint_lines(:b_return, filename)
513

  
514
    assert_equal [10, 10], lines, '[Bug #14702]'
454 515
  end
455 516
end