Skip to content

Commit 067d8a6

Browse files
committed
op_dump(): display names of variables for pad ops.
Make op_dump(), as used by 'perl -Dx', display the names of pad variables when dumping pad ops. The runtime perl -Dt already does this (note the $x, $y etc appearing in the op name displays): $ perl -Dt -e'my ($x, $y); $y = 1+$x' (-e:0) enter (-e:0) nextstate (-e:1) padrange($x,$y) (-e:1) nextstate (-e:1) const(IV(1)) (-e:1) padsv($x) (-e:1) add($y) (-e:1) leave While the (typically compile-time) -Dx detailed optree dumping didn't. Here are some 'before this commit' and 'after' examples of how some of those ops were/are now displayed. Note the changes in the 'TARG = N' lines for the following code: $ perl -Dx -e'my ($x, $y); $y = 1+$x' Before: 4 | +--padrange OP(0x31b08960) ===> 6 [nextstate 0x31b09fc0] | | TARG = 1 | | FLAGS = (VOID,MOD,SLABBED,MORESIB) | | PRIVATE = (LVINTRO,range=0x2) 10 +--add BINOP(0x31b0a060) ===> 1 [leave 0x31b08880] TARG = 2 FLAGS = (VOID,KIDS,SLABBED) PRIVATE = (TARGMY,0x2) 11 +--padsv OP(0x31b0a0a0) ===> 10 [add 0x31b0a060] TARG = 1 FLAGS = (SCALAR,SLABBED) After: 4 | +--padrange OP(0x18ffe920) ===> 6 [nextstate 0x18ffff80] | | TARG = 1 ($x,$y) | | FLAGS = (VOID,MOD,SLABBED,MORESIB) | | PRIVATE = (LVINTRO,range=0x2) 10 +--add BINOP(0x19000020) ===> 1 [leave 0x18ffe840] TARG = 2 ($y) FLAGS = (VOID,KIDS,SLABBED) PRIVATE = (TARGMY,0x2) 11 +--padsv OP(0x19000060) ===> 10 [add 0x19000020] TARG = 1 ($x) FLAGS = (SCALAR,SLABBED)
1 parent a95603a commit 067d8a6

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

dump.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,9 @@ S_sequence_num(pTHX_ const OP *o)
12851285
}
12861286

12871287

1288-
1288+
/* forward declaration */
1289+
STATIC void
1290+
S_deb_padvar_cv(pTHX_ CV *cv, PADOFFSET off, int n, bool paren);
12891291

12901292

12911293
const struct flag_to_name op_flags_names[] = {
@@ -1379,9 +1381,39 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o,
13791381
}
13801382
}
13811383

1382-
if (o->op_targ && optype != OP_NULL)
1383-
S_opdump_indent(aTHX_ o, level, bar, file, "TARG = %ld\n",
1384-
(long)o->op_targ);
1384+
if (o->op_targ && optype != OP_NULL) {
1385+
S_opdump_indent(aTHX_ o, level, bar, file, "TARG = %ld",
1386+
(long)o->op_targ);
1387+
1388+
/* Display the names of the lexical variables (if any)
1389+
* associated with op_targ */
1390+
int n = 1;
1391+
1392+
switch (o->op_type) {
1393+
case OP_PADRANGE:
1394+
n = o->op_private & OPpPADRANGE_COUNTMASK;
1395+
/* FALLTHROUGH */
1396+
case OP_PADSV:
1397+
case OP_PADAV:
1398+
case OP_PADHV:
1399+
case OP_ARGELEM:
1400+
case OP_PADSV_STORE:
1401+
case OP_AELEMFAST_LEX:
1402+
do_lex:
1403+
PerlIO_puts(file, " ");
1404+
S_deb_padvar_cv(aTHX_ S_get_cv_from_op(aTHX_ o, rootcv),
1405+
o->op_targ,
1406+
n, 1);
1407+
break;
1408+
1409+
default:
1410+
if ( (PL_opargs[o->op_type] & OA_TARGLEX)
1411+
&& (o->op_private & OPpTARGET_MY))
1412+
goto do_lex;
1413+
}
1414+
1415+
PerlIO_puts(file, "\n");
1416+
}
13851417

13861418
if (o->op_flags || o->op_slabbed || o->op_savefree || o->op_static) {
13871419
SV * const tmpsv = newSVpvs("");

0 commit comments

Comments
 (0)