There's a ruby patch to show what objects are reachable from the roots
(and the chain of references in each case):
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/151854?151368-152549
It should easy to modify it to just show the roots.
I tried to use the patch with Ruby 1.8.3 and the current CVS Trunk
snapshot as of today (2005-12-02). With Ruby 1.8.3 I had to adjust the
rb_sprintf calls to use snprintf. In order to use the patch with the
current Trunk, I had to apply part of the patch by hand. However, I got
no usable output by trying to use it on both versions, so I don't know
whether the patch is actually able to access the GC roots.
The output looks on both ruby 1.8.3 and the CVS Trunk as this:
irb(main):001:0> $a = File.open("fo", "w")
=> #<File:fo>
irb(main):002:0> $b = [$a]
=> [#<File:fo>]
irb(main):003:0> GC.reachability_paths($a)
(irb):3: warning: Checking frame stack...
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: Checking ruby_class...
(irb):3: warning: Checking ruby_scope...
(irb):3: warning: Checking save_regs_gc_mark...
(irb):3: warning: Checking stack_start...
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: Checking threads...
(irb):3: warning: Checking C globals...
(irb):3: warning: Checking end_proc...
(irb):3: warning: Checking global_tbl...
(irb):3: warning: Checking class_tbl...
(irb):3: warning: ...found, after 0 steps!
(irb):3: warning: Checking trap_list...
(irb):3: warning: Checking generic_ivar_tbl...
(irb):3: warning: Checking mark parser...
(irb):3: warning: Checking mark stack...
(irb):3: warning: Unmarking...
(irb):3: warning: Done.
=> [[], [], [], [], [], [], [], [], [], [], []]
I would have expected $a to be reachable via $b.
Best wishes,
Sven C. Koehler