diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-06 06:36:51 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-06 06:36:51 +0000 |
commit | 09821dd2a5b59024976b01ac7aa445b6fc14b681 (patch) | |
tree | 3416c5fecbad301c2d88094609e91aec94a52172 /test/ruby | |
parent | b11b804f8f4c84c7f5d59dd215e3d8a3d4d9d889 (diff) | |
download | ruby-09821dd2a5b59024976b01ac7aa445b6fc14b681.tar.gz |
Fix TracePoint for nested iseq loaded from binary [Bug#14702]
When loading iseq from binary while a TracePoint is on, we need to
recompile instructions to their "trace_" variant. Before this commit
we only recompiled instructions in the top level iseq, which meant
that TracePoint was malfunctioning for code inside module/class/method
definitions.
* compile.c: Move rb_iseq_init_trace to rb_ibf_load_iseq_complete.
It is called on all iseqs during loading.
* test_iseq.rb: Test that tracepoints fire within children iseq when
using load_from_binary.
This patch is from: Alan Wu <XrXr@users.noreply.github.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65567 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_iseq.rb | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index d193f41c6e..078c11472d 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -286,8 +286,12 @@ class TestISeq < Test::Unit::TestCase 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 @@ -439,17 +443,74 @@ class TestISeq < Test::Unit::TestCase 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 |