Friday, February 27, 2009

Devel::Peek

Consider:

$ perl -MDevel::Peek -e 'my $x; Dump($x);'
SV = NULL(0x0) at 0x9c90cdc
  REFCNT = 1
  FLAGS = (PADBUSY,PADMY)
$ perl -MDevel::Peek -e 'my $x = 10; Dump($x);'
SV = IV(0x8a5a9b0) at 0x8a3ecdc
  REFCNT = 1
  FLAGS = (PADBUSY,PADMY,IOK,pIOK)
  IV = 10
[ian@alula ~]$ perl -MDevel::Peek -e 'my $x = 10; Dump(\$x);'
SV = RV(0x809d158) at 0x8074c28
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x8074cdc
  SV = IV(0x80909b0) at 0x8074cdc
  REFCNT = 2
  FLAGS = (PADBUSY,PADMY,IOK,pIOK)
  IV = 10

What are all the addresses?

perldoc Devel::Peek doesn't say.

Every value has data stored in a structure 'struct sv'. Dump reports the address where this structure is located in memory as "at 0xXXXXXXXX". For example, in

SV = IV(0x8a5a9b0) at 0x8a3ecdc

The 'struct sv' for this SV is located at 0x8a3ecdc.

Most values (all but NULL values) also have data stored in a second, type specific structure. The 'struct sv' includes a pointer to this secondary structure. Dump reports the address where this secondary structure is located in memory in parentheses after the type of the value. For example, in

SV = IV(0x8a5a9b0) at 0x8a3ecdc

The type of the value is IV (which determines the type of the secondary structure) and the secondary structure is located at 0x8a5a9b0.

No comments:

Labels