From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id C3A1D1F466 for ; Thu, 16 Jan 2020 07:29:00 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D98FB120BEB; Thu, 16 Jan 2020 16:28:46 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 06EEC120BEA for ; Thu, 16 Jan 2020 16:28:43 +0900 (JST) Received: by filterdrecv-p3mdw1-56c97568b5-m6gw4 with SMTP id filterdrecv-p3mdw1-56c97568b5-m6gw4-19-5E2010B4-C 2020-01-16 07:28:52.197450197 +0000 UTC m=+2616345.422460462 Received: from herokuapp.com (unknown [54.158.130.18]) by ismtpd0116p1mdw1.sendgrid.net (SG) with ESMTP id QIt0lywCT76SN6xc_LF7Wg for ; Thu, 16 Jan 2020 07:28:52.100 +0000 (UTC) Date: Thu, 16 Jan 2020 07:28:52 +0000 (UTC) From: ko1@atdot.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72558 X-Redmine-Project: ruby-master X-Redmine-Issue-Id: 16383 X-Redmine-Issue-Author: AndyMaleh X-Redmine-Sender: ko1 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?fVTMYOBjtdvXNcWwrscBhLsHItUXVK5L4mtnq0mdcRdTbgAAUJXIpISiDh4Z+b?= =?us-ascii?Q?1LsHyzUwf5V48BQPKryMOZx=2FWmkqVkBUc0NQ5O4?= =?us-ascii?Q?YSHkBCD7vxi0Jwgh5n43yXYcCNjXnfSRnSsx=2FJQ?= =?us-ascii?Q?blAJLyrfmSeRTzDmSkguUINgyunVwIZbXEwIyk8?= =?us-ascii?Q?NTeEpUVLohQJwDuM4zdlh5+dDDydD1A1oYw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96896 Subject: [ruby-core:96896] [Ruby master Bug#16383] TracePoint does not report calls to attribute reader methods X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16383 has been updated by ko1 (Koichi Sasada). * matz: good to have, but not a showstopper ---------------------------------------- Bug #16383: TracePoint does not report calls to attribute reader methods https://bugs.ruby-lang.org/issues/16383#change-83910 * Author: AndyMaleh (Andy Maleh) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-darwin19] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- TracePoint does not report calls to attribute reader methods (e.g. methods defined using `attr_accessor` or `attr_reader`.) **Code sample to demonstrate:** ```ruby class Person attr_accessor :first_name attr_accessor :last_name def name "#{self.last_name}, #{self.first_name}" end end person = Person.new person.first_name = 'Josh' person.last_name = 'McGibbon' trace = TracePoint.new(:call) do |tp| p [tp.path, tp.lineno, tp.defined_class, tp.event, tp.method_id] end trace.enable person.name trace.disable class Person attr_writer :first_name attr_writer :last_name def name "#{self.last_name}, #{self.first_name}" end def first_name @first_name end def last_name @last_name end end person = Person.new person.first_name = 'Josh' person.last_name = 'McGibbon' trace = TracePoint.new(:call) do |tp| p [tp.path, tp.lineno, tp.defined_class, tp.event, tp.method_id] end trace.enable person.name trace.disable ``` **Output:** ``` ["trace_point_issue.rb", 4, Person, :call, :name] ["trace_point_issue.rb", 22, Person, :call, :name] ["trace_point_issue.rb", 28, Person, :call, :last_name] ["trace_point_issue.rb", 25, Person, :call, :first_name] ``` Please note how `:last_name` and `:first_name` show up only the second time `Person#name` is called. In other words, they show up when defined as actual methods using `def` keyword, but not when defined via `attr_accessor`. **Expected Output:** ``` ["trace_point_issue.rb", 22, Person, :call, :name] ["trace_point_issue.rb", 28, Person, :call, :last_name] ["trace_point_issue.rb", 25, Person, :call, :first_name] ["trace_point_issue.rb", 22, Person, :call, :name] ["trace_point_issue.rb", 28, Person, :call, :last_name] ["trace_point_issue.rb", 25, Person, :call, :first_name] ``` Your help in fixing or explaining this issue is greatly appreciated. My goal is to monitor all method calls when invoking a certain method (Person#name in this case) in order to attach observers to them dynamically for desktop UI data-binding use in my open-source project Glimmer: https://github.com/AndyObtiva/glimmer Cheers, Andy Maleh ---Files-------------------------------- trace_point_issue.rb (791 Bytes) tracepoint-attr-16383.patch (1.97 KB) -- https://bugs.ruby-lang.org/