This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow regexp-to-pvlv assignment
[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
3ed356df 244 REFCNT = [12]
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
8d919b0a
FC
336 FLAGS = \\(OBJECT,POK,FAKE,pPOK\\) # $] < 5.017006
337 FLAGS = \\(OBJECT,FAKE\\) # $] >= 5.017006
fb85c044
KW
338 PV = $ADDR "\\(\\?\\^:tic\\)"
339 CUR = 8
8d919b0a 340 LEN = 0 # $] < 5.017006
d63e6659
DM
341 STASH = $ADDR\\t"Regexp"'
342. ($] < 5.013 ? '' :
343'
344 EXTFLAGS = 0x680000 \(CHECK_ALL,USE_INTUIT_NOML,USE_INTUIT_ML\)
345 INTFLAGS = 0x0
346 NPARENS = 0
347 LASTPAREN = 0
348 LASTCLOSEPAREN = 0
349 MINLEN = 3
350 MINLENRET = 3
351 GOFS = 0
352 PRE_PREFIX = 4
d63e6659 353 SUBLEN = 0
6502e081
DM
354 SUBOFFSET = 0
355 SUBCOFFSET = 0
d63e6659
DM
356 SUBBEG = 0x0
357 ENGINE = $ADDR
358 MOTHER_RE = $ADDR
359 PAREN_NAMES = 0x0
360 SUBSTRS = $ADDR
361 PPRIVATE = $ADDR
d63c20f2
DM
362 OFFS = $ADDR
363 QR_ANONCV = 0x0'
d63e6659 364));
3ce3ed55 365} else {
06a5cade 366do_test('reference to regexp',
9248c45a 367 qr(tic),
4df7f6af 368'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
369 REFCNT = 1
370 FLAGS = \\(ROK\\)
371 RV = $ADDR
372 SV = PVMG\\($ADDR\\) at $ADDR
373 REFCNT = 1
faf82a0b 374 FLAGS = \\(OBJECT,SMG\\)
9248c45a
JH
375 IV = 0
376 NV = 0
377 PV = 0
378 MAGIC = $ADDR
379 MG_VIRTUAL = $ADDR
14befaf4 380 MG_TYPE = PERL_MAGIC_qr\(r\)
9248c45a 381 MG_OBJ = $ADDR
fb85c044 382 PAT = "\(\?^:tic\)" # $] >= 5.009
1bcecb77 383 REFCNT = 2 # $] >= 5.009
9248c45a 384 STASH = $ADDR\\t"Regexp"');
3ce3ed55 385}
9248c45a 386
06a5cade 387do_test('reference to blessed hash',
9248c45a 388 (bless {}, "Tac"),
4df7f6af 389'SV = $RV\\($ADDR\\) at $ADDR
9248c45a
JH
390 REFCNT = 1
391 FLAGS = \\(ROK\\)
392 RV = $ADDR
393 SV = PVHV\\($ADDR\\) at $ADDR
3ed356df 394 REFCNT = [12]
9248c45a 395 FLAGS = \\(OBJECT,SHAREKEYS\\)
1bcecb77
NC
396 IV = 0 # $] < 5.009
397 NV = 0 # $] < 5.009
9248c45a
JH
398 STASH = $ADDR\\t"Tac"
399 ARRAY = 0x0
400 KEYS = 0
401 FILL = 0
402 MAX = 7
403 RITER = -1
000fd473 404 EITER = 0x0', '',
f3ce8053
FC
405 $] > 5.009
406 ? $] >= 5.015
407 ? 0
408 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 409 : "Something causes the HV's array to become allocated");
9248c45a 410
06a5cade 411do_test('typeglob',
9248c45a
JH
412 *a,
413'SV = PVGV\\($ADDR\\) at $ADDR
414 REFCNT = 5
000fd473
NC
415 FLAGS = \\(MULTI(?:,IN_PAD)?\\) # $] >= 5.009
416 FLAGS = \\(GMG,SMG,MULTI(?:,IN_PAD)?\\) # $] < 5.009
417 IV = 0 # $] < 5.009
418 NV = 0 # $] < 5.009
419 PV = 0 # $] < 5.009
420 MAGIC = $ADDR # $] < 5.009
421 MG_VIRTUAL = &PL_vtbl_glob # $] < 5.009
422 MG_TYPE = PERL_MAGIC_glob\(\*\) # $] < 5.009
423 MG_OBJ = $ADDR # $] < 5.009
9248c45a
JH
424 NAME = "a"
425 NAMELEN = 1
426 GvSTASH = $ADDR\\t"main"
427 GP = $ADDR
428 SV = $ADDR
429 REFCNT = 1
430 IO = 0x0
431 FORM = 0x0
432 AV = 0x0
433 HV = 0x0
434 CV = 0x0
435 CVGEN = 0x0
000fd473 436 GPFLAGS = 0x0 # $] < 5.009
9ec58fb7 437 LINE = \\d+
084d946d 438 FILE = ".*\\b(?i:peek\\.t)"
e39917cc 439 FLAGS = $ADDR
9248c45a
JH
440 EGV = $ADDR\\t"a"');
441
cdb2dd7b 442if (ord('A') == 193) {
06a5cade 443do_test('string with Unicode',
cdb2dd7b
JH
444 chr(256).chr(0).chr(512),
445'SV = PV\\($ADDR\\) at $ADDR
446 REFCNT = 1
000fd473 447 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
cdb2dd7b
JH
448 PV = $ADDR "\\\214\\\101\\\0\\\235\\\101"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
449 CUR = 5
1badabf5 450 LEN = \\d+');
cdb2dd7b 451} else {
06a5cade 452do_test('string with Unicode',
e6abe6d8
JH
453 chr(256).chr(0).chr(512),
454'SV = PV\\($ADDR\\) at $ADDR
455 REFCNT = 1
000fd473 456 FLAGS = \\((?:$PADTMP,)?POK,READONLY,pPOK,UTF8\\)
98c991d1 457 PV = $ADDR "\\\304\\\200\\\0\\\310\\\200"\\\0 \[UTF8 "\\\x\{100\}\\\x\{0\}\\\x\{200\}"\]
e6abe6d8 458 CUR = 5
1badabf5 459 LEN = \\d+');
cdb2dd7b 460}
e6abe6d8 461
cdb2dd7b 462if (ord('A') == 193) {
06a5cade 463do_test('reference to hash containing Unicode',
cdb2dd7b 464 {chr(256)=>chr(512)},
4df7f6af 465'SV = $RV\\($ADDR\\) at $ADDR
cdb2dd7b
JH
466 REFCNT = 1
467 FLAGS = \\(ROK\\)
468 RV = $ADDR
469 SV = PVHV\\($ADDR\\) at $ADDR
3ed356df 470 REFCNT = [12]
b2caaddd 471 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
472 UV = 1 # $] < 5.009
473 NV = $FLOAT # $] < 5.009
cdb2dd7b
JH
474 ARRAY = $ADDR \\(0:7, 1:1\\)
475 hash quality = 100.0%
476 KEYS = 1
477 FILL = 1
478 MAX = 7
479 RITER = -1
480 EITER = $ADDR
6cbfa5b4 481 Elt "\\\214\\\101" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
cdb2dd7b
JH
482 SV = PV\\($ADDR\\) at $ADDR
483 REFCNT = 1
484 FLAGS = \\(POK,pPOK,UTF8\\)
485 PV = $ADDR "\\\235\\\101"\\\0 \[UTF8 "\\\x\{200\}"\]
486 CUR = 2
000fd473 487 LEN = \\d+',
f3ce8053
FC
488 $] > 5.009
489 ? $] >= 5.015
490 ? 0
491 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 492 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 493} else {
06a5cade 494do_test('reference to hash containing Unicode',
98c991d1 495 {chr(256)=>chr(512)},
4df7f6af 496'SV = $RV\\($ADDR\\) at $ADDR
98c991d1
JH
497 REFCNT = 1
498 FLAGS = \\(ROK\\)
499 RV = $ADDR
500 SV = PVHV\\($ADDR\\) at $ADDR
3ed356df 501 REFCNT = [12]
19692e8d 502 FLAGS = \\(SHAREKEYS,HASKFLAGS\\)
1bcecb77
NC
503 UV = 1 # $] < 5.009
504 NV = 0 # $] < 5.009
98c991d1
JH
505 ARRAY = $ADDR \\(0:7, 1:1\\)
506 hash quality = 100.0%
507 KEYS = 1
508 FILL = 1
509 MAX = 7
510 RITER = -1
511 EITER = $ADDR
512 Elt "\\\304\\\200" \[UTF8 "\\\x\{100\}"\] HASH = $ADDR
513 SV = PV\\($ADDR\\) at $ADDR
514 REFCNT = 1
515 FLAGS = \\(POK,pPOK,UTF8\\)
516 PV = $ADDR "\\\310\\\200"\\\0 \[UTF8 "\\\x\{200\}"\]
517 CUR = 2
000fd473 518 LEN = \\d+', '',
f3ce8053
FC
519 $] > 5.009
520 ? $] >= 5.015
521 ? 0
522 : 'The hash iterator used in dump.c sets the OOK flag'
000fd473 523 : 'sv_length has been called on the element, and cached the result in MAGIC');
cdb2dd7b 524}
98c991d1 525
99331854
YST
526my $x="";
527$x=~/.??/g;
06a5cade 528do_test('scalar with pos magic',
99331854
YST
529 $x,
530'SV = PVMG\\($ADDR\\) at $ADDR
531 REFCNT = 1
000fd473 532 FLAGS = \\($PADMY,SMG,POK,pPOK\\)
99331854
YST
533 IV = 0
534 NV = 0
535 PV = $ADDR ""\\\0
536 CUR = 0
1936d2a7 537 LEN = \d+
99331854
YST
538 MAGIC = $ADDR
539 MG_VIRTUAL = &PL_vtbl_mglob
540 MG_TYPE = PERL_MAGIC_regex_global\\(g\\)
541 MG_FLAGS = 0x01
542 MINMATCH');
543
f24fdb76
HS
544#
545# TAINTEDDIR is not set on: OS2, AMIGAOS, WIN32, MSDOS
546# environment variables may be invisibly case-forced, hence the (?i:PATH)
5e836f43 547# C<scalar(@ARGV)> is turned into an IV on VMS hence the (?:IV)?
12033064
CS
548# Perl 5.18 ensures all env vars end up as strings only, hence the (?:,pIOK)?
549# Perl 5.18 ensures even magic vars have public OK, hence the (?:,POK)?
d9baf692
JM
550# VMS is setting FAKE and READONLY flags. What VMS uses for storing
551# ENV hashes is also not always null terminated.
f24fdb76 552#
06a5cade 553do_test('tainted value in %ENV',
99331854
YST
554 $ENV{PATH}=@ARGV, # scalar(@ARGV) is a handy known tainted value
555'SV = PVMG\\($ADDR\\) at $ADDR
556 REFCNT = 1
12033064 557 FLAGS = \\(GMG,SMG,RMG(?:,POK)?(?:,pIOK)?,pPOK\\)
99331854
YST
558 IV = 0
559 NV = 0
560 PV = $ADDR "0"\\\0
561 CUR = 1
562 LEN = \d+
563 MAGIC = $ADDR
564 MG_VIRTUAL = &PL_vtbl_envelem
565 MG_TYPE = PERL_MAGIC_envelem\\(e\\)
d25a523c 566(?: MG_FLAGS = 0x01
99331854 567 TAINTEDDIR
143a3e5e
CB
568)? MG_LEN = -?\d+
569 MG_PTR = $ADDR (?:"(?i:PATH)"|=> HEf_SVKEY
5e836f43 570 SV = PV(?:IV)?\\($ADDR\\) at $ADDR
143a3e5e 571 REFCNT = \d+
11e2783c 572 FLAGS = \\(TEMP,POK,(?:FAKE,READONLY,)?pPOK\\)
f0fabfd7 573(?: IV = 0
d9baf692 574)? PV = $ADDR "(?i:PATH)"(?:\\\0)?
143a3e5e
CB
575 CUR = \d+
576 LEN = \d+)
99331854
YST
577 MAGIC = $ADDR
578 MG_VIRTUAL = &PL_vtbl_taint
579 MG_TYPE = PERL_MAGIC_taint\\(t\\)');
580
06a5cade 581do_test('blessed reference',
6bf47b08 582 bless(\\undef, 'Foobar'),
4df7f6af 583'SV = $RV\\($ADDR\\) at $ADDR
6bf47b08
SR
584 REFCNT = 1
585 FLAGS = \\(ROK\\)
586 RV = $ADDR
587 SV = PVMG\\($ADDR\\) at $ADDR
588 REFCNT = 2
589 FLAGS = \\(OBJECT,ROK\\)
7957ad98
MB
590 IV = -?\d+
591 NV = $FLOAT
6bf47b08
SR
592 RV = $ADDR
593 SV = NULL\\(0x0\\) at $ADDR
594 REFCNT = \d+
595 FLAGS = \\(READONLY\\)
596 PV = $ADDR ""
597 CUR = 0
598 LEN = 0
599 STASH = $ADDR\s+"Foobar"');
b1886099 600
b1886099
NC
601sub const () {
602 "Perl rules";
603}
604
06a5cade 605do_test('constant subroutine',
b1886099 606 \&const,
4df7f6af 607'SV = $RV\\($ADDR\\) at $ADDR
b1886099
NC
608 REFCNT = 1
609 FLAGS = \\(ROK\\)
610 RV = $ADDR
611 SV = PVCV\\($ADDR\\) at $ADDR
612 REFCNT = (2)
bad4ae38
FC
613 FLAGS = \\(POK,pPOK,CONST,ISXSUB\\) # $] < 5.015
614 FLAGS = \\(POK,pPOK,CONST,DYNFILE,ISXSUB\\) # $] >= 5.015
1bcecb77
NC
615 IV = 0 # $] < 5.009
616 NV = 0 # $] < 5.009
b1886099
NC
617 PROTOTYPE = ""
618 COMP_STASH = 0x0
1bcecb77 619 ROOT = 0x0 # $] < 5.009
b1886099
NC
620 XSUB = $ADDR
621 XSUBANY = $ADDR \\(CONST SV\\)
622 SV = PV\\($ADDR\\) at $ADDR
623 REFCNT = 1
624 FLAGS = \\(.*POK,READONLY,pPOK\\)
625 PV = $ADDR "Perl rules"\\\0
626 CUR = 10
627 LEN = \\d+
628 GVGV::GV = $ADDR\\t"main" :: "const"
629 FILE = ".*\\b(?i:peek\\.t)"
000fd473
NC
630 DEPTH = 0(?:
631 MUTEXP = $ADDR
632 OWNER = $ADDR)?
1bcecb77 633 FLAGS = 0x200 # $] < 5.009
c2485e0c 634 FLAGS = 0xc00 # $] >= 5.009 && $] < 5.013
bad4ae38
FC
635 FLAGS = 0xc # $] >= 5.013 && $] < 5.015
636 FLAGS = 0x100c # $] >= 5.015
b1886099
NC
637 OUTSIDE_SEQ = 0
638 PADLIST = 0x0
639 OUTSIDE = 0x0 \\(null\\)');
2e94196c 640
06a5cade 641do_test('isUV should show on PVMG',
2e94196c
NC
642 do { my $v = $1; $v = ~0; $v },
643'SV = PVMG\\($ADDR\\) at $ADDR
644 REFCNT = 1
645 FLAGS = \\(IOK,pIOK,IsUV\\)
646 UV = \d+
647 NV = 0
648 PV = 0');
c0a413d1 649
06a5cade 650do_test('IO',
c0a413d1
NC
651 *STDOUT{IO},
652'SV = $RV\\($ADDR\\) at $ADDR
653 REFCNT = 1
654 FLAGS = \\(ROK\\)
655 RV = $ADDR
656 SV = PVIO\\($ADDR\\) at $ADDR
657 REFCNT = 3
658 FLAGS = \\(OBJECT\\)
3cf51070 659 IV = 0 # $] < 5.011
1bcecb77 660 NV = 0 # $] < 5.011
d963bf01 661 STASH = $ADDR\s+"IO::File"
c0a413d1
NC
662 IFP = $ADDR
663 OFP = $ADDR
664 DIRP = 0x0
665 LINES = 0
666 PAGE = 0
667 PAGE_LEN = 60
668 LINES_LEFT = 0
669 TOP_GV = 0x0
670 FMT_GV = 0x0
671 BOTTOM_GV = 0x0
1bcecb77 672 SUBPROCESS = 0 # $] < 5.009
c0a413d1 673 TYPE = \'>\'
50a9fad1 674 FLAGS = 0x4');
bfe27a58 675
06a5cade 676do_test('FORMAT',
bfe27a58
NC
677 *PIE{FORMAT},
678'SV = $RV\\($ADDR\\) at $ADDR
679 REFCNT = 1
680 FLAGS = \\(ROK\\)
681 RV = $ADDR
682 SV = PVFM\\($ADDR\\) at $ADDR
683 REFCNT = 2
bad4ae38
FC
684 FLAGS = \\(\\) # $] < 5.015 || !thr
685 FLAGS = \\(DYNFILE\\) # $] >= 5.015 && thr
30ec677d 686 IV = 0 # $] < 5.009
bfe27a58 687 NV = 0 # $] < 5.009
251a4af1
DM
688(?: PV = 0
689)? COMP_STASH = 0x0
bfe27a58
NC
690 START = $ADDR ===> \\d+
691 ROOT = $ADDR
692 XSUB = 0x0 # $] < 5.009
693 XSUBANY = 0 # $] < 5.009
694 GVGV::GV = $ADDR\\t"main" :: "PIE"
bad4ae38 695 FILE = ".*\\b(?i:peek\\.t)"(?:
d3810ef8 696 DEPTH = 0)?(?:
c12100a4 697 MUTEXP = $ADDR
bad4ae38
FC
698 OWNER = $ADDR)?
699 FLAGS = 0x0 # $] < 5.015 || !thr
700 FLAGS = 0x1000 # $] >= 5.015 && thr
bfe27a58 701 OUTSIDE_SEQ = \\d+
d3810ef8 702 LINES = 0 # $] < 5.017_003
bfe27a58
NC
703 PADLIST = $ADDR
704 PADNAME = $ADDR\\($ADDR\\) PAD = $ADDR\\($ADDR\\)
705 OUTSIDE = $ADDR \\(MAIN\\)');
d7d51f4b 706
b7b1e41b 707do_test('blessing to a class with embedded NUL characters',
d7d51f4b
YO
708 (bless {}, "\0::foo::\n::baz::\t::\0"),
709'SV = $RV\\($ADDR\\) at $ADDR
710 REFCNT = 1
711 FLAGS = \\(ROK\\)
712 RV = $ADDR
713 SV = PVHV\\($ADDR\\) at $ADDR
3ed356df 714 REFCNT = [12]
d7d51f4b
YO
715 FLAGS = \\(OBJECT,SHAREKEYS\\)
716 IV = 0 # $] < 5.009
717 NV = 0 # $] < 5.009
718 STASH = $ADDR\\t"\\\\0::foo::\\\\n::baz::\\\\t::\\\\0"
719 ARRAY = $ADDR
720 KEYS = 0
721 FILL = 0
722 MAX = 7
723 RITER = -1
724 EITER = 0x0', '',
f3ce8053
FC
725 $] > 5.009
726 ? $] >= 5.015
727 ? 0
728 : 'The hash iterator used in dump.c sets the OOK flag'
d7d51f4b
YO
729 : "Something causes the HV's array to become allocated");
730
bed53064
NC
731do_test('ENAME on a stash',
732 \%RWOM::,
733'SV = $RV\\($ADDR\\) at $ADDR
734 REFCNT = 1
735 FLAGS = \\(ROK\\)
736 RV = $ADDR
737 SV = PVHV\\($ADDR\\) at $ADDR
738 REFCNT = 2
739 FLAGS = \\(OOK,SHAREKEYS\\)
740 IV = 1 # $] < 5.009
741 NV = $FLOAT # $] < 5.009
742 ARRAY = $ADDR
743 KEYS = 0
744 FILL = 0
745 MAX = 7
746 RITER = -1
747 EITER = 0x0
748 NAME = "RWOM"
749 ENAME = "RWOM" # $] > 5.012
750');
751
752*KLANK:: = \%RWOM::;
753
754do_test('ENAMEs on a stash',
755 \%RWOM::,
756'SV = $RV\\($ADDR\\) at $ADDR
757 REFCNT = 1
758 FLAGS = \\(ROK\\)
759 RV = $ADDR
760 SV = PVHV\\($ADDR\\) at $ADDR
761 REFCNT = 3
762 FLAGS = \\(OOK,SHAREKEYS\\)
763 IV = 1 # $] < 5.009
764 NV = $FLOAT # $] < 5.009
765 ARRAY = $ADDR
766 KEYS = 0
767 FILL = 0
768 MAX = 7
769 RITER = -1
770 EITER = 0x0
771 NAME = "RWOM"
772 NAMECOUNT = 2 # $] > 5.012
773 ENAME = "RWOM", "KLANK" # $] > 5.012
774');
775
776undef %RWOM::;
777
778do_test('ENAMEs on a stash with no NAME',
779 \%RWOM::,
780'SV = $RV\\($ADDR\\) at $ADDR
781 REFCNT = 1
782 FLAGS = \\(ROK\\)
783 RV = $ADDR
784 SV = PVHV\\($ADDR\\) at $ADDR
785 REFCNT = 3
6acb8aa1
FC
786 FLAGS = \\(OOK,SHAREKEYS\\) # $] < 5.017
787 FLAGS = \\(OOK,OVERLOAD,SHAREKEYS\\) # $] >=5.017
bed53064
NC
788 IV = 1 # $] < 5.009
789 NV = $FLOAT # $] < 5.009
790 ARRAY = $ADDR
791 KEYS = 0
792 FILL = 0
793 MAX = 7
794 RITER = -1
795 EITER = 0x0
796 NAMECOUNT = -3 # $] > 5.012
797 ENAME = "RWOM", "KLANK" # $] > 5.012
798');
799
4ab5bd5f
FC
800SKIP: {
801 skip "Not built with usemymalloc", 1
802 unless $Config{usemymalloc} eq 'y';
803 my $x = __PACKAGE__;
804 ok eval { fill_mstats($x); 1 }, 'fill_mstats on COW scalar'
805 or diag $@;
806}
807
bc9a5256
NC
808# This is more a test of fbm_compile/pp_study (non) interaction than dumping
809# prowess, but short of duplicating all the gubbins of this file, I can't see
810# a way to make a better place for it:
811
ccbcbb3d
NC
812use constant {
813 perl => 'rules',
814 beer => 'foamy',
815};
0a0c4b76
NC
816
817unless ($Config{useithreads}) {
818 # These end up as copies in pads under ithreads, which rather defeats the
819 # the point of what we're trying to test here.
820
821 do_test('regular string constant', perl,
822'SV = PV\\($ADDR\\) at $ADDR
bc9a5256 823 REFCNT = 5
0a0c4b76
NC
824 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
825 PV = $ADDR "rules"\\\0
826 CUR = 5
827 LEN = \d+
828');
829
830 eval 'index "", perl';
831
832 # FIXME - really this shouldn't say EVALED. It's a false posistive on
833 # 0x40000000 being used for several things, not a flag for "I'm in a string
834 # eval"
835
836 do_test('string constant now an FBM', perl,
c13a5c80 837'SV = PVMG\\($ADDR\\) at $ADDR
bc9a5256
NC
838 REFCNT = 5
839 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
840 PV = $ADDR "rules"\\\0
841 CUR = 5
842 LEN = \d+
843 MAGIC = $ADDR
b76b0bf9 844 MG_VIRTUAL = &PL_vtbl_regexp
bc9a5256 845 MG_TYPE = PERL_MAGIC_bm\\(B\\)
2bda37ba
NC
846 MG_LEN = 256
847 MG_PTR = $ADDR "(?:\\\\\d){256}"
bc9a5256
NC
848 RARE = \d+
849 PREVIOUS = 1
850 USEFUL = 100
851');
852
853 is(study perl, '', "Not allowed to study an FBM");
854
855 do_test('string constant still an FBM', perl,
c13a5c80 856'SV = PVMG\\($ADDR\\) at $ADDR
bc9a5256 857 REFCNT = 5
0a0c4b76
NC
858 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
859 PV = $ADDR "rules"\\\0
860 CUR = 5
861 LEN = \d+
862 MAGIC = $ADDR
b76b0bf9 863 MG_VIRTUAL = &PL_vtbl_regexp
0a0c4b76 864 MG_TYPE = PERL_MAGIC_bm\\(B\\)
2bda37ba
NC
865 MG_LEN = 256
866 MG_PTR = $ADDR "(?:\\\\\d){256}"
0a0c4b76
NC
867 RARE = \d+
868 PREVIOUS = 1
869 USEFUL = 100
870');
ccbcbb3d
NC
871
872 do_test('regular string constant', beer,
873'SV = PV\\($ADDR\\) at $ADDR
4185c919 874 REFCNT = 6
ccbcbb3d
NC
875 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
876 PV = $ADDR "foamy"\\\0
877 CUR = 5
878 LEN = \d+
879');
880
a58a85fa
AMS
881 is(study beer, 1, "Our studies were successful");
882
883 do_test('string constant quite unaffected', beer, 'SV = PV\\($ADDR\\) at $ADDR
884 REFCNT = 6
885 FLAGS = \\(PADMY,POK,READONLY,pPOK\\)
886 PV = $ADDR "foamy"\\\0
887 CUR = 5
888 LEN = \d+
889');
890
4185c919 891 my $want = 'SV = PVMG\\($ADDR\\) at $ADDR
4265b45d 892 REFCNT = 6
a58a85fa 893 FLAGS = \\(PADMY,SMG,POK,READONLY,pPOK,VALID,EVALED\\)
4265b45d
NC
894 PV = $ADDR "foamy"\\\0
895 CUR = 5
896 LEN = \d+
897 MAGIC = $ADDR
0177730e 898 MG_VIRTUAL = &PL_vtbl_regexp
a58a85fa
AMS
899 MG_TYPE = PERL_MAGIC_bm\\(B\\)
900 MG_LEN = 256
901 MG_PTR = $ADDR "(?:\\\\\d){256}"
902 RARE = \d+
903 PREVIOUS = \d+
904 USEFUL = 100
4185c919
NC
905';
906
4265b45d
NC
907 is (eval 'index "not too foamy", beer', 8, 'correct index');
908
a58a85fa 909 do_test('string constant now FBMed', beer, $want);
4185c919
NC
910
911 my $pie = 'good';
912
913 is(study $pie, 1, "Our studies were successful");
914
a58a85fa 915 do_test('string constant still FBMed', beer, $want);
4185c919 916
a58a85fa 917 do_test('second string also unaffected', $pie, 'SV = PV\\($ADDR\\) at $ADDR
4185c919 918 REFCNT = 1
a58a85fa 919 FLAGS = \\(PADMY,POK,pPOK\\)
4185c919
NC
920 PV = $ADDR "good"\\\0
921 CUR = 4
ccbcbb3d 922 LEN = \d+
ccbcbb3d 923');
0a0c4b76
NC
924}
925
a58a85fa 926# (One block of study tests removed when study was made a no-op.)
72de20cd 927
486ffce2
FC
928{
929 open(OUT,">peek$$") or die "Failed to open peek $$: $!";
930 open(STDERR, ">&OUT") or die "Can't dup OUT: $!";
931 DeadCode();
932 open(STDERR, ">&SAVERR") or die "Can't restore STDERR: $!";
933 pass "no crash with DeadCode";
7bf23f34 934 close OUT;
486ffce2
FC
935}
936
06a5cade 937done_testing();