This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: regpiece() Don't match 0 length more than once
[perl5.git] / dump.c
diff --git a/dump.c b/dump.c
index 5a3f281..e395790 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -21,7 +21,7 @@
  *
  * It also holds the debugging version of the  runops function.
 
-=head1 Display and Dump functions
+=for apidoc_section Display and Dump functions
  */
 
 #include "EXTERN.h"
@@ -132,6 +132,23 @@ sequences, whereas C<"%"> is not a particularly common character in patterns.
 
 Returns a pointer to the escaped text as held by C<dsv>.
 
+=for apidoc Amnh||PERL_PV_ESCAPE_ALL
+=for apidoc Amnh||PERL_PV_ESCAPE_FIRSTCHAR
+=for apidoc Amnh||PERL_PV_ESCAPE_NOBACKSLASH
+=for apidoc Amnh||PERL_PV_ESCAPE_NOCLEAR
+=for apidoc Amnh||PERL_PV_ESCAPE_NONASCII
+=for apidoc Amnh||PERL_PV_ESCAPE_QUOTE
+=for apidoc Amnh||PERL_PV_ESCAPE_RE
+=for apidoc Amnh||PERL_PV_ESCAPE_UNI
+=for apidoc Amnh||PERL_PV_ESCAPE_UNI_DETECT
+
+=cut
+
+Unused or not for public use
+=for apidoc Cmnh||PERL_PV_PRETTY_REGPROP
+=for apidoc Cmnh||PERL_PV_PRETTY_DUMP
+=for apidoc Cmnh||PERL_PV_PRETTY_NOCLEAR
+
 =cut
 */
 #define PV_ESCAPE_OCTBUFSIZE 32
@@ -205,16 +222,16 @@ Perl_pv_escape( pTHX_ SV *dsv, char const * const str,
                             chsize = 1;
                         break;
                default:
-                     if ( (flags & PERL_PV_ESCAPE_DWIM) && c != '\0' ) {
+                    if ( (flags & PERL_PV_ESCAPE_DWIM) && c != '\0' ) {
                         chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
                                       isuni ? "%cx{%02" UVxf "}" : "%cx%02" UVxf,
                                       esc, u);
-                     }
-                     else if ( (pv+readsize < end) && isDIGIT((U8)*(pv+readsize)) )
-                            chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE, 
+                    }
+                    else if ((pv+readsize < end) && isDIGIT((U8)*(pv+readsize)))
+                        chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
                                                   "%c%03o", esc, c);
-                       else
-                            chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE, 
+                    else
+                        chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE,
                                                   "%c%o", esc, c);
                 }
             } else {
@@ -267,6 +284,10 @@ any quotes or ellipses.
 
 Returns a pointer to the prettified text as held by C<dsv>.
 
+=for apidoc Amnh||PERL_PV_PRETTY_QUOTE
+=for apidoc Amnh||PERL_PV_PRETTY_LTGT
+=for apidoc Amnh||PERL_PV_PRETTY_ELLIPSES
+
 =cut           
 */
 
@@ -353,7 +374,6 @@ Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pv
 char *
 Perl_sv_peek(pTHX_ SV *sv)
 {
-    dVAR;
     SV * const t = sv_newmortal();
     int unref = 0;
     U32 type;
@@ -361,24 +381,26 @@ Perl_sv_peek(pTHX_ SV *sv)
     SvPVCLEAR(t);
   retry:
     if (!sv) {
-       sv_catpv(t, "VOID");
+       sv_catpvs(t, "VOID");
        goto finish;
     }
     else if (sv == (const SV *)0x55555555 || ((char)SvTYPE(sv)) == 'U') {
         /* detect data corruption under memory poisoning */
-       sv_catpv(t, "WILD");
+       sv_catpvs(t, "WILD");
        goto finish;
     }
-    else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) {
+    else if (  sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes
+            || sv == &PL_sv_zero || sv == &PL_sv_placeholder)
+    {
        if (sv == &PL_sv_undef) {
-           sv_catpv(t, "SV_UNDEF");
+           sv_catpvs(t, "SV_UNDEF");
            if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
                                 SVs_GMG|SVs_SMG|SVs_RMG)) &&
                SvREADONLY(sv))
                goto finish;
        }
        else if (sv == &PL_sv_no) {
-           sv_catpv(t, "SV_NO");
+           sv_catpvs(t, "SV_NO");
            if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
                                 SVs_GMG|SVs_SMG|SVs_RMG)) &&
                !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
@@ -388,7 +410,7 @@ Perl_sv_peek(pTHX_ SV *sv)
                goto finish;
        }
        else if (sv == &PL_sv_yes) {
-           sv_catpv(t, "SV_YES");
+           sv_catpvs(t, "SV_YES");
            if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
                                 SVs_GMG|SVs_SMG|SVs_RMG)) &&
                !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
@@ -398,17 +420,28 @@ Perl_sv_peek(pTHX_ SV *sv)
                SvNVX(sv) == 1.0)
                goto finish;
        }
+       else if (sv == &PL_sv_zero) {
+           sv_catpvs(t, "SV_ZERO");
+           if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
+                                SVs_GMG|SVs_SMG|SVs_RMG)) &&
+               !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
+                                 SVp_POK|SVp_NOK)) &&
+               SvCUR(sv) == 1 &&
+               SvPVX_const(sv) && *SvPVX_const(sv) == '0' &&
+               SvNVX(sv) == 0.0)
+               goto finish;
+       }
        else {
-           sv_catpv(t, "SV_PLACEHOLDER");
+           sv_catpvs(t, "SV_PLACEHOLDER");
            if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
                                 SVs_GMG|SVs_SMG|SVs_RMG)) &&
                SvREADONLY(sv))
                goto finish;
        }
-       sv_catpv(t, ":");
+       sv_catpvs(t, ":");
     }
     else if (SvREFCNT(sv) == 0) {
-       sv_catpv(t, "(");
+       sv_catpvs(t, "(");
        unref++;
     }
     else if (DEBUG_R_TEST_) {
@@ -432,11 +465,11 @@ Perl_sv_peek(pTHX_ SV *sv)
     }
 
     if (SvROK(sv)) {
-       sv_catpv(t, "\\");
+       sv_catpvs(t, "\\");
        if (SvCUR(t) + unref > 10) {
            SvCUR_set(t, unref + 3);
            *SvEND(t) = '\0';
-           sv_catpv(t, "...");
+           sv_catpvs(t, "...");
            goto finish;
        }
        sv = SvRV(sv);
@@ -456,16 +489,16 @@ Perl_sv_peek(pTHX_ SV *sv)
        if (type == SVt_NULL)
            goto finish;
     } else {
-       sv_catpv(t, "FREED");
+       sv_catpvs(t, "FREED");
        goto finish;
     }
 
     if (SvPOKp(sv)) {
        if (!SvPVX_const(sv))
-           sv_catpv(t, "(null)");
+           sv_catpvs(t, "(null)");
        else {
            SV * const tmp = newSVpvs("");
-           sv_catpv(t, "(");
+           sv_catpvs(t, "(");
            if (SvOOK(sv)) {
                STRLEN delta;
                SvOOK_offset(sv, delta);
@@ -480,9 +513,10 @@ Perl_sv_peek(pTHX_ SV *sv)
        }
     }
     else if (SvNOKp(sv)) {
-       STORE_LC_NUMERIC_UNDERLYING_SET_STANDARD();
+        DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
+        STORE_LC_NUMERIC_SET_STANDARD();
        Perl_sv_catpvf(aTHX_ t, "(%" NVgf ")",SvNVX(sv));
-       RESTORE_LC_NUMERIC_UNDERLYING();
+        RESTORE_LC_NUMERIC();
     }
     else if (SvIOKp(sv)) {
        if (SvIsUV(sv))
@@ -491,20 +525,16 @@ Perl_sv_peek(pTHX_ SV *sv)
             Perl_sv_catpvf(aTHX_ t, "(%" IVdf ")", (IV)SvIVX(sv));
     }
     else
-       sv_catpv(t, "()");
+       sv_catpvs(t, "()");
 
   finish:
     while (unref--)
-       sv_catpv(t, ")");
+       sv_catpvs(t, ")");
     if (TAINTING_get && sv && SvTAINTED(sv))
-       sv_catpv(t, " [tainted]");
+       sv_catpvs(t, " [tainted]");
     return SvPV_nolen(t);
 }
 
-/*
-=head1 Debugging Utilities
-*/
-
 void
 Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...)
 {
@@ -523,6 +553,91 @@ Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
     PerlIO_vprintf(file, pat, *args);
 }
 
+
+/* Like Perl_dump_indent(), but specifically for ops: adds a vertical bar
+ * for each indent level as appropriate.
+ *
+ * bar contains bits indicating which indent columns should have a
+ * vertical bar displayed. Bit 0 is the RH-most column. If there are more
+ * levels than bits in bar, then the first few indents are displayed
+ * without a bar.
+ *
+ * The start of a new op is signalled by passing a value for level which
+ * has been negated and offset by 1 (so that level 0 is passed as -1 and
+ * can thus be distinguished from -0); in this case, emit a suitably
+ * indented blank line, then on the next line, display the op's sequence
+ * number, and make the final indent an '+----'.
+ *
+ * e.g.
+ *
+ *      |   FOO       # level = 1,   bar = 0b1
+ *      |   |         # level =-2-1, bar = 0b11
+ * 1234 |   +---BAR
+ *      |       BAZ   # level = 2,   bar = 0b10
+ */
+
+static void
+S_opdump_indent(pTHX_ const OP *o, I32 level, UV bar, PerlIO *file,
+                const char* pat, ...)
+{
+    va_list args;
+    I32 i;
+    bool newop = (level < 0);
+
+    va_start(args, pat);
+
+    /* start displaying a new op? */
+    if (newop) {
+        UV seq = sequence_num(o);
+
+        level = -level - 1;
+
+        /* output preceding blank line */
+        PerlIO_puts(file, "     ");
+        for (i = level-1; i >= 0; i--)
+            PerlIO_puts(file,  (   i == 0
+                                || (i < UVSIZE*8 && (bar & ((UV)1 << i)))
+                               )
+                                    ?  "|   " : "    ");
+        PerlIO_puts(file, "\n");
+
+        /* output sequence number */
+        if (seq)
+            PerlIO_printf(file, "%-4" UVuf " ", seq);
+        else
+            PerlIO_puts(file, "???? ");
+
+    }
+    else
+       PerlIO_printf(file, "     ");
+
+    for (i = level-1; i >= 0; i--)
+            PerlIO_puts(file,
+                  (i == 0 && newop) ? "+--"
+                : (bar & (1 << i))  ? "|   "
+                :                     "    ");
+    PerlIO_vprintf(file, pat, args);
+    va_end(args);
+}
+
+
+/* display a link field (e.g. op_next) in the format
+ *     ====> sequence_number [opname 0x123456]
+ */
+
+static void
+S_opdump_link(pTHX_ const OP *base, const OP *o, PerlIO *file)
+{
+    PerlIO_puts(file, " ===> ");
+    if (o == base)
+        PerlIO_puts(file, "[SELF]\n");
+    else if (o)
+        PerlIO_printf(file, "%" UVuf " [%s 0x%" UVxf "]\n",
+            sequence_num(o), OP_NAME(o), PTR2UV(o));
+    else
+        PerlIO_puts(file, "[0x0]\n");
+}
+
 /*
 =for apidoc dump_all
 
@@ -604,27 +719,33 @@ Perl_dump_sub(pTHX_ const GV *gv)
 void
 Perl_dump_sub_perl(pTHX_ const GV *gv, bool justperl)
 {
-    STRLEN len;
-    SV * const sv = newSVpvs_flags("", SVs_TEMP);
-    SV *tmpsv;
-    const char * name;
+    CV *cv;
 
     PERL_ARGS_ASSERT_DUMP_SUB_PERL;
 
-    if (justperl && (CvISXSUB(GvCV(gv)) || !CvROOT(GvCV(gv))))
+    cv = isGV_with_GP(gv) ? GvCV(gv) :
+           (assert(SvROK((SV*)gv)), (CV*)SvRV((SV*)gv));
+    if (justperl && (CvISXSUB(cv) || !CvROOT(cv)))
        return;
 
-    tmpsv = newSVpvs_flags("", SVs_TEMP);
-    gv_fullname3(sv, gv, NULL);
-    name = SvPV_const(sv, len);
-    Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ",
-                     generic_pv_escape(tmpsv, name, len, SvUTF8(sv)));
-    if (CvISXSUB(GvCV(gv)))
+    if (isGV_with_GP(gv)) {
+       SV * const namesv = newSVpvs_flags("", SVs_TEMP);
+       SV *escsv = newSVpvs_flags("", SVs_TEMP);
+       const char *namepv;
+       STRLEN namelen;
+       gv_fullname3(namesv, gv, NULL);
+       namepv = SvPV_const(namesv, namelen);
+       Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ",
+                    generic_pv_escape(escsv, namepv, namelen, SvUTF8(namesv)));
+    } else {
+       Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB = ");
+    }
+    if (CvISXSUB(cv))
        Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%" UVxf " %d)\n",
-           PTR2UV(CvXSUB(GvCV(gv))),
-           (int)CvXSUBANY(GvCV(gv)).any_i32);
-    else if (CvROOT(GvCV(gv)))
-       op_dump(CvROOT(GvCV(gv)));
+           PTR2UV(CvXSUB(cv)),
+           (int)CvXSUBANY(cv).any_i32);
+    else if (CvROOT(cv))
+       op_dump(CvROOT(cv));
     else
        Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n");
 }
@@ -650,51 +771,103 @@ Perl_dump_eval(pTHX)
     op_dump(PL_eval_root);
 }
 
-void
-Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
+
+/* returns a temp SV displaying the name of a GV. Handles the case where
+ * a GV is in fact a ref to a CV */
+
+static SV *
+S_gv_display(pTHX_ GV *gv)
 {
-    char ch;
+    SV * const name = newSVpvs_flags("", SVs_TEMP);
+    if (gv) {
+        SV * const raw = newSVpvs_flags("", SVs_TEMP);
+        STRLEN len;
+        const char * rawpv;
+
+        if (isGV_with_GP(gv))
+            gv_fullname3(raw, gv, NULL);
+        else {
+            assert(SvROK(gv));
+            assert(SvTYPE(SvRV(gv)) == SVt_PVCV);
+            Perl_sv_catpvf(aTHX_ raw, "cv ref: %s",
+                    SvPV_nolen_const(cv_name((CV *)SvRV(gv), name, 0)));
+        }
+        rawpv = SvPV_const(raw, len);
+        generic_pv_escape(name, rawpv, len, SvUTF8(raw));
+    }
+    else
+        sv_catpvs(name, "(NULL)");
 
-    PERL_ARGS_ASSERT_DO_PMOP_DUMP;
+    return name;
+}
+
+
+
+/* forward decl */
+static void
+S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o);
+
+
+static void
+S_do_pmop_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const PMOP *pm)
+{
+    UV kidbar;
 
     if (!pm)
        return;
-    if (pm->op_pmflags & PMf_ONCE)
-       ch = '?';
-    else
-       ch = '/';
-    if (PM_GETRE(pm))
-       Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%.*s%c\n",
+
+    kidbar = ((bar << 1) | cBOOL(pm->op_flags & OPf_KIDS)) << 1;
+
+    if (PM_GETRE(pm)) {
+        char ch = (pm->op_pmflags & PMf_ONCE) ? '?' : '/';
+       S_opdump_indent(aTHX_ (OP*)pm, level, bar, file, "PMf_PRE %c%.*s%c\n",
             ch,(int)RX_PRELEN(PM_GETRE(pm)), RX_PRECOMP(PM_GETRE(pm)), ch);
+    }
     else
-       Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n");
+       S_opdump_indent(aTHX_ (OP*)pm, level, bar, file, "PMf_PRE (RUNTIME)\n");
+
+    if (pm->op_pmflags || (PM_GETRE(pm) && RX_CHECK_SUBSTR(PM_GETRE(pm)))) {
+       SV * const tmpsv = pm_description(pm);
+       S_opdump_indent(aTHX_ (OP*)pm, level, bar, file, "PMFLAGS = (%s)\n",
+                        SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
+       SvREFCNT_dec_NN(tmpsv);
+    }
 
     if (pm->op_type == OP_SPLIT)
-        Perl_dump_indent(aTHX_ level, file, "TARGOFF/GV = 0x%" UVxf "\n",
-                PTR2UV(pm->op_pmreplrootu.op_pmtargetgv));
+        S_opdump_indent(aTHX_ (OP*)pm, level, bar, file,
+                    "TARGOFF/GV = 0x%" UVxf "\n",
+                    PTR2UV(pm->op_pmreplrootu.op_pmtargetgv));
     else {
         if (pm->op_pmreplrootu.op_pmreplroot) {
-            Perl_dump_indent(aTHX_ level, file, "PMf_REPL = ");
-            op_dump(pm->op_pmreplrootu.op_pmreplroot);
+            S_opdump_indent(aTHX_ (OP*)pm, level, bar, file, "PMf_REPL =\n");
+           S_do_op_dump_bar(aTHX_ level + 2,
+                (kidbar|cBOOL(OpHAS_SIBLING(pm->op_pmreplrootu.op_pmreplroot))),
+                file, pm->op_pmreplrootu.op_pmreplroot);
         }
     }
 
     if (pm->op_code_list) {
        if (pm->op_pmflags & PMf_CODELIST_PRIVATE) {
-           Perl_dump_indent(aTHX_ level, file, "CODE_LIST =\n");
-           do_op_dump(level, file, pm->op_code_list);
+           S_opdump_indent(aTHX_ (OP*)pm, level, bar, file, "CODE_LIST =\n");
+           S_do_op_dump_bar(aTHX_ level + 2,
+                            (kidbar | cBOOL(OpHAS_SIBLING(pm->op_code_list))),
+                            file, pm->op_code_list);
        }
        else
-           Perl_dump_indent(aTHX_ level, file, "CODE_LIST = 0x%" UVxf "\n",
-                                   PTR2UV(pm->op_code_list));
-    }
-    if (pm->op_pmflags || (PM_GETRE(pm) && RX_CHECK_SUBSTR(PM_GETRE(pm)))) {
-       SV * const tmpsv = pm_description(pm);
-       Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
-       SvREFCNT_dec_NN(tmpsv);
+           S_opdump_indent(aTHX_ (OP*)pm, level, bar, file,
+                        "CODE_LIST = 0x%" UVxf "\n", PTR2UV(pm->op_code_list));
     }
 }
 
+
+void
+Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm)
+{
+    PERL_ARGS_ASSERT_DO_PMOP_DUMP;
+    S_do_pmop_dump_bar(aTHX_ level, 0, file, pm);
+}
+
+
 const struct flag_to_name pmflags_flags_names[] = {
     {PMf_CONST, ",CONST"},
     {PMf_KEEP, ",KEEP"},
@@ -718,26 +891,26 @@ S_pm_description(pTHX_ const PMOP *pm)
     PERL_ARGS_ASSERT_PM_DESCRIPTION;
 
     if (pmflags & PMf_ONCE)
-       sv_catpv(desc, ",ONCE");
+       sv_catpvs(desc, ",ONCE");
 #ifdef USE_ITHREADS
     if (SvREADONLY(PL_regex_pad[pm->op_pmoffset]))
-        sv_catpv(desc, ":USED");
+        sv_catpvs(desc, ":USED");
 #else
     if (pmflags & PMf_USED)
-        sv_catpv(desc, ":USED");
+        sv_catpvs(desc, ":USED");
 #endif
 
     if (regex) {
         if (RX_ISTAINTED(regex))
-            sv_catpv(desc, ",TAINTED");
+            sv_catpvs(desc, ",TAINTED");
         if (RX_CHECK_SUBSTR(regex)) {
             if (!(RX_INTFLAGS(regex) & PREGf_NOSCAN))
-                sv_catpv(desc, ",SCANFIRST");
+                sv_catpvs(desc, ",SCANFIRST");
             if (RX_EXTFLAGS(regex) & RXf_CHECK_ALL)
-                sv_catpv(desc, ",ALL");
+                sv_catpvs(desc, ",ALL");
         }
         if (RX_EXTFLAGS(regex) & RXf_SKIPWHITE)
-            sv_catpv(desc, ",SKIPWHITE");
+            sv_catpvs(desc, ",SKIPWHITE");
     }
 
     append_flags(desc, pmflags, pmflags_flags_names);
@@ -758,7 +931,6 @@ Perl_pmop_dump(pTHX_ PMOP *pm)
 STATIC UV
 S_sequence_num(pTHX_ const OP *o)
 {
-    dVAR;
     SV     *op,
           **seq;
     const char *key;
@@ -791,56 +963,101 @@ const struct flag_to_name op_flags_names[] = {
 };
 
 
-void
-Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
+/* indexed by enum OPclass */
+const char * const op_class_names[] = {
+    "NULL",
+    "OP",
+    "UNOP",
+    "BINOP",
+    "LOGOP",
+    "LISTOP",
+    "PMOP",
+    "SVOP",
+    "PADOP",
+    "PVOP",
+    "LOOP",
+    "COP",
+    "METHOP",
+    "UNOP_AUX",
+};
+
+
+/* dump an op and any children. level indicates the initial indent.
+ * The bits of bar indicate which indents should receive a vertical bar.
+ * For example if level == 5 and bar == 0b01101, then the indent prefix
+ * emitted will be (not including the <>'s):
+ *
+ *   <    |   |       |   >
+ *    55554444333322221111
+ *
+ * For heavily nested output, the level may exceed the number of bits
+ * in bar; in this case the first few columns in the output will simply
+ * not have a bar, which is harmless.
+ */
+
+static void
+S_do_op_dump_bar(pTHX_ I32 level, UV bar, PerlIO *file, const OP *o)
 {
-    UV      seq;
     const OPCODE optype = o->op_type;
 
     PERL_ARGS_ASSERT_DO_OP_DUMP;
 
-    Perl_dump_indent(aTHX_ level, file, "{\n");
-    level++;
-    seq = sequence_num(o);
-    if (seq)
-       PerlIO_printf(file, "%-4" UVuf, seq);
-    else
-       PerlIO_printf(file, "????");
-    PerlIO_printf(file,
-                 "%*sTYPE = %s  ===> ",
-                 (int)(PL_dumpindent*level-4), "", OP_NAME(o));
-    if (o->op_next)
-       PerlIO_printf(file,
-                       o->op_type == OP_NULL ? "(%" UVuf ")\n" : "%" UVuf "\n",
-                               sequence_num(o->op_next));
-    else
-       PerlIO_printf(file, "NULL\n");
-    if (o->op_targ) {
-       if (optype == OP_NULL) {
-           Perl_dump_indent(aTHX_ level, file, "  (was %s)\n", PL_op_name[o->op_targ]);
-       }
-       else
-           Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ);
+    /* print op header line */
+
+    S_opdump_indent(aTHX_ o, -level-1, bar, file, "%s", OP_NAME(o));
+
+    if (optype == OP_NULL && o->op_targ)
+        PerlIO_printf(file, " (ex-%s)",PL_op_name[o->op_targ]);
+
+    PerlIO_printf(file, " %s(0x%" UVxf ")",
+                    op_class_names[op_class(o)], PTR2UV(o));
+    S_opdump_link(aTHX_ o, o->op_next, file);
+
+    /* print op common fields */
+
+    if (level == 0) {
+        S_opdump_indent(aTHX_ o, level, bar, file, "PARENT");
+        S_opdump_link(aTHX_ o, op_parent((OP*)o), file);
     }
-#ifdef DUMPADDR
-    Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%" UVxf " => 0x%" UVxf "\n",
-                                        (UV)o, (UV)o->op_next);
-#endif
+    else if (!OpHAS_SIBLING(o)) {
+        bool ok = TRUE;
+        OP *p = o->op_sibparent;
+        if (!p || !(p->op_flags & OPf_KIDS))
+            ok = FALSE;
+        else {
+            OP *kid = cUNOPx(p)->op_first;
+            while (kid != o) {
+                kid = OpSIBLING(kid);
+                if (!kid) {
+                    ok = FALSE;
+                    break;
+                }
+            }
+        }
+        if (!ok) {
+            S_opdump_indent(aTHX_ o, level, bar, file,
+                            "*** WILD PARENT 0x%p\n", p);
+        }
+    }
+
+    if (o->op_targ && optype != OP_NULL)
+           S_opdump_indent(aTHX_ o, level, bar, file, "TARG = %ld\n",
+                (long)o->op_targ);
 
     if (o->op_flags || o->op_slabbed || o->op_savefree || o->op_static) {
         SV * const tmpsv = newSVpvs("");
         switch (o->op_flags & OPf_WANT) {
         case OPf_WANT_VOID:
-            sv_catpv(tmpsv, ",VOID");
+            sv_catpvs(tmpsv, ",VOID");
             break;
         case OPf_WANT_SCALAR:
-            sv_catpv(tmpsv, ",SCALAR");
+            sv_catpvs(tmpsv, ",SCALAR");
             break;
         case OPf_WANT_LIST:
-            sv_catpv(tmpsv, ",LIST");
+            sv_catpvs(tmpsv, ",LIST");
             break;
         default:
-            sv_catpv(tmpsv, ",UNKNOWN");
+            sv_catpvs(tmpsv, ",UNKNOWN");
             break;
         }
         append_flags(tmpsv, o->op_flags, op_flags_names);
@@ -849,7 +1066,7 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
         if (o->op_static)   sv_catpvs(tmpsv, ",STATIC");
         if (o->op_folded)   sv_catpvs(tmpsv, ",FOLDED");
         if (o->op_moresib)  sv_catpvs(tmpsv, ",MORESIB");
-        Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n",
+        S_opdump_indent(aTHX_ o, level, bar, file, "FLAGS = (%s)\n",
                          SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : "");
     }
 
@@ -904,10 +1121,10 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
                         /* don't display anonymous zero values */
                         continue;
 
-                    sv_catpv(tmpsv, ",");
+                    sv_catpvs(tmpsv, ",");
                     if (label != -1) {
                         sv_catpv(tmpsv, &PL_op_private_labels[label]);
-                        sv_catpv(tmpsv, "=");
+                        sv_catpvs(tmpsv, "=");
                     }
                     if (enum_label == -1)
                         Perl_sv_catpvf(aTHX_ tmpsv, "0x%" UVxf, (UV)val);
@@ -922,21 +1139,22 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
                              && PL_op_private_labels[ix+1] == '\0'))
                     {
                         oppriv -= (1<<bit);
-                        sv_catpv(tmpsv, ",");
+                        sv_catpvs(tmpsv, ",");
                         sv_catpv(tmpsv, &PL_op_private_labels[ix]);
                     }
                 }
             }
             if (oppriv) {
-                sv_catpv(tmpsv, ",");
+                sv_catpvs(tmpsv, ",");
                 Perl_sv_catpvf(aTHX_ tmpsv, "0x%" UVxf, (UV)oppriv);
             }
         }
        if (tmpsv && SvCUR(tmpsv)) {
-            Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1);
+            S_opdump_indent(aTHX_ o, level, bar, file, "PRIVATE = (%s)\n",
+                            SvPVX_const(tmpsv) + 1);
        } else
-            Perl_dump_indent(aTHX_ level, file, "PRIVATE = (0x%" UVxf ")\n",
-                                   (UV)oppriv);
+            S_opdump_indent(aTHX_ o, level, bar, file,
+                            "PRIVATE = (0x%" UVxf ")\n", (UV)oppriv);
     }
 
     switch (optype) {
@@ -944,22 +1162,12 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
     case OP_GVSV:
     case OP_GV:
 #ifdef USE_ITHREADS
-       Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
+       S_opdump_indent(aTHX_ o, level, bar, file,
+                        "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix);
 #else
-       if ( ! (o->op_flags & OPf_SPECIAL)) { /* not lexical */
-           if (cSVOPo->op_sv) {
-      STRLEN len;
-      const char * name;
-      SV * const tmpsv  = newSVpvs_flags("", SVs_TEMP);
-      SV * const tmpsv2 = newSVpvs_flags("", SVs_TEMP);
-               gv_fullname3(tmpsv, MUTABLE_GV(cSVOPo->op_sv), NULL);
-      name = SvPV_const(tmpsv, len);
-               Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
-                       generic_pv_escape( tmpsv2, name, len, SvUTF8(tmpsv)));
-           }
-           else
-               Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
-       }
+        S_opdump_indent(aTHX_ o, level, bar, file,
+            "GV = %" SVf " (0x%" UVxf ")\n",
+            SVfARG(S_gv_display(aTHX_ cGVOPo_gv)), PTR2UV(cGVOPo_gv));
 #endif
        break;
 
@@ -968,13 +1176,23 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
         UNOP_AUX_item *items = cUNOP_AUXo->op_aux;
         UV i, count = items[-1].uv;
 
-       Perl_dump_indent(aTHX_ level, file, "ARGS = \n");
+       S_opdump_indent(aTHX_ o, level, bar, file, "ARGS = \n");
         for (i=0; i < count;  i++)
-            Perl_dump_indent(aTHX_ level+1, file, "%" UVuf " => 0x%" UVxf "\n",
+            S_opdump_indent(aTHX_ o, level+1, (bar << 1), file,
+                                    "%" UVuf " => 0x%" UVxf "\n",
                                     i, items[i].uv);
        break;
     }
 
+    case OP_MULTICONCAT:
+       S_opdump_indent(aTHX_ o, level, bar, file, "NARGS = %" IVdf "\n",
+            (IV)cUNOP_AUXo->op_aux[PERL_MULTICONCAT_IX_NARGS].ssize);
+        /* XXX really ought to dump each field individually,
+         * but that's too much like hard work */
+       S_opdump_indent(aTHX_ o, level, bar, file, "CONSTS = (%" SVf ")\n",
+            SVfARG(multiconcat_stringify(o)));
+       break;
+
     case OP_CONST:
     case OP_HINTSEVAL:
     case OP_METHOD_NAMED:
@@ -984,7 +1202,8 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
 #ifndef USE_ITHREADS
        /* with ITHREADS, consts are stored in the pad, and the right pad
         * may not be active here, so skip */
-       Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cMETHOPx_meth(o)));
+       S_opdump_indent(aTHX_ o, level, bar, file, "SV = %s\n",
+                        SvPEEK(cMETHOPx_meth(o)));
 #endif
        break;
     case OP_NULL:
@@ -994,64 +1213,69 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
     case OP_NEXTSTATE:
     case OP_DBSTATE:
        if (CopLINE(cCOPo))
-           Perl_dump_indent(aTHX_ level, file, "LINE = %" UVuf "\n",
+           S_opdump_indent(aTHX_ o, level, bar, file, "LINE = %" UVuf "\n",
                             (UV)CopLINE(cCOPo));
-    if (CopSTASHPV(cCOPo)) {
-        SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
-        HV *stash = CopSTASH(cCOPo);
-        const char * const hvname = HvNAME_get(stash);
-        
-           Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n",
-                           generic_pv_escape(tmpsv, hvname,
-                              HvNAMELEN(stash), HvNAMEUTF8(stash)));
-    }
-  if (CopLABEL(cCOPo)) {
-       SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
-       STRLEN label_len;
-       U32 label_flags;
-       const char *label = CopLABEL_len_flags(cCOPo,
-                                                &label_len, &label_flags);
-       Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
-                           generic_pv_escape( tmpsv, label, label_len,
-                                      (label_flags & SVf_UTF8)));
-   }
-        Perl_dump_indent(aTHX_ level, file, "SEQ = %u\n",
+
+        if (CopSTASHPV(cCOPo)) {
+            SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+            HV *stash = CopSTASH(cCOPo);
+            const char * const hvname = HvNAME_get(stash);
+
+            S_opdump_indent(aTHX_ o, level, bar, file, "PACKAGE = \"%s\"\n",
+                               generic_pv_escape(tmpsv, hvname,
+                                  HvNAMELEN(stash), HvNAMEUTF8(stash)));
+        }
+
+        if (CopLABEL(cCOPo)) {
+            SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+            STRLEN label_len;
+            U32 label_flags;
+            const char *label = CopLABEL_len_flags(cCOPo,
+                                                     &label_len, &label_flags);
+            S_opdump_indent(aTHX_ o, level, bar, file, "LABEL = \"%s\"\n",
+                                generic_pv_escape( tmpsv, label, label_len,
+                                           (label_flags & SVf_UTF8)));
+        }
+
+        S_opdump_indent(aTHX_ o, level, bar, file, "SEQ = %u\n",
                          (unsigned int)cCOPo->cop_seq);
        break;
+
+    case OP_ENTERITER:
     case OP_ENTERLOOP:
-       Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
-       if (cLOOPo->op_redoop)
-           PerlIO_printf(file, "%" UVuf "\n", sequence_num(cLOOPo->op_redoop));
-       else
-           PerlIO_printf(file, "DONE\n");
-       Perl_dump_indent(aTHX_ level, file, "NEXT ===> ");
-       if (cLOOPo->op_nextop)
-           PerlIO_printf(file, "%" UVuf "\n", sequence_num(cLOOPo->op_nextop));
-       else
-           PerlIO_printf(file, "DONE\n");
-       Perl_dump_indent(aTHX_ level, file, "LAST ===> ");
-       if (cLOOPo->op_lastop)
-           PerlIO_printf(file, "%" UVuf "\n", sequence_num(cLOOPo->op_lastop));
-       else
-           PerlIO_printf(file, "DONE\n");
+       S_opdump_indent(aTHX_ o, level, bar, file, "REDO");
+        S_opdump_link(aTHX_ o, cLOOPo->op_redoop, file);
+       S_opdump_indent(aTHX_ o, level, bar, file, "NEXT");
+        S_opdump_link(aTHX_ o, cLOOPo->op_nextop, file);
+       S_opdump_indent(aTHX_ o, level, bar, file, "LAST");
+        S_opdump_link(aTHX_ o, cLOOPo->op_lastop, file);
        break;
+
+    case OP_REGCOMP:
+    case OP_SUBSTCONT:
     case OP_COND_EXPR:
     case OP_RANGE:
     case OP_MAPWHILE:
     case OP_GREPWHILE:
     case OP_OR:
+    case OP_DOR:
     case OP_AND:
-       Perl_dump_indent(aTHX_ level, file, "OTHER ===> ");
-       if (cLOGOPo->op_other)
-           PerlIO_printf(file, "%" UVuf "\n", sequence_num(cLOGOPo->op_other));
-       else
-           PerlIO_printf(file, "DONE\n");
+    case OP_ORASSIGN:
+    case OP_DORASSIGN:
+    case OP_ANDASSIGN:
+    case OP_ARGDEFELEM:
+    case OP_ENTERGIVEN:
+    case OP_ENTERWHEN:
+    case OP_ENTERTRY:
+    case OP_ONCE:
+       S_opdump_indent(aTHX_ o, level, bar, file, "OTHER");
+        S_opdump_link(aTHX_ o, cLOGOPo->op_other, file);
        break;
     case OP_SPLIT:
     case OP_MATCH:
     case OP_QR:
     case OP_SUBST:
-       do_pmop_dump(level, file, cPMOPo);
+       S_do_pmop_dump_bar(aTHX_ level, bar, file, cPMOPo);
        break;
     case OP_LEAVE:
     case OP_LEAVEEVAL:
@@ -1060,19 +1284,88 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
     case OP_LEAVEWRITE:
     case OP_SCOPE:
        if (o->op_private & OPpREFCOUNTED)
-           Perl_dump_indent(aTHX_ level, file, "REFCNT = %" UVuf "\n", (UV)o->op_targ);
+           S_opdump_indent(aTHX_ o, level, bar, file,
+                            "REFCNT = %" UVuf "\n", (UV)o->op_targ);
        break;
+
+    case OP_DUMP:
+    case OP_GOTO:
+    case OP_NEXT:
+    case OP_LAST:
+    case OP_REDO:
+       if (o->op_flags & (OPf_SPECIAL|OPf_STACKED|OPf_KIDS))
+           break;
+        {
+            SV * const label = newSVpvs_flags("", SVs_TEMP);
+            generic_pv_escape(label, cPVOPo->op_pv, strlen(cPVOPo->op_pv), 0);
+            S_opdump_indent(aTHX_ o, level, bar, file,
+                            "PV = \"%" SVf "\" (0x%" UVxf ")\n",
+                            SVfARG(label), PTR2UV(cPVOPo->op_pv));
+            break;
+        }
+
+    case OP_TRANS:
+    case OP_TRANSR:
+        if (o->op_private & OPpTRANS_USE_SVOP) {
+            /* utf8: table stored as an inversion map */
+#ifndef USE_ITHREADS
+       /* with ITHREADS, it is stored in the pad, and the right pad
+        * may not be active here, so skip */
+            S_opdump_indent(aTHX_ o, level, bar, file,
+                            "INVMAP = 0x%" UVxf "\n",
+                            PTR2UV(MUTABLE_SV(cSVOPo->op_sv)));
+#endif
+        }
+        else {
+            const OPtrans_map * const tbl = (OPtrans_map*)cPVOPo->op_pv;
+            SSize_t i, size = tbl->size;
+
+            S_opdump_indent(aTHX_ o, level, bar, file,
+                            "TABLE = 0x%" UVxf "\n",
+                            PTR2UV(tbl));
+            S_opdump_indent(aTHX_ o, level, bar, file,
+                "  SIZE: 0x%" UVxf "\n", (UV)size);
+
+            /* dump size+1 values, to include the extra slot at the end */
+            for (i = 0; i <= size; i++) {
+                short val = tbl->map[i];
+                if ((i & 0xf) == 0)
+                    S_opdump_indent(aTHX_ o, level, bar, file,
+                        " %4" UVxf ":", (UV)i);
+                if (val < 0)
+                    PerlIO_printf(file, " %2"  IVdf, (IV)val);
+                else
+                    PerlIO_printf(file, " %02" UVxf, (UV)val);
+
+                if ( i == size || (i & 0xf) == 0xf)
+                    PerlIO_printf(file, "\n");
+            }
+        }
+        break;
+
+
     default:
        break;
     }
     if (o->op_flags & OPf_KIDS) {
        OP *kid;
+        level++;
+        bar <<= 1;
        for (kid = cUNOPo->op_first; kid; kid = OpSIBLING(kid))
-           do_op_dump(level, file, kid);
+           S_do_op_dump_bar(aTHX_ level,
+                            (bar | cBOOL(OpHAS_SIBLING(kid))),
+                            file, kid);
     }
-    Perl_dump_indent(aTHX_ level-1, file, "}\n");
 }
 
+
+void
+Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
+{
+    S_do_op_dump_bar(aTHX_ level, 0, file, o);
+}
+
+
 /*
 =for apidoc op_dump
 
@@ -1132,9 +1425,9 @@ Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32
     PERL_ARGS_ASSERT_DO_MAGIC_DUMP;
 
     for (; mg; mg = mg->mg_moremagic) {
-       Perl_dump_indent(aTHX_ level, file,
+        Perl_dump_indent(aTHX_ level, file,
                         "  MAGIC = 0x%" UVxf "\n", PTR2UV(mg));
-       if (mg->mg_virtual) {
+        if (mg->mg_virtual) {
             const MGVTBL * const v = mg->mg_virtual;
            if (v >= PL_magic_vtables
                && v < PL_magic_vtables + magic_vtable_max) {
@@ -1305,7 +1598,7 @@ Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
        const char *hvname;
         HV * const stash = GvSTASH(sv);
        PerlIO_printf(file, "\t");
-   /* TODO might have an extra \" here */
+        /* TODO might have an extra \" here */
        if (stash && (hvname = HvNAME_get(stash))) {
             PerlIO_printf(file, "\"%s\" :: \"",
                                   generic_pv_escape(tmp, hvname,
@@ -1465,22 +1758,22 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                   (int)(PL_dumpindent*level), "");
 
     if ((flags & SVs_PADSTALE))
-           sv_catpv(d, "PADSTALE,");
+           sv_catpvs(d, "PADSTALE,");
     if ((flags & SVs_PADTMP))
-           sv_catpv(d, "PADTMP,");
+           sv_catpvs(d, "PADTMP,");
     append_flags(d, flags, first_sv_flags_names);
     if (flags & SVf_ROK)  {    
-                               sv_catpv(d, "ROK,");
-       if (SvWEAKREF(sv))      sv_catpv(d, "WEAKREF,");
+                                sv_catpvs(d, "ROK,");
+       if (SvWEAKREF(sv))      sv_catpvs(d, "WEAKREF,");
     }
     if (flags & SVf_IsCOW && type != SVt_PVHV) sv_catpvs(d, "IsCOW,");
     append_flags(d, flags, second_sv_flags_names);
     if (flags & SVp_SCREAM && type != SVt_PVHV && !isGV_with_GP(sv)
                           && type != SVt_PVAV) {
        if (SvPCS_IMPORTED(sv))
-                               sv_catpv(d, "PCS_IMPORTED,");
+                               sv_catpvs(d, "PCS_IMPORTED,");
        else
-                               sv_catpv(d, "SCREAM,");
+                               sv_catpvs(d, "SCREAM,");
     }
 
     /* process type-specific SV flags */
@@ -1499,19 +1792,19 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            append_flags(d, GvFLAGS(sv), gp_flags_names);
        }
        if (isGV_with_GP(sv) && GvIMPORTED(sv)) {
-           sv_catpv(d, "IMPORT");
+           sv_catpvs(d, "IMPORT");
            if (GvIMPORTED(sv) == GVf_IMPORTED)
-               sv_catpv(d, "ALL,");
+               sv_catpvs(d, "ALL,");
            else {
-               sv_catpv(d, "(");
+               sv_catpvs(d, "(");
                append_flags(d, GvFLAGS(sv), gp_flags_imported_names);
-               sv_catpv(d, " ),");
+               sv_catpvs(d, " ),");
            }
        }
        /* FALLTHROUGH */
     case SVt_PVMG:
     default:
-       if (SvIsUV(sv) && !(flags & SVf_ROK))   sv_catpv(d, "IsUV,");
+       if (SvIsUV(sv) && !(flags & SVf_ROK))   sv_catpvs(d, "IsUV,");
        break;
 
     case SVt_PVAV:
@@ -1519,13 +1812,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
     }
     /* SVphv_SHAREKEYS is also 0x20000000 */
     if ((type != SVt_PVHV) && SvUTF8(sv))
-        sv_catpv(d, "UTF8");
+        sv_catpvs(d, "UTF8");
 
     if (*(SvEND(d) - 1) == ',') {
         SvCUR_set(d, SvCUR(d) - 1);
        SvPVX(d)[SvCUR(d)] = '\0';
     }
-    sv_catpv(d, ")");
+    sv_catpvs(d, ")");
     s = SvPVX_const(d);
 
     /* dump initial SV details */
@@ -1576,9 +1869,10 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                && type != SVt_PVCV && type != SVt_PVFM  && type != SVt_REGEXP
                && type != SVt_PVIO && !isGV_with_GP(sv) && !SvVALID(sv))
               || type == SVt_NV) {
-       STORE_LC_NUMERIC_UNDERLYING_SET_STANDARD();
+        DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
+        STORE_LC_NUMERIC_SET_STANDARD();
        Perl_dump_indent(aTHX_ level, file, "  NV = %.*" NVgf "\n", NV_DIG, SvNVX(sv));
-       RESTORE_LC_NUMERIC_UNDERLYING();
+        RESTORE_LC_NUMERIC();
     }
 
     if (SvROK(sv)) {
@@ -1630,7 +1924,12 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                 PerlIO_printf(file, "\n");
             }
            Perl_dump_indent(aTHX_ level, file, "  CUR = %" IVdf "\n", (IV)SvCUR(sv));
-           if (!re)
+           if (re && type == SVt_PVLV)
+                /* LV-as-REGEXP usurps len field to store pointer to
+                 * regexp struct */
+               Perl_dump_indent(aTHX_ level, file, "  REGEXP = 0x%" UVxf "\n",
+                   PTR2UV(((XPV*)SvANY(sv))->xpv_len_u.xpvlenu_rx));
+            else
                Perl_dump_indent(aTHX_ level, file, "  LEN = %" IVdf "\n",
                                       (IV)SvLEN(sv));
 #ifdef PERL_COPY_ON_WRITE
@@ -1674,8 +1973,8 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        Perl_dump_indent(aTHX_ level, file, "  MAX = %" IVdf "\n",
                                (IV)AvMAX(sv));
         SvPVCLEAR(d);
-       if (AvREAL(sv)) sv_catpv(d, ",REAL");
-       if (AvREIFY(sv))        sv_catpv(d, ",REIFY");
+       if (AvREAL(sv)) sv_catpvs(d, ",REAL");
+       if (AvREIFY(sv))        sv_catpvs(d, ",REIFY");
        Perl_dump_indent(aTHX_ level, file, "  FLAGS = (%s)\n",
                         SvCUR(d) ? SvPVX_const(d) + 1 : "");
        if (nest < maxnest && AvARRAY(MUTABLE_AV(sv))) {
@@ -1700,7 +1999,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                              (UV)aux->xhv_aux_flags);
         }
        Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%" UVxf, PTR2UV(HvARRAY(sv)));
-       usedkeys = HvUSEDKEYS(sv);
+       usedkeys = HvUSEDKEYS(MUTABLE_HV(sv));
        if (HvARRAY(sv) && usedkeys) {
            /* Show distribution of HEs in the ARRAY */
            int freq[200];
@@ -1801,8 +2100,8 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        {
            const char * const hvname = HvNAME_get(sv);
            if (hvname) {
-          SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
-     Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n",
+                SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+                Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n",
                                        generic_pv_escape( tmpsv, hvname,
                                            HvNAMELEN(sv), HvNAMEUTF8(sv)));
         }
@@ -1828,7 +2127,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                        + (count < 0 ? -count : count);
                    while (hekp < endp) {
                        if (*hekp) {
-             SV *tmp = newSVpvs_flags("", SVs_TEMP);
+                            SV *tmp = newSVpvs_flags("", SVs_TEMP);
                            Perl_sv_catpvf(aTHX_ names, ", \"%s\"",
                               generic_pv_escape(tmp, HEK_KEY(*hekp), HEK_LEN(*hekp), HEK_UTF8(*hekp)));
                        } else {
@@ -1938,14 +2237,14 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
     case SVt_PVCV:
        if (CvAUTOLOAD(sv)) {
            SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
-       STRLEN len;
+            STRLEN len;
            const char *const name =  SvPV_const(sv, len);
            Perl_dump_indent(aTHX_ level, file, "  AUTOLOAD = \"%s\"\n",
                             generic_pv_escape(tmpsv, name, len, SvUTF8(sv)));
        }
        if (SvPOK(sv)) {
-       SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
-       const char *const proto = CvPROTO(sv);
+            SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+            const char *const proto = CvPROTO(sv);
            Perl_dump_indent(aTHX_ level, file, "  PROTOTYPE = \"%s\"\n",
                             generic_pv_escape(tmpsv, proto, CvPROTOLEN(sv),
                                 SvUTF8(sv)));
@@ -2040,13 +2339,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        if (isREGEXP(sv)) goto dumpregexp;
        if (!isGV_with_GP(sv))
            break;
-       {
-          SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
-          Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n",
-                    generic_pv_escape(tmpsv, GvNAME(sv),
-                                      GvNAMELEN(sv),
-                                      GvNAMEUTF8(sv)));
-       }
+        {
+            SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+            Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n",
+                     generic_pv_escape(tmpsv, GvNAME(sv),
+                                       GvNAMELEN(sv),
+                                       GvNAMEUTF8(sv)));
+        }
        Perl_dump_indent(aTHX_ level, file, "  NAMELEN = %" IVdf "\n", (IV)GvNAMELEN(sv));
        do_hv_dump (level, file, "  GvSTASH", GvSTASH(sv));
        Perl_dump_indent(aTHX_ level, file, "  FLAGS = 0x%" UVxf "\n", (UV)GvFLAGS(sv));
@@ -2211,9 +2510,7 @@ For an example of its output, see L<Devel::Peek>.
 void
 Perl_sv_dump(pTHX_ SV *sv)
 {
-    PERL_ARGS_ASSERT_SV_DUMP;
-
-    if (SvROK(sv))
+    if (sv && SvROK(sv))
        do_sv_dump(0, Perl_debug_log, sv, 0, 4, 0, 0);
     else
        do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0);
@@ -2222,16 +2519,30 @@ Perl_sv_dump(pTHX_ SV *sv)
 int
 Perl_runops_debug(pTHX)
 {
+#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
+    SSize_t orig_stack_hwm = PL_curstackinfo->si_stack_hwm;
+
+    PL_curstackinfo->si_stack_hwm = PL_stack_sp - PL_stack_base;
+#endif
+
     if (!PL_op) {
        Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN");
        return 0;
     }
-
     DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n"));
     do {
 #ifdef PERL_TRACE_OPS
         ++PL_op_exec_cnt[PL_op->op_type];
 #endif
+#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
+        if (PL_curstackinfo->si_stack_hwm < PL_stack_sp - PL_stack_base)
+            Perl_croak_nocontext(
+                "panic: previous op failed to extend arg stack: "
+                "base=%p, sp=%p, hwm=%p\n",
+                    PL_stack_base, PL_stack_sp,
+                    PL_stack_base + PL_curstackinfo->si_stack_hwm);
+        PL_curstackinfo->si_stack_hwm = PL_stack_sp - PL_stack_base;
+#endif
        if (PL_debug) {
             ENTER;
             SAVETMPS;
@@ -2261,6 +2572,10 @@ Perl_runops_debug(pTHX)
     DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n"));
     PERL_ASYNC_CHECK();
 
+#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY
+    if (PL_curstackinfo->si_stack_hwm < orig_stack_hwm)
+        PL_curstackinfo->si_stack_hwm = orig_stack_hwm;
+#endif
     TAINT_NOT;
     return 0;
 }
@@ -2498,6 +2813,47 @@ Perl_multideref_stringify(pTHX_ const OP *o, CV *cv)
 }
 
 
+/* Return a temporary SV containing a stringified representation of
+ * the op_aux field of a MULTICONCAT op. Note that if the aux contains
+ * both plain and utf8 versions of the const string and indices, only
+ * the first is displayed.
+ */
+
+SV*
+Perl_multiconcat_stringify(pTHX_ const OP *o)
+{
+    UNOP_AUX_item *aux = cUNOP_AUXo->op_aux;
+    UNOP_AUX_item *lens;
+    STRLEN len;
+    SSize_t nargs;
+    char *s;
+    SV *out = newSVpvn_flags("", 0, SVs_TEMP);
+
+    PERL_ARGS_ASSERT_MULTICONCAT_STRINGIFY;
+
+    nargs = aux[PERL_MULTICONCAT_IX_NARGS].ssize;
+    s   = aux[PERL_MULTICONCAT_IX_PLAIN_PV].pv;
+    len = aux[PERL_MULTICONCAT_IX_PLAIN_LEN].ssize;
+    if (!s) {
+        s   = aux[PERL_MULTICONCAT_IX_UTF8_PV].pv;
+        len = aux[PERL_MULTICONCAT_IX_UTF8_LEN].ssize;
+        sv_catpvs(out, "UTF8 ");
+    }
+    pv_pretty(out, s, len, 50,
+                NULL, NULL,
+                (PERL_PV_PRETTY_NOCLEAR
+                |PERL_PV_PRETTY_QUOTE
+                |PERL_PV_PRETTY_ELLIPSES));
+
+    lens = aux + PERL_MULTICONCAT_IX_LENGTHS;
+    while (nargs-- >= 0) {
+        Perl_sv_catpvf(aTHX_ out, ",%" IVdf, (IV)lens->ssize);
+        lens++;
+    }
+    return out;
+}
+
+
 I32
 Perl_debop(pTHX_ const OP *o)
 {
@@ -2521,22 +2877,8 @@ Perl_debop(pTHX_ const OP *o)
        break;
     case OP_GVSV:
     case OP_GV:
-       if (cGVOPo_gv && isGV(cGVOPo_gv)) {
-           SV * const sv = newSV(0);
-           gv_fullname3(sv, cGVOPo_gv, NULL);
-           PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv));
-           SvREFCNT_dec_NN(sv);
-       }
-       else if (cGVOPo_gv) {
-           SV * const sv = newSV(0);
-           assert(SvROK(cGVOPo_gv));
-           assert(SvTYPE(SvRV(cGVOPo_gv)) == SVt_PVCV);
-           PerlIO_printf(Perl_debug_log, "(cv ref: %s)",
-                   SvPV_nolen_const(cv_name((CV *)SvRV(cGVOPo_gv),sv,0)));
-           SvREFCNT_dec_NN(sv);
-       }
-       else
-           PerlIO_printf(Perl_debug_log, "(NULL)");
+        PerlIO_printf(Perl_debug_log, "(%" SVf ")",
+                SVfARG(S_gv_display(aTHX_ cGVOPo_gv)));
        break;
 
     case OP_PADSV:
@@ -2556,6 +2898,11 @@ Perl_debop(pTHX_ const OP *o)
             SVfARG(multideref_stringify(o, deb_curcv(cxstack_ix))));
         break;
 
+    case OP_MULTICONCAT:
+        PerlIO_printf(Perl_debug_log, "(%" SVf ")",
+            SVfARG(multiconcat_stringify(o)));
+        break;
+
     default:
        break;
     }
@@ -2639,11 +2986,10 @@ Perl_op_class(pTHX_ const OP *o)
          * pointer to a table of shorts used to look up translations.
          * Under utf8, however, a simple table isn't practical; instead,
          * the OP is an SVOP (or, under threads, a PADOP),
-         * and the SV is a reference to a swash
-         * (i.e., an RV pointing to an HV).
+         * and the SV is an AV.
          */
        return (!custom &&
-                  (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))
+                  (o->op_private & OPpTRANS_USE_SVOP)
               )
 #if  defined(USE_ITHREADS)
                ? OPclass_PADOP : OPclass_PVOP;