File tree Expand file tree Collapse file tree 2 files changed +19
-10
lines changed
gems/codetracer-pure-ruby-recorder/lib Expand file tree Collapse file tree 2 files changed +19
-10
lines changed Original file line number Diff line number Diff line change 1- No insights yet. Please add content here and remove this line.
1+ When the pure Ruby recorder traces a script that holds a reference to the
2+ `PureRubyRecorder` instance in a local variable, the variable inspection code
3+ would recursively serialise the tracer's internal state. This results in an
4+ explosive amount of output and may appear as an infinite recursion when running
5+ `examples/selective_tracing_pure.rb`. To avoid this, `load_variables` now skips
6+ values that refer to the recorder or its `TraceRecord`.
Original file line number Diff line number Diff line change @@ -268,16 +268,20 @@ def disable_tracepoints
268268 @tracing = false
269269 end
270270
271+ # Collect local variables from the current binding and convert them
272+ # into CodeTracer values. Variables that refer to the recorder itself
273+ # (or its TraceRecord) are ignored to avoid serialising the entire
274+ # tracer state, which quickly leads to deep recursion and huge traces.
271275 def load_variables ( binding )
272- if ! binding . nil?
273- # $stdout.write binding.local_variables
274- binding . local_variables . map do |name |
275- v = binding . local_variable_get ( name )
276- out = @record . to_value ( v )
277- [ name , out ]
278- end
279- else
280- [ ]
276+ return [ ] if binding . nil?
277+
278+ binding . local_variables . filter_map do |name |
279+ v = binding . local_variable_get ( name )
280+
281+ next if v . equal? ( self ) || v . equal? ( @record )
282+
283+ out = @record . to_value ( v )
284+ [ name , out ]
281285 end
282286 end
283287 end
You can’t perform that action at this time.
0 commit comments