Bug #10449
closed[TracePoint API] Duplicated line events when using parenthesis
Description
Sometimes, when using parenthesis, I get duplicated lines events from the TracePoint API. See the failing test case, it generates 2 line events where I think it should generate just one.
def test_no_duplicate_line_events
events = []
TracePoint.new(:line) { |tp| events << tp.event }.enable { a = (1) * 5 }
assert_equal [:line], events
end
Thanks!!
Updated by ko1 (Koichi Sasada) over 9 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r48609.
- compile.c (iseq_compile_each): remove duplicated line event.
[Bug #10449] - test/ruby/test_settracefunc.rb: add and fix tests.
Updated by deivid (David Rodríguez) over 9 years ago
Hi Koichi, I've looked at the patch and it seems to me that every duplicated event has been removed. So if I do something like
object.method1.method2.method3
only one line event will be generated. Is this the case?
If that's the case I actually preferred the previous behaviour so it is possible to inspect intermediate results. byebug
is aware of this duplication and even provides an option that ignores duplicated events in case the user wants to always change line when stepping through the code.
I just reported this specific case cause I couldn't recognize the "separate line events" but in general I think the behaviour was fine.
Updated by deivid (David Rodríguez) over 9 years ago
Confirmed, this commit breaks some tests in Byebug, I think it should be reverted.
Updated by deivid (David Rodríguez) over 9 years ago
Actually I've given this a second thought and I'm fine with the change. The funcionality loss is minimal (and easy to do it in other ways), the patch corrects issues like this one and the code using the API will be simpler as it will not need to handle the duplication.
So basically, I'm fine with anything. :)
Updated by ko1 (Koichi Sasada) over 9 years ago
Hi Koichi, I've looked at the patch and it seems to me that every duplicated event has been removed. So if I do something like
object.method1.method2.method3
only one line event will be generated. Is this the case?
Before this fix, only 1 line event (for the method chain line) is generated, isn't?
1 obj = Object.new
2 def obj.method_missing *args
3 p args
4 self
5 end
6
7 TracePoint.new(:line){|tp|
8 p [tp.event, tp.lineno]
9 }.enable{
10 obj.method1.method2.method3 # method chain line
11 }
#=>
ruby 2.1.4p261 (2014-10-19 revision 48004) [x86_64-linux]
[:line, 10] #<-- this line
[:line, 3]
[:method1]
[:line, 4]
[:line, 3]
[:method2]
[:line, 4]
[:line, 3]
[:method3]
[:line, 4]
Updated by deivid (David Rodríguez) over 9 years ago
Oops, I need to start thinking before talking... :) The change in the behaviour actually happened in this example so something like the following used to generate 2 line events before the change.
TracePoint.new(:line){|tp|
p [tp.event, tp.lineno]
}.enable{
num = 1 ; num += 1
}
Using semicolon is the only case I found when this happened (other that this issue), and it's not a very popular style anyways.
So definitely up for keeping this fix. Could we get this backported to 2.0 and 2.1?
THANKS!
Updated by usa (Usaku NAKAMURA) over 8 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: UNKNOWN, 2.1: REQUIRED, 2.2: DONTNEED
Updated by usa (Usaku NAKAMURA) over 8 years ago
- Related to Backport #11651: Please backport r48609 added
Updated by usa (Usaku NAKAMURA) over 8 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: REQUIRED, 2.2: DONTNEED to 2.0.0: UNKNOWN, 2.1: DONE, 2.2: DONTNEED
ruby_2_1 r52640 merged revision(s) 48609.