Project

General

Profile

Actions

Bug #10470

closed

TracePoint cannot trace attr_accessor/reader/writer method

Added by joker1007 (Tomohiro Hashidate) over 9 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-11-01 trunk 48219) [x86_64-darwin13]
[ruby-dev:48729]

Description

TracePointを利用してattr_accessorで定義したメソッドの:c_call, :c_returnイベントを取得することができません。

class Foo
  attr_accessor :hoge

  def bar
    @bar
  end

  def initialize(val)
    @bar = val
  end
end

foo = Foo.new("FOO")

trace = TracePoint.new(:return, :c_return) do |tp|
  p [tp.lineno, tp.defined_class, tp.method_id, tp.event, tp.binding, tp.return_value]
end

trace.enable do
  foo.bar
  foo.hoge = "hoge"
  foo.hoge
end

上記のコードを実行した時、attr_accessorで定義したhogeメソッドのイベントが発生しません。
調査した所、EXEC_EVENT_HOOKの呼び出し自体が無いようです。
このため、例えばpower_assertを利用した時にアクセサメソッドの戻り値を取得できない等の問題が発生します。

attributeの読み書きを行う処理の中にEXEC_EVENT_HOOKを呼び出す簡単なパッチを書きましたので、添付します。


Files

fix_attr_accessor_event.diff (1.98 KB) fix_attr_accessor_event.diff joker1007 (Tomohiro Hashidate), 11/03/2014 07:24 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #16383: TracePoint does not report calls to attribute reader methodsClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0