From 919fa894f5e0fed105ad1513cb8be0748ae46295 Mon Sep 17 00:00:00 2001 From: ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Sat, 23 Dec 2017 11:00:48 +0000 Subject: [PATCH] revert line number spec of *return events. * compile.c (rb_iseq_compile_node): line number spec of :return, :b_return and :end events of 'TracePoint` is changed for [Feature #14104]. Quoted from [Feature #14104]: > Line numbers on :return/:b_return events show the last executed lines, > instead of end lines (without return statement). Note that :end event also affected. However, "buybug", a well-known ruby debugger depends on previous behavior so that I reverted this specification. * test/ruby/test_settracefunc.rb: catch up this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 3 +++ test/ruby/test_settracefunc.rb | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/compile.c b/compile.c index 4ca855b002..95d0e5f891 100644 --- a/compile.c +++ b/compile.c @@ -646,6 +646,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) CHECK(COMPILE(ret, "block body", node->nd_body)); ADD_LABEL(ret, end); ADD_TRACE(ret, RUBY_EVENT_B_RETURN); + ISEQ_COMPILE_DATA(iseq)->last_line = iseq->body->location.code_range.last_loc.lineno; /* wide range catch handler must put at last */ ADD_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start); @@ -657,6 +658,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) ADD_TRACE(ret, RUBY_EVENT_CLASS); CHECK(COMPILE(ret, "scoped node", node->nd_body)); ADD_TRACE(ret, RUBY_EVENT_END); + ISEQ_COMPILE_DATA(iseq)->last_line = nd_line(node); break; } case ISEQ_TYPE_METHOD: @@ -664,6 +666,7 @@ rb_iseq_compile_node(rb_iseq_t *iseq, const NODE *node) ADD_TRACE(ret, RUBY_EVENT_CALL); CHECK(COMPILE(ret, "scoped node", node->nd_body)); ADD_TRACE(ret, RUBY_EVENT_RETURN); + ISEQ_COMPILE_DATA(iseq)->last_line = nd_line(node); break; } default: { diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index dfdbeeea8f..69ddc05979 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -77,7 +77,7 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["c-return", 5, :+, Integer], events.shift) - assert_equal(["return", 5, :add, self.class], + assert_equal(["return", 6, :add, self.class], events.shift) assert_equal(["line", 8, __method__, self.class], events.shift) @@ -116,7 +116,7 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["c-return", 5, :method_added, Module], events.shift) - assert_equal(["end", 5, nil, nil], + assert_equal(["end", 7, nil, nil], events.shift) assert_equal(["line", 8, __method__, self.class], events.shift) @@ -130,7 +130,7 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["call", 5, :bar, Foo], events.shift) - assert_equal(["return", 5, :bar, Foo], + assert_equal(["return", 6, :bar, Foo], events.shift) assert_equal(["line", 9, __method__, self.class], events.shift) @@ -176,7 +176,7 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["line", 5, :meth_return, self.class], events.shift) - assert_equal(["return", 5, :meth_return, self.class], + assert_equal(["return", 7, :meth_return, self.class], events.shift) assert_equal(["line", 10, :test_return, self.class], events.shift) @@ -215,7 +215,7 @@ class TestSetTraceFunc < Test::Unit::TestCase events.shift) assert_equal(["line", 6, :meth_return2, self.class], events.shift) - assert_equal(["return", 6, :meth_return2, self.class], + assert_equal(["return", 7, :meth_return2, self.class], events.shift) assert_equal(["line", 9, :test_return2, self.class], events.shift) @@ -343,7 +343,7 @@ class TestSetTraceFunc < Test::Unit::TestCase ["line", 4, nil, nil], ["c-call", 4, :method_added, Module], ["c-return", 4, :method_added, Module], - ["end", 4, nil, nil], + ["end", 7, nil, nil], ["line", 8, __method__, self.class], ["c-call", 8, :new, Class], ["c-call", 8, :initialize, BasicObject], @@ -353,7 +353,7 @@ class TestSetTraceFunc < Test::Unit::TestCase ["line", 5, :foo, ThreadTraceInnerClass], ["c-call", 5, :+, Integer], ["c-return", 5, :+, Integer], - ["return", 5, :foo, ThreadTraceInnerClass], + ["return", 6, :foo, ThreadTraceInnerClass], ["line", 9, __method__, self.class], ["c-call", 9, :set_trace_func, Thread]].each do |e| [:set, :add].each do |type| @@ -487,7 +487,7 @@ class TestSetTraceFunc < Test::Unit::TestCase [:line, 13, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer, :nothing], [:c_call, 13, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer, :nothing], [:c_return,13, "xyzzy", Module, :method_added, xyzzy.class, :XYZZY_outer, nil], - [:end, 13, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer, :nothing], + [:end, 17, "xyzzy", nil, nil, xyzzy.class, :XYZZY_outer, :nothing], [:line, 18, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing], [:c_call, 18, "xyzzy", Class, :new, xyzzy.class, :outer, :nothing], [:c_call, 18, "xyzzy", BasicObject, :initialize, xyzzy, :outer, :nothing], @@ -502,8 +502,8 @@ class TestSetTraceFunc < Test::Unit::TestCase [:line, 15, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar, :nothing], [:c_call, 15, "xyzzy", Kernel, :tap, xyzzy, :XYZZY_bar, :nothing], [:c_return,15, "xyzzy", Kernel, :tap, xyzzy, :XYZZY_bar, xyzzy], - [:return, 15, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar, xyzzy], - [:return, 11, "xyzzy", xyzzy.class, :foo, xyzzy, :XYZZY_foo, xyzzy], + [:return, 16, "xyzzy", xyzzy.class, :bar, xyzzy, :XYZZY_bar, xyzzy], + [:return, 12, "xyzzy", xyzzy.class, :foo, xyzzy, :XYZZY_foo, xyzzy], [:line, 20, "xyzzy", TestSetTraceFunc, method, self, :outer, :nothing], [:c_call, 20, "xyzzy", Kernel, :raise, self, :outer, :nothing], [:c_call, 20, "xyzzy", Exception, :exception, RuntimeError, :outer, :nothing], @@ -1800,7 +1800,7 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_equal ["line", base_line + 7], events[4] assert_equal ["line", base_line + 8], events[5] assert_equal ["call", base_line + -6], events[6] - assert_equal ["return", base_line + -6], events[7] + assert_equal ["return", base_line + -4], events[7] assert_equal ["line", base_line + 9], events[8] assert_equal nil, events[9] @@ -1835,7 +1835,7 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_equal ["line", base_line + 32], events[1] assert_equal ["line", base_line + 33], events[2] assert_equal ["call", base_line + -6], events[3] - assert_equal ["return", base_line + -6], events[4] + assert_equal ["return", base_line + -4], events[4] assert_equal ["line", base_line + 34], events[5] assert_equal ["line", base_line + 35], events[6] assert_equal ["c-call", base_line + 35], events[7] # Thread.current