ActivePerl Documentation
|
NAMEDevel::Peek - A data debugging tool for the XS programmer
SUPPORTED PLATFORMS
SYNOPSIS
use Devel::Peek;
Dump( $a );
Dump( $a, 5 );
DumpArray( 5, $a, $b, ... );
mstat "Point 5";
DESCRIPTIONDevel::Peek contains functions which allows raw Perl datatypes to be manipulated from a Perl script. This is used by those who do XS programming to check that the data they are sending from C to Perl looks as they think it should look. The trick, then, is to know what the raw datatype is supposed to look like when it gets to Perl. This document offers some tips and hints to describe good and bad raw data. It is very possible that this document will fall far short of being useful to the casual reader. The reader is expected to understand the material in the first few sections of the perlguts manpage. Devel::Peek supplies a Function The global variable $Devel::Peek::pv_limit can be set to limit the number of character printed in various string values. Setting it to 0 means no limit.
EXAMPLESThe following examples don't attempt to show everything as that would be a monumental task, and, frankly, we don't want this manpage to be an internals document for Perl. The examples do demonstrate some basics of the raw Perl datatypes, and should suffice to get most determined people on their way. There are no guidewires or safety nets, nor blazed trails, so be prepared to travel alone from this point and on and, if at all possible, don't fall into the quicksand (it's bad for business). Oh, one final bit of advice: take the perlguts manpage with you. When you return we expect to see it well-thumbed.
A simple scalar stringLet's begin by looking a simple scalar which is holding a string.
use Devel::Peek;
$a = "hello";
Dump $a;
The output:
SV = PVIV(0xbc288)
REFCNT = 1
FLAGS = (POK,pPOK)
IV = 0
PV = 0xb2048 "hello"\0
CUR = 5
LEN = 6
This says
A simple scalar numberIf the scalar contains a number the raw SV will be leaner.
use Devel::Peek;
$a = 42;
Dump $a;
The output:
SV = IV(0xbc818)
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 42
This says
A simple scalar with an extra referenceIf the scalar from the previous example had an extra reference:
use Devel::Peek;
$a = 42;
$b = \$a;
Dump $a;
The output:
SV = IV(0xbe860)
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 42
Notice that this example differs from the previous example only in its
reference count. Compare this to the next example, where we dump
A reference to a simple scalarThis shows what a reference looks like when it references a simple scalar.
use Devel::Peek;
$a = 42;
$b = \$a;
Dump $b;
The output:
SV = RV(0xf041c)
REFCNT = 1
FLAGS = (ROK)
RV = 0xbab08
SV = IV(0xbe860)
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 42
Starting from the top, this says Note that the value of
A reference to an arrayThis shows what a reference to an array looks like.
use Devel::Peek;
$a = [42];
Dump $a;
The output:
SV = RV(0xf041c)
REFCNT = 1
FLAGS = (ROK)
RV = 0xb2850
SV = PVAV(0xbd448)
REFCNT = 1
FLAGS = ()
IV = 0
NV = 0
ARRAY = 0xb2048
ALLOC = 0xb2048
FILL = 0
MAX = 0
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0 0xb5658
SV = IV(0xbe860)
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 42
This says If
use Devel::Peek 'Dump';
$a = [42,24];
Dump $a;
The output:
SV = RV(0xf041c)
REFCNT = 1
FLAGS = (ROK)
RV = 0xb2850
SV = PVAV(0xbd448)
REFCNT = 1
FLAGS = ()
IV = 0
NV = 0
ARRAY = 0xb2048
ALLOC = 0xb2048
FILL = 0
MAX = 0
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0 0xb5658
SV = IV(0xbe860)
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 42
Elt No. 1 0xb5680
SV = IV(0xbe818)
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 24
Note that
A reference to a hashThe following shows the raw form of a reference to a hash.
use Devel::Peek;
$a = {hello=>42};
Dump $a;
The output:
SV = RV(0xf041c)
REFCNT = 1
FLAGS = (ROK)
RV = 0xb2850
SV = PVHV(0xbd448)
REFCNT = 1
FLAGS = ()
NV = 0
ARRAY = 0xbd748
KEYS = 1
FILL = 1
MAX = 7
RITER = -1
EITER = 0x0
Elt "hello" => 0xbaaf0
SV = IV(0xbe860)
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 42
This shows
Dumping a large array or hashThe
use Devel::Peek;
$a = [10,11,12,13,14];
Dump $a;
Notice that
use Devel::Peek 'Dump';
$a = [10,11,12,13,14];
Dump $a, 5;
A reference to an SV which holds a C pointerThis is what you really need to know as an XS programmer, of course. When an XSUB returns a pointer to a C structure that pointer is stored in an SV and a reference to that SV is placed on the XSUB stack. So the output from an XSUB which uses something like the T_PTROBJ map might look something like this:
SV = RV(0xf381c)
REFCNT = 1
FLAGS = (ROK)
RV = 0xb8ad8
SV = PVMG(0xbb3c8)
REFCNT = 1
FLAGS = (OBJECT,IOK,pIOK)
IV = 729160
NV = 0
PV = 0
STASH = 0xc1d10 "CookBookB::Opaque"
This shows that we have an SV which is an RV. That RV points at another
SV. In this case that second SV is a PVMG, a blessed scalar. Because it is
blessed it has the The output from an XSUB which uses something like the T_PTRREF map, which doesn't bless the object, might look something like this:
SV = RV(0xf381c)
REFCNT = 1
FLAGS = (ROK)
RV = 0xb8ad8
SV = PVMG(0xbb3c8)
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 729160
NV = 0
PV = 0
A reference to a subroutineLooks like this:
SV = RV(0x798ec)
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x1d453c
SV = PVCV(0x1c768c)
REFCNT = 2
FLAGS = ()
IV = 0
NV = 0
COMP_STASH = 0x31068 "main"
START = 0xb20e0
ROOT = 0xbece0
XSUB = 0x0
XSUBANY = 0
GVGV::GV = 0x1d44e8 "MY" :: "top_targets"
FILE = "(eval 5)"
DEPTH = 0
PADLIST = 0x1c9338
This shows that
EXPORTS
BUGSReaders have been known to skip important parts of the perlguts manpage, causing much frustration for all.
AUTHORIlya Zakharevich ilya@math.ohio-state.edu Copyright (c) 1995-98 Ilya Zakharevich. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Author of this software makes no claim whatsoever about suitability, reliability, edability, editability or usability of this product, and should not be kept liable for any damage resulting from the use of it. If you can use it, you are in luck, if not, I should not be kept responsible. Keep a handy copy of your backup tape at hand.
SEE ALSOthe perlguts manpage, and the perlguts manpage, again.
|