This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix Peek.t
[perl5.git] / ext / Devel-Peek / t / Peek.t
CommitLineData
99331854 1#!./perl -T
9ec58fb7
JH
2
3BEGIN {
9ec58fb7 4 require Config; import Config;
e7ecf62c 5 if ($Config{'extensions'} !~ /\bDevel\/Peek\b/) {
9ec58fb7
JH
6 print "1..0 # Skip: Devel::Peek was not built\n";
7 exit 0;
8 }
9}
10
06a5cade 11use Test::More;
e7ecf62c 12
9248c45a
JH
13use Devel::Peek;
14
9248c45a 15our $DEBUG = 0;
277ddfaf 16open(SAVERR, ">&STDERR") or die "Can't dup STDERR: $!";
9248c45a 17
bfe27a58
NC
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
20# maintain that.
21format PIE =
22Pie @<<<<<
23$::type
24Good @>>>>>
25$::mmmm
26.
27
bad4ae38
FC
28use constant thr => $Config{useithreads};
29
9248c45a 30sub do_test {
000fd473
NC
31 my $todo = $_[3];
32 my $repeat_todo = $_[4];
33 my $pattern = $_[2];
277ddfaf
GS
34 if (open(OUT,">peek$$")) {
35 open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
9248c45a 36 Dump($_[1]);
e9569a7a
GG
37 print STDERR "*****\n";
38 Dump($_[1]); # second dump to compare with the first to make sure nothing changed.
277ddfaf
GS
39 open(STDERR, ">&SAVERR") or die "Can't restore STDERR: $!";
40 close(OUT);
9248c45a
JH
41 if (open(IN, "peek$$")) {
42 local $/;
43 $pattern =~ s/\$ADDR/0x[[:xdigit:]]+/g;
8aacddc1 44 $pattern =~ s/\$FLOAT/(?:\\d*\\.\\d+(?:e[-+]\\d+)?|\\d+)/g;
fd0854ff 45 # handle DEBUG_LEAKING_SCALARS prefix
d94a5950 46 $pattern =~ s/^(\s*)(SV =.* at )/(?:$1ALLOCATED at .*?\n)?$1$2/mg;
bf53b3a5 47
000fd473
NC
48 # Need some clear generic mechanism to eliminate (or add) lines
49 # of dump output dependant on perl version. The (previous) use of
50 # things like $IVNV gave the illusion that the string passed in was
51 # a regexp into which variables were interpolated, but this wasn't
52 # actually true as those 'variables' actually also ate the
b7b1e41b 53 # whitespace on the line. So it seems better to mark lines that
000fd473
NC
54 # need to be eliminated. I considered (?# ... ) and (?{ ... }),
55 # but whilst embedded code or comment syntax would keep it as a
56 # legitimate regexp, it still isn't true. Seems easier and clearer
57 # things that look like comments.
58
59 # Could do this is in a s///mge but seems clearer like this:
60 $pattern = join '', map {
61 # If we identify the version condition, take *it* out whatever
bad4ae38 62 s/\s*# (\$].*)$//
000fd473
NC
63 ? (eval $1 ? $_ : '')
64 : $_ # Didn't match, so this line is in
65 } split /^/, $pattern;
66
67 $pattern =~ s/\$PADMY/
68 ($] < 5.009) ? 'PADBUSY,PADMY' : 'PADMY';
69 /mge;
70 $pattern =~ s/\$PADTMP/
71 ($] < 5.009) ? 'PADBUSY,PADTMP' : 'PADTMP';
72 /mge;
2b631c93
NC
73 $pattern =~ s/\$RV/
74 ($] < 5.011) ? 'RV' : 'IV';
75 /mge;
d04ba589 76
9248c45a 77 print $pattern, "\n" if $DEBUG;
e9569a7a 78 my ($dump, $dump2) = split m/\*\*\*\*\*\n/, scalar <IN>;
9248c45a 79 print $dump, "\n" if $DEBUG;
06a5cade
NC
80 like( $dump, qr/\A$pattern\Z/ms, $_[0])
81 or note("line " . (caller)[2]);
e9569a7a 82
000fd473 83 local $TODO = $repeat_todo;
06a5cade
NC
84 is($dump2, $dump, "$_[0] (unchanged by dump)")
85 or note("line " . (caller)[2]);
e9569a7a 86
9248c45a 87 close(IN);
e9569a7a 88
59d8ce62 89 return $1;
9248c45a
JH
90 } else {
91 die "$0: failed to open peek$$: !\n";
92 }
93 } else {
94 die "$0: failed to create peek$$: $!\n";
95 }
96}
97
98our $a;
99our $b;
100my $c;
208edb77 101local $d = 0;
9248c45a 102
e7ecf62c
RGS
103END {
104 1 while unlink("peek$$");
105}
bf53b3a5 106
06a5cade 107do_test('assignment of immediate constant (string)',
9248c45a
JH
108 $a = "foo",
109'SV = PV\\($ADDR\\) at $ADDR
110 REFCNT = 1
111 FLAGS = \\(POK,pPOK\\)
112 PV = $ADDR "foo"\\\0
113 CUR = 3
1badabf5 114 LEN = \\d+'
9248c45a
JH
115 );
116
06a5cade 117do_test('immediate constant (string)',
9248c45a
JH
118 "bar",
119'SV = PV\\($ADDR\\) at $ADDR
120 REFCNT = 1
7766e686 121 FLAGS = \\(.*POK,READONLY,pPOK\\)
9248c45a
JH
122 PV = $ADDR "bar"\\\0
123 CUR = 3
1badabf5 124 LEN = \\d+');
9248c45a 125
b7b1e41b 126do_test('assignment of immediate constant (integer)',
9248c45a
JH
127 $b = 123,
128'SV = IV\\($ADDR\\) at $ADDR
129 REFCNT = 1
130 FLAGS = \\(IOK,pIOK\\)
131 IV = 123');
132
06a5cade 133do_test('immediate constant (integer)',
9248c45a
JH
134 456,
135'SV = IV\\($ADDR\\) at $ADDR
136 REFCNT = 1
7766e686 137 FLAGS = \\(.*IOK,READONLY,pIOK\\)
9248c45a
JH
138 IV = 456');
139
06a5cade 140do_test('assignment of immediate constant (integer)',
9248c45a
JH
141 $c = 456,
142'SV = IV\\($ADDR\\) at $ADDR
143 REFCNT = 1
000fd473 144 FLAGS = \\($PADMY,IOK,pIOK\\)
9248c45a
JH
145 IV = 456');
146
59d8ce62
NC
147# If perl is built with PERL_PRESERVE_IVUV then maths is done as integers
148# where possible and this scalar will be an IV. If NO_PERL_PRESERVE_IVUV then
149# maths is done in floating point always, and this scalar will be an NV.
150# ([NI]) captures the type, referred to by \1 in this regexp and $type for
151# building subsequent regexps.
06a5cade 152my $type = do_test('result of addition',
9248c45a 153 $c + $d,
59d8ce62 154'SV = ([NI])V\\($ADDR\\) at $ADDR
9248c45a 155 REFCNT = 1
59d8ce62
NC
156 FLAGS = \\(PADTMP,\1OK,p\1OK\\)
157 \1V = 456');
9248c45a
JH
158
159($d = "789") += 0.1;
160
06a5cade 161do_test('floating point value',
9248c45a
JH
162 $d,
163'SV = PVNV\\($ADDR\\) at $ADDR
164 REFCNT = 1
165 FLAGS = \\(NOK,pNOK\\)
78d00c47 166 IV = \d+
ac634a9a 167 NV = 789\\.(?:1(?:000+\d+)?|0999+\d+)
9248c45a
JH
168 PV = $ADDR "789"\\\0
169 CUR = 3
1badabf5 170 LEN = \\d+');
9248c45a 171
06a5cade 172do_test('integer constant',
9248c45a
JH
173 0xabcd,
174'SV = IV\\($ADDR\\) at $ADDR
175 REFCNT = 1
28e5dec8
JH
176 FLAGS = \\(.*IOK,READONLY,pIOK\\)
177 IV = 43981');
9248c45a 178
06a5cade 179do_test('undef',
9248c45a
JH
180 undef,
181'SV = NULL\\(0x0\\) at $ADDR
182 REFCNT = 1
183 FLAGS = \\(\\)');
184
06a5cade 185do_test('reference to scalar',
9248c45a 186 \$a,
4df7f6af 187'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
188 REFCNT = 1
189 FLAGS = \\(ROK\\)
190 RV = $ADDR
191 SV = PV\\($ADDR\\) at $ADDR
192 REFCNT = 2
193 FLAGS = \\(POK,pPOK\\)
194 PV = $ADDR "foo"\\\0
195 CUR = 3
1badabf5 196 LEN = \\d+');
9248c45a 197
59d8ce62
NC
198my $c_pattern;
199if ($type eq 'N') {
200 $c_pattern = '
201 SV = PVNV\\($ADDR\\) at $ADDR
202 REFCNT = 1
203 FLAGS = \\(IOK,NOK,pIOK,pNOK\\)
204 IV = 456
205 NV = 456
206 PV = 0';
207} else {
208 $c_pattern = '
209 SV = IV\\($ADDR\\) at $ADDR
210 REFCNT = 1
211 FLAGS = \\(IOK,pIOK\\)
212 IV = 456';
213}
06a5cade 214do_test('reference to array',
9248c45a 215 [$b,$c],
4df7f6af 216'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
217 REFCNT = 1
218 FLAGS = \\(ROK\\)
219 RV = $ADDR
220 SV = PVAV\\($ADDR\\) at $ADDR
78c72037 221 REFCNT = 1
9248c45a 222 FLAGS = \\(\\)
1bcecb77
NC
223 IV = 0 # $] < 5.009
224 NV = 0 # $] < 5.009
9248c45a
JH
225 ARRAY = $ADDR
226 FILL = 1
227 MAX = 1
228 ARYLEN = 0x0
229 FLAGS = \\(REAL\\)
230 Elt No. 0
231 SV = IV\\($ADDR\\) at $ADDR
232 REFCNT = 1
233 FLAGS = \\(IOK,pIOK\\)
234 IV = 123
59d8ce62 235 Elt No. 1' . $c_pattern);
9248c45a 236
06a5cade 237do_test('reference to hash',
9248c45a 238 {$b=>$c},
4df7f6af 239'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
240 REFCNT = 1
241 FLAGS = \\(ROK\\)
242 RV = $ADDR
243 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 244 REFCNT = 1
9248c45a 245 FLAGS = \\(SHAREKEYS\\)
1bcecb77
NC
246 IV = 1 # $] < 5.009
247 NV = $FLOAT # $] < 5.009
9248c45a 248 ARRAY = $ADDR \\(0:7, 1:1\\)
b8fa94d8 249 hash quality = 100.0%
9248c45a
JH
250 KEYS = 1
251 FILL = 1
252 MAX = 7
253 RITER = -1
254 EITER = 0x0
000fd473
NC
255 Elt "123" HASH = $ADDR' . $c_pattern,
256 '',
f3ce8053
FC
257 $] > 5.009 && $] < 5.015
258 && 'The hash iterator used in dump.c sets the OOK flag');
9248c45a 259
06a5cade 260do_test('reference to anon sub with empty prototype',
9248c45a 261 sub(){@_},
4df7f6af 262'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
263 REFCNT = 1
264 FLAGS = \\(ROK\\)
265 RV = $ADDR
266 SV = PVCV\\($ADDR\\) at $ADDR
267 REFCNT = 2
bad4ae38
FC
268 FLAGS = \\($PADMY,POK,pPOK,ANON,WEAKOUTSIDE,CVGV_RC\\) # $] < 5.015 || !thr
269 FLAGS = \\($PADMY,POK,pPOK,ANON,WEAKOUTSIDE,CVGV_RC,DYNFILE\\) # $] >= 5.015 && thr
1bcecb77
NC
270 IV = 0 # $] < 5.009
271 NV = 0 # $] < 5.009
9248c45a
JH
272 PROTOTYPE = ""
273 COMP_STASH = $ADDR\\t"main"
274 START = $ADDR ===> \\d+
275 ROOT = $ADDR
1bcecb77
NC
276 XSUB = 0x0 # $] < 5.009
277 XSUBANY = 0 # $] < 5.009
208edb77 278 GVGV::GV = $ADDR\\t"main" :: "__ANON__[^"]*"
084d946d 279 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
280 DEPTH = 0(?:
281 MUTEXP = $ADDR
282 OWNER = $ADDR)?
1bcecb77 283 FLAGS = 0x404 # $] < 5.009
bad4ae38
FC
284 FLAGS = 0x490 # $] >= 5.009 && ($] < 5.015 || !thr)
285 FLAGS = 0x1490 # $] >= 5.015 && thr
a3985cdc 286 OUTSIDE_SEQ = \\d+
9248c45a 287 PADLIST = $ADDR
dd2155a4 288 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
9248c45a
JH
289 OUTSIDE = $ADDR \\(MAIN\\)');
290
06a5cade 291do_test('reference to named subroutine without prototype',
9248c45a 292 \&do_test,
4df7f6af 293'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
294 REFCNT = 1
295 FLAGS = \\(ROK\\)
296 RV = $ADDR
297 SV = PVCV\\($ADDR\\) at $ADDR
9856a127 298 REFCNT = (3|4)
2156df4b
FC
299 FLAGS = \\((?:HASEVAL)?\\) # $] < 5.015 || !thr
300 FLAGS = \\(DYNFILE(?:,HASEVAL)?\\) # $] >= 5.015 && thr
1bcecb77
NC
301 IV = 0 # $] < 5.009
302 NV = 0 # $] < 5.009
9248c45a
JH
303 COMP_STASH = $ADDR\\t"main"
304 START = $ADDR ===> \\d+
305 ROOT = $ADDR
1bcecb77
NC
306 XSUB = 0x0 # $] < 5.009
307 XSUBANY = 0 # $] < 5.009
9248c45a 308 GVGV::GV = $ADDR\\t"main" :: "do_test"
084d946d 309 FILE = ".*\\b(?i:peek\\.t)"
bad4ae38
FC
310 DEPTH = 1(?:
311 MUTEXP = $ADDR
312 OWNER = $ADDR)?
2156df4b
FC
313 FLAGS = 0x(?:400)?0 # $] < 5.015 || !thr
314 FLAGS = 0x[145]000 # $] >= 5.015 && thr
a3985cdc 315 OUTSIDE_SEQ = \\d+
9248c45a 316 PADLIST = $ADDR
dd2155a4 317 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
000fd473
NC
318 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$todo"
319 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$repeat_todo"
ee6cee0c 320 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$pattern"
000fd473
NC
321 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" # $] < 5.009
322 \\d+\\. $ADDR<\\d+> FAKE "\\$DEBUG" flags=0x0 index=0 # $] >= 5.009
ee6cee0c 323 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump"
e9569a7a 324 \\d+\\. $ADDR<\\d+> \\(\\d+,\\d+\\) "\\$dump2"
9248c45a
JH
325 OUTSIDE = $ADDR \\(MAIN\\)');
326
3ce3ed55 327if ($] >= 5.011) {
06a5cade 328do_test('reference to regexp',
3ce3ed55
NC
329 qr(tic),
330'SV = $RV\\($ADDR\\) at $ADDR
331 REFCNT = 1
332 FLAGS = \\(ROK\\)
333 RV = $ADDR
5c35adbb 334 SV = REGEXP\\($ADDR\\) at $ADDR
c2123ae3 335 REFCNT = 1
b9ad13ac 336 FLAGS = \\(OBJECT,POK,FAKE,pPOK\\)
fb85c044
KW
337 PV = $ADDR "\\(\\?\\^:tic\\)"
338 CUR = 8
c2123ae3 339 LEN = 0
d63e6659
DM
340 STASH = $ADDR\\t"Regexp"'
341. ($] < 5.013 ? '' :
342'
343 EXTFLAGS = 0x680000 \(CHECK_ALL,USE_INTUIT_NOML,USE_INTUIT_ML\)
344 INTFLAGS = 0x0
345 NPARENS = 0
346 LASTPAREN = 0
347 LASTCLOSEPAREN = 0
348 MINLEN = 3
349 MINLENRET = 3
350 GOFS = 0
351 PRE_PREFIX = 4
d63e6659 352 SUBLEN = 0
6502e081
DM
353 SUBOFFSET = 0
354 SUBCOFFSET = 0
d63e6659
DM
355 SUBBEG = 0x0
356 ENGINE = $ADDR
357 MOTHER_RE = $ADDR
358 PAREN_NAMES = 0x0
359 SUBSTRS = $ADDR
360 PPRIVATE = $ADDR
d63c20f2
DM
361 OFFS = $ADDR
362 QR_ANONCV = 0x0'
d63e6659 363));
3ce3ed55 364} else {
06a5cade 365do_test('reference to regexp',
9248c45a 366 qr(tic),
4df7f6af 367'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
368 REFCNT = 1
369 FLAGS = \\(ROK\\)
370 RV = $ADDR
371 SV = PVMG\\($ADDR\\) at $ADDR
372 REFCNT = 1
faf82a0b 373 FLAGS = \\(OBJECT,SMG\\)
9248c45a
JH
374 IV = 0
375 NV = 0
376 PV = 0
377 MAGIC = $ADDR
378 MG_VIRTUAL = $ADDR
14befaf4 379 MG_TYPE = PERL_MAGIC_qr\(r\)
9248c45a 380 MG_OBJ = $ADDR
fb85c044 381 PAT = "\(\?^:tic\)" # $] >= 5.009
1bcecb77 382 REFCNT = 2 # $] >= 5.009
9248c45a 383 STASH = $ADDR\\t"Regexp"');
3ce3ed55 384}
9248c45a 385
06a5cade 386do_test('reference to blessed hash',
9248c45a 387 (bless {}, "Tac"),
4df7f6af 388'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
389 REFCNT = 1
390 FLAGS = \\(ROK\\)
391 RV = $ADDR
392 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 393 REFCNT = 1
9248c45a 394 FLAGS = \\(OBJECT,SHAREKEYS\\)
1bcecb77
NC
395 IV = 0 # $] < 5.009
396 NV = 0 # $] < 5.009
9248c45a
JH
397 STASH = $ADDR\\t"Tac"
398 ARRAY = 0x0
399 KEYS = 0
400 FILL = 0
401 MAX = 7
402 RITER = -1
000fd473 403 EITER = 0x0', '',
f3ce8053
FC
404 $] > 5.009
405 ? $] >= 5.015
406 ? 0
407 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 408 : "Something causes the HV's array to become allocated");
9248c45a 409
06a5cade 410do_test('typeglob',
9248c45a
JH
411 *a,
412'SV = PVGV\\($ADDR\\) at $ADDR
413 REFCNT = 5
000fd473
NC
414 FLAGS = \\(MULTI(?:,IN_PAD)?\\) # $] >= 5.009
415 FLAGS = \\(GMG,SMG,MULTI(?:,IN_PAD)?\\) # $] < 5.009
416 IV = 0 # $] < 5.009
417 NV = 0 # $] < 5.009
418 PV = 0 # $] < 5.009
419 MAGIC = $ADDR # $] < 5.009
420 MG_VIRTUAL = &PL_vtbl_glob # $] < 5.009
421 MG_TYPE = PERL_MAGIC_glob\(\*\) # $] < 5.009
422 MG_OBJ = $ADDR # $] < 5.009
9248c45a
JH
423 NAME = "a"
424 NAMELEN = 1
425 GvSTASH = $ADDR\\t"main"
426 GP = $ADDR
427 SV = $ADDR
428 REFCNT = 1
429 IO = 0x0
430 FORM = 0x0
431 AV = 0x0
432 HV = 0x0
433 CV = 0x0
434 CVGEN = 0x0
000fd473 435 GPFLAGS = 0x0 # $] < 5.009
9ec58fb7 436 LINE = \\d+
084d946d 437 FILE = ".*\\b(?i:peek\\.t)"
e39917cc 438 FLAGS = $ADDR
9248c45a
JH
439 EGV = $ADDR\\t"a"');
440
cdb2dd7b 441if (ord('A') == 193) {
06a5cade 442do_test('string with Unicode',
cdb2dd7b
JH
443 chr(256).chr(0).chr(512),
444'SV = PV\\($ADDR\\) at $ADDR
445 REFCNT = 1
000fd473 446 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
cdb2dd7b
JH
447 PV = $ADDR "\\\214\\\101\\\0\\\235\\\101"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
448 CUR = 5
1badabf5 449 LEN = \\d+');
cdb2dd7b 450} else {
06a5cade 451do_test('string with Unicode',
e6abe6d8
JH
452 chr(256).chr(0).chr(512),
453'SV = PV\\($ADDR\\) at $ADDR
454 REFCNT = 1
000fd473 455 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
98c991d1 456 PV = $ADDR "\\\304\\\200\\\0\\\310\\\200"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
e6abe6d8 457 CUR = 5
1badabf5 458 LEN = \\d+');
cdb2dd7b 459}
e6abe6d8 460
cdb2dd7b 461if (ord('A') == 193) {
06a5cade 462do_test('reference to hash containing Unicode',
cdb2dd7b 463 {chr(256)=>chr(512)},
4df7f6af 464'SV = $RV\\($ADDR\\) at $ADDR
cdb2dd7b
JH
465 REFCNT = 1
466 FLAGS = \\(ROK\\)
467 RV = $ADDR
468 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 469 REFCNT = 1
b2caaddd 470 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
471 UV = 1 # $] < 5.009
472 NV = $FLOAT # $] < 5.009
cdb2dd7b
JH
473 ARRAY = $ADDR \\(0:7, 1:1\\)
474 hash quality = 100.0%
475 KEYS = 1
476 FILL = 1
477 MAX = 7
478 RITER = -1
479 EITER = $ADDR
6cbfa5b4 480 Elt "\\\214\\\101" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
cdb2dd7b
JH
481 SV = PV\\($ADDR\\) at $ADDR
482 REFCNT = 1
483 FLAGS = \\(POK,pPOK,UTF8\\)
484 PV = $ADDR "\\\235\\\101"\\\0 \[UTF8 "\\\x\{200\}"\]
485 CUR = 2
000fd473 486 LEN = \\d+',
f3ce8053
FC
487 $] > 5.009
488 ? $] >= 5.015
489 ? 0
490 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 491 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 492} else {
06a5cade 493do_test('reference to hash containing Unicode',
98c991d1 494 {chr(256)=>chr(512)},
4df7f6af 495'SV = $RV\\($ADDR\\) at $ADDR
98c991d1
JH
496 REFCNT = 1
497 FLAGS = \\(ROK\\)
498 RV = $ADDR
499 SV = PVHV\\($ADDR\\) at $ADDR
78c72037 500 REFCNT = 1
19692e8d 501 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
502 UV = 1 # $] < 5.009
503 NV = 0 # $] < 5.009
98c991d1
JH
504 ARRAY = $ADDR \\(0:7, 1:1\\)
505 hash quality = 100.0%
506 KEYS = 1
507 FILL = 1
508 MAX = 7
509 RITER = -1
510 EITER = $ADDR
511 Elt "\\\304\\\200" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
512 SV = PV\\($ADDR\\) at $ADDR
513 REFCNT = 1
514 FLAGS = \\(POK,pPOK,UTF8\\)
515 PV = $ADDR "\\\310\\\200"\\\0 \[UTF8 "\\\x\{200\}"\]
516 CUR = 2
000fd473 517 LEN = \\d+', '',
f3ce8053
FC
518 $] > 5.009
519 ? $] >= 5.015
520 ? 0
521 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 522 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 523}
98c991d1 524
99331854
YST
525my $x="";
526$x=~/.??/g;
06a5cade 527do_test('scalar with pos magic',
99331854
YST
528 $x,
529'SV = PVMG\\($ADDR\\) at $ADDR
530 REFCNT = 1
000fd473 531 FLAGS = \\($PADMY,SMG,POK,pPOK\\)
99331854
YST
532 IV = 0
533 NV = 0
534 PV = $ADDR ""\\\0
535 CUR = 0
1936d2a7 536 LEN = \d+
99331854
YST
537 MAGIC = $ADDR
538 MG_VIRTUAL = &PL_vtbl_mglob
539 MG_TYPE = PERL_MAGIC_regex_global\\(g\\)
540 MG_FLAGS = 0x01
541 MINMATCH');
542
f24fdb76
HS
543#
544# TAINTEDDIR is not set on: OS2, AMIGAOS, WIN32, MSDOS
545# environment variables may be invisibly case-forced, hence the (?i:PATH)
5e836f43 546# C<scalar(@ARGV)> is turned into an IV on VMS hence the (?:IV)?
12033064
CS
547# Perl 5.18 ensures all env vars end up as strings only, hence the (?:,pIOK)?
548# Perl 5.18 ensures even magic vars have public OK, hence the (?:,POK)?
d9baf692
JM
549# VMS is setting FAKE and READONLY flags. What VMS uses for storing
550# ENV hashes is also not always null terminated.
f24fdb76 551#
06a5cade 552do_test('tainted value in %ENV',
99331854
YST
553 $ENV{PATH}=@ARGV, # scalar(@ARGV) is a handy known tainted value
554'SV = PVMG\\($ADDR\\) at $ADDR
555 REFCNT = 1
12033064 556 FLAGS = \\(GMG,SMG,RMG(?:,POK)?(?:,pIOK)?,pPOK\\)
99331854
YST
557 IV = 0
558 NV = 0
559 PV = $ADDR "0"\\\0
560 CUR = 1
561 LEN = \d+
562 MAGIC = $ADDR
563 MG_VIRTUAL = &PL_vtbl_envelem
564 MG_TYPE = PERL_MAGIC_envelem\\(e\\)
d25a523c 565(?: MG_FLAGS = 0x01
99331854 566 TAINTEDDIR
143a3e5e
CB
567)? MG_LEN = -?\d+
568 MG_PTR = $ADDR (?:"(?i:PATH)"|=> HEf_SVKEY
5e836f43 569 SV = PV(?:IV)?\\($ADDR\\) at $ADDR
143a3e5e 570 REFCNT = \d+
11e2783c 571 FLAGS = \\(TEMP,POK,(?:FAKE,READONLY,)?pPOK\\)
f0fabfd7 572(?: IV = 0
d9baf692 573)? PV = $ADDR "(?i:PATH)"(?:\\\0)?
143a3e5e
CB
574 CUR = \d+
575 LEN = \d+)
99331854
YST
576 MAGIC = $ADDR
577 MG_VIRTUAL = &PL_vtbl_taint
578 MG_TYPE = PERL_MAGIC_taint\\(t\\)');
579
06a5cade 580do_test('blessed reference',
6bf47b08 581 bless(\\undef, 'Foobar'),
4df7f6af 582'SV = $RV\\($ADDR\\) at $ADDR
6bf47b08
SR
583 REFCNT = 1
584 FLAGS = \\(ROK\\)
585 RV = $ADDR
586 SV = PVMG\\($ADDR\\) at $ADDR
587 REFCNT = 2
588 FLAGS = \\(OBJECT,ROK\\)
7957ad98
MB
589 IV = -?\d+
590 NV = $FLOAT
6bf47b08
SR
591 RV = $ADDR
592 SV = NULL\\(0x0\\) at $ADDR
593 REFCNT = \d+
594 FLAGS = \\(READONLY\\)
595 PV = $ADDR ""
596 CUR = 0
597 LEN = 0
598 STASH = $ADDR\s+"Foobar"');
b1886099 599
b1886099
NC
600sub const () {
601 "Perl rules";
602}
603
06a5cade 604do_test('constant subroutine',
b1886099 605 \&const,
4df7f6af 606'SV = $RV\\($ADDR\\) at $ADDR
b1886099
NC
607 REFCNT = 1
608 FLAGS = \\(ROK\\)
609 RV = $ADDR
610 SV = PVCV\\($ADDR\\) at $ADDR
611 REFCNT = (2)
bad4ae38
FC
612 FLAGS = \\(POK,pPOK,CONST,ISXSUB\\) # $] < 5.015
613 FLAGS = \\(POK,pPOK,CONST,DYNFILE,ISXSUB\\) # $] >= 5.015
1bcecb77
NC
614 IV = 0 # $] < 5.009
615 NV = 0 # $] < 5.009
b1886099
NC
616 PROTOTYPE = ""
617 COMP_STASH = 0x0
1bcecb77 618 ROOT = 0x0 # $] < 5.009
b1886099
NC
619 XSUB = $ADDR
620 XSUBANY = $ADDR \\(CONST SV\\)
621 SV = PV\\($ADDR\\) at $ADDR
622 REFCNT = 1
623 FLAGS = \\(.*POK,READONLY,pPOK\\)
624 PV = $ADDR "Perl rules"\\\0
625 CUR = 10
626 LEN = \\d+
627 GVGV::GV = $ADDR\\t"main" :: "const"
628 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
629 DEPTH = 0(?:
630 MUTEXP = $ADDR
631 OWNER = $ADDR)?
1bcecb77 632 FLAGS = 0x200 # $] < 5.009
c2485e0c 633 FLAGS = 0xc00 # $] >= 5.009 && $] < 5.013
bad4ae38
FC
634 FLAGS = 0xc # $] >= 5.013 && $] < 5.015
635 FLAGS = 0x100c # $] >= 5.015
b1886099
NC
636 OUTSIDE_SEQ = 0
637 PADLIST = 0x0
638 OUTSIDE = 0x0 \\(null\\)');
2e94196c 639
06a5cade 640do_test('isUV should show on PVMG',
2e94196c
NC
641 do { my $v = $1; $v = ~0; $v },
642'SV = PVMG\\($ADDR\\) at $ADDR
643 REFCNT = 1
644 FLAGS = \\(IOK,pIOK,IsUV\\)
645 UV = \d+
646 NV = 0
647 PV = 0');
c0a413d1 648
06a5cade 649do_test('IO',
c0a413d1
NC
650 *STDOUT{IO},
651'SV = $RV\\($ADDR\\) at $ADDR
652 REFCNT = 1
653 FLAGS = \\(ROK\\)
654 RV = $ADDR
655 SV = PVIO\\($ADDR\\) at $ADDR
656 REFCNT = 3
657 FLAGS = \\(OBJECT\\)
3cf51070 658 IV = 0 # $] < 5.011
1bcecb77 659 NV = 0 # $] < 5.011
d963bf01 660 STASH = $ADDR\s+"IO::File"
c0a413d1
NC
661 IFP = $ADDR
662 OFP = $ADDR
663 DIRP = 0x0
664 LINES = 0
665 PAGE = 0
666 PAGE_LEN = 60
667 LINES_LEFT = 0
668 TOP_GV = 0x0
669 FMT_GV = 0x0
670 BOTTOM_GV = 0x0
1bcecb77 671 SUBPROCESS = 0 # $] < 5.009
c0a413d1 672 TYPE = \'>\'
50a9fad1 673 FLAGS = 0x4');
bfe27a58 674
06a5cade 675do_test('FORMAT',
bfe27a58
NC
676 *PIE{FORMAT},
677'SV = $RV\\($ADDR\\) at $ADDR
678 REFCNT = 1
679 FLAGS = \\(ROK\\)
680 RV = $ADDR
681 SV = PVFM\\($ADDR\\) at $ADDR
682 REFCNT = 2
bad4ae38
FC
683 FLAGS = \\(\\) # $] < 5.015 || !thr
684 FLAGS = \\(DYNFILE\\) # $] >= 5.015 && thr
30ec677d 685 IV = 0 # $] < 5.009
bfe27a58 686 NV = 0 # $] < 5.009
251a4af1
DM
687(?: PV = 0
688)? COMP_STASH = 0x0
bfe27a58
NC
689 START = $ADDR ===> \\d+
690 ROOT = $ADDR
691 XSUB = 0x0 # $] < 5.009
692 XSUBANY = 0 # $] < 5.009
693 GVGV::GV = $ADDR\\t"main" :: "PIE"
bad4ae38 694 FILE = ".*\\b(?i:peek\\.t)"(?:
d3810ef8 695 DEPTH = 0)?(?:
c12100a4 696 MUTEXP = $ADDR
bad4ae38
FC
697 OWNER = $ADDR)?
698 FLAGS = 0x0 # $] < 5.015 || !thr
699 FLAGS = 0x1000 # $] >= 5.015 && thr
bfe27a58 700 OUTSIDE_SEQ = \\d+
d3810ef8 701 LINES = 0 # $] < 5.017_003
bfe27a58
NC
702 PADLIST = $ADDR
703 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
704 OUTSIDE = $ADDR \\(MAIN\\)');
d7d51f4b 705
b7b1e41b 706do_test('blessing to a class with embedded NUL characters',
d7d51f4b
YO
707 (bless {}, "\0::foo::\n::baz::\t::\0"),
708'SV = $RV\\($ADDR\\) at $ADDR
709 REFCNT = 1
710 FLAGS = \\(ROK\\)
711 RV = $ADDR
712 SV = PVHV\\($ADDR\\) at $ADDR
713 REFCNT = 1
714 FLAGS = \\(OBJECT,SHAREKEYS\\)
715 IV = 0 # $] < 5.009
716 NV = 0 # $] < 5.009
717 STASH = $ADDR\\t"\\\\0::foo::\\\\n::baz::\\\\t::\\\\0"
718 ARRAY = $ADDR
719 KEYS = 0
720 FILL = 0
721 MAX = 7
722 RITER = -1
723 EITER = 0x0', '',
f3ce8053
FC
724 $] > 5.009
725 ? $] >= 5.015
726 ? 0
727 : 'The hash iterator used in dump.c sets the OOK flag'
d7d51f4b
YO
728 : "Something causes the HV's array to become allocated");
729
bed53064
NC
730do_test('ENAME on a stash',
731 \%RWOM::,
732'SV = $RV\\($ADDR\\) at $ADDR
733 REFCNT = 1
734 FLAGS = \\(ROK\\)
735 RV = $ADDR
736 SV = PVHV\\($ADDR\\) at $ADDR
737 REFCNT = 2
738 FLAGS = \\(OOK,SHAREKEYS\\)
739 IV = 1 # $] < 5.009
740 NV = $FLOAT # $] < 5.009
741 ARRAY = $ADDR
742 KEYS = 0
743 FILL = 0
744 MAX = 7
745 RITER = -1
746 EITER = 0x0
747 NAME = "RWOM"
748 ENAME = "RWOM" # $] > 5.012
749');
750
751*KLANK:: = \%RWOM::;
752
753do_test('ENAMEs on a stash',
754 \%RWOM::,
755'SV = $RV\\($ADDR\\) at $ADDR
756 REFCNT = 1
757 FLAGS = \\(ROK\\)
758 RV = $ADDR
759 SV = PVHV\\($ADDR\\) at $ADDR
760 REFCNT = 3
761 FLAGS = \\(OOK,SHAREKEYS\\)
762 IV = 1 # $] < 5.009
763 NV = $FLOAT # $] < 5.009
764 ARRAY = $ADDR
765 KEYS = 0
766 FILL = 0
767 MAX = 7
768 RITER = -1
769 EITER = 0x0
770 NAME = "RWOM"
771 NAMECOUNT = 2 # $] > 5.012
772 ENAME = "RWOM", "KLANK" # $] > 5.012
773');
774
775undef %RWOM::;
776
777do_test('ENAMEs on a stash with no NAME',
778 \%RWOM::,
779'SV = $RV\\($ADDR\\) at $ADDR
780 REFCNT = 1
781 FLAGS = \\(ROK\\)
782 RV = $ADDR
783 SV = PVHV\\($ADDR\\) at $ADDR
784 REFCNT = 3
6acb8aa1
FC
785 FLAGS = \\(OOK,SHAREKEYS\\) # $] < 5.017
786 FLAGS = \\(OOK,OVERLOAD,SHAREKEYS\\) # $] >=5.017
bed53064
NC
787 IV = 1 # $] < 5.009
788 NV = $FLOAT # $] < 5.009
789 ARRAY = $ADDR
790 KEYS = 0
791 FILL = 0
792 MAX = 7
793 RITER = -1
794 EITER = 0x0
795 NAMECOUNT = -3 # $] > 5.012
796 ENAME = "RWOM", "KLANK" # $] > 5.012
797');
798
4ab5bd5f
FC
799SKIP: {
800 skip "Not built with usemymalloc", 1
801 unless $Config{usemymalloc} eq 'y';
802 my $x = __PACKAGE__;
803 ok eval { fill_mstats($x); 1 }, 'fill_mstats on COW scalar'
804 or diag $@;
805}
806
bc9a5256
NC
807# This is more a test of fbm_compile/pp_study (non) interaction than dumping
808# prowess, but short of duplicating all the gubbins of this file, I can't see
809# a way to make a better place for it:
810
ccbcbb3d
NC
811use constant {
812 perl => 'rules',
813 beer => 'foamy',
814};
0a0c4b76
NC
815
816unless ($Config{useithreads}) {
817 # These end up as copies in pads under ithreads, which rather defeats the
818 # the point of what we're trying to test here.
819
820 do_test('regular string constant', perl,
821'SV = PV\\($ADDR\\) at $ADDR
bc9a5256 822 REFCNT = 5
0a0c4b76
NC
823 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
824 PV = $ADDR "rules"\\\0
825 CUR = 5
826 LEN = \d+
827');
828
829 eval 'index "", perl';
830
831 # FIXME - really this shouldn't say EVALED. It's a false posistive on
832 # 0x40000000 being used for several things, not a flag for "I'm in a string
833 # eval"
834
835 do_test('string constant now an FBM', perl,
c13a5c80 836'SV = PVMG\\($ADDR\\) at $ADDR
bc9a5256
NC
837 REFCNT = 5
838 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
839 PV = $ADDR "rules"\\\0
840 CUR = 5
841 LEN = \d+
842 MAGIC = $ADDR
b76b0bf9 843 MG_VIRTUAL = &PL_vtbl_regexp
bc9a5256 844 MG_TYPE = PERL_MAGIC_bm\\(B\\)
2bda37ba
NC
845 MG_LEN = 256
846 MG_PTR = $ADDR "(?:\\\\\d){256}"
bc9a5256
NC
847 RARE = \d+
848 PREVIOUS = 1
849 USEFUL = 100
850');
851
852 is(study perl, '', "Not allowed to study an FBM");
853
854 do_test('string constant still an FBM', perl,
c13a5c80 855'SV = PVMG\\($ADDR\\) at $ADDR
bc9a5256 856 REFCNT = 5
0a0c4b76
NC
857 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
858 PV = $ADDR "rules"\\\0
859 CUR = 5
860 LEN = \d+
861 MAGIC = $ADDR
b76b0bf9 862 MG_VIRTUAL = &PL_vtbl_regexp
0a0c4b76 863 MG_TYPE = PERL_MAGIC_bm\\(B\\)
2bda37ba
NC
864 MG_LEN = 256
865 MG_PTR = $ADDR "(?:\\\\\d){256}"
0a0c4b76
NC
866 RARE = \d+
867 PREVIOUS = 1
868 USEFUL = 100
869');
ccbcbb3d
NC
870
871 do_test('regular string constant', beer,
872'SV = PV\\($ADDR\\) at $ADDR
4185c919 873 REFCNT = 6
ccbcbb3d
NC
874 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
875 PV = $ADDR "foamy"\\\0
876 CUR = 5
877 LEN = \d+
878');
879
a58a85fa
AMS
880 is(study beer, 1, "Our studies were successful");
881
882 do_test('string constant quite unaffected', beer, 'SV = PV\\($ADDR\\) at $ADDR
883 REFCNT = 6
884 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
885 PV = $ADDR "foamy"\\\0
886 CUR = 5
887 LEN = \d+
888');
889
4185c919 890 my $want = 'SV = PVMG\\($ADDR\\) at $ADDR
4265b45d 891 REFCNT = 6
a58a85fa 892 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
4265b45d
NC
893 PV = $ADDR "foamy"\\\0
894 CUR = 5
895 LEN = \d+
896 MAGIC = $ADDR
0177730e 897 MG_VIRTUAL = &PL_vtbl_regexp
a58a85fa
AMS
898 MG_TYPE = PERL_MAGIC_bm\\(B\\)
899 MG_LEN = 256
900 MG_PTR = $ADDR "(?:\\\\\d){256}"
901 RARE = \d+
902 PREVIOUS = \d+
903 USEFUL = 100
4185c919
NC
904';
905
4265b45d
NC
906 is (eval 'index "not too foamy", beer', 8, 'correct index');
907
a58a85fa 908 do_test('string constant now FBMed', beer, $want);
4185c919
NC
909
910 my $pie = 'good';
911
912 is(study $pie, 1, "Our studies were successful");
913
a58a85fa 914 do_test('string constant still FBMed', beer, $want);
4185c919 915
a58a85fa 916 do_test('second string also unaffected', $pie, 'SV = PV\\($ADDR\\) at $ADDR
4185c919 917 REFCNT = 1
a58a85fa 918 FLAGS = \\(PADMY,POK,pPOK\\)
4185c919
NC
919 PV = $ADDR "good"\\\0
920 CUR = 4
ccbcbb3d 921 LEN = \d+
ccbcbb3d 922');
0a0c4b76
NC
923}
924
a58a85fa 925# (One block of study tests removed when study was made a no-op.)
72de20cd 926
486ffce2
FC
927{
928 open(OUT,">peek$$") or die "Failed to open peek $$: $!";
929 open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
930 DeadCode();
931 open(STDERR, ">&SAVERR") or die "Can't restore STDERR: $!";
932 pass "no crash with DeadCode";
7bf23f34 933 close OUT;
486ffce2
FC
934}
935
06a5cade 936done_testing();