This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Silence compiler warning
[perl5.git] / dump.c
diff --git a/dump.c b/dump.c
index ac46ad8..ae0ca1e 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -84,6 +84,11 @@ S_append_flags(pTHX_ SV *sv, U32 flags, const struct flag_to_name *start,
 #define append_flags(sv, f, flags) \
     S_append_flags(aTHX_ (sv), (f), (flags), C_ARRAY_END(flags))
 
+#define generic_pv_escape(sv,s,len,utf8) pv_escape( (sv), (s), (len), \
+                              (len) * (4+UTF8_MAXBYTES) + 1, NULL, \
+                              PERL_PV_ESCAPE_NONASCII | PERL_PV_ESCAPE_DWIM \
+                              | ((utf8) ? PERL_PV_ESCAPE_UNI : 0) )
+
 /*
 =for apidoc pv_escape
 
@@ -105,18 +110,19 @@ If PERL_PV_ESCAPE_ALL is set then all input chars will be output
 using C<\x01F1> style escapes, otherwise if PERL_PV_ESCAPE_NONASCII is set, only
 non-ASCII chars will be escaped using this style; otherwise, only chars above
 255 will be so escaped; other non printable chars will use octal or
-common escaped patterns like C<\n>. Otherwise, if PERL_PV_ESCAPE_NOBACKSLASH
+common escaped patterns like C<\n>.
+Otherwise, if PERL_PV_ESCAPE_NOBACKSLASH
 then all chars below 255 will be treated as printable and
 will be output as literals.
 
 If PERL_PV_ESCAPE_FIRSTCHAR is set then only the first char of the
-string will be escaped, regardless of max. If the output is to be in hex,
+string will be escaped, regardless of max.  If the output is to be in hex,
 then it will be returned as a plain hex
-sequence. Thus the output will either be a single char,
+sequence.  Thus the output will either be a single char,
 an octal escape sequence, a special escape like C<\n> or a hex value.
 
 If PERL_PV_ESCAPE_RE is set then the escape char used will be a '%' and
-not a '\\'. This is because regexes very often contain backslashed
+not a '\\'.  This is because regexes very often contain backslashed
 sequences, whereas '%' is not a particularly common character in patterns.
 
 Returns a pointer to the escaped text as held by dsv.
@@ -157,14 +163,17 @@ Perl_pv_escape( pTHX_ SV *dsv, char const * const str,
         
         if ( ( u > 255 )
          || (flags & PERL_PV_ESCAPE_ALL)
-         || (( ! isASCII(u) ) && (flags & PERL_PV_ESCAPE_NONASCII)))
+         || (( ! isASCII(u) ) && (flags & (PERL_PV_ESCAPE_NONASCII|PERL_PV_ESCAPE_DWIM))))
        {
             if (flags & PERL_PV_ESCAPE_FIRSTCHAR) 
                 chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE, 
                                       "%"UVxf, u);
             else
                 chsize = my_snprintf( octbuf, PV_ESCAPE_OCTBUFSIZE, 
-                                      "%cx{%"UVxf"}", esc, u);
+                                      ((flags & PERL_PV_ESCAPE_DWIM) && !isuni)
+                                      ? "%cx%02"UVxf
+                                      : "%cx{%02"UVxf"}", esc, u);
+
         } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) {
             chsize = 1;            
         } else {         
@@ -172,7 +181,7 @@ Perl_pv_escape( pTHX_ SV *dsv, char const * const str,
                chsize = 2;
                 switch (c) {
                 
-               case '\\' : /* fallthrough */
+               case '\\' : /* FALLTHROUGH */
                case '%'  : if ( c == esc )  {
                                octbuf[1] = esc;  
                            } else {
@@ -191,7 +200,12 @@ Perl_pv_escape( pTHX_ SV *dsv, char const * const str,
                             chsize = 1;
                         break;
                default:
-                        if ( (pv+readsize < end) && isDIGIT((U8)*(pv+readsize)) )
+                     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, 
                                                   "%c%03o", esc, c);
                        else
@@ -231,16 +245,16 @@ Converts a string into something presentable, handling escaping via
 pv_escape() and supporting quoting and ellipses.
 
 If the PERL_PV_PRETTY_QUOTE flag is set then the result will be 
-double quoted with any double quotes in the string escaped. Otherwise
+double quoted with any double quotes in the string escaped.  Otherwise
 if the PERL_PV_PRETTY_LTGT flag is set then the result be wrapped in
 angle brackets. 
 
 If the PERL_PV_PRETTY_ELLIPSES flag is set and not all characters in
 string were output then an ellipsis C<...> will be appended to the
-string. Note that this happens AFTER it has been quoted.
+string.  Note that this happens AFTER it has been quoted.
 
 If start_color is non-null then it will be inserted after the opening
-quote (if there is one) but before the escaped text. If end_color
+quote (if there is one) but before the escaped text.  If end_color
 is non-null then it will be inserted after the escaped text but before
 any quotes or ellipses.
 
@@ -405,7 +419,11 @@ Perl_sv_peek(pTHX_ SV *sv)
     }
     type = SvTYPE(sv);
     if (type == SVt_PVCV) {
-       Perl_sv_catpvf(aTHX_ t, "CV(%s)", CvGV(sv) ? GvNAME(CvGV(sv)) : "");
+        SV * const tmp = newSVpvs_flags("", SVs_TEMP);
+        GV* gvcv = CvGV(sv);
+        Perl_sv_catpvf(aTHX_ t, "CV(%s)", gvcv
+                       ? generic_pv_escape( tmp, GvNAME(gvcv), GvNAMELEN(gvcv), GvNAMEUTF8(gvcv))
+                       : "");
        goto finish;
     } else if (type < SVt_LAST) {
        sv_catpv(t, svshorttypenames[type]);
@@ -453,7 +471,7 @@ Perl_sv_peek(pTHX_ SV *sv)
   finish:
     while (unref--)
        sv_catpv(t, ")");
-    if (TAINTING_get && SvTAINTED(sv))
+    if (TAINTING_get && sv && SvTAINTED(sv))
        sv_catpv(t, " [tainted]");
     return SvPV_nolen(t);
 }
@@ -485,7 +503,8 @@ Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args)
 =for apidoc dump_all
 
 Dumps the entire optree of the current program starting at C<PL_main_root> to 
-C<STDERR>. Also dumps the optrees for all visible subroutines in C<PL_defstash>.
+C<STDERR>.  Also dumps the optrees for all visible subroutines in
+C<PL_defstash>.
 
 =cut
 */
@@ -561,16 +580,21 @@ Perl_dump_sub(pTHX_ const GV *gv)
 void
 Perl_dump_sub_perl(pTHX_ const GV *gv, bool justperl)
 {
-    SV * sv;
+    STRLEN len;
+    SV * const sv = newSVpvs_flags("", SVs_TEMP);
+    SV *tmpsv;
+    const char * name;
 
     PERL_ARGS_ASSERT_DUMP_SUB_PERL;
 
     if (justperl && (CvISXSUB(GvCV(gv)) || !CvROOT(GvCV(gv))))
        return;
 
-    sv = sv_newmortal();
+    tmpsv = newSVpvs_flags("", SVs_TEMP);
     gv_fullname3(sv, gv, NULL);
-    Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_const(sv));
+    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)))
        Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n",
            PTR2UV(CvXSUB(GvCV(gv))),
@@ -684,7 +708,7 @@ S_pm_description(pTHX_ const PMOP *pm)
         if (RX_ISTAINTED(regex))
             sv_catpv(desc, ",TAINTED");
         if (RX_CHECK_SUBSTR(regex)) {
-            if (!(RX_EXTFLAGS(regex) & RXf_NOSCAN))
+            if (!(RX_INTFLAGS(regex) & PREGf_NOSCAN))
                 sv_catpv(desc, ",SCANFIRST");
             if (RX_EXTFLAGS(regex) & RXf_CHECK_ALL)
                 sv_catpv(desc, ",ALL");
@@ -844,8 +868,7 @@ const struct op_private_by_op op_private_names[] = {
 static bool
 S_op_private_to_names(pTHX_ SV *tmpsv, U32 optype, U32 op_private) {
     const struct op_private_by_op *start = op_private_names;
-    const struct op_private_by_op *const end
-       = op_private_names + C_ARRAY_LENGTH(op_private_names);
+    const struct op_private_by_op *const end = C_ARRAY_END(op_private_names);
 
     /* This is a linear search, but no worse than the code that it replaced.
        It's debugging code - size is more important than speed.  */
@@ -887,7 +910,6 @@ S_op_private_to_names(pTHX_ SV *tmpsv, U32 optype, U32 op_private) {
         else                                                            \
             PerlIO_printf(file, " flags=\"%s\"",                        \
                           SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");        \
-        SvREFCNT_dec_NN(tmpsv);                                            \
     }
 
 #if !defined(PERL_MAD)
@@ -986,7 +1008,6 @@ S_op_private_to_names(pTHX_ SV *tmpsv, U32 optype, U32 op_private) {
        } else if (!xml)                                                \
             Perl_dump_indent(aTHX_ level, file, "PRIVATE = (0x%"UVxf")\n", \
                              (UV)oppriv);                               \
-       SvREFCNT_dec_NN(tmpsv);                                         \
     }
 
 
@@ -1022,12 +1043,25 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
                if (CopLINE(cCOPo))
                    Perl_dump_indent(aTHX_ level, file, "LINE = %"UVuf"\n",
                                     (UV)CopLINE(cCOPo));
-               if (CopSTASHPV(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",
-                                    CopSTASHPV(cCOPo));
-               if (CopLABEL(cCOPo))
+                           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",
-                                    CopLABEL(cCOPo));
+                           generic_pv_escape( tmpsv, label, label_len,(label_flags & SVf_UTF8)));
+      }
+
            }
        }
        else
@@ -1078,8 +1112,6 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
        }
        level--;
        Perl_dump_indent(aTHX_ level, file, "}\n");
-
-       SvREFCNT_dec_NN(tmpsv);
     }
 #endif
 
@@ -1092,18 +1124,19 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
 #else
        if ( ! (o->op_flags & OPf_SPECIAL)) { /* not lexical */
            if (cSVOPo->op_sv) {
-               SV * const tmpsv = newSV(0);
-               ENTER;
-               SAVEFREESV(tmpsv);
+      STRLEN len;
+      const char * name;
+      SV * const tmpsv  = newSVpvs_flags("", SVs_TEMP);
+      SV * const tmpsv2 = newSVpvs_flags("", SVs_TEMP);
 #ifdef PERL_MAD
                /* FIXME - is this making unwarranted assumptions about the
                   UTF-8 cleanliness of the dump file handle?  */
                SvUTF8_on(tmpsv);
 #endif
                gv_fullname3(tmpsv, MUTABLE_GV(cSVOPo->op_sv), NULL);
+      name = SvPV_const(tmpsv, len);
                Perl_dump_indent(aTHX_ level, file, "GV = %s\n",
-                                SvPV_nolen_const(tmpsv));
-               LEAVE;
+                       generic_pv_escape( tmpsv2, name, len, SvUTF8(tmpsv)));
            }
            else
                Perl_dump_indent(aTHX_ level, file, "GV = NULL\n");
@@ -1124,12 +1157,25 @@ Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o)
        if (CopLINE(cCOPo))
            Perl_dump_indent(aTHX_ level, file, "LINE = %"UVuf"\n",
                             (UV)CopLINE(cCOPo));
-       if (CopSTASHPV(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",
-                            CopSTASHPV(cCOPo));
-       if (CopLABEL(cCOPo))
-           Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n",
-                            CopLABEL(cCOPo));
+                           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)));
+   }
        break;
     case OP_ENTERLOOP:
        Perl_dump_indent(aTHX_ level, file, "REDO ===> ");
@@ -1204,7 +1250,10 @@ Perl_op_dump(pTHX_ const OP *o)
 void
 Perl_gv_dump(pTHX_ GV *gv)
 {
-    SV *sv;
+    STRLEN len;
+    const char* name;
+    SV *sv, *tmp = newSVpvs_flags("", SVs_TEMP);
+
 
     PERL_ARGS_ASSERT_GV_DUMP;
 
@@ -1215,10 +1264,14 @@ Perl_gv_dump(pTHX_ GV *gv)
     sv = sv_newmortal();
     PerlIO_printf(Perl_debug_log, "{\n");
     gv_fullname3(sv, gv, NULL);
-    Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv));
+    name = SvPV_const(sv, len);
+    Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s",
+                     generic_pv_escape( tmp, name, len, SvUTF8(sv) ));
     if (gv != GvEGV(gv)) {
        gv_efullname3(sv, GvEGV(gv), NULL);
-       Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv));
+        name = SvPV_const(sv, len);
+        Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s",
+                     generic_pv_escape( tmp, name, len, SvUTF8(sv) ));
     }
     PerlIO_putc(Perl_debug_log, '\n');
     Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n");
@@ -1378,8 +1431,10 @@ Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv)
            name which quite legally could contain insane things like tabs, newlines, nulls or
            other scary crap - this should produce sane results - except maybe for unicode package
            names - but we will wait for someone to file a bug on that - demerphq */
-        SV * const tmpsv = newSVpvs("");
-        PerlIO_printf(file, "\t%s\n", pv_display(tmpsv, hvname, HvNAMELEN_get(sv), 0, 1024));
+        SV * const tmpsv = newSVpvs_flags("", SVs_TEMP);
+        PerlIO_printf(file, "\t\"%s\"\n",
+                              generic_pv_escape( tmpsv, hvname,
+                                   HvNAMELEN(sv), HvNAMEUTF8(sv)));
     }
     else
        PerlIO_putc(file, '\n');
@@ -1391,8 +1446,11 @@ Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
     PERL_ARGS_ASSERT_DO_GV_DUMP;
 
     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
-    if (sv && GvNAME(sv))
-       PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv));
+    if (sv && GvNAME(sv)) {
+        SV * const tmpsv = newSVpvs("");
+        PerlIO_printf(file, "\t\"%s\"\n",
+                              generic_pv_escape( tmpsv, GvNAME(sv), GvNAMELEN(sv), GvNAMEUTF8(sv) ));
+    }
     else
        PerlIO_putc(file, '\n');
 }
@@ -1404,11 +1462,18 @@ Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv)
 
     Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv));
     if (sv && GvNAME(sv)) {
+       SV *tmp = newSVpvs_flags("", SVs_TEMP);
        const char *hvname;
-       PerlIO_printf(file, "\t\"");
-       if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv))))
-           PerlIO_printf(file, "%s\" :: \"", hvname);
-       PerlIO_printf(file, "%s\"\n", GvNAME(sv));
+        HV * const stash = GvSTASH(sv);
+       PerlIO_printf(file, "\t");
+   /* TODO might have an extra \" here */
+       if (stash && (hvname = HvNAME_get(stash))) {
+            PerlIO_printf(file, "\"%s\" :: \"",
+                                  generic_pv_escape(tmp, hvname,
+                                      HvNAMELEN(stash), HvNAMEUTF8(stash)));
+        }
+        PerlIO_printf(file, "%s\"\n",
+                              generic_pv_escape( tmp, GvNAME(sv), GvNAMELEN(sv), GvNAMEUTF8(sv)));
     }
     else
        PerlIO_putc(file, '\n');
@@ -1476,22 +1541,18 @@ const struct flag_to_name gp_flags_imported_names[] = {
     {GVf_IMPORTED_CV, " CV"},
 };
 
-const struct flag_to_name regexp_flags_names[] = {
+/* NOTE: this structure is mostly duplicative of one generated by
+ * 'make regen' in regnodes.h - perhaps we should somehow integrate
+ * the two. - Yves */
+const struct flag_to_name regexp_extflags_names[] = {
     {RXf_PMf_MULTILINE,   "PMf_MULTILINE,"},
     {RXf_PMf_SINGLELINE,  "PMf_SINGLELINE,"},
     {RXf_PMf_FOLD,        "PMf_FOLD,"},
     {RXf_PMf_EXTENDED,    "PMf_EXTENDED,"},
     {RXf_PMf_KEEPCOPY,    "PMf_KEEPCOPY,"},
-    {RXf_ANCH_BOL,        "ANCH_BOL,"},
-    {RXf_ANCH_MBOL,       "ANCH_MBOL,"},
-    {RXf_ANCH_SBOL,       "ANCH_SBOL,"},
-    {RXf_ANCH_GPOS,       "ANCH_GPOS,"},
-    {RXf_GPOS_SEEN,       "GPOS_SEEN,"},
-    {RXf_GPOS_FLOAT,      "GPOS_FLOAT,"},
+    {RXf_IS_ANCHORED,     "IS_ANCHORED,"},
     {RXf_NO_INPLACE_SUBST, "NO_INPLACE_SUBST,"},
     {RXf_EVAL_SEEN,       "EVAL_SEEN,"},
-    {RXf_CANY_SEEN,       "CANY_SEEN,"},
-    {RXf_NOSCAN,          "NOSCAN,"},
     {RXf_CHECK_ALL,       "CHECK_ALL,"},
     {RXf_MATCH_UTF8,      "MATCH_UTF8,"},
     {RXf_USE_INTUIT_NOML, "USE_INTUIT_NOML,"},
@@ -1507,6 +1568,26 @@ const struct flag_to_name regexp_flags_names[] = {
     {RXf_NULL,            "NULL,"},
 };
 
+/* NOTE: this structure is mostly duplicative of one generated by
+ * 'make regen' in regnodes.h - perhaps we should somehow integrate
+ * the two. - Yves */
+const struct flag_to_name regexp_core_intflags_names[] = {
+    {PREGf_SKIP,            "SKIP,"},
+    {PREGf_IMPLICIT,        "IMPLICIT,"},
+    {PREGf_NAUGHTY,         "NAUGHTY,"},
+    {PREGf_VERBARG_SEEN,    "VERBARG_SEEN,"},
+    {PREGf_CUTGROUP_SEEN,   "CUTGROUP_SEEN,"},
+    {PREGf_USE_RE_EVAL,     "USE_RE_EVAL,"},
+    {PREGf_NOSCAN,          "NOSCAN,"},
+    {PREGf_CANY_SEEN,       "CANY_SEEN,"},
+    {PREGf_GPOS_SEEN,       "GPOS_SEEN,"},
+    {PREGf_GPOS_FLOAT,      "GPOS_FLOAT,"},
+    {PREGf_ANCH_BOL,        "ANCH_BOL,"},
+    {PREGf_ANCH_MBOL,       "ANCH_MBOL,"},
+    {PREGf_ANCH_SBOL,       "ANCH_SBOL,"},
+    {PREGf_ANCH_GPOS,       "ANCH_GPOS,"},
+};
+
 void
 Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim)
 {
@@ -1583,7 +1664,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                sv_catpv(d, " ),");
            }
        }
-       /* FALL THROUGH */
+       /* FALLTHROUGH */
     default:
     evaled_or_uv:
        if (SvEVALED(sv))       sv_catpv(d, "EVALED,");
@@ -1594,7 +1675,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        if (SvVALID(sv))        sv_catpv(d, "VALID,");
        if (SvPAD_TYPED(sv))    sv_catpv(d, "TYPED,");
        if (SvPAD_OUR(sv))      sv_catpv(d, "OUR,");
-       /* FALL THROUGH */
+       /* FALLTHROUGH */
     case SVt_PVNV:
        if (SvPAD_STATE(sv))    sv_catpv(d, "STATE,");
        goto evaled_or_uv;
@@ -1789,9 +1870,9 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
        if (AvREIFY(sv))        sv_catpv(d, ",REIFY");
        Perl_dump_indent(aTHX_ level, file, "  FLAGS = (%s)\n",
                         SvCUR(d) ? SvPVX_const(d) + 1 : "");
-       if (nest < maxnest && av_len(MUTABLE_AV(sv)) >= 0) {
+       if (nest < maxnest && av_tindex(MUTABLE_AV(sv)) >= 0) {
            SSize_t count;
-           for (count = 0; count <=  av_len(MUTABLE_AV(sv)) && count < maxnest; count++) {
+           for (count = 0; count <=  av_tindex(MUTABLE_AV(sv)) && count < maxnest; count++) {
                SV** const elt = av_fetch(MUTABLE_AV(sv),count,0);
 
                Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count);
@@ -1800,15 +1881,22 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            }
        }
        break;
-    case SVt_PVHV:
+    case SVt_PVHV: {
+       U32 usedkeys;
+        if (SvOOK(sv)) {
+            struct xpvhv_aux *const aux = HvAUX(sv);
+            Perl_dump_indent(aTHX_ level, file, "  AUX_FLAGS = %"UVuf"\n",
+                             (UV)aux->xhv_aux_flags);
+        }
        Perl_dump_indent(aTHX_ level, file, "  ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv)));
-       if (HvARRAY(sv) && HvUSEDKEYS(sv)) {
+       usedkeys = HvUSEDKEYS(sv);
+       if (HvARRAY(sv) && usedkeys) {
            /* Show distribution of HEs in the ARRAY */
            int freq[200];
-#define FREQ_MAX ((int)(sizeof freq / sizeof freq[0] - 1))
+#define FREQ_MAX ((int)(C_ARRAY_LENGTH(freq) - 1))
            int i;
            int max = 0;
-           U32 pow2 = 2, keys = HvUSEDKEYS(sv);
+           U32 pow2 = 2, keys = usedkeys;
            NV theoret, sum = 0;
 
            PerlIO_printf(file, "  (");
@@ -1850,13 +1938,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
             }
            while ((keys = keys >> 1))
                pow2 = pow2 << 1;
-           theoret = HvUSEDKEYS(sv);
+           theoret = usedkeys;
            theoret += theoret * (theoret-1)/pow2;
            PerlIO_putc(file, '\n');
            Perl_dump_indent(aTHX_ level, file, "  hash quality = %.1"NVff"%%", theoret/sum*100);
        }
        PerlIO_putc(file, '\n');
-       Perl_dump_indent(aTHX_ level, file, "  KEYS = %"IVdf"\n", (IV)HvUSEDKEYS(sv));
+       Perl_dump_indent(aTHX_ level, file, "  KEYS = %"IVdf"\n", (IV)usedkeys);
         {
             STRLEN count = 0;
             HE **ents = HvARRAY(sv);
@@ -1901,8 +1989,12 @@ 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)
-               Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n", hvname);
+           if (hvname) {
+          SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+     Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n",
+                                       generic_pv_escape( tmpsv, hvname,
+                                           HvNAMELEN(sv), HvNAMEUTF8(sv)));
+        }
        }
        if (SvOOK(sv)) {
            AV * const backrefs
@@ -1924,10 +2016,10 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                    HEK *const *const endp = HvAUX(sv)->xhv_name_u.xhvnameu_names
                        + (count < 0 ? -count : count);
                    while (hekp < endp) {
-                       if (*hekp) {
-                           sv_catpvs(names, ", \"");
-                           sv_catpvn(names, HEK_KEY(*hekp), HEK_LEN(*hekp));
-                           sv_catpvs(names, "\"");
+                       if (HEK_LEN(*hekp)) {
+             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 {
                            /* This should never happen. */
                            sv_catpvs(names, ", (null)");
@@ -1938,10 +2030,14 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                     level, file, "  ENAME = %s\n", SvPV_nolen(names)+2
                    );
                }
-               else
+               else {
+                    SV * const tmp = newSVpvs_flags("", SVs_TEMP);
+                    const char *const hvename = HvENAME_get(sv);
                    Perl_dump_indent(aTHX_
-                    level, file, "  ENAME = \"%s\"\n", HvENAME_get(sv)
-                   );
+                    level, file, "  ENAME = \"%s\"\n",
+                     generic_pv_escape(tmp, hvename,
+                                       HvENAMELEN_get(sv), HvENAMEUTF8(sv)));
+                }
            }
            if (backrefs) {
                Perl_dump_indent(aTHX_ level, file, "  BACKREFS = 0x%"UVxf"\n",
@@ -1950,10 +2046,11 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                           dumpops, pvlim);
            }
            if (meta) {
-               /* FIXME - mro_algs kflags can signal a UTF-8 name.  */
-               Perl_dump_indent(aTHX_ level, file, "  MRO_WHICH = \"%.*s\" (0x%"UVxf")\n",
-                                (int)meta->mro_which->length,
-                                meta->mro_which->name,
+               SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+               Perl_dump_indent(aTHX_ level, file, "  MRO_WHICH = \"%s\" (0x%"UVxf")\n",
+                                generic_pv_escape( tmpsv, meta->mro_which->name,
+                                meta->mro_which->length,
+                                (meta->mro_which->kflags & HVhek_UTF8)),
                                 PTR2UV(meta->mro_which));
                Perl_dump_indent(aTHX_ level, file, "  CACHE_GEN = 0x%"UVxf"\n",
                                 (UV)meta->cache_gen);
@@ -2020,19 +2117,24 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
            }
        }
        break;
+    } /* case SVt_PVHV */
 
     case SVt_PVCV:
        if (CvAUTOLOAD(sv)) {
-           STRLEN len;
+           SV* tmpsv = newSVpvs_flags("", SVs_TEMP);
+       STRLEN len;
            const char *const name =  SvPV_const(sv, len);
-           Perl_dump_indent(aTHX_ level, file, "  AUTOLOAD = \"%.*s\"\n",
-                            (int) len, name);
+           Perl_dump_indent(aTHX_ level, file, "  AUTOLOAD = \"%s\"\n",
+                            generic_pv_escape(tmpsv, name, len, SvUTF8(sv)));
        }
        if (SvPOK(sv)) {
-           Perl_dump_indent(aTHX_ level, file, "  PROTOTYPE = \"%.*s\"\n",
-                            (int) CvPROTOLEN(sv), 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)));
        }
-       /* FALL THROUGH */
+       /* FALLTHROUGH */
     case SVt_PVFM:
        do_hv_dump(level, file, "  COMP_STASH", CvSTASH(sv));
        if (!CvISXSUB(sv)) {
@@ -2083,7 +2185,13 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                         : CvANON(outside) ? "ANON"
                         : (outside == PL_main_cv) ? "MAIN"
                         : CvUNIQUE(outside) ? "UNIQUE"
-                        : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED"));
+                        : CvGV(outside) ?
+                            generic_pv_escape(
+                                newSVpvs_flags("", SVs_TEMP),
+                                GvNAME(CvGV(outside)),
+                                GvNAMELEN(CvGV(outside)),
+                                GvNAMEUTF8(CvGV(outside)))
+                        : "UNDEFINED"));
        }
        if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv)))
            do_sv_dump(level+1, file, MUTABLE_SV(CvOUTSIDE(sv)), nest+1, maxnest, dumpops, pvlim);
@@ -2104,7 +2212,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;
-       Perl_dump_indent(aTHX_ level, file, "  NAME = \"%s\"\n", GvNAME(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, "  GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv)));
@@ -2173,25 +2287,34 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
       dumpregexp:
        {
            struct regexp * const r = ReANY((REGEXP*)sv);
-#define SV_SET_STRINGIFY_REGEXP_FLAGS(d,flags) STMT_START { \
+
+#define SV_SET_STRINGIFY_REGEXP_FLAGS(d,flags,names) STMT_START { \
             sv_setpv(d,"");                                 \
-            append_flags(d, flags, regexp_flags_names);     \
+            append_flags(d, flags, names);     \
             if (SvCUR(d) > 0 && *(SvEND(d) - 1) == ',') {       \
                 SvCUR_set(d, SvCUR(d) - 1);                 \
                 SvPVX(d)[SvCUR(d)] = '\0';                  \
             }                                               \
 } STMT_END
-            SV_SET_STRINGIFY_REGEXP_FLAGS(d,r->compflags);
+            SV_SET_STRINGIFY_REGEXP_FLAGS(d,r->compflags,regexp_extflags_names);
             Perl_dump_indent(aTHX_ level, file, "  COMPFLAGS = 0x%"UVxf" (%s)\n",
                                 (UV)(r->compflags), SvPVX_const(d));
 
-            SV_SET_STRINGIFY_REGEXP_FLAGS(d,r->extflags);
+            SV_SET_STRINGIFY_REGEXP_FLAGS(d,r->extflags,regexp_extflags_names);
            Perl_dump_indent(aTHX_ level, file, "  EXTFLAGS = 0x%"UVxf" (%s)\n",
                                 (UV)(r->extflags), SvPVX_const(d));
-#undef SV_SET_STRINGIFY_REGEXP_FLAGS
 
-           Perl_dump_indent(aTHX_ level, file, "  INTFLAGS = 0x%"UVxf"\n",
+            Perl_dump_indent(aTHX_ level, file, "  ENGINE = 0x%"UVxf" (%s)\n",
+                                PTR2UV(r->engine), (r->engine == &PL_core_reg_engine) ? "STANDARD" : "PLUG-IN" );
+            if (r->engine == &PL_core_reg_engine) {
+                SV_SET_STRINGIFY_REGEXP_FLAGS(d,r->intflags,regexp_core_intflags_names);
+                Perl_dump_indent(aTHX_ level, file, "  INTFLAGS = 0x%"UVxf" (%s)\n",
+                                (UV)(r->intflags), SvPVX_const(d));
+            } else {
+                Perl_dump_indent(aTHX_ level, file, "  INTFLAGS = 0x%"UVxf"\n",
                                (UV)(r->intflags));
+            }
+#undef SV_SET_STRINGIFY_REGEXP_FLAGS
            Perl_dump_indent(aTHX_ level, file, "  NPARENS = %"UVuf"\n",
                                (UV)(r->nparens));
            Perl_dump_indent(aTHX_ level, file, "  LASTPAREN = %"UVuf"\n",
@@ -2218,8 +2341,6 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                            pv_display(d, r->subbeg, r->sublen, 50, pvlim));
            else
                Perl_dump_indent(aTHX_ level, file, "  SUBBEG = 0x0\n");
-           Perl_dump_indent(aTHX_ level, file, "  ENGINE = 0x%"UVxf"\n",
-                               PTR2UV(r->engine));
            Perl_dump_indent(aTHX_ level, file, "  MOTHER_RE = 0x%"UVxf"\n",
                                PTR2UV(r->mother_re));
            if (nest < maxnest && r->mother_re)