4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bDevel\/Peek\b/) {
6 print "1..0 # Skip: Devel::Peek was not built\n";
11 use Test::More tests => 54;
16 open(SAVERR, ">&STDERR") or die "Can't dup STDERR: $!";
18 # If I reference any lexicals in this, I get the entire outer subroutine (or
19 # MAIN) dumped too, which isn't really what I want, as it's a lot of faff to
30 my $repeat_todo = $_[4];
32 if (open(OUT,">peek$$")) {
33 open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
35 print STDERR "*****\n";
36 Dump($_[1]); # second dump to compare with the first to make sure nothing changed.
37 open(STDERR, ">&SAVERR") or die "Can't restore STDERR: $!";
39 if (open(IN, "peek$$")) {
41 $pattern =~ s/\$ADDR/0x[[:xdigit:]]+/g;
42 $pattern =~ s/\$FLOAT/(?:\\d*\\.\\d+(?:e[-+]\\d+)?|\\d+)/g;
43 # handle DEBUG_LEAKING_SCALARS prefix
44 $pattern =~ s/^(\s*)(SV =.* at )/(?:$1ALLOCATED at .*?\n)?$1$2/mg;
46 # Need some clear generic mechanism to eliminate (or add) lines
47 # of dump output dependant on perl version. The (previous) use of
48 # things like $IVNV gave the illusion that the string passed in was
49 # a regexp into which variables were interpolated, but this wasn't
50 # actually true as those 'variables' actually also ate the
51 # whitspace on the line. So it seems better to mark lines that
52 # need to be eliminated. I considered (?# ... ) and (?{ ... }),
53 # but whilst embedded code or comment syntax would keep it as a
54 # legitimate regexp, it still isn't true. Seems easier and clearer
55 # things that look like comments.
57 my $version_condition = qr/\$] [<>]=? 5\.\d\d\d/;
58 # Could do this is in a s///mge but seems clearer like this:
59 $pattern = join '', map {
60 # If we identify the version condition, take *it* out whatever
61 s/\s*# ($version_condition(?: && $version_condition)?)$//
63 : $_ # Didn't match, so this line is in
64 } split /^/, $pattern;
66 $pattern =~ s/\$PADMY/
67 ($] < 5.009) ? 'PADBUSY,PADMY' : 'PADMY';
69 $pattern =~ s/\$PADTMP/
70 ($] < 5.009) ? 'PADBUSY,PADTMP' : 'PADTMP';
73 ($] < 5.011) ? 'RV' : 'IV';
76 print $pattern, "\n" if $DEBUG;
77 my ($dump, $dump2) = split m/\*\*\*\*\*\n/, scalar <IN>;
78 print $dump, "\n" if $DEBUG;
79 like( $dump, qr/\A$pattern\Z/ms,
80 "test id $_[0], line " . (caller)[2]);
83 local $TODO = $repeat_todo;
90 die "$0: failed to open peek$$: !\n";
93 die "$0: failed to create peek$$: $!\n";
103 1 while unlink("peek$$");
108 'SV = PV\\($ADDR\\) at $ADDR
110 FLAGS = \\(POK,pPOK\\)
118 'SV = PV\\($ADDR\\) at $ADDR
120 FLAGS = \\(.*POK,READONLY,pPOK\\)
127 'SV = IV\\($ADDR\\) at $ADDR
129 FLAGS = \\(IOK,pIOK\\)
134 'SV = IV\\($ADDR\\) at $ADDR
136 FLAGS = \\(.*IOK,READONLY,pIOK\\)
141 'SV = IV\\($ADDR\\) at $ADDR
143 FLAGS = \\($PADMY,IOK,pIOK\\)
146 # If perl is built with PERL_PRESERVE_IVUV then maths is done as integers
147 # where possible and this scalar will be an IV. If NO_PERL_PRESERVE_IVUV then
148 # maths is done in floating point always, and this scalar will be an NV.
149 # ([NI]) captures the type, referred to by \1 in this regexp and $type for
150 # building subsequent regexps.
151 my $type = do_test( 6,
153 'SV = ([NI])V\\($ADDR\\) at $ADDR
155 FLAGS = \\(PADTMP,\1OK,p\1OK\\)
162 'SV = PVNV\\($ADDR\\) at $ADDR
164 FLAGS = \\(NOK,pNOK\\)
166 NV = 789\\.(?:1(?:000+\d+)?|0999+\d+)
173 'SV = IV\\($ADDR\\) at $ADDR
175 FLAGS = \\(.*IOK,READONLY,pIOK\\)
180 'SV = NULL\\(0x0\\) at $ADDR
186 'SV = $RV\\($ADDR\\) at $ADDR
190 SV = PV\\($ADDR\\) at $ADDR
192 FLAGS = \\(POK,pPOK\\)
200 SV = PVNV\\($ADDR\\) at $ADDR
202 FLAGS = \\(IOK,NOK,pIOK,pNOK\\)
208 SV = IV\\($ADDR\\) at $ADDR
210 FLAGS = \\(IOK,pIOK\\)
215 'SV = $RV\\($ADDR\\) at $ADDR
219 SV = PVAV\\($ADDR\\) at $ADDR
230 SV = IV\\($ADDR\\) at $ADDR
232 FLAGS = \\(IOK,pIOK\\)
234 Elt No. 1' . $c_pattern);
238 'SV = $RV\\($ADDR\\) at $ADDR
242 SV = PVHV\\($ADDR\\) at $ADDR
244 FLAGS = \\(SHAREKEYS\\)
246 NV = $FLOAT # $] < 5.009
247 ARRAY = $ADDR \\(0:7, 1:1\\)
248 hash quality = 100.0%
254 Elt "123" HASH = $ADDR' . $c_pattern,
256 $] > 5.009 && 'The hash iterator used in dump.c sets the OOK flag');
260 'SV = $RV\\($ADDR\\) at $ADDR
264 SV = PVCV\\($ADDR\\) at $ADDR
266 FLAGS = \\($PADMY,POK,pPOK,ANON,WEAKOUTSIDE,CVGV_RC\\)
270 COMP_STASH = $ADDR\\t"main"
271 START = $ADDR ===> \\d+
273 XSUB = 0x0 # $] < 5.009
274 XSUBANY = 0 # $] < 5.009
275 GVGV::GV = $ADDR\\t"main" :: "__ANON__[^"]*"
276 FILE = ".*\\b(?i:peek\\.t)"
280 FLAGS = 0x404 # $] < 5.009
281 FLAGS = 0x490 # $] >= 5.009
284 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
285 OUTSIDE = $ADDR \\(MAIN\\)');
289 'SV = $RV\\($ADDR\\) at $ADDR
293 SV = PVCV\\($ADDR\\) at $ADDR
298 COMP_STASH = $ADDR\\t"main"
299 START = $ADDR ===> \\d+
301 XSUB = 0x0 # $] < 5.009
302 XSUBANY = 0 # $] < 5.009
303 GVGV::GV = $ADDR\\t"main" :: "do_test"
304 FILE = ".*\\b(?i:peek\\.t)"
311 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
312 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$todo"
313 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$repeat_todo"
314 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$pattern"
315 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$version_condition"
316 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" # $] < 5.009
317 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" flags=0x0 index=0 # $] >= 5.009
318 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump"
319 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump2"
320 OUTSIDE = $ADDR \\(MAIN\\)');
325 'SV = $RV\\($ADDR\\) at $ADDR
329 SV = REGEXP\\($ADDR\\) at $ADDR
331 FLAGS = \\(OBJECT,POK,FAKE,pPOK\\)
332 PV = $ADDR "\\(\\?-xism:tic\\)"
335 STASH = $ADDR\\t"Regexp"');
339 'SV = $RV\\($ADDR\\) at $ADDR
343 SV = PVMG\\($ADDR\\) at $ADDR
345 FLAGS = \\(OBJECT,SMG\\)
351 MG_TYPE = PERL_MAGIC_qr\(r\)
353 PAT = "\(\?-xism:tic\)" # $] >= 5.009
354 REFCNT = 2 # $] >= 5.009
355 STASH = $ADDR\\t"Regexp"');
360 'SV = $RV\\($ADDR\\) at $ADDR
364 SV = PVHV\\($ADDR\\) at $ADDR
366 FLAGS = \\(OBJECT,SHAREKEYS\\)
369 STASH = $ADDR\\t"Tac"
376 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
377 : "Something causes the HV's array to become allocated");
381 'SV = PVGV\\($ADDR\\) at $ADDR
383 FLAGS = \\(MULTI(?:,IN_PAD)?\\) # $] >= 5.009
384 FLAGS = \\(GMG,SMG,MULTI(?:,IN_PAD)?\\) # $] < 5.009
388 MAGIC = $ADDR # $] < 5.009
389 MG_VIRTUAL = &PL_vtbl_glob # $] < 5.009
390 MG_TYPE = PERL_MAGIC_glob\(\*\) # $] < 5.009
391 MG_OBJ = $ADDR # $] < 5.009
394 GvSTASH = $ADDR\\t"main"
404 GPFLAGS = 0x0 # $] < 5.009
406 FILE = ".*\\b(?i:peek\\.t)"
410 if (ord('A') == 193) {
412 chr(256).chr(0).chr(512),
413 'SV = PV\\($ADDR\\) at $ADDR
415 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
416 PV = $ADDR "\\\214\\\101\\\0\\\235\\\101"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
421 chr(256).chr(0).chr(512),
422 'SV = PV\\($ADDR\\) at $ADDR
424 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
425 PV = $ADDR "\\\304\\\200\\\0\\\310\\\200"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
430 if (ord('A') == 193) {
432 {chr(256)=>chr(512)},
433 'SV = $RV\\($ADDR\\) at $ADDR
437 SV = PVHV\\($ADDR\\) at $ADDR
439 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
441 NV = $FLOAT # $] < 5.009
442 ARRAY = $ADDR \\(0:7, 1:1\\)
443 hash quality = 100.0%
449 Elt "\\\214\\\101" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
450 SV = PV\\($ADDR\\) at $ADDR
452 FLAGS = \\(POK,pPOK,UTF8\\)
453 PV = $ADDR "\\\235\\\101"\\\0 \[UTF8 "\\\x\{200\}"\]
456 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
457 : 'sv_length has been called on the element, and cached the result in MAGIC');
460 {chr(256)=>chr(512)},
461 'SV = $RV\\($ADDR\\) at $ADDR
465 SV = PVHV\\($ADDR\\) at $ADDR
467 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
470 ARRAY = $ADDR \\(0:7, 1:1\\)
471 hash quality = 100.0%
477 Elt "\\\304\\\200" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
478 SV = PV\\($ADDR\\) at $ADDR
480 FLAGS = \\(POK,pPOK,UTF8\\)
481 PV = $ADDR "\\\310\\\200"\\\0 \[UTF8 "\\\x\{200\}"\]
484 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
485 : 'sv_length has been called on the element, and cached the result in MAGIC');
492 'SV = PVMG\\($ADDR\\) at $ADDR
494 FLAGS = \\($PADMY,SMG,POK,pPOK\\)
501 MG_VIRTUAL = &PL_vtbl_mglob
502 MG_TYPE = PERL_MAGIC_regex_global\\(g\\)
507 # TAINTEDDIR is not set on: OS2, AMIGAOS, WIN32, MSDOS
508 # environment variables may be invisibly case-forced, hence the (?i:PATH)
509 # C<scalar(@ARGV)> is turned into an IV on VMS hence the (?:IV)?
510 # VMS is setting FAKE and READONLY flags. What VMS uses for storing
511 # ENV hashes is also not always null terminated.
514 $ENV{PATH}=@ARGV, # scalar(@ARGV) is a handy known tainted value
515 'SV = PVMG\\($ADDR\\) at $ADDR
517 FLAGS = \\(GMG,SMG,RMG,pIOK,pPOK\\)
524 MG_VIRTUAL = &PL_vtbl_envelem
525 MG_TYPE = PERL_MAGIC_envelem\\(e\\)
529 MG_PTR = $ADDR (?:"(?i:PATH)"|=> HEf_SVKEY
530 SV = PV(?:IV)?\\($ADDR\\) at $ADDR
532 FLAGS = \\(TEMP,POK,(?:FAKE,READONLY,)?pPOK\\)
534 )? PV = $ADDR "(?i:PATH)"(?:\\\0)?
538 MG_VIRTUAL = &PL_vtbl_taint
539 MG_TYPE = PERL_MAGIC_taint\\(t\\)');
543 bless(\\undef, 'Foobar'),
544 'SV = $RV\\($ADDR\\) at $ADDR
548 SV = PVMG\\($ADDR\\) at $ADDR
550 FLAGS = \\(OBJECT,ROK\\)
554 SV = NULL\\(0x0\\) at $ADDR
556 FLAGS = \\(READONLY\\)
560 STASH = $ADDR\s+"Foobar"');
562 # Constant subroutines
570 'SV = $RV\\($ADDR\\) at $ADDR
574 SV = PVCV\\($ADDR\\) at $ADDR
576 FLAGS = \\(POK,pPOK,CONST,ISXSUB\\)
581 ROOT = 0x0 # $] < 5.009
583 XSUBANY = $ADDR \\(CONST SV\\)
584 SV = PV\\($ADDR\\) at $ADDR
586 FLAGS = \\(.*POK,READONLY,pPOK\\)
587 PV = $ADDR "Perl rules"\\\0
590 GVGV::GV = $ADDR\\t"main" :: "const"
591 FILE = ".*\\b(?i:peek\\.t)"
595 FLAGS = 0x200 # $] < 5.009
596 FLAGS = 0xc00 # $] >= 5.009 && $] < 5.013
597 FLAGS = 0xc # $] >= 5.013
600 OUTSIDE = 0x0 \\(null\\)');
602 # isUV should show on PVMG
604 do { my $v = $1; $v = ~0; $v },
605 'SV = PVMG\\($ADDR\\) at $ADDR
607 FLAGS = \\(IOK,pIOK,IsUV\\)
614 'SV = $RV\\($ADDR\\) at $ADDR
618 SV = PVIO\\($ADDR\\) at $ADDR
623 STASH = $ADDR\s+"IO::File"
634 SUBPROCESS = 0 # $] < 5.009
640 'SV = $RV\\($ADDR\\) at $ADDR
644 SV = PVFM\\($ADDR\\) at $ADDR
651 START = $ADDR ===> \\d+
653 XSUB = 0x0 # $] < 5.009
654 XSUBANY = 0 # $] < 5.009
655 GVGV::GV = $ADDR\\t"main" :: "PIE"
656 FILE = ".*\\b(?i:peek\\.t)"
664 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
665 OUTSIDE = $ADDR \\(MAIN\\)');
668 (bless {}, "\0::foo::\n::baz::\t::\0"),
669 'SV = $RV\\($ADDR\\) at $ADDR
673 SV = PVHV\\($ADDR\\) at $ADDR
675 FLAGS = \\(OBJECT,SHAREKEYS\\)
678 STASH = $ADDR\\t"\\\\0::foo::\\\\n::baz::\\\\t::\\\\0"
685 $] > 5.009 ? 'The hash iterator used in dump.c sets the OOK flag'
686 : "Something causes the HV's array to become allocated");