[ruby-core:123474] [Ruby Feature#21637] Tracing global variable assignment

Issue #21637 has been reported by viralpraxis (Iaroslav Kurbatov). ---------------------------------------- Feature #21637: Tracing global variable assignment https://bugs.ruby-lang.org/issues/21637 * Author: viralpraxis (Iaroslav Kurbatov) * Status: Open ---------------------------------------- ## Motivation Currently, there is no straightforward way to track global variable assignments at runtime. The only workaround I am aware of involves using the `line` TracePoint event, combined with manipulation of the source code's AST, but this approach is extremely slow and impractical. I'd like to propose a new `gvar_set` (and probably `gvar_get`, but that's out of the scope of this ticket) event which would fire whenever a global variable is written to. ## Context There's current an open https://bugs.ruby-lang.org/issues/15854 feature request with a PR by @st0012, but they currently do not address the global variables, so I've decided to open a new one and a new PR. There's an open gvar-specific question: should "system" global variables like `$!` trigger the `gvar_set` event? (the current implementation does not) ## Usage example ```ruby # frozen-string-literal: true TracePoint.new(:gvar_set) { p [it.gvar_name, it.return_value] }.enable do $G1 = 1 $G2 = 2 $G3 = 3 end # [:$G1, 1] # [:$G2, 2] # [:$G3, 3] ``` -- https://bugs.ruby-lang.org/

Issue #21637 has been updated by alanwu (Alan Wu).
Currently, there is no straightforward way to track global variable assignments at runtime.
There is [Kernel#trace_var](https://docs.ruby-lang.org/en/3.4/Kernel.html#method-i-trace_var) that does this. ---------------------------------------- Feature #21637: Tracing global variable assignment https://bugs.ruby-lang.org/issues/21637#change-114841 * Author: viralpraxis (Iaroslav Kurbatov) * Status: Open ---------------------------------------- ## Motivation Currently, there is no straightforward way to track global variable assignments at runtime. The only workaround I am aware of involves using the `line` TracePoint event, combined with manipulation of the source code's AST, but this approach is extremely slow and impractical. I'd like to propose a new `gvar_set` (and probably `gvar_get`, but that's out of the scope of this ticket) event which would fire whenever a global variable is written to. ## Context There's current an open https://bugs.ruby-lang.org/issues/15854 feature request with a PR by @st0012, but they currently do not address the global variables, so I've decided to open a new one and a new PR. There's an open gvar-specific question: should "system" global variables like `$!` trigger the `gvar_set` event? (the current implementation does not) ## Usage example ```ruby # frozen-string-literal: true TracePoint.new(:gvar_set) { p [it.gvar_name, it.return_value] }.enable do $G1 = 1 $G2 = 2 $G3 = 3 end # [:$G1, 1] # [:$G2, 2] # [:$G3, 3] ``` PR: https://github.com/ruby/ruby/pull/14827 -- https://bugs.ruby-lang.org/

Issue #21637 has been updated by viralpraxis (Iaroslav Kurbatov). alanwu (Alan Wu) wrote in #note-2:
Currently, there is no straightforward way to track global variable assignments at runtime.
There is [Kernel#trace_var](https://docs.ruby-lang.org/en/3.4/Kernel.html#method-i-trace_var).
I'm aware of `Kernel#trace_var`, but it does not cover cases where the global variables aren't known beforehand ---------------------------------------- Feature #21637: Tracing global variable assignment https://bugs.ruby-lang.org/issues/21637#change-114842 * Author: viralpraxis (Iaroslav Kurbatov) * Status: Open ---------------------------------------- ## Motivation Currently, there is no straightforward way to track global variable assignments at runtime. The only workaround I am aware of involves using the `line` TracePoint event, combined with manipulation of the source code's AST, but this approach is extremely slow and impractical. I'd like to propose a new `gvar_set` (and probably `gvar_get`, but that's out of the scope of this ticket) event which would fire whenever a global variable is written to. ## Context There's current an open https://bugs.ruby-lang.org/issues/15854 feature request with a PR by @st0012, but they currently do not address the global variables, so I've decided to open a new one and a new PR. There's an open gvar-specific question: should "system" global variables like `$!` trigger the `gvar_set` event? (the current implementation does not) ## Usage example ```ruby # frozen-string-literal: true TracePoint.new(:gvar_set) { p [it.gvar_name, it.return_value] }.enable do $G1 = 1 $G2 = 2 $G3 = 3 end # [:$G1, 1] # [:$G2, 2] # [:$G3, 3] ``` PR: https://github.com/ruby/ruby/pull/14827 -- https://bugs.ruby-lang.org/
participants (2)
-
alanwu (Alan Wu)
-
viralpraxis (Iaroslav Kurbatov)