ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:108237] [Ruby master Bug#18730] Double `return` event handling with different tracepoints
@ 2022-04-14 14:50 hurricup (Alexandr Evstigneev)
  2022-04-26 20:40 ` [ruby-core:108408] " jeremyevans0 (Jeremy Evans)
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hurricup (Alexandr Evstigneev) @ 2022-04-14 14:50 UTC (permalink / raw
  To: ruby-core

Issue #18730 has been reported by hurricup (Alexandr Evstigneev).

----------------------------------------
Bug #18730: Double `return` event handling with different tracepoints
https://bugs.ruby-lang.org/issues/18730

* Author: hurricup (Alexandr Evstigneev)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I'm not sure if this is a bug or intentional behavior, but feels a bit unexpected. Ruby 3.0.x, 3.1.x affected.

Here is the script demonstrating the issue:
```
def bar
  42 #bp here
end

tp_line = TracePoint.new(:line) do |tp0|
  puts "Got line event from #{tp0.path}:#{tp0.lineno}"

  tp_multi1 = TracePoint.new(:return, :b_return, :line) do |tp|
    if tp.lineno == 3
      puts "Got first return `#{tp.event}` from #{tp.path}:#{tp.lineno}"
      tp.disable

      tp_multi2 = TracePoint.new(:return, :b_return, :line) do |tps|
        puts "Got second return `#{tps.event}` from #{tps.path}:#{tps.lineno}"
      end
      tp_multi2.enable(target: RubyVM::InstructionSequence.of(method :bar))
    end
  end
  tp_multi1.enable
end

tp_line.enable(target: RubyVM::InstructionSequence.of(method :bar))

bar
```
1. We set a line TP to the `bar` method `iseq` (consider it a line breakpoint)
2. When line event is triggered we setting another untargeted tracepoint for the same method, to catch `line`, `return` and `b_return` events (consider it attempt to step into something)
3. When return event of the `bar` method is triggered, we disabling second tracepoint and setting another one, targeted to the same method and multiple events.

Output i get:
```
Got line event from /home/hurricup/test.rb:2
Got first return `return` from /home/hurricup/test.rb:3
Got second return `return` from /home/hurricup/test.rb:3
```
The question is: why return triggered on the second tracepoint, when we already handeled it?




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-01 16:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-14 14:50 [ruby-core:108237] [Ruby master Bug#18730] Double `return` event handling with different tracepoints hurricup (Alexandr Evstigneev)
2022-04-26 20:40 ` [ruby-core:108408] " jeremyevans0 (Jeremy Evans)
2022-04-28 22:37 ` [ruby-core:108437] " jeremyevans0 (Jeremy Evans)
2022-04-29 11:05 ` [ruby-core:108444] " hurricup (Alexandr Evstigneev)
2022-04-30  0:50 ` [ruby-core:108449] " alanwu (Alan Wu)
2022-04-30  5:32 ` [ruby-core:108450] " hurricup (Alexandr Evstigneev)
2022-05-02 18:33 ` [ruby-core:108459] " alanwu (Alan Wu)
2022-06-01 16:36 ` [ruby-core:108748] " alanwu (Alan Wu)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).