My gladiators are getting entangled

Hi, I've had a long-standing interesting in having a nice way to browse through perl's memory space. Here's today's attempt. It almost works great except that the two introspection modules Devel::FindRef and Devel::Gladiator don't know enough to stay hands-off from each other.

require Data::Dumper;
# require Data::Dump::Streamer;
require Devel::Gladiator;
require Devel::FindRef;
require Scalar::Util;
require B;

my %SKIP_REF;
my $all;

$SKIP_REF{ Scalar::Util::refaddr( \ %SKIP_REF  ) } = undef;
$SKIP_REF{ Scalar::Util::refaddr( \ %seen      ) } = undef;

$all = Devel::Gladiator::walk_arena();
for ( @$all ) {
    Devel::Peek::SvREFCNT_inc( $_ );
    print STDERR Data::Dumper::Dumper($_);

    # Skip the local variables
    next if
        # Skip any variables local to this probe
        exists( $SKIP_REF{ Scalar::Util::refaddr( $_ ) } )

        # Skip the global shared hash
        || ( 'HASH' eq Scalar::Util::reftype( $_ )
             && ! ( B::svref_2object( $_ )->FLAGS() & 0x2000_0000 ) )
    ;

    print STDERR Devel::FindRef::track( $_ );
}
print STDERR "Decrementing refcnts\n";
Devel::Peek::SvREFCNT_dec($_) for @$all;
print STDERR "Done\n";

Here's a sample of the output before any attempts to make this less voluminous:

$VAR_0x17b308f81 = \*B::RXf_PMf_EXTENDED;
GLOB(0x17b308f8) [refcount 5] is
+- referenced by REF(0x17b81148) [refcount 1], which is
|  the array element 1 of ARRAY(0x17b81118) [refcount 1], which is
|     referenced by REF(0x17b81178) [refcount 1], which is
|        the member '\{f8}\{08}\{b3}\{17}' of HASH(0x17b80e30) [refcount 1], which is
|           referenced by REF(0x17b80f20) [refcount 1], which is
|              the member 'seen' of Data::Dumper=HASH(0x17b80e60) [refcount 3], which is
|                 +- referenced by REF(0x17a3b6b8) [refcount 1], which is
|                 |  referenced by REF(0x17afe3f8) [refcount 1], which is
|                 |     the array element 5296 of ARRAY(0x17b16018) [refcount 2], which is
|                 |        referenced by REF(0x179f5730) [refcount 2], which is
|                 |              not referenced within the search depth.
|                 +- referenced by REF(0x17a306d8) [refcount 1], which is
|                 |  referenced by REF(0x17b59868) [refcount 1], which is
|                 |     the array element 5461 of ARRAY(0x17b16018) [refcount 2], which was seen before.
|                 +- referenced by REF(0x17a21f78) [refcount 1], which is
|                    referenced by REF(0x17b57360) [refcount 1], which is
|                       the array element 5856 of ARRAY(0x17b16018) [refcount 2], which was seen before.
+- referenced by REF(0x17b80db8) [refcount 1], which is
|  the array element 0 of ARRAY(0x17b80da0) [refcount 2], which is
|     +- referenced by REF(0x17b80f38) [refcount 1], which is
|     |  the member 'todump' of Data::Dumper=HASH(0x17b80e60) [refcount 3], which was seen before.
|     +- referenced by REF(0x17a21e70) [refcount 1], which is
|        referenced by REF(0x17b57468) [refcount 1], which is
|           the array element 5845 of ARRAY(0x17b16018) [refcount 2], which was seen before.
+- referenced by REF(0x17b80d70) [refcount 3], which is
|  +- the array element 0 of ARRAY(0x17b16018) [refcount 2], which was seen before.
|  +- the global $main::_.
+- referenced by REF(0x17a3b6e8) [refcount 1], which is
|  referenced by REF(0x17afe3c8) [refcount 1], which is
|     the array element 5298 of ARRAY(0x17b16018) [refcount 2], which was seen before.
+- the member 'RXf_PMf_EXTENDED' of HASH(0x179f5670) [refcount 3], which is
+- referenced by REF(0x17b54420) [refcount 1], which is
|  the array element 6360 of ARRAY(0x17b16018) [refcount 2], which was seen before.
+- the global %main::B::.
$VAR_0x17b309101 = sub () { 32768 };
CODE(0x17b30910) [refcount 2] is
+- referenced by REF(0x17b80d58) [refcount 3], which is
|  +- the array element 1 of ARRAY(0x17b16018) [refcount 2], which is
|  |  referenced by REF(0x179f5730) [refcount 2], which is
|  |     +- referenced by REF(0x17b54360) [refcount 1], which is
|  |     |  the array element 6368 of ARRAY(0x17b16018) [refcount 2], which was seen before.
|  |     +- the lexical '$all' in CODE(0x179d7530) [refcount 1], which is
|  |        the main body of the program.
|  +- the global $main::_.
+- the global &B::RXf_PMf_EXTENDED.

Leave a comment

About Josh ben Jore

user-pic I blog about Perl.