From 5bdd03936c2a7fb5c835587535466ec76bf0ca9e Mon Sep 17 00:00:00 2001 From: ko1 Date: Sat, 1 Dec 2012 20:07:58 +0000 Subject: [PATCH] * iseq.c (rb_iseq_line_trace_each): iterate `line' event only. * test/ruby/test_iseq.rb: add a test for this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ iseq.c | 20 ++++++++++++-------- test/ruby/test_iseq.rb | 12 ++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19cfc9226f..bc2511a651 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Dec 2 05:01:58 2012 Koichi Sasada + + * iseq.c (rb_iseq_line_trace_each): iterate `line' event only. + + * test/ruby/test_iseq.rb: add a test for this change. + Sun Dec 2 02:46:04 2012 Koichi Sasada * vm_trace.c: add TracePoint#inspect. diff --git a/iseq.c b/iseq.c index 7fc35df3e7..42eba6eb25 100644 --- a/iseq.c +++ b/iseq.c @@ -1954,15 +1954,19 @@ rb_iseq_line_trace_each(VALUE iseqval, int (*func)(int line, rb_event_flag_t *ev if (insn == BIN(trace)) { rb_event_flag_t current_events = (VALUE)iseq->iseq[pos+1]; - rb_event_flag_t events = current_events & RUBY_EVENT_SPECIFIED_LINE; - trace_num++; - if (func) { - int line = find_line_no(iseq, pos); - /* printf("line: %d\n", line); */ - cont = (*func)(line, &events, data); - if (current_events != events) { - iseq->iseq[pos+1] = iseq->iseq_encoded[pos+1] = (VALUE)(current_events | (events & RUBY_EVENT_SPECIFIED_LINE)); + if (current_events & RUBY_EVENT_LINE) { + rb_event_flag_t events = current_events & RUBY_EVENT_SPECIFIED_LINE; + trace_num++; + + if (func) { + int line = find_line_no(iseq, pos); + /* printf("line: %d\n", line); */ + cont = (*func)(line, &events, data); + if (current_events != events) { + iseq->iseq[pos+1] = iseq->iseq_encoded[pos+1] = + (VALUE)(current_events | (events & RUBY_EVENT_SPECIFIED_LINE)); + } } } } diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index b31fcb70dd..7d46004802 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -26,6 +26,15 @@ class TestISeq < Test::Unit::TestCase Encoding.default_internal = enc end + LINE_BEFORE_METHOD = __LINE__ + def method_test_line_trace + + a = 1 + + b = 2 + + end + def test_line_trace iseq = ISeq.compile \ %q{ a = 1 @@ -48,6 +57,9 @@ class TestISeq < Test::Unit::TestCase iseq.eval } assert_equal([2, 5], result) + + iseq = ISeq.of(self.class.instance_method(:method_test_line_trace)) + assert_equal([LINE_BEFORE_METHOD + 3, LINE_BEFORE_METHOD + 5], iseq.line_trace_all) end LINE_OF_HERE = __LINE__