diff --git a/ext/objspace/lib/objspace/trace.rb b/ext/objspace/lib/objspace/trace.rb new file mode 100644 index 0000000000..fa122e3eb1 --- /dev/null +++ b/ext/objspace/lib/objspace/trace.rb @@ -0,0 +1,19 @@ +require 'objspace.so' + +module Kernel + define_method(:p) do |*objs| + objs.each do |obj| + file = ObjectSpace.allocation_sourcefile(obj) + line = ObjectSpace.allocation_sourceline(obj) + if file + puts "#{ obj.inspect } @ #{ file }:#{ line }" + else + puts obj.inspect + end + end + end +end + +ObjectSpace.trace_object_allocations_start + +warn "objspace/trace is enabled"