@@ -876,7 +876,8 @@ Perl_dump_sub(pTHX_ const GV *gv)
876
876
877
877
/* forward decl */
878
878
static void
879
- S_do_op_dump_bar (pTHX_ I32 level , UV bar , PerlIO * file , const OP * o );
879
+ S_do_op_dump_bar (pTHX_ I32 level , UV bar , PerlIO * file , const OP * o ,
880
+ CV * rootcv );
880
881
881
882
882
883
void
@@ -907,7 +908,7 @@ Perl_dump_sub_perl(pTHX_ const GV *gv, bool justperl)
907
908
PTR2UV (CvXSUB (cv )),
908
909
(int )CvXSUBANY (cv ).any_i32 );
909
910
else if (CvROOT (cv ))
910
- S_do_op_dump_bar (aTHX_ 0 , 0 , Perl_debug_log , CvROOT (cv ));
911
+ S_do_op_dump_bar (aTHX_ 0 , 0 , Perl_debug_log , CvROOT (cv ), cv );
911
912
else
912
913
Perl_dump_indent (aTHX_ 0 , Perl_debug_log , "<undef>\n" );
913
914
}
@@ -973,7 +974,8 @@ S_gv_display(pTHX_ GV *gv)
973
974
974
975
975
976
static void
976
- S_do_pmop_dump_bar (pTHX_ I32 level , UV bar , PerlIO * file , const PMOP * pm )
977
+ S_do_pmop_dump_bar (pTHX_ I32 level , UV bar , PerlIO * file , const PMOP * pm ,
978
+ CV * rootcv )
977
979
{
978
980
UV kidbar ;
979
981
@@ -1013,7 +1015,7 @@ S_do_pmop_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const PMOP *pm)
1013
1015
S_opdump_indent (aTHX_ (OP * )pm , level , bar , file , "PMf_REPL = \n ");
1014
1016
S_do_op_dump_bar (aTHX_ level + 2 ,
1015
1017
(kidbar |cBOOL (OpHAS_SIBLING (pm -> op_pmreplrootu .op_pmreplroot ))),
1016
- file , pm -> op_pmreplrootu .op_pmreplroot );
1018
+ file , pm -> op_pmreplrootu .op_pmreplroot , rootcv );
1017
1019
}
1018
1020
}
1019
1021
@@ -1022,7 +1024,7 @@ S_do_pmop_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const PMOP *pm)
1022
1024
S_opdump_indent (aTHX_ (OP * )pm , level , bar , file , "CODE_LIST = \n ");
1023
1025
S_do_op_dump_bar (aTHX_ level + 2 ,
1024
1026
(kidbar | cBOOL (OpHAS_SIBLING (pm -> op_code_list ))),
1025
- file , pm -> op_code_list );
1027
+ file , pm -> op_code_list , rootcv );
1026
1028
}
1027
1029
else
1028
1030
S_opdump_indent (aTHX_ (OP * )pm , level , bar , file ,
@@ -1035,7 +1037,7 @@ void
1035
1037
Perl_do_pmop_dump (pTHX_ I32 level , PerlIO * file , const PMOP * pm )
1036
1038
{
1037
1039
PERL_ARGS_ASSERT_DO_PMOP_DUMP ;
1038
- S_do_pmop_dump_bar (aTHX_ level , 0 , file , pm );
1040
+ S_do_pmop_dump_bar (aTHX_ level , 0 , file , pm , NULL );
1039
1041
}
1040
1042
1041
1043
@@ -1107,13 +1109,16 @@ S_pm_description(pTHX_ const PMOP *pm)
1107
1109
*
1108
1110
* Return NULL if it can't be found.
1109
1111
*
1112
+ * Sometimes the caller *does* know what CV is being dumped; if so, it
1113
+ * is passed as rootcv.
1114
+ *
1110
1115
* Since this may be called during debugging and things may not be in a
1111
1116
* sane state, be conservative, and if in doubt, return NULL.
1112
1117
*/
1113
1118
1114
1119
#ifdef USE_ITHREADS
1115
1120
static SV *
1116
- S_get_sv_from_pad (pTHX_ const OP * o , PADOFFSET po )
1121
+ S_get_sv_from_pad (pTHX_ const OP * o , PADOFFSET po , CV * rootcv )
1117
1122
{
1118
1123
PADLIST * padlist ; /* declare early to work round compiler quirks */
1119
1124
@@ -1122,6 +1127,11 @@ S_get_sv_from_pad(pTHX_ const OP *o, PADOFFSET po)
1122
1127
1123
1128
CV * cv = NULL ;
1124
1129
1130
+ if (rootcv ) {
1131
+ cv = rootcv ;
1132
+ goto got_cv ;
1133
+ }
1134
+
1125
1135
/* Find the root of the optree this op is embedded in. For a compiled
1126
1136
* sub, this root will typically be a leavesub or similar attached to
1127
1137
* a CV. If compiling, this may be a small subtree on the parser
@@ -1296,10 +1306,14 @@ const char * const op_class_names[] = {
1296
1306
* For heavily nested output, the level may exceed the number of bits
1297
1307
* in bar; in this case the first few columns in the output will simply
1298
1308
* not have a bar, which is harmless.
1309
+ *
1310
+ * rootcv is the CV (if any) whose CvROOT() is the root of the optree
1311
+ * currently being dumped.
1299
1312
*/
1300
1313
1301
1314
static void
1302
- S_do_op_dump_bar (pTHX_ I32 level , UV bar , PerlIO * file , const OP * o )
1315
+ S_do_op_dump_bar (pTHX_ I32 level , UV bar , PerlIO * file , const OP * o ,
1316
+ CV * rootcv )
1303
1317
{
1304
1318
const OPCODE optype = o -> op_type ;
1305
1319
@@ -1469,7 +1483,7 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
1469
1483
#ifdef USE_ITHREADS
1470
1484
S_opdump_indent (aTHX_ o , level , bar , file ,
1471
1485
"PADIX = %" IVdf "\n" , (IV )cPADOPo -> op_padix );
1472
- gv = (GV * )S_get_sv_from_pad (aTHX_ o , cPADOPx (o )-> op_padix );
1486
+ gv = (GV * )S_get_sv_from_pad (aTHX_ o , cPADOPx (o )-> op_padix , rootcv );
1473
1487
#else
1474
1488
gv = (GV * )cSVOPx (o )-> op_sv ;
1475
1489
#endif
@@ -1518,7 +1532,7 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
1518
1532
S_opdump_indent (aTHX_ o , level , bar , file ,
1519
1533
"OP_SV = 0x0 \n ");
1520
1534
#ifdef USE_ITHREADS
1521
- sv = S_get_sv_from_pad (aTHX_ o , o -> op_targ );
1535
+ sv = S_get_sv_from_pad (aTHX_ o , o -> op_targ , rootcv );
1522
1536
#endif
1523
1537
}
1524
1538
@@ -1545,7 +1559,7 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
1545
1559
S_opdump_indent (aTHX_ o , level , bar , file ,
1546
1560
"OP_METH_SV = 0x0 \n ");
1547
1561
#ifdef USE_ITHREADS
1548
- sv = S_get_sv_from_pad (aTHX_ o , o -> op_targ );
1562
+ sv = S_get_sv_from_pad (aTHX_ o , o -> op_targ , rootcv );
1549
1563
#endif
1550
1564
}
1551
1565
@@ -1561,7 +1575,8 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
1561
1575
#ifdef USE_ITHREADS
1562
1576
S_opdump_indent (aTHX_ o , level , bar , file ,
1563
1577
"RCLASS_TARG = %" IVdf "\n" , (IV )cMETHOPo -> op_rclass_targ );
1564
- sv = S_get_sv_from_pad (aTHX_ o , cMETHOPo -> op_rclass_targ );
1578
+ sv = S_get_sv_from_pad (aTHX_ o , cMETHOPo -> op_rclass_targ ,
1579
+ rootcv );
1565
1580
#else
1566
1581
sv = cMETHOPo -> op_rclass_sv ;
1567
1582
#endif
@@ -1651,7 +1666,7 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
1651
1666
case OP_MATCH :
1652
1667
case OP_QR :
1653
1668
case OP_SUBST :
1654
- S_do_pmop_dump_bar (aTHX_ level , bar , file , cPMOPo );
1669
+ S_do_pmop_dump_bar (aTHX_ level , bar , file , cPMOPo , rootcv );
1655
1670
break ;
1656
1671
case OP_LEAVE :
1657
1672
case OP_LEAVEEVAL :
@@ -1788,15 +1803,15 @@ S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
1788
1803
for (kid = cUNOPo -> op_first ; kid ; kid = OpSIBLING (kid ))
1789
1804
S_do_op_dump_bar (aTHX_ level ,
1790
1805
(bar | cBOOL (OpHAS_SIBLING (kid ))),
1791
- file , kid );
1806
+ file , kid , rootcv );
1792
1807
}
1793
1808
}
1794
1809
1795
1810
1796
1811
void
1797
1812
Perl_do_op_dump (pTHX_ I32 level , PerlIO * file , const OP * o )
1798
1813
{
1799
- S_do_op_dump_bar (aTHX_ level , 0 , file , o );
1814
+ S_do_op_dump_bar (aTHX_ level , 0 , file , o , NULL );
1800
1815
}
1801
1816
1802
1817
0 commit comments