8000 Support `ivar_set` TracePoint event by st0012 · Pull Request #13369 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Support ivar_set TracePoint event #13369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Conversation

st0012
Copy link
Member
@st0012 st0012 commented May 18, 2025

Feature #15854

This PR introduces:

  • A new ivar_set event to TracePoint, which will be triggered when a instance variable is set through:
    • Direct assignment, like @a = 1 8000
    • Attribute setters, like Foo.a = 1
    • instance_variable_set
  • A new ivar_name method to TracePoint instances that's only available for this event to retrieve the ivar's name in Symbol
    • The value can be retrieved through TracePoint#return_value

Example

TracePoint.trace(:ivar_set) do |tp|
  puts "ivar_set: #{tp.ivar_name.inspect}, value: #{tp.return_value.inspect}"
end

class Foo
  attr_accessor :b

  def initialize
    @a = 1
  end
end

foo = Foo.new
foo.b = 2
foo.instance_variable_set(:@c, 3)
# ivar_set: :@a, value: 1, lineno: 9
# ivar_set: :@b, value: 2, lineno: 14
# ivar_set: :@c, value: 3, lineno: 15

This comment has been minimized.

@st0012 st0012 force-pushed the tp-ivar-set branch 2 times, most recently from 825ac0f to d77b090 Compare June 5, 2025 21:31
@st0012 st0012 changed the title [WIP] Support ivar_set TracePoint event Support ivar_set TracePoint event Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0