Issue #18031 has been updated by alanwu (Alan Wu).


I don't think the overriding behavior is intentional, since it doesn't happen for other kinds of targets.
There is an existing [test case][1] that tests this for `Proc`.
I also found a leak specific to targeting bmethods while looking at this bug.

Here's my PR to fix these two problems assuming my assessment is right:
https://github.com/ruby/ruby/pull/4651


[1]:https://github.com/ruby/ruby/blob/2fa3209a350f21f31d65e0d85f9903244d40f8f1/test/ruby/test_settracefunc.rb#L2175-L2185


----------------------------------------
Bug #18031: Nested TracePoint#enable with target crashes
https://bugs.ruby-lang.org/issues/18031#change-92890

* Author: alanwu (Alan Wu)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Found this crash while looking at tracing related code.
Haven't had time to dig deeper, so I'm making a ticket for now.

```ruby
one = TracePoint.new(:call) {}
two = TracePoint.new(:call) {}

obj = Object.new
obj.define_singleton_method(:foo) {} # a bmethod

foo = obj.method(:foo)
one.enable(target: foo) do
  two.enable(target: foo) {}
end
```

It crashes on 2.6.5 and master (a7c85cc).



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>