Issue #10689 has been updated by Yui NARUSE.

Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE

ruby_2_2 r49374 merged revision(s) 49266.

----------------------------------------
Bug #10689: `unexpected break' occurs when TracePoint#binding is called
https://bugs.ruby-lang.org/issues/10689#change-51171

* Author: Kazuki Tsujimoto
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-01-02 trunk 49102) [x86_64-linux]
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE
----------------------------------------
以下のコードでunexpected breakになります。

~~~ruby
class Bug
  include Enumerable

  def each
    [0].each do 
      yield
    end
  end
end

TracePoint.trace(:c_return) do |tp|
  tp.binding
end

Bug.new.all? { false }
~~~

all?中のrb_iter_breakによってth->errinfoがセットされた後に、
TracePoint#binding呼び出しによってcfpのepがヒープを指すようになってしまうのが原因です。

とりあえずTracePoint呼び出し後にth->errinfoのepを書き換えるようにしてみたパッチを添付します。


---Files--------------------------------
fix-unexpected-break.patch (3.32 KB)
save-target-cfp-in-errinfo.patch (6.26 KB)


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