| 1 | /* dump.c |
| 2 | * |
| 3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
| 4 | * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others |
| 5 | * |
| 6 | * You may distribute under the terms of either the GNU General Public |
| 7 | * License or the Artistic License, as specified in the README file. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and |
| 13 | * it has not been hard for me to read your mind and memory.'" |
| 14 | */ |
| 15 | |
| 16 | /* This file contains utility routines to dump the contents of SV and OP |
| 17 | * structures, as used by command-line options like -Dt and -Dx, and |
| 18 | * by Devel::Peek. |
| 19 | * |
| 20 | * It also holds the debugging version of the runops function. |
| 21 | */ |
| 22 | |
| 23 | #include "EXTERN.h" |
| 24 | #define PERL_IN_DUMP_C |
| 25 | #include "perl.h" |
| 26 | #include "regcomp.h" |
| 27 | #include "proto.h" |
| 28 | |
| 29 | |
| 30 | #define Sequence PL_op_sequence |
| 31 | |
| 32 | void |
| 33 | Perl_dump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...) |
| 34 | { |
| 35 | va_list args; |
| 36 | va_start(args, pat); |
| 37 | dump_vindent(level, file, pat, &args); |
| 38 | va_end(args); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | Perl_dump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args) |
| 43 | { |
| 44 | dVAR; |
| 45 | PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), ""); |
| 46 | PerlIO_vprintf(file, pat, *args); |
| 47 | } |
| 48 | |
| 49 | void |
| 50 | Perl_dump_all(pTHX) |
| 51 | { |
| 52 | dVAR; |
| 53 | PerlIO_setlinebuf(Perl_debug_log); |
| 54 | if (PL_main_root) |
| 55 | op_dump(PL_main_root); |
| 56 | dump_packsubs(PL_defstash); |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | Perl_dump_packsubs(pTHX_ const HV *stash) |
| 61 | { |
| 62 | dVAR; |
| 63 | I32 i; |
| 64 | |
| 65 | if (!HvARRAY(stash)) |
| 66 | return; |
| 67 | for (i = 0; i <= (I32) HvMAX(stash); i++) { |
| 68 | const HE *entry; |
| 69 | for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) { |
| 70 | const GV *gv = (GV*)HeVAL(entry); |
| 71 | const HV *hv; |
| 72 | if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv)) |
| 73 | continue; |
| 74 | if (GvCVu(gv)) |
| 75 | dump_sub(gv); |
| 76 | if (GvFORM(gv)) |
| 77 | dump_form(gv); |
| 78 | if (HeKEY(entry)[HeKLEN(entry)-1] == ':' |
| 79 | && (hv = GvHV(gv)) && hv != PL_defstash) |
| 80 | dump_packsubs(hv); /* nested package */ |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | Perl_dump_sub(pTHX_ const GV *gv) |
| 87 | { |
| 88 | SV * const sv = sv_newmortal(); |
| 89 | |
| 90 | gv_fullname3(sv, gv, NULL); |
| 91 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nSUB %s = ", SvPVX_const(sv)); |
| 92 | if (CvISXSUB(GvCV(gv))) |
| 93 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "(xsub 0x%"UVxf" %d)\n", |
| 94 | PTR2UV(CvXSUB(GvCV(gv))), |
| 95 | (int)CvXSUBANY(GvCV(gv)).any_i32); |
| 96 | else if (CvROOT(GvCV(gv))) |
| 97 | op_dump(CvROOT(GvCV(gv))); |
| 98 | else |
| 99 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n"); |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | Perl_dump_form(pTHX_ const GV *gv) |
| 104 | { |
| 105 | SV * const sv = sv_newmortal(); |
| 106 | |
| 107 | gv_fullname3(sv, gv, NULL); |
| 108 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "\nFORMAT %s = ", SvPVX_const(sv)); |
| 109 | if (CvROOT(GvFORM(gv))) |
| 110 | op_dump(CvROOT(GvFORM(gv))); |
| 111 | else |
| 112 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "<undef>\n"); |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | Perl_dump_eval(pTHX) |
| 117 | { |
| 118 | dVAR; |
| 119 | op_dump(PL_eval_root); |
| 120 | } |
| 121 | |
| 122 | char * |
| 123 | Perl_pv_display(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) |
| 124 | { |
| 125 | const bool nul_terminated = len > cur && pv[cur] == '\0'; |
| 126 | bool truncated = 0; |
| 127 | |
| 128 | sv_setpvn(dsv, "\"", 1); |
| 129 | for (; cur--; pv++) { |
| 130 | if (pvlim && SvCUR(dsv) >= pvlim) { |
| 131 | truncated = 1; |
| 132 | break; |
| 133 | } |
| 134 | switch (*pv) { |
| 135 | case '\t': sv_catpvs(dsv, "\\t"); break; |
| 136 | case '\n': sv_catpvs(dsv, "\\n"); break; |
| 137 | case '\r': sv_catpvs(dsv, "\\r"); break; |
| 138 | case '\f': sv_catpvs(dsv, "\\f"); break; |
| 139 | case '"': sv_catpvs(dsv, "\\\""); break; |
| 140 | case '\\': sv_catpvs(dsv, "\\\\"); break; |
| 141 | default: |
| 142 | if (isPRINT(*pv)) |
| 143 | sv_catpvn(dsv, pv, 1); |
| 144 | else if (cur && isDIGIT(*(pv+1))) |
| 145 | Perl_sv_catpvf(aTHX_ dsv, "\\%03o", (U8)*pv); |
| 146 | else |
| 147 | Perl_sv_catpvf(aTHX_ dsv, "\\%o", (U8)*pv); |
| 148 | } |
| 149 | } |
| 150 | sv_catpvs(dsv, "\""); |
| 151 | if (truncated) |
| 152 | sv_catpvs(dsv, "..."); |
| 153 | if (nul_terminated) |
| 154 | sv_catpvs(dsv, "\\0"); |
| 155 | |
| 156 | return SvPVX(dsv); |
| 157 | } |
| 158 | |
| 159 | char * |
| 160 | Perl_sv_peek(pTHX_ SV *sv) |
| 161 | { |
| 162 | dVAR; |
| 163 | SV * const t = sv_newmortal(); |
| 164 | int unref = 0; |
| 165 | |
| 166 | sv_setpvn(t, "", 0); |
| 167 | retry: |
| 168 | if (!sv) { |
| 169 | sv_catpv(t, "VOID"); |
| 170 | goto finish; |
| 171 | } |
| 172 | else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') { |
| 173 | sv_catpv(t, "WILD"); |
| 174 | goto finish; |
| 175 | } |
| 176 | else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) { |
| 177 | if (sv == &PL_sv_undef) { |
| 178 | sv_catpv(t, "SV_UNDEF"); |
| 179 | if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT| |
| 180 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 181 | SvREADONLY(sv)) |
| 182 | goto finish; |
| 183 | } |
| 184 | else if (sv == &PL_sv_no) { |
| 185 | sv_catpv(t, "SV_NO"); |
| 186 | if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT| |
| 187 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 188 | !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| |
| 189 | SVp_POK|SVp_NOK)) && |
| 190 | SvCUR(sv) == 0 && |
| 191 | SvNVX(sv) == 0.0) |
| 192 | goto finish; |
| 193 | } |
| 194 | else if (sv == &PL_sv_yes) { |
| 195 | sv_catpv(t, "SV_YES"); |
| 196 | if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT| |
| 197 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 198 | !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| |
| 199 | SVp_POK|SVp_NOK)) && |
| 200 | SvCUR(sv) == 1 && |
| 201 | SvPVX_const(sv) && *SvPVX_const(sv) == '1' && |
| 202 | SvNVX(sv) == 1.0) |
| 203 | goto finish; |
| 204 | } |
| 205 | else { |
| 206 | sv_catpv(t, "SV_PLACEHOLDER"); |
| 207 | if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT| |
| 208 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 209 | SvREADONLY(sv)) |
| 210 | goto finish; |
| 211 | } |
| 212 | sv_catpv(t, ":"); |
| 213 | } |
| 214 | else if (SvREFCNT(sv) == 0) { |
| 215 | sv_catpv(t, "("); |
| 216 | unref++; |
| 217 | } |
| 218 | else if (DEBUG_R_TEST_) { |
| 219 | int is_tmp = 0; |
| 220 | I32 ix; |
| 221 | /* is this SV on the tmps stack? */ |
| 222 | for (ix=PL_tmps_ix; ix>=0; ix--) { |
| 223 | if (PL_tmps_stack[ix] == sv) { |
| 224 | is_tmp = 1; |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | if (SvREFCNT(sv) > 1) |
| 229 | Perl_sv_catpvf(aTHX_ t, "<%"UVuf"%s>", (UV)SvREFCNT(sv), |
| 230 | is_tmp ? "T" : ""); |
| 231 | else if (is_tmp) |
| 232 | sv_catpv(t, "<T>"); |
| 233 | } |
| 234 | |
| 235 | if (SvROK(sv)) { |
| 236 | sv_catpv(t, "\\"); |
| 237 | if (SvCUR(t) + unref > 10) { |
| 238 | SvCUR_set(t, unref + 3); |
| 239 | *SvEND(t) = '\0'; |
| 240 | sv_catpv(t, "..."); |
| 241 | goto finish; |
| 242 | } |
| 243 | sv = (SV*)SvRV(sv); |
| 244 | goto retry; |
| 245 | } |
| 246 | switch (SvTYPE(sv)) { |
| 247 | default: |
| 248 | sv_catpv(t, "FREED"); |
| 249 | goto finish; |
| 250 | |
| 251 | case SVt_NULL: |
| 252 | sv_catpv(t, "UNDEF"); |
| 253 | goto finish; |
| 254 | case SVt_IV: |
| 255 | sv_catpv(t, "IV"); |
| 256 | break; |
| 257 | case SVt_NV: |
| 258 | sv_catpv(t, "NV"); |
| 259 | break; |
| 260 | case SVt_RV: |
| 261 | sv_catpv(t, "RV"); |
| 262 | break; |
| 263 | case SVt_PV: |
| 264 | sv_catpv(t, "PV"); |
| 265 | break; |
| 266 | case SVt_PVIV: |
| 267 | sv_catpv(t, "PVIV"); |
| 268 | break; |
| 269 | case SVt_PVNV: |
| 270 | sv_catpv(t, "PVNV"); |
| 271 | break; |
| 272 | case SVt_PVMG: |
| 273 | sv_catpv(t, "PVMG"); |
| 274 | break; |
| 275 | case SVt_PVLV: |
| 276 | sv_catpv(t, "PVLV"); |
| 277 | break; |
| 278 | case SVt_PVAV: |
| 279 | sv_catpv(t, "AV"); |
| 280 | break; |
| 281 | case SVt_PVHV: |
| 282 | sv_catpv(t, "HV"); |
| 283 | break; |
| 284 | case SVt_PVCV: |
| 285 | if (CvGV(sv)) |
| 286 | Perl_sv_catpvf(aTHX_ t, "CV(%s)", GvNAME(CvGV(sv))); |
| 287 | else |
| 288 | sv_catpv(t, "CV()"); |
| 289 | goto finish; |
| 290 | case SVt_PVGV: |
| 291 | sv_catpv(t, "GV"); |
| 292 | break; |
| 293 | case SVt_PVBM: |
| 294 | sv_catpv(t, "BM"); |
| 295 | break; |
| 296 | case SVt_PVFM: |
| 297 | sv_catpv(t, "FM"); |
| 298 | break; |
| 299 | case SVt_PVIO: |
| 300 | sv_catpv(t, "IO"); |
| 301 | break; |
| 302 | } |
| 303 | |
| 304 | if (SvPOKp(sv)) { |
| 305 | if (!SvPVX_const(sv)) |
| 306 | sv_catpv(t, "(null)"); |
| 307 | else { |
| 308 | SV *tmp = newSVpvs(""); |
| 309 | sv_catpv(t, "("); |
| 310 | if (SvOOK(sv)) |
| 311 | Perl_sv_catpvf(aTHX_ t, "[%s]", pv_display(tmp, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, 127)); |
| 312 | Perl_sv_catpvf(aTHX_ t, "%s)", pv_display(tmp, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), 127)); |
| 313 | if (SvUTF8(sv)) |
| 314 | Perl_sv_catpvf(aTHX_ t, " [UTF8 \"%s\"]", |
| 315 | sv_uni_display(tmp, sv, 8 * sv_len_utf8(sv), |
| 316 | UNI_DISPLAY_QQ)); |
| 317 | SvREFCNT_dec(tmp); |
| 318 | } |
| 319 | } |
| 320 | else if (SvNOKp(sv)) { |
| 321 | STORE_NUMERIC_LOCAL_SET_STANDARD(); |
| 322 | Perl_sv_catpvf(aTHX_ t, "(%"NVgf")",SvNVX(sv)); |
| 323 | RESTORE_NUMERIC_LOCAL(); |
| 324 | } |
| 325 | else if (SvIOKp(sv)) { |
| 326 | if (SvIsUV(sv)) |
| 327 | Perl_sv_catpvf(aTHX_ t, "(%"UVuf")", (UV)SvUVX(sv)); |
| 328 | else |
| 329 | Perl_sv_catpvf(aTHX_ t, "(%"IVdf")", (IV)SvIVX(sv)); |
| 330 | } |
| 331 | else |
| 332 | sv_catpv(t, "()"); |
| 333 | |
| 334 | finish: |
| 335 | if (unref) { |
| 336 | while (unref--) |
| 337 | sv_catpv(t, ")"); |
| 338 | } |
| 339 | return SvPV_nolen(t); |
| 340 | } |
| 341 | |
| 342 | void |
| 343 | Perl_do_pmop_dump(pTHX_ I32 level, PerlIO *file, const PMOP *pm) |
| 344 | { |
| 345 | char ch; |
| 346 | |
| 347 | if (!pm) { |
| 348 | Perl_dump_indent(aTHX_ level, file, "{}\n"); |
| 349 | return; |
| 350 | } |
| 351 | Perl_dump_indent(aTHX_ level, file, "{\n"); |
| 352 | level++; |
| 353 | if (pm->op_pmflags & PMf_ONCE) |
| 354 | ch = '?'; |
| 355 | else |
| 356 | ch = '/'; |
| 357 | if (PM_GETRE(pm)) |
| 358 | Perl_dump_indent(aTHX_ level, file, "PMf_PRE %c%s%c%s\n", |
| 359 | ch, PM_GETRE(pm)->precomp, ch, |
| 360 | (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : ""); |
| 361 | else |
| 362 | Perl_dump_indent(aTHX_ level, file, "PMf_PRE (RUNTIME)\n"); |
| 363 | if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) { |
| 364 | Perl_dump_indent(aTHX_ level, file, "PMf_REPL = "); |
| 365 | op_dump(pm->op_pmreplroot); |
| 366 | } |
| 367 | if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) { |
| 368 | SV *tmpsv = newSVpvs(""); |
| 369 | if (pm->op_pmdynflags & PMdf_USED) |
| 370 | sv_catpv(tmpsv, ",USED"); |
| 371 | if (pm->op_pmdynflags & PMdf_TAINTED) |
| 372 | sv_catpv(tmpsv, ",TAINTED"); |
| 373 | if (pm->op_pmflags & PMf_ONCE) |
| 374 | sv_catpv(tmpsv, ",ONCE"); |
| 375 | if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr |
| 376 | && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN)) |
| 377 | sv_catpv(tmpsv, ",SCANFIRST"); |
| 378 | if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr |
| 379 | && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL) |
| 380 | sv_catpv(tmpsv, ",ALL"); |
| 381 | if (pm->op_pmflags & PMf_SKIPWHITE) |
| 382 | sv_catpv(tmpsv, ",SKIPWHITE"); |
| 383 | if (pm->op_pmflags & PMf_CONST) |
| 384 | sv_catpv(tmpsv, ",CONST"); |
| 385 | if (pm->op_pmflags & PMf_KEEP) |
| 386 | sv_catpv(tmpsv, ",KEEP"); |
| 387 | if (pm->op_pmflags & PMf_GLOBAL) |
| 388 | sv_catpv(tmpsv, ",GLOBAL"); |
| 389 | if (pm->op_pmflags & PMf_CONTINUE) |
| 390 | sv_catpv(tmpsv, ",CONTINUE"); |
| 391 | if (pm->op_pmflags & PMf_RETAINT) |
| 392 | sv_catpv(tmpsv, ",RETAINT"); |
| 393 | if (pm->op_pmflags & PMf_EVAL) |
| 394 | sv_catpv(tmpsv, ",EVAL"); |
| 395 | Perl_dump_indent(aTHX_ level, file, "PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : ""); |
| 396 | SvREFCNT_dec(tmpsv); |
| 397 | } |
| 398 | |
| 399 | Perl_dump_indent(aTHX_ level-1, file, "}\n"); |
| 400 | } |
| 401 | |
| 402 | void |
| 403 | Perl_pmop_dump(pTHX_ PMOP *pm) |
| 404 | { |
| 405 | do_pmop_dump(0, Perl_debug_log, pm); |
| 406 | } |
| 407 | |
| 408 | /* An op sequencer. We visit the ops in the order they're to execute. */ |
| 409 | |
| 410 | STATIC void |
| 411 | S_sequence(pTHX_ register const OP *o) |
| 412 | { |
| 413 | dVAR; |
| 414 | SV *op; |
| 415 | const char *key; |
| 416 | STRLEN len; |
| 417 | const OP *oldop = NULL; |
| 418 | OP *l; |
| 419 | |
| 420 | if (!o) |
| 421 | return; |
| 422 | |
| 423 | #ifdef PERL_MAD |
| 424 | if (o->op_next == 0) |
| 425 | return; |
| 426 | #endif |
| 427 | |
| 428 | if (!Sequence) |
| 429 | Sequence = newHV(); |
| 430 | |
| 431 | for (; o; o = o->op_next) { |
| 432 | op = newSVuv(PTR2UV(o)); |
| 433 | key = SvPV_const(op, len); |
| 434 | if (hv_exists(Sequence, key, len)) |
| 435 | break; |
| 436 | |
| 437 | switch (o->op_type) { |
| 438 | case OP_STUB: |
| 439 | if ((o->op_flags & OPf_WANT) != OPf_WANT_LIST) { |
| 440 | hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); |
| 441 | break; |
| 442 | } |
| 443 | goto nothin; |
| 444 | case OP_NULL: |
| 445 | #ifdef PERL_MAD |
| 446 | if (o == o->op_next) |
| 447 | return; |
| 448 | #endif |
| 449 | if (oldop && o->op_next) |
| 450 | continue; |
| 451 | break; |
| 452 | case OP_SCALAR: |
| 453 | case OP_LINESEQ: |
| 454 | case OP_SCOPE: |
| 455 | nothin: |
| 456 | if (oldop && o->op_next) |
| 457 | continue; |
| 458 | hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); |
| 459 | break; |
| 460 | |
| 461 | case OP_MAPWHILE: |
| 462 | case OP_GREPWHILE: |
| 463 | case OP_AND: |
| 464 | case OP_OR: |
| 465 | case OP_DOR: |
| 466 | case OP_ANDASSIGN: |
| 467 | case OP_ORASSIGN: |
| 468 | case OP_DORASSIGN: |
| 469 | case OP_COND_EXPR: |
| 470 | case OP_RANGE: |
| 471 | hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); |
| 472 | for (l = cLOGOPo->op_other; l && l->op_type == OP_NULL; l = l->op_next) |
| 473 | ; |
| 474 | sequence(l); |
| 475 | break; |
| 476 | |
| 477 | case OP_ENTERLOOP: |
| 478 | case OP_ENTERITER: |
| 479 | hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); |
| 480 | for (l = cLOOPo->op_redoop; l && l->op_type == OP_NULL; l = l->op_next) |
| 481 | ; |
| 482 | sequence(l); |
| 483 | for (l = cLOOPo->op_nextop; l && l->op_type == OP_NULL; l = l->op_next) |
| 484 | ; |
| 485 | sequence(l); |
| 486 | for (l = cLOOPo->op_lastop; l && l->op_type == OP_NULL; l = l->op_next) |
| 487 | ; |
| 488 | sequence(l); |
| 489 | break; |
| 490 | |
| 491 | case OP_QR: |
| 492 | case OP_MATCH: |
| 493 | case OP_SUBST: |
| 494 | hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); |
| 495 | for (l = cPMOPo->op_pmreplstart; l && l->op_type == OP_NULL; l = l->op_next) |
| 496 | ; |
| 497 | sequence(l); |
| 498 | break; |
| 499 | |
| 500 | case OP_HELEM: |
| 501 | break; |
| 502 | |
| 503 | default: |
| 504 | hv_store(Sequence, key, len, newSVuv(++PL_op_seq), 0); |
| 505 | break; |
| 506 | } |
| 507 | oldop = o; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | STATIC UV |
| 512 | S_sequence_num(pTHX_ const OP *o) |
| 513 | { |
| 514 | dVAR; |
| 515 | SV *op, |
| 516 | **seq; |
| 517 | const char *key; |
| 518 | STRLEN len; |
| 519 | if (!o) return 0; |
| 520 | op = newSVuv(PTR2UV(o)); |
| 521 | key = SvPV_const(op, len); |
| 522 | seq = hv_fetch(Sequence, key, len, 0); |
| 523 | return seq ? SvUV(*seq): 0; |
| 524 | } |
| 525 | |
| 526 | void |
| 527 | Perl_do_op_dump(pTHX_ I32 level, PerlIO *file, const OP *o) |
| 528 | { |
| 529 | dVAR; |
| 530 | UV seq; |
| 531 | sequence(o); |
| 532 | Perl_dump_indent(aTHX_ level, file, "{\n"); |
| 533 | level++; |
| 534 | seq = sequence_num(o); |
| 535 | if (seq) |
| 536 | PerlIO_printf(file, "%-4"UVf, seq); |
| 537 | else |
| 538 | PerlIO_printf(file, " "); |
| 539 | PerlIO_printf(file, |
| 540 | "%*sTYPE = %s ===> ", |
| 541 | (int)(PL_dumpindent*level-4), "", OP_NAME(o)); |
| 542 | if (o->op_next) |
| 543 | PerlIO_printf(file, seq ? "%"UVf"\n" : "(%"UVf")\n", |
| 544 | sequence_num(o->op_next)); |
| 545 | else |
| 546 | PerlIO_printf(file, "DONE\n"); |
| 547 | if (o->op_targ) { |
| 548 | if (o->op_type == OP_NULL) |
| 549 | { |
| 550 | Perl_dump_indent(aTHX_ level, file, " (was %s)\n", PL_op_name[o->op_targ]); |
| 551 | if (o->op_targ == OP_NEXTSTATE) |
| 552 | { |
| 553 | if (CopLINE(cCOPo)) |
| 554 | Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n", |
| 555 | (UV)CopLINE(cCOPo)); |
| 556 | if (CopSTASHPV(cCOPo)) |
| 557 | Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n", |
| 558 | CopSTASHPV(cCOPo)); |
| 559 | if (cCOPo->cop_label) |
| 560 | Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n", |
| 561 | cCOPo->cop_label); |
| 562 | } |
| 563 | } |
| 564 | else |
| 565 | Perl_dump_indent(aTHX_ level, file, "TARG = %ld\n", (long)o->op_targ); |
| 566 | } |
| 567 | #ifdef DUMPADDR |
| 568 | Perl_dump_indent(aTHX_ level, file, "ADDR = 0x%"UVxf" => 0x%"UVxf"\n", (UV)o, (UV)o->op_next); |
| 569 | #endif |
| 570 | if (o->op_flags) { |
| 571 | SV *tmpsv = newSVpvs(""); |
| 572 | switch (o->op_flags & OPf_WANT) { |
| 573 | case OPf_WANT_VOID: |
| 574 | sv_catpv(tmpsv, ",VOID"); |
| 575 | break; |
| 576 | case OPf_WANT_SCALAR: |
| 577 | sv_catpv(tmpsv, ",SCALAR"); |
| 578 | break; |
| 579 | case OPf_WANT_LIST: |
| 580 | sv_catpv(tmpsv, ",LIST"); |
| 581 | break; |
| 582 | default: |
| 583 | sv_catpv(tmpsv, ",UNKNOWN"); |
| 584 | break; |
| 585 | } |
| 586 | if (o->op_flags & OPf_KIDS) |
| 587 | sv_catpv(tmpsv, ",KIDS"); |
| 588 | if (o->op_flags & OPf_PARENS) |
| 589 | sv_catpv(tmpsv, ",PARENS"); |
| 590 | if (o->op_flags & OPf_STACKED) |
| 591 | sv_catpv(tmpsv, ",STACKED"); |
| 592 | if (o->op_flags & OPf_REF) |
| 593 | sv_catpv(tmpsv, ",REF"); |
| 594 | if (o->op_flags & OPf_MOD) |
| 595 | sv_catpv(tmpsv, ",MOD"); |
| 596 | if (o->op_flags & OPf_SPECIAL) |
| 597 | sv_catpv(tmpsv, ",SPECIAL"); |
| 598 | Perl_dump_indent(aTHX_ level, file, "FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX_const(tmpsv) + 1 : ""); |
| 599 | SvREFCNT_dec(tmpsv); |
| 600 | } |
| 601 | if (o->op_private) { |
| 602 | SV *tmpsv = newSVpvs(""); |
| 603 | if (PL_opargs[o->op_type] & OA_TARGLEX) { |
| 604 | if (o->op_private & OPpTARGET_MY) |
| 605 | sv_catpv(tmpsv, ",TARGET_MY"); |
| 606 | } |
| 607 | else if (o->op_type == OP_LEAVESUB || |
| 608 | o->op_type == OP_LEAVE || |
| 609 | o->op_type == OP_LEAVESUBLV || |
| 610 | o->op_type == OP_LEAVEWRITE) { |
| 611 | if (o->op_private & OPpREFCOUNTED) |
| 612 | sv_catpv(tmpsv, ",REFCOUNTED"); |
| 613 | } |
| 614 | else if (o->op_type == OP_AASSIGN) { |
| 615 | if (o->op_private & OPpASSIGN_COMMON) |
| 616 | sv_catpv(tmpsv, ",COMMON"); |
| 617 | } |
| 618 | else if (o->op_type == OP_SASSIGN) { |
| 619 | if (o->op_private & OPpASSIGN_BACKWARDS) |
| 620 | sv_catpv(tmpsv, ",BACKWARDS"); |
| 621 | } |
| 622 | else if (o->op_type == OP_TRANS) { |
| 623 | if (o->op_private & OPpTRANS_SQUASH) |
| 624 | sv_catpv(tmpsv, ",SQUASH"); |
| 625 | if (o->op_private & OPpTRANS_DELETE) |
| 626 | sv_catpv(tmpsv, ",DELETE"); |
| 627 | if (o->op_private & OPpTRANS_COMPLEMENT) |
| 628 | sv_catpv(tmpsv, ",COMPLEMENT"); |
| 629 | if (o->op_private & OPpTRANS_IDENTICAL) |
| 630 | sv_catpv(tmpsv, ",IDENTICAL"); |
| 631 | if (o->op_private & OPpTRANS_GROWS) |
| 632 | sv_catpv(tmpsv, ",GROWS"); |
| 633 | } |
| 634 | else if (o->op_type == OP_REPEAT) { |
| 635 | if (o->op_private & OPpREPEAT_DOLIST) |
| 636 | sv_catpv(tmpsv, ",DOLIST"); |
| 637 | } |
| 638 | else if (o->op_type == OP_ENTERSUB || |
| 639 | o->op_type == OP_RV2SV || |
| 640 | o->op_type == OP_GVSV || |
| 641 | o->op_type == OP_RV2AV || |
| 642 | o->op_type == OP_RV2HV || |
| 643 | o->op_type == OP_RV2GV || |
| 644 | o->op_type == OP_AELEM || |
| 645 | o->op_type == OP_HELEM ) |
| 646 | { |
| 647 | if (o->op_type == OP_ENTERSUB) { |
| 648 | if (o->op_private & OPpENTERSUB_AMPER) |
| 649 | sv_catpv(tmpsv, ",AMPER"); |
| 650 | if (o->op_private & OPpENTERSUB_DB) |
| 651 | sv_catpv(tmpsv, ",DB"); |
| 652 | if (o->op_private & OPpENTERSUB_HASTARG) |
| 653 | sv_catpv(tmpsv, ",HASTARG"); |
| 654 | if (o->op_private & OPpENTERSUB_NOPAREN) |
| 655 | sv_catpv(tmpsv, ",NOPAREN"); |
| 656 | if (o->op_private & OPpENTERSUB_INARGS) |
| 657 | sv_catpv(tmpsv, ",INARGS"); |
| 658 | if (o->op_private & OPpENTERSUB_NOMOD) |
| 659 | sv_catpv(tmpsv, ",NOMOD"); |
| 660 | } |
| 661 | else { |
| 662 | switch (o->op_private & OPpDEREF) { |
| 663 | case OPpDEREF_SV: |
| 664 | sv_catpv(tmpsv, ",SV"); |
| 665 | break; |
| 666 | case OPpDEREF_AV: |
| 667 | sv_catpv(tmpsv, ",AV"); |
| 668 | break; |
| 669 | case OPpDEREF_HV: |
| 670 | sv_catpv(tmpsv, ",HV"); |
| 671 | break; |
| 672 | } |
| 673 | if (o->op_private & OPpMAYBE_LVSUB) |
| 674 | sv_catpv(tmpsv, ",MAYBE_LVSUB"); |
| 675 | } |
| 676 | if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) { |
| 677 | if (o->op_private & OPpLVAL_DEFER) |
| 678 | sv_catpv(tmpsv, ",LVAL_DEFER"); |
| 679 | } |
| 680 | else { |
| 681 | if (o->op_private & HINT_STRICT_REFS) |
| 682 | sv_catpv(tmpsv, ",STRICT_REFS"); |
| 683 | if (o->op_private & OPpOUR_INTRO) |
| 684 | sv_catpv(tmpsv, ",OUR_INTRO"); |
| 685 | } |
| 686 | } |
| 687 | else if (o->op_type == OP_CONST) { |
| 688 | if (o->op_private & OPpCONST_BARE) |
| 689 | sv_catpv(tmpsv, ",BARE"); |
| 690 | if (o->op_private & OPpCONST_STRICT) |
| 691 | sv_catpv(tmpsv, ",STRICT"); |
| 692 | if (o->op_private & OPpCONST_ARYBASE) |
| 693 | sv_catpv(tmpsv, ",ARYBASE"); |
| 694 | if (o->op_private & OPpCONST_WARNING) |
| 695 | sv_catpv(tmpsv, ",WARNING"); |
| 696 | if (o->op_private & OPpCONST_ENTERED) |
| 697 | sv_catpv(tmpsv, ",ENTERED"); |
| 698 | } |
| 699 | else if (o->op_type == OP_FLIP) { |
| 700 | if (o->op_private & OPpFLIP_LINENUM) |
| 701 | sv_catpv(tmpsv, ",LINENUM"); |
| 702 | } |
| 703 | else if (o->op_type == OP_FLOP) { |
| 704 | if (o->op_private & OPpFLIP_LINENUM) |
| 705 | sv_catpv(tmpsv, ",LINENUM"); |
| 706 | } |
| 707 | else if (o->op_type == OP_RV2CV) { |
| 708 | if (o->op_private & OPpLVAL_INTRO) |
| 709 | sv_catpv(tmpsv, ",INTRO"); |
| 710 | } |
| 711 | else if (o->op_type == OP_GV) { |
| 712 | if (o->op_private & OPpEARLY_CV) |
| 713 | sv_catpv(tmpsv, ",EARLY_CV"); |
| 714 | } |
| 715 | else if (o->op_type == OP_LIST) { |
| 716 | if (o->op_private & OPpLIST_GUESSED) |
| 717 | sv_catpv(tmpsv, ",GUESSED"); |
| 718 | } |
| 719 | else if (o->op_type == OP_DELETE) { |
| 720 | if (o->op_private & OPpSLICE) |
| 721 | sv_catpv(tmpsv, ",SLICE"); |
| 722 | } |
| 723 | else if (o->op_type == OP_EXISTS) { |
| 724 | if (o->op_private & OPpEXISTS_SUB) |
| 725 | sv_catpv(tmpsv, ",EXISTS_SUB"); |
| 726 | } |
| 727 | else if (o->op_type == OP_SORT) { |
| 728 | if (o->op_private & OPpSORT_NUMERIC) |
| 729 | sv_catpv(tmpsv, ",NUMERIC"); |
| 730 | if (o->op_private & OPpSORT_INTEGER) |
| 731 | sv_catpv(tmpsv, ",INTEGER"); |
| 732 | if (o->op_private & OPpSORT_REVERSE) |
| 733 | sv_catpv(tmpsv, ",REVERSE"); |
| 734 | } |
| 735 | else if (o->op_type == OP_THREADSV) { |
| 736 | if (o->op_private & OPpDONE_SVREF) |
| 737 | sv_catpv(tmpsv, ",SVREF"); |
| 738 | } |
| 739 | else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) { |
| 740 | if (o->op_private & OPpOPEN_IN_RAW) |
| 741 | sv_catpv(tmpsv, ",IN_RAW"); |
| 742 | if (o->op_private & OPpOPEN_IN_CRLF) |
| 743 | sv_catpv(tmpsv, ",IN_CRLF"); |
| 744 | if (o->op_private & OPpOPEN_OUT_RAW) |
| 745 | sv_catpv(tmpsv, ",OUT_RAW"); |
| 746 | if (o->op_private & OPpOPEN_OUT_CRLF) |
| 747 | sv_catpv(tmpsv, ",OUT_CRLF"); |
| 748 | } |
| 749 | else if (o->op_type == OP_EXIT) { |
| 750 | if (o->op_private & OPpEXIT_VMSISH) |
| 751 | sv_catpv(tmpsv, ",EXIT_VMSISH"); |
| 752 | if (o->op_private & OPpHUSH_VMSISH) |
| 753 | sv_catpv(tmpsv, ",HUSH_VMSISH"); |
| 754 | } |
| 755 | else if (o->op_type == OP_DIE) { |
| 756 | if (o->op_private & OPpHUSH_VMSISH) |
| 757 | sv_catpv(tmpsv, ",HUSH_VMSISH"); |
| 758 | } |
| 759 | else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) { |
| 760 | if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS) |
| 761 | sv_catpv(tmpsv, ",FT_ACCESS"); |
| 762 | if (o->op_private & OPpFT_STACKED) |
| 763 | sv_catpv(tmpsv, ",FT_STACKED"); |
| 764 | } |
| 765 | if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO) |
| 766 | sv_catpv(tmpsv, ",INTRO"); |
| 767 | if (SvCUR(tmpsv)) |
| 768 | Perl_dump_indent(aTHX_ level, file, "PRIVATE = (%s)\n", SvPVX_const(tmpsv) + 1); |
| 769 | SvREFCNT_dec(tmpsv); |
| 770 | } |
| 771 | |
| 772 | #ifdef PERL_MAD |
| 773 | if (PL_madskills && o->op_madprop) { |
| 774 | SV *tmpsv = newSVpvn("", 0); |
| 775 | MADPROP* mp = o->op_madprop; |
| 776 | Perl_dump_indent(aTHX_ level, file, "MADPROPS = {\n"); |
| 777 | level++; |
| 778 | while (mp) { |
| 779 | char tmp = mp->mad_key; |
| 780 | sv_setpvn(tmpsv,"'",1); |
| 781 | if (tmp) |
| 782 | sv_catpvn(tmpsv, &tmp, 1); |
| 783 | sv_catpv(tmpsv, "'="); |
| 784 | switch (mp->mad_type) { |
| 785 | case MAD_NULL: |
| 786 | sv_catpv(tmpsv, "NULL"); |
| 787 | Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv)); |
| 788 | break; |
| 789 | case MAD_PV: |
| 790 | sv_catpv(tmpsv, "<"); |
| 791 | sv_catpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen); |
| 792 | sv_catpv(tmpsv, ">"); |
| 793 | Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv)); |
| 794 | break; |
| 795 | case MAD_OP: |
| 796 | if ((OP*)mp->mad_val) { |
| 797 | Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv)); |
| 798 | do_op_dump(level, file, (OP*)mp->mad_val); |
| 799 | } |
| 800 | break; |
| 801 | default: |
| 802 | sv_catpv(tmpsv, "(UNK)"); |
| 803 | Perl_dump_indent(aTHX_ level, file, "%s\n", SvPVX(tmpsv)); |
| 804 | break; |
| 805 | } |
| 806 | mp = mp->mad_next; |
| 807 | } |
| 808 | level--; |
| 809 | Perl_dump_indent(aTHX_ level, file, "}\n"); |
| 810 | |
| 811 | SvREFCNT_dec(tmpsv); |
| 812 | } |
| 813 | #endif |
| 814 | |
| 815 | switch (o->op_type) { |
| 816 | case OP_AELEMFAST: |
| 817 | case OP_GVSV: |
| 818 | case OP_GV: |
| 819 | #ifdef USE_ITHREADS |
| 820 | Perl_dump_indent(aTHX_ level, file, "PADIX = %" IVdf "\n", (IV)cPADOPo->op_padix); |
| 821 | #else |
| 822 | if ( ! PL_op->op_flags & OPf_SPECIAL) { /* not lexical */ |
| 823 | if (cSVOPo->op_sv) { |
| 824 | SV *tmpsv = newSV(0); |
| 825 | ENTER; |
| 826 | SAVEFREESV(tmpsv); |
| 827 | #ifdef PERL_MAD |
| 828 | /* FIXME - it this making unwarranted assumptions about the |
| 829 | UTF-8 cleanliness of the dump file handle? */ |
| 830 | SvUTF8_on(tmpsv); |
| 831 | #endif |
| 832 | gv_fullname3(tmpsv, (GV*)cSVOPo->op_sv, NULL); |
| 833 | Perl_dump_indent(aTHX_ level, file, "GV = %s\n", |
| 834 | SvPV_nolen_const(tmpsv)); |
| 835 | LEAVE; |
| 836 | } |
| 837 | else |
| 838 | Perl_dump_indent(aTHX_ level, file, "GV = NULL\n"); |
| 839 | } |
| 840 | #endif |
| 841 | break; |
| 842 | case OP_CONST: |
| 843 | case OP_METHOD_NAMED: |
| 844 | #ifndef USE_ITHREADS |
| 845 | /* with ITHREADS, consts are stored in the pad, and the right pad |
| 846 | * may not be active here, so skip */ |
| 847 | Perl_dump_indent(aTHX_ level, file, "SV = %s\n", SvPEEK(cSVOPo_sv)); |
| 848 | #endif |
| 849 | break; |
| 850 | case OP_SETSTATE: |
| 851 | case OP_NEXTSTATE: |
| 852 | case OP_DBSTATE: |
| 853 | if (CopLINE(cCOPo)) |
| 854 | Perl_dump_indent(aTHX_ level, file, "LINE = %"UVf"\n", |
| 855 | (UV)CopLINE(cCOPo)); |
| 856 | if (CopSTASHPV(cCOPo)) |
| 857 | Perl_dump_indent(aTHX_ level, file, "PACKAGE = \"%s\"\n", |
| 858 | CopSTASHPV(cCOPo)); |
| 859 | if (cCOPo->cop_label) |
| 860 | Perl_dump_indent(aTHX_ level, file, "LABEL = \"%s\"\n", |
| 861 | cCOPo->cop_label); |
| 862 | break; |
| 863 | case OP_ENTERLOOP: |
| 864 | Perl_dump_indent(aTHX_ level, file, "REDO ===> "); |
| 865 | if (cLOOPo->op_redoop) |
| 866 | PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_redoop)); |
| 867 | else |
| 868 | PerlIO_printf(file, "DONE\n"); |
| 869 | Perl_dump_indent(aTHX_ level, file, "NEXT ===> "); |
| 870 | if (cLOOPo->op_nextop) |
| 871 | PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_nextop)); |
| 872 | else |
| 873 | PerlIO_printf(file, "DONE\n"); |
| 874 | Perl_dump_indent(aTHX_ level, file, "LAST ===> "); |
| 875 | if (cLOOPo->op_lastop) |
| 876 | PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOOPo->op_lastop)); |
| 877 | else |
| 878 | PerlIO_printf(file, "DONE\n"); |
| 879 | break; |
| 880 | case OP_COND_EXPR: |
| 881 | case OP_RANGE: |
| 882 | case OP_MAPWHILE: |
| 883 | case OP_GREPWHILE: |
| 884 | case OP_OR: |
| 885 | case OP_AND: |
| 886 | Perl_dump_indent(aTHX_ level, file, "OTHER ===> "); |
| 887 | if (cLOGOPo->op_other) |
| 888 | PerlIO_printf(file, "%"UVf"\n", sequence_num(cLOGOPo->op_other)); |
| 889 | else |
| 890 | PerlIO_printf(file, "DONE\n"); |
| 891 | break; |
| 892 | case OP_PUSHRE: |
| 893 | case OP_MATCH: |
| 894 | case OP_QR: |
| 895 | case OP_SUBST: |
| 896 | do_pmop_dump(level, file, cPMOPo); |
| 897 | break; |
| 898 | case OP_LEAVE: |
| 899 | case OP_LEAVEEVAL: |
| 900 | case OP_LEAVESUB: |
| 901 | case OP_LEAVESUBLV: |
| 902 | case OP_LEAVEWRITE: |
| 903 | case OP_SCOPE: |
| 904 | if (o->op_private & OPpREFCOUNTED) |
| 905 | Perl_dump_indent(aTHX_ level, file, "REFCNT = %"UVuf"\n", (UV)o->op_targ); |
| 906 | break; |
| 907 | default: |
| 908 | break; |
| 909 | } |
| 910 | if (o->op_flags & OPf_KIDS) { |
| 911 | OP *kid; |
| 912 | for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
| 913 | do_op_dump(level, file, kid); |
| 914 | } |
| 915 | Perl_dump_indent(aTHX_ level-1, file, "}\n"); |
| 916 | } |
| 917 | |
| 918 | void |
| 919 | Perl_op_dump(pTHX_ const OP *o) |
| 920 | { |
| 921 | do_op_dump(0, Perl_debug_log, o); |
| 922 | } |
| 923 | |
| 924 | void |
| 925 | Perl_gv_dump(pTHX_ GV *gv) |
| 926 | { |
| 927 | SV *sv; |
| 928 | |
| 929 | if (!gv) { |
| 930 | PerlIO_printf(Perl_debug_log, "{}\n"); |
| 931 | return; |
| 932 | } |
| 933 | sv = sv_newmortal(); |
| 934 | PerlIO_printf(Perl_debug_log, "{\n"); |
| 935 | gv_fullname3(sv, gv, NULL); |
| 936 | Perl_dump_indent(aTHX_ 1, Perl_debug_log, "GV_NAME = %s", SvPVX_const(sv)); |
| 937 | if (gv != GvEGV(gv)) { |
| 938 | gv_efullname3(sv, GvEGV(gv), NULL); |
| 939 | Perl_dump_indent(aTHX_ 1, Perl_debug_log, "-> %s", SvPVX_const(sv)); |
| 940 | } |
| 941 | PerlIO_putc(Perl_debug_log, '\n'); |
| 942 | Perl_dump_indent(aTHX_ 0, Perl_debug_log, "}\n"); |
| 943 | } |
| 944 | |
| 945 | |
| 946 | /* map magic types to the symbolic names |
| 947 | * (with the PERL_MAGIC_ prefixed stripped) |
| 948 | */ |
| 949 | |
| 950 | static const struct { const char type; const char *name; } magic_names[] = { |
| 951 | { PERL_MAGIC_sv, "sv(\\0)" }, |
| 952 | { PERL_MAGIC_arylen, "arylen(#)" }, |
| 953 | { PERL_MAGIC_rhash, "rhash(%)" }, |
| 954 | { PERL_MAGIC_pos, "pos(.)" }, |
| 955 | { PERL_MAGIC_symtab, "symtab(:)" }, |
| 956 | { PERL_MAGIC_backref, "backref(<)" }, |
| 957 | { PERL_MAGIC_arylen_p, "arylen_p(@)" }, |
| 958 | { PERL_MAGIC_overload, "overload(A)" }, |
| 959 | { PERL_MAGIC_bm, "bm(B)" }, |
| 960 | { PERL_MAGIC_regdata, "regdata(D)" }, |
| 961 | { PERL_MAGIC_env, "env(E)" }, |
| 962 | { PERL_MAGIC_isa, "isa(I)" }, |
| 963 | { PERL_MAGIC_dbfile, "dbfile(L)" }, |
| 964 | { PERL_MAGIC_shared, "shared(N)" }, |
| 965 | { PERL_MAGIC_tied, "tied(P)" }, |
| 966 | { PERL_MAGIC_sig, "sig(S)" }, |
| 967 | { PERL_MAGIC_uvar, "uvar(U)" }, |
| 968 | { PERL_MAGIC_overload_elem, "overload_elem(a)" }, |
| 969 | { PERL_MAGIC_overload_table, "overload_table(c)" }, |
| 970 | { PERL_MAGIC_regdatum, "regdatum(d)" }, |
| 971 | { PERL_MAGIC_envelem, "envelem(e)" }, |
| 972 | { PERL_MAGIC_fm, "fm(f)" }, |
| 973 | { PERL_MAGIC_regex_global, "regex_global(g)" }, |
| 974 | { PERL_MAGIC_isaelem, "isaelem(i)" }, |
| 975 | { PERL_MAGIC_nkeys, "nkeys(k)" }, |
| 976 | { PERL_MAGIC_dbline, "dbline(l)" }, |
| 977 | { PERL_MAGIC_mutex, "mutex(m)" }, |
| 978 | { PERL_MAGIC_shared_scalar, "shared_scalar(n)" }, |
| 979 | { PERL_MAGIC_collxfrm, "collxfrm(o)" }, |
| 980 | { PERL_MAGIC_tiedelem, "tiedelem(p)" }, |
| 981 | { PERL_MAGIC_tiedscalar, "tiedscalar(q)" }, |
| 982 | { PERL_MAGIC_qr, "qr(r)" }, |
| 983 | { PERL_MAGIC_sigelem, "sigelem(s)" }, |
| 984 | { PERL_MAGIC_taint, "taint(t)" }, |
| 985 | { PERL_MAGIC_uvar_elem, "uvar_elem(v)" }, |
| 986 | { PERL_MAGIC_vec, "vec(v)" }, |
| 987 | { PERL_MAGIC_vstring, "vstring(V)" }, |
| 988 | { PERL_MAGIC_utf8, "utf8(w)" }, |
| 989 | { PERL_MAGIC_substr, "substr(x)" }, |
| 990 | { PERL_MAGIC_defelem, "defelem(y)" }, |
| 991 | { PERL_MAGIC_ext, "ext(~)" }, |
| 992 | /* this null string terminates the list */ |
| 993 | { 0, 0 }, |
| 994 | }; |
| 995 | |
| 996 | void |
| 997 | Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) |
| 998 | { |
| 999 | for (; mg; mg = mg->mg_moremagic) { |
| 1000 | Perl_dump_indent(aTHX_ level, file, |
| 1001 | " MAGIC = 0x%"UVxf"\n", PTR2UV(mg)); |
| 1002 | if (mg->mg_virtual) { |
| 1003 | const MGVTBL * const v = mg->mg_virtual; |
| 1004 | const char *s = NULL; |
| 1005 | if (v == &PL_vtbl_sv) s = "sv"; |
| 1006 | else if (v == &PL_vtbl_env) s = "env"; |
| 1007 | else if (v == &PL_vtbl_envelem) s = "envelem"; |
| 1008 | else if (v == &PL_vtbl_sig) s = "sig"; |
| 1009 | else if (v == &PL_vtbl_sigelem) s = "sigelem"; |
| 1010 | else if (v == &PL_vtbl_pack) s = "pack"; |
| 1011 | else if (v == &PL_vtbl_packelem) s = "packelem"; |
| 1012 | else if (v == &PL_vtbl_dbline) s = "dbline"; |
| 1013 | else if (v == &PL_vtbl_isa) s = "isa"; |
| 1014 | else if (v == &PL_vtbl_arylen) s = "arylen"; |
| 1015 | else if (v == &PL_vtbl_mglob) s = "mglob"; |
| 1016 | else if (v == &PL_vtbl_nkeys) s = "nkeys"; |
| 1017 | else if (v == &PL_vtbl_taint) s = "taint"; |
| 1018 | else if (v == &PL_vtbl_substr) s = "substr"; |
| 1019 | else if (v == &PL_vtbl_vec) s = "vec"; |
| 1020 | else if (v == &PL_vtbl_pos) s = "pos"; |
| 1021 | else if (v == &PL_vtbl_bm) s = "bm"; |
| 1022 | else if (v == &PL_vtbl_fm) s = "fm"; |
| 1023 | else if (v == &PL_vtbl_uvar) s = "uvar"; |
| 1024 | else if (v == &PL_vtbl_defelem) s = "defelem"; |
| 1025 | #ifdef USE_LOCALE_COLLATE |
| 1026 | else if (v == &PL_vtbl_collxfrm) s = "collxfrm"; |
| 1027 | #endif |
| 1028 | else if (v == &PL_vtbl_amagic) s = "amagic"; |
| 1029 | else if (v == &PL_vtbl_amagicelem) s = "amagicelem"; |
| 1030 | else if (v == &PL_vtbl_backref) s = "backref"; |
| 1031 | else if (v == &PL_vtbl_utf8) s = "utf8"; |
| 1032 | else if (v == &PL_vtbl_arylen_p) s = "arylen_p"; |
| 1033 | if (s) |
| 1034 | Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s); |
| 1035 | else |
| 1036 | Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v)); |
| 1037 | } |
| 1038 | else |
| 1039 | Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0\n"); |
| 1040 | |
| 1041 | if (mg->mg_private) |
| 1042 | Perl_dump_indent(aTHX_ level, file, " MG_PRIVATE = %d\n", mg->mg_private); |
| 1043 | |
| 1044 | { |
| 1045 | int n; |
| 1046 | const char *name = NULL; |
| 1047 | for (n = 0; magic_names[n].name; n++) { |
| 1048 | if (mg->mg_type == magic_names[n].type) { |
| 1049 | name = magic_names[n].name; |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | if (name) |
| 1054 | Perl_dump_indent(aTHX_ level, file, |
| 1055 | " MG_TYPE = PERL_MAGIC_%s\n", name); |
| 1056 | else |
| 1057 | Perl_dump_indent(aTHX_ level, file, |
| 1058 | " MG_TYPE = UNKNOWN(\\%o)\n", mg->mg_type); |
| 1059 | } |
| 1060 | |
| 1061 | if (mg->mg_flags) { |
| 1062 | Perl_dump_indent(aTHX_ level, file, " MG_FLAGS = 0x%02X\n", mg->mg_flags); |
| 1063 | if (mg->mg_type == PERL_MAGIC_envelem && |
| 1064 | mg->mg_flags & MGf_TAINTEDDIR) |
| 1065 | Perl_dump_indent(aTHX_ level, file, " TAINTEDDIR\n"); |
| 1066 | if (mg->mg_flags & MGf_REFCOUNTED) |
| 1067 | Perl_dump_indent(aTHX_ level, file, " REFCOUNTED\n"); |
| 1068 | if (mg->mg_flags & MGf_GSKIP) |
| 1069 | Perl_dump_indent(aTHX_ level, file, " GSKIP\n"); |
| 1070 | if (mg->mg_type == PERL_MAGIC_regex_global && |
| 1071 | mg->mg_flags & MGf_MINMATCH) |
| 1072 | Perl_dump_indent(aTHX_ level, file, " MINMATCH\n"); |
| 1073 | } |
| 1074 | if (mg->mg_obj) { |
| 1075 | Perl_dump_indent(aTHX_ level, file, " MG_OBJ = 0x%"UVxf"\n", PTR2UV(mg->mg_obj)); |
| 1076 | if (mg->mg_flags & MGf_REFCOUNTED) |
| 1077 | do_sv_dump(level+2, file, mg->mg_obj, nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ |
| 1078 | } |
| 1079 | if (mg->mg_len) |
| 1080 | Perl_dump_indent(aTHX_ level, file, " MG_LEN = %ld\n", (long)mg->mg_len); |
| 1081 | if (mg->mg_ptr) { |
| 1082 | Perl_dump_indent(aTHX_ level, file, " MG_PTR = 0x%"UVxf, PTR2UV(mg->mg_ptr)); |
| 1083 | if (mg->mg_len >= 0) { |
| 1084 | if (mg->mg_type != PERL_MAGIC_utf8) { |
| 1085 | SV *sv = newSVpvs(""); |
| 1086 | PerlIO_printf(file, " %s", pv_display(sv, mg->mg_ptr, mg->mg_len, 0, pvlim)); |
| 1087 | SvREFCNT_dec(sv); |
| 1088 | } |
| 1089 | } |
| 1090 | else if (mg->mg_len == HEf_SVKEY) { |
| 1091 | PerlIO_puts(file, " => HEf_SVKEY\n"); |
| 1092 | do_sv_dump(level+2, file, (SV*)((mg)->mg_ptr), nest+1, maxnest, dumpops, pvlim); /* MG is already +1 */ |
| 1093 | continue; |
| 1094 | } |
| 1095 | else |
| 1096 | PerlIO_puts(file, " ???? - please notify IZ"); |
| 1097 | PerlIO_putc(file, '\n'); |
| 1098 | } |
| 1099 | if (mg->mg_type == PERL_MAGIC_utf8) { |
| 1100 | STRLEN *cache = (STRLEN *) mg->mg_ptr; |
| 1101 | if (cache) { |
| 1102 | IV i; |
| 1103 | for (i = 0; i < PERL_MAGIC_UTF8_CACHESIZE; i++) |
| 1104 | Perl_dump_indent(aTHX_ level, file, |
| 1105 | " %2"IVdf": %"UVuf" -> %"UVuf"\n", |
| 1106 | i, |
| 1107 | (UV)cache[i * 2], |
| 1108 | (UV)cache[i * 2 + 1]); |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | void |
| 1115 | Perl_magic_dump(pTHX_ const MAGIC *mg) |
| 1116 | { |
| 1117 | do_magic_dump(0, Perl_debug_log, mg, 0, 0, 0, 0); |
| 1118 | } |
| 1119 | |
| 1120 | void |
| 1121 | Perl_do_hv_dump(pTHX_ I32 level, PerlIO *file, const char *name, HV *sv) |
| 1122 | { |
| 1123 | const char *hvname; |
| 1124 | Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv)); |
| 1125 | if (sv && (hvname = HvNAME_get(sv))) |
| 1126 | PerlIO_printf(file, "\t\"%s\"\n", hvname); |
| 1127 | else |
| 1128 | PerlIO_putc(file, '\n'); |
| 1129 | } |
| 1130 | |
| 1131 | void |
| 1132 | Perl_do_gv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv) |
| 1133 | { |
| 1134 | Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv)); |
| 1135 | if (sv && GvNAME(sv)) |
| 1136 | PerlIO_printf(file, "\t\"%s\"\n", GvNAME(sv)); |
| 1137 | else |
| 1138 | PerlIO_putc(file, '\n'); |
| 1139 | } |
| 1140 | |
| 1141 | void |
| 1142 | Perl_do_gvgv_dump(pTHX_ I32 level, PerlIO *file, const char *name, GV *sv) |
| 1143 | { |
| 1144 | Perl_dump_indent(aTHX_ level, file, "%s = 0x%"UVxf, name, PTR2UV(sv)); |
| 1145 | if (sv && GvNAME(sv)) { |
| 1146 | const char *hvname; |
| 1147 | PerlIO_printf(file, "\t\""); |
| 1148 | if (GvSTASH(sv) && (hvname = HvNAME_get(GvSTASH(sv)))) |
| 1149 | PerlIO_printf(file, "%s\" :: \"", hvname); |
| 1150 | PerlIO_printf(file, "%s\"\n", GvNAME(sv)); |
| 1151 | } |
| 1152 | else |
| 1153 | PerlIO_putc(file, '\n'); |
| 1154 | } |
| 1155 | |
| 1156 | void |
| 1157 | Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bool dumpops, STRLEN pvlim) |
| 1158 | { |
| 1159 | dVAR; |
| 1160 | SV *d; |
| 1161 | const char *s; |
| 1162 | U32 flags; |
| 1163 | U32 type; |
| 1164 | |
| 1165 | if (!sv) { |
| 1166 | Perl_dump_indent(aTHX_ level, file, "SV = 0\n"); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | flags = SvFLAGS(sv); |
| 1171 | type = SvTYPE(sv); |
| 1172 | |
| 1173 | d = Perl_newSVpvf(aTHX_ |
| 1174 | "(0x%"UVxf") at 0x%"UVxf"\n%*s REFCNT = %"IVdf"\n%*s FLAGS = (", |
| 1175 | PTR2UV(SvANY(sv)), PTR2UV(sv), |
| 1176 | (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv), |
| 1177 | (int)(PL_dumpindent*level), ""); |
| 1178 | |
| 1179 | if (flags & SVs_PADSTALE) sv_catpv(d, "PADSTALE,"); |
| 1180 | if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,"); |
| 1181 | if (flags & SVs_PADMY) sv_catpv(d, "PADMY,"); |
| 1182 | if (flags & SVs_TEMP) sv_catpv(d, "TEMP,"); |
| 1183 | if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,"); |
| 1184 | if (flags & SVs_GMG) sv_catpv(d, "GMG,"); |
| 1185 | if (flags & SVs_SMG) sv_catpv(d, "SMG,"); |
| 1186 | if (flags & SVs_RMG) sv_catpv(d, "RMG,"); |
| 1187 | |
| 1188 | if (flags & SVf_IOK) sv_catpv(d, "IOK,"); |
| 1189 | if (flags & SVf_NOK) sv_catpv(d, "NOK,"); |
| 1190 | if (flags & SVf_POK) sv_catpv(d, "POK,"); |
| 1191 | if (flags & SVf_ROK) { |
| 1192 | sv_catpv(d, "ROK,"); |
| 1193 | if (SvWEAKREF(sv)) sv_catpv(d, "WEAKREF,"); |
| 1194 | } |
| 1195 | if (flags & SVf_OOK) sv_catpv(d, "OOK,"); |
| 1196 | if (flags & SVf_FAKE) sv_catpv(d, "FAKE,"); |
| 1197 | if (flags & SVf_READONLY) sv_catpv(d, "READONLY,"); |
| 1198 | |
| 1199 | if (flags & SVf_AMAGIC && type != SVt_PVHV) |
| 1200 | sv_catpv(d, "OVERLOAD,"); |
| 1201 | if (flags & SVp_IOK) sv_catpv(d, "pIOK,"); |
| 1202 | if (flags & SVp_NOK) sv_catpv(d, "pNOK,"); |
| 1203 | if (flags & SVp_POK) sv_catpv(d, "pPOK,"); |
| 1204 | if (flags & SVp_SCREAM && type != SVt_PVHV) |
| 1205 | sv_catpv(d, "SCREAM,"); |
| 1206 | |
| 1207 | switch (type) { |
| 1208 | case SVt_PVCV: |
| 1209 | case SVt_PVFM: |
| 1210 | if (CvANON(sv)) sv_catpv(d, "ANON,"); |
| 1211 | if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,"); |
| 1212 | if (CvCLONE(sv)) sv_catpv(d, "CLONE,"); |
| 1213 | if (CvCLONED(sv)) sv_catpv(d, "CLONED,"); |
| 1214 | if (CvCONST(sv)) sv_catpv(d, "CONST,"); |
| 1215 | if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,"); |
| 1216 | if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,"); |
| 1217 | if (CvLVALUE(sv)) sv_catpv(d, "LVALUE,"); |
| 1218 | if (CvMETHOD(sv)) sv_catpv(d, "METHOD,"); |
| 1219 | if (CvLOCKED(sv)) sv_catpv(d, "LOCKED,"); |
| 1220 | if (CvWEAKOUTSIDE(sv)) sv_catpv(d, "WEAKOUTSIDE,"); |
| 1221 | if (CvASSERTION(sv)) sv_catpv(d, "ASSERTION,"); |
| 1222 | break; |
| 1223 | case SVt_PVHV: |
| 1224 | if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,"); |
| 1225 | if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,"); |
| 1226 | if (HvHASKFLAGS(sv)) sv_catpv(d, "HASKFLAGS,"); |
| 1227 | if (HvREHASH(sv)) sv_catpv(d, "REHASH,"); |
| 1228 | if (flags & SVphv_CLONEABLE) sv_catpv(d, "CLONEABLE,"); |
| 1229 | break; |
| 1230 | case SVt_PVGV: case SVt_PVLV: |
| 1231 | if (GvINTRO(sv)) sv_catpv(d, "INTRO,"); |
| 1232 | if (GvMULTI(sv)) sv_catpv(d, "MULTI,"); |
| 1233 | if (GvUNIQUE(sv)) sv_catpv(d, "UNIQUE,"); |
| 1234 | if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,"); |
| 1235 | if (GvIN_PAD(sv)) sv_catpv(d, "IN_PAD,"); |
| 1236 | if (SvPAD_OUR(sv)) sv_catpv(d, "OUR,"); |
| 1237 | if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,"); |
| 1238 | if (GvIMPORTED(sv)) { |
| 1239 | sv_catpv(d, "IMPORT"); |
| 1240 | if (GvIMPORTED(sv) == GVf_IMPORTED) |
| 1241 | sv_catpv(d, "ALL,"); |
| 1242 | else { |
| 1243 | sv_catpv(d, "("); |
| 1244 | if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV"); |
| 1245 | if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV"); |
| 1246 | if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV"); |
| 1247 | if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV"); |
| 1248 | sv_catpv(d, " ),"); |
| 1249 | } |
| 1250 | } |
| 1251 | /* FALL THROUGH */ |
| 1252 | default: |
| 1253 | if (SvEVALED(sv)) sv_catpv(d, "EVALED,"); |
| 1254 | if (SvIsUV(sv) && !(flags & SVf_ROK)) sv_catpv(d, "IsUV,"); |
| 1255 | break; |
| 1256 | case SVt_PVBM: |
| 1257 | if (SvTAIL(sv)) sv_catpv(d, "TAIL,"); |
| 1258 | if (SvVALID(sv)) sv_catpv(d, "VALID,"); |
| 1259 | break; |
| 1260 | case SVt_PVMG: |
| 1261 | if (SvPAD_TYPED(sv)) sv_catpv(d, "TYPED,"); |
| 1262 | break; |
| 1263 | case SVt_PVAV: |
| 1264 | break; |
| 1265 | } |
| 1266 | /* SVphv_SHAREKEYS is also 0x20000000 */ |
| 1267 | if ((type != SVt_PVHV) && SvUTF8(sv)) |
| 1268 | sv_catpv(d, "UTF8"); |
| 1269 | |
| 1270 | if (*(SvEND(d) - 1) == ',') { |
| 1271 | SvCUR_set(d, SvCUR(d) - 1); |
| 1272 | SvPVX(d)[SvCUR(d)] = '\0'; |
| 1273 | } |
| 1274 | sv_catpv(d, ")"); |
| 1275 | s = SvPVX_const(d); |
| 1276 | |
| 1277 | #ifdef DEBUG_LEAKING_SCALARS |
| 1278 | Perl_dump_indent(aTHX_ level, file, "ALLOCATED at %s:%d %s %s%s\n", |
| 1279 | sv->sv_debug_file ? sv->sv_debug_file : "(unknown)", |
| 1280 | sv->sv_debug_line, |
| 1281 | sv->sv_debug_inpad ? "for" : "by", |
| 1282 | sv->sv_debug_optype ? PL_op_name[sv->sv_debug_optype]: "(none)", |
| 1283 | sv->sv_debug_cloned ? " (cloned)" : ""); |
| 1284 | #endif |
| 1285 | Perl_dump_indent(aTHX_ level, file, "SV = "); |
| 1286 | switch (type) { |
| 1287 | case SVt_NULL: |
| 1288 | PerlIO_printf(file, "NULL%s\n", s); |
| 1289 | SvREFCNT_dec(d); |
| 1290 | return; |
| 1291 | case SVt_IV: |
| 1292 | PerlIO_printf(file, "IV%s\n", s); |
| 1293 | break; |
| 1294 | case SVt_NV: |
| 1295 | PerlIO_printf(file, "NV%s\n", s); |
| 1296 | break; |
| 1297 | case SVt_RV: |
| 1298 | PerlIO_printf(file, "RV%s\n", s); |
| 1299 | break; |
| 1300 | case SVt_PV: |
| 1301 | PerlIO_printf(file, "PV%s\n", s); |
| 1302 | break; |
| 1303 | case SVt_PVIV: |
| 1304 | PerlIO_printf(file, "PVIV%s\n", s); |
| 1305 | break; |
| 1306 | case SVt_PVNV: |
| 1307 | PerlIO_printf(file, "PVNV%s\n", s); |
| 1308 | break; |
| 1309 | case SVt_PVBM: |
| 1310 | PerlIO_printf(file, "PVBM%s\n", s); |
| 1311 | break; |
| 1312 | case SVt_PVMG: |
| 1313 | PerlIO_printf(file, "PVMG%s\n", s); |
| 1314 | break; |
| 1315 | case SVt_PVLV: |
| 1316 | PerlIO_printf(file, "PVLV%s\n", s); |
| 1317 | break; |
| 1318 | case SVt_PVAV: |
| 1319 | PerlIO_printf(file, "PVAV%s\n", s); |
| 1320 | break; |
| 1321 | case SVt_PVHV: |
| 1322 | PerlIO_printf(file, "PVHV%s\n", s); |
| 1323 | break; |
| 1324 | case SVt_PVCV: |
| 1325 | PerlIO_printf(file, "PVCV%s\n", s); |
| 1326 | break; |
| 1327 | case SVt_PVGV: |
| 1328 | PerlIO_printf(file, "PVGV%s\n", s); |
| 1329 | break; |
| 1330 | case SVt_PVFM: |
| 1331 | PerlIO_printf(file, "PVFM%s\n", s); |
| 1332 | break; |
| 1333 | case SVt_PVIO: |
| 1334 | PerlIO_printf(file, "PVIO%s\n", s); |
| 1335 | break; |
| 1336 | default: |
| 1337 | PerlIO_printf(file, "UNKNOWN(0x%"UVxf") %s\n", (UV)type, s); |
| 1338 | SvREFCNT_dec(d); |
| 1339 | return; |
| 1340 | } |
| 1341 | if ((type >= SVt_PVIV && type != SVt_PVAV && type != SVt_PVHV |
| 1342 | && type != SVt_PVCV && !isGV_with_GP(sv)) |
| 1343 | || type == SVt_IV) { |
| 1344 | if (SvIsUV(sv) |
| 1345 | #ifdef PERL_OLD_COPY_ON_WRITE |
| 1346 | || SvIsCOW(sv) |
| 1347 | #endif |
| 1348 | ) |
| 1349 | Perl_dump_indent(aTHX_ level, file, " UV = %"UVuf, (UV)SvUVX(sv)); |
| 1350 | else |
| 1351 | Perl_dump_indent(aTHX_ level, file, " IV = %"IVdf, (IV)SvIVX(sv)); |
| 1352 | if (SvOOK(sv)) |
| 1353 | PerlIO_printf(file, " (OFFSET)"); |
| 1354 | #ifdef PERL_OLD_COPY_ON_WRITE |
| 1355 | if (SvIsCOW_shared_hash(sv)) |
| 1356 | PerlIO_printf(file, " (HASH)"); |
| 1357 | else if (SvIsCOW_normal(sv)) |
| 1358 | PerlIO_printf(file, " (COW from 0x%"UVxf")", (UV)SvUVX(sv)); |
| 1359 | #endif |
| 1360 | PerlIO_putc(file, '\n'); |
| 1361 | } |
| 1362 | if ((type >= SVt_PVNV && type != SVt_PVAV && type != SVt_PVHV |
| 1363 | && type != SVt_PVCV && type != SVt_PVFM && !isGV_with_GP(sv)) |
| 1364 | || type == SVt_NV) { |
| 1365 | STORE_NUMERIC_LOCAL_SET_STANDARD(); |
| 1366 | /* %Vg doesn't work? --jhi */ |
| 1367 | #ifdef USE_LONG_DOUBLE |
| 1368 | Perl_dump_indent(aTHX_ level, file, " NV = %.*" PERL_PRIgldbl "\n", LDBL_DIG, SvNVX(sv)); |
| 1369 | #else |
| 1370 | Perl_dump_indent(aTHX_ level, file, " NV = %.*g\n", DBL_DIG, SvNVX(sv)); |
| 1371 | #endif |
| 1372 | RESTORE_NUMERIC_LOCAL(); |
| 1373 | } |
| 1374 | if (SvROK(sv)) { |
| 1375 | Perl_dump_indent(aTHX_ level, file, " RV = 0x%"UVxf"\n", PTR2UV(SvRV(sv))); |
| 1376 | if (nest < maxnest) |
| 1377 | do_sv_dump(level+1, file, SvRV(sv), nest+1, maxnest, dumpops, pvlim); |
| 1378 | } |
| 1379 | if (type < SVt_PV) { |
| 1380 | SvREFCNT_dec(d); |
| 1381 | return; |
| 1382 | } |
| 1383 | if (type <= SVt_PVLV && !isGV_with_GP(sv)) { |
| 1384 | if (SvPVX_const(sv)) { |
| 1385 | Perl_dump_indent(aTHX_ level, file," PV = 0x%"UVxf" ", PTR2UV(SvPVX_const(sv))); |
| 1386 | if (SvOOK(sv)) |
| 1387 | PerlIO_printf(file, "( %s . ) ", pv_display(d, SvPVX_const(sv)-SvIVX(sv), SvIVX(sv), 0, pvlim)); |
| 1388 | PerlIO_printf(file, "%s", pv_display(d, SvPVX_const(sv), SvCUR(sv), SvLEN(sv), pvlim)); |
| 1389 | if (SvUTF8(sv)) /* the 8? \x{....} */ |
| 1390 | PerlIO_printf(file, " [UTF8 \"%s\"]", sv_uni_display(d, sv, 8 * sv_len_utf8(sv), UNI_DISPLAY_QQ)); |
| 1391 | PerlIO_printf(file, "\n"); |
| 1392 | Perl_dump_indent(aTHX_ level, file, " CUR = %"IVdf"\n", (IV)SvCUR(sv)); |
| 1393 | Perl_dump_indent(aTHX_ level, file, " LEN = %"IVdf"\n", (IV)SvLEN(sv)); |
| 1394 | } |
| 1395 | else |
| 1396 | Perl_dump_indent(aTHX_ level, file, " PV = 0\n"); |
| 1397 | } |
| 1398 | if (type >= SVt_PVMG) { |
| 1399 | if (SvMAGIC(sv)) |
| 1400 | do_magic_dump(level, file, SvMAGIC(sv), nest, maxnest, dumpops, pvlim); |
| 1401 | if (SvSTASH(sv)) |
| 1402 | do_hv_dump(level, file, " STASH", SvSTASH(sv)); |
| 1403 | } |
| 1404 | switch (type) { |
| 1405 | case SVt_PVAV: |
| 1406 | Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(AvARRAY(sv))); |
| 1407 | if (AvARRAY(sv) != AvALLOC(sv)) { |
| 1408 | PerlIO_printf(file, " (offset=%"IVdf")\n", (IV)(AvARRAY(sv) - AvALLOC(sv))); |
| 1409 | Perl_dump_indent(aTHX_ level, file, " ALLOC = 0x%"UVxf"\n", PTR2UV(AvALLOC(sv))); |
| 1410 | } |
| 1411 | else |
| 1412 | PerlIO_putc(file, '\n'); |
| 1413 | Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)AvFILLp(sv)); |
| 1414 | Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)AvMAX(sv)); |
| 1415 | Perl_dump_indent(aTHX_ level, file, " ARYLEN = 0x%"UVxf"\n", SvMAGIC(sv) ? PTR2UV(AvARYLEN(sv)) : 0); |
| 1416 | sv_setpvn(d, "", 0); |
| 1417 | if (AvREAL(sv)) sv_catpv(d, ",REAL"); |
| 1418 | if (AvREIFY(sv)) sv_catpv(d, ",REIFY"); |
| 1419 | Perl_dump_indent(aTHX_ level, file, " FLAGS = (%s)\n", |
| 1420 | SvCUR(d) ? SvPVX_const(d) + 1 : ""); |
| 1421 | if (nest < maxnest && av_len((AV*)sv) >= 0) { |
| 1422 | int count; |
| 1423 | for (count = 0; count <= av_len((AV*)sv) && count < maxnest; count++) { |
| 1424 | SV** elt = av_fetch((AV*)sv,count,0); |
| 1425 | |
| 1426 | Perl_dump_indent(aTHX_ level + 1, file, "Elt No. %"IVdf"\n", (IV)count); |
| 1427 | if (elt) |
| 1428 | do_sv_dump(level+1, file, *elt, nest+1, maxnest, dumpops, pvlim); |
| 1429 | } |
| 1430 | } |
| 1431 | break; |
| 1432 | case SVt_PVHV: |
| 1433 | Perl_dump_indent(aTHX_ level, file, " ARRAY = 0x%"UVxf, PTR2UV(HvARRAY(sv))); |
| 1434 | if (HvARRAY(sv) && HvKEYS(sv)) { |
| 1435 | /* Show distribution of HEs in the ARRAY */ |
| 1436 | int freq[200]; |
| 1437 | #define FREQ_MAX (sizeof freq / sizeof freq[0] - 1) |
| 1438 | int i; |
| 1439 | int max = 0; |
| 1440 | U32 pow2 = 2, keys = HvKEYS(sv); |
| 1441 | NV theoret, sum = 0; |
| 1442 | |
| 1443 | PerlIO_printf(file, " ("); |
| 1444 | Zero(freq, FREQ_MAX + 1, int); |
| 1445 | for (i = 0; (STRLEN)i <= HvMAX(sv); i++) { |
| 1446 | HE* h; |
| 1447 | int count = 0; |
| 1448 | for (h = HvARRAY(sv)[i]; h; h = HeNEXT(h)) |
| 1449 | count++; |
| 1450 | if (count > FREQ_MAX) |
| 1451 | count = FREQ_MAX; |
| 1452 | freq[count]++; |
| 1453 | if (max < count) |
| 1454 | max = count; |
| 1455 | } |
| 1456 | for (i = 0; i <= max; i++) { |
| 1457 | if (freq[i]) { |
| 1458 | PerlIO_printf(file, "%d%s:%d", i, |
| 1459 | (i == FREQ_MAX) ? "+" : "", |
| 1460 | freq[i]); |
| 1461 | if (i != max) |
| 1462 | PerlIO_printf(file, ", "); |
| 1463 | } |
| 1464 | } |
| 1465 | PerlIO_putc(file, ')'); |
| 1466 | /* The "quality" of a hash is defined as the total number of |
| 1467 | comparisons needed to access every element once, relative |
| 1468 | to the expected number needed for a random hash. |
| 1469 | |
| 1470 | The total number of comparisons is equal to the sum of |
| 1471 | the squares of the number of entries in each bucket. |
| 1472 | For a random hash of n keys into k buckets, the expected |
| 1473 | value is |
| 1474 | n + n(n-1)/2k |
| 1475 | */ |
| 1476 | |
| 1477 | for (i = max; i > 0; i--) { /* Precision: count down. */ |
| 1478 | sum += freq[i] * i * i; |
| 1479 | } |
| 1480 | while ((keys = keys >> 1)) |
| 1481 | pow2 = pow2 << 1; |
| 1482 | theoret = HvKEYS(sv); |
| 1483 | theoret += theoret * (theoret-1)/pow2; |
| 1484 | PerlIO_putc(file, '\n'); |
| 1485 | Perl_dump_indent(aTHX_ level, file, " hash quality = %.1"NVff"%%", theoret/sum*100); |
| 1486 | } |
| 1487 | PerlIO_putc(file, '\n'); |
| 1488 | Perl_dump_indent(aTHX_ level, file, " KEYS = %"IVdf"\n", (IV)HvKEYS(sv)); |
| 1489 | Perl_dump_indent(aTHX_ level, file, " FILL = %"IVdf"\n", (IV)HvFILL(sv)); |
| 1490 | Perl_dump_indent(aTHX_ level, file, " MAX = %"IVdf"\n", (IV)HvMAX(sv)); |
| 1491 | Perl_dump_indent(aTHX_ level, file, " RITER = %"IVdf"\n", (IV)HvRITER_get(sv)); |
| 1492 | Perl_dump_indent(aTHX_ level, file, " EITER = 0x%"UVxf"\n", PTR2UV(HvEITER_get(sv))); |
| 1493 | { |
| 1494 | MAGIC *mg = mg_find(sv, PERL_MAGIC_symtab); |
| 1495 | if (mg && mg->mg_obj) { |
| 1496 | Perl_dump_indent(aTHX_ level, file, " PMROOT = 0x%"UVxf"\n", PTR2UV(mg->mg_obj)); |
| 1497 | } |
| 1498 | } |
| 1499 | { |
| 1500 | const char *hvname = HvNAME_get(sv); |
| 1501 | if (hvname) |
| 1502 | Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", hvname); |
| 1503 | } |
| 1504 | if (SvOOK(sv)) { |
| 1505 | AV *backrefs = *Perl_hv_backreferences_p(aTHX_ (HV*)sv); |
| 1506 | if (backrefs) { |
| 1507 | Perl_dump_indent(aTHX_ level, file, " BACKREFS = 0x%"UVxf"\n", |
| 1508 | PTR2UV(backrefs)); |
| 1509 | do_sv_dump(level+1, file, (SV*)backrefs, nest+1, maxnest, |
| 1510 | dumpops, pvlim); |
| 1511 | } |
| 1512 | } |
| 1513 | if (nest < maxnest && !HvEITER_get(sv)) { /* Try to preserve iterator */ |
| 1514 | HE *he; |
| 1515 | HV * const hv = (HV*)sv; |
| 1516 | int count = maxnest - nest; |
| 1517 | |
| 1518 | hv_iterinit(hv); |
| 1519 | while ((he = hv_iternext_flags(hv, HV_ITERNEXT_WANTPLACEHOLDERS)) |
| 1520 | && count--) { |
| 1521 | SV *elt, *keysv; |
| 1522 | const char *keypv; |
| 1523 | STRLEN len; |
| 1524 | const U32 hash = HeHASH(he); |
| 1525 | |
| 1526 | keysv = hv_iterkeysv(he); |
| 1527 | keypv = SvPV_const(keysv, len); |
| 1528 | elt = hv_iterval(hv, he); |
| 1529 | Perl_dump_indent(aTHX_ level+1, file, "Elt %s ", pv_display(d, keypv, len, 0, pvlim)); |
| 1530 | if (SvUTF8(keysv)) |
| 1531 | PerlIO_printf(file, "[UTF8 \"%s\"] ", sv_uni_display(d, keysv, 8 * sv_len_utf8(keysv), UNI_DISPLAY_QQ)); |
| 1532 | if (HeKREHASH(he)) |
| 1533 | PerlIO_printf(file, "[REHASH] "); |
| 1534 | PerlIO_printf(file, "HASH = 0x%"UVxf"\n", (UV)hash); |
| 1535 | do_sv_dump(level+1, file, elt, nest+1, maxnest, dumpops, pvlim); |
| 1536 | } |
| 1537 | hv_iterinit(hv); /* Return to status quo */ |
| 1538 | } |
| 1539 | break; |
| 1540 | case SVt_PVCV: |
| 1541 | if (SvPOK(sv)) |
| 1542 | Perl_dump_indent(aTHX_ level, file, " PROTOTYPE = \"%s\"\n", SvPV_nolen_const(sv)); |
| 1543 | /* FALL THROUGH */ |
| 1544 | case SVt_PVFM: |
| 1545 | do_hv_dump(level, file, " COMP_STASH", CvSTASH(sv)); |
| 1546 | if (!CvISXSUB(sv)) { |
| 1547 | if (CvSTART(sv)) { |
| 1548 | Perl_dump_indent(aTHX_ level, file, |
| 1549 | " START = 0x%"UVxf" ===> %"IVdf"\n", |
| 1550 | PTR2UV(CvSTART(sv)), |
| 1551 | (IV)sequence_num(CvSTART(sv))); |
| 1552 | } |
| 1553 | Perl_dump_indent(aTHX_ level, file, " ROOT = 0x%"UVxf"\n", |
| 1554 | PTR2UV(CvROOT(sv))); |
| 1555 | if (CvROOT(sv) && dumpops) { |
| 1556 | do_op_dump(level+1, file, CvROOT(sv)); |
| 1557 | } |
| 1558 | } else { |
| 1559 | SV *constant = cv_const_sv((CV *)sv); |
| 1560 | |
| 1561 | Perl_dump_indent(aTHX_ level, file, " XSUB = 0x%"UVxf"\n", PTR2UV(CvXSUB(sv))); |
| 1562 | |
| 1563 | if (constant) { |
| 1564 | Perl_dump_indent(aTHX_ level, file, " XSUBANY = 0x%"UVxf |
| 1565 | " (CONST SV)\n", |
| 1566 | PTR2UV(CvXSUBANY(sv).any_ptr)); |
| 1567 | do_sv_dump(level+1, file, constant, nest+1, maxnest, dumpops, |
| 1568 | pvlim); |
| 1569 | } else { |
| 1570 | Perl_dump_indent(aTHX_ level, file, " XSUBANY = %"IVdf"\n", |
| 1571 | (IV)CvXSUBANY(sv).any_i32); |
| 1572 | } |
| 1573 | } |
| 1574 | do_gvgv_dump(level, file, " GVGV::GV", CvGV(sv)); |
| 1575 | Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", CvFILE(sv)); |
| 1576 | Perl_dump_indent(aTHX_ level, file, " DEPTH = %"IVdf"\n", (IV)CvDEPTH(sv)); |
| 1577 | Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)CvFLAGS(sv)); |
| 1578 | Perl_dump_indent(aTHX_ level, file, " OUTSIDE_SEQ = %"UVuf"\n", (UV)CvOUTSIDE_SEQ(sv)); |
| 1579 | if (type == SVt_PVFM) |
| 1580 | Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)FmLINES(sv)); |
| 1581 | Perl_dump_indent(aTHX_ level, file, " PADLIST = 0x%"UVxf"\n", PTR2UV(CvPADLIST(sv))); |
| 1582 | if (nest < maxnest) { |
| 1583 | do_dump_pad(level+1, file, CvPADLIST(sv), 0); |
| 1584 | } |
| 1585 | { |
| 1586 | const CV *outside = CvOUTSIDE(sv); |
| 1587 | Perl_dump_indent(aTHX_ level, file, " OUTSIDE = 0x%"UVxf" (%s)\n", |
| 1588 | PTR2UV(outside), |
| 1589 | (!outside ? "null" |
| 1590 | : CvANON(outside) ? "ANON" |
| 1591 | : (outside == PL_main_cv) ? "MAIN" |
| 1592 | : CvUNIQUE(outside) ? "UNIQUE" |
| 1593 | : CvGV(outside) ? GvNAME(CvGV(outside)) : "UNDEFINED")); |
| 1594 | } |
| 1595 | if (nest < maxnest && (CvCLONE(sv) || CvCLONED(sv))) |
| 1596 | do_sv_dump(level+1, file, (SV*)CvOUTSIDE(sv), nest+1, maxnest, dumpops, pvlim); |
| 1597 | break; |
| 1598 | case SVt_PVGV: case SVt_PVLV: |
| 1599 | if (type == SVt_PVLV) { |
| 1600 | Perl_dump_indent(aTHX_ level, file, " TYPE = %c\n", LvTYPE(sv)); |
| 1601 | Perl_dump_indent(aTHX_ level, file, " TARGOFF = %"IVdf"\n", (IV)LvTARGOFF(sv)); |
| 1602 | Perl_dump_indent(aTHX_ level, file, " TARGLEN = %"IVdf"\n", (IV)LvTARGLEN(sv)); |
| 1603 | Perl_dump_indent(aTHX_ level, file, " TARG = 0x%"UVxf"\n", PTR2UV(LvTARG(sv))); |
| 1604 | if (LvTYPE(sv) != 't' && LvTYPE(sv) != 'T') |
| 1605 | do_sv_dump(level+1, file, LvTARG(sv), nest+1, maxnest, |
| 1606 | dumpops, pvlim); |
| 1607 | } |
| 1608 | Perl_dump_indent(aTHX_ level, file, " NAME = \"%s\"\n", GvNAME(sv)); |
| 1609 | Perl_dump_indent(aTHX_ level, file, " NAMELEN = %"IVdf"\n", (IV)GvNAMELEN(sv)); |
| 1610 | do_hv_dump (level, file, " GvSTASH", GvSTASH(sv)); |
| 1611 | if (!isGV_with_GP(sv)) |
| 1612 | break; |
| 1613 | Perl_dump_indent(aTHX_ level, file, " GP = 0x%"UVxf"\n", PTR2UV(GvGP(sv))); |
| 1614 | if (!GvGP(sv)) |
| 1615 | break; |
| 1616 | Perl_dump_indent(aTHX_ level, file, " SV = 0x%"UVxf"\n", PTR2UV(GvSV(sv))); |
| 1617 | Perl_dump_indent(aTHX_ level, file, " REFCNT = %"IVdf"\n", (IV)GvREFCNT(sv)); |
| 1618 | Perl_dump_indent(aTHX_ level, file, " IO = 0x%"UVxf"\n", PTR2UV(GvIOp(sv))); |
| 1619 | Perl_dump_indent(aTHX_ level, file, " FORM = 0x%"UVxf" \n", PTR2UV(GvFORM(sv))); |
| 1620 | Perl_dump_indent(aTHX_ level, file, " AV = 0x%"UVxf"\n", PTR2UV(GvAV(sv))); |
| 1621 | Perl_dump_indent(aTHX_ level, file, " HV = 0x%"UVxf"\n", PTR2UV(GvHV(sv))); |
| 1622 | Perl_dump_indent(aTHX_ level, file, " CV = 0x%"UVxf"\n", PTR2UV(GvCV(sv))); |
| 1623 | Perl_dump_indent(aTHX_ level, file, " CVGEN = 0x%"UVxf"\n", (UV)GvCVGEN(sv)); |
| 1624 | Perl_dump_indent(aTHX_ level, file, " LINE = %"IVdf"\n", (IV)GvLINE(sv)); |
| 1625 | Perl_dump_indent(aTHX_ level, file, " FILE = \"%s\"\n", GvFILE(sv)); |
| 1626 | Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)GvFLAGS(sv)); |
| 1627 | do_gv_dump (level, file, " EGV", GvEGV(sv)); |
| 1628 | break; |
| 1629 | case SVt_PVIO: |
| 1630 | Perl_dump_indent(aTHX_ level, file, " IFP = 0x%"UVxf"\n", PTR2UV(IoIFP(sv))); |
| 1631 | Perl_dump_indent(aTHX_ level, file, " OFP = 0x%"UVxf"\n", PTR2UV(IoOFP(sv))); |
| 1632 | Perl_dump_indent(aTHX_ level, file, " DIRP = 0x%"UVxf"\n", PTR2UV(IoDIRP(sv))); |
| 1633 | Perl_dump_indent(aTHX_ level, file, " LINES = %"IVdf"\n", (IV)IoLINES(sv)); |
| 1634 | Perl_dump_indent(aTHX_ level, file, " PAGE = %"IVdf"\n", (IV)IoPAGE(sv)); |
| 1635 | Perl_dump_indent(aTHX_ level, file, " PAGE_LEN = %"IVdf"\n", (IV)IoPAGE_LEN(sv)); |
| 1636 | Perl_dump_indent(aTHX_ level, file, " LINES_LEFT = %"IVdf"\n", (IV)IoLINES_LEFT(sv)); |
| 1637 | if (IoTOP_NAME(sv)) |
| 1638 | Perl_dump_indent(aTHX_ level, file, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv)); |
| 1639 | do_gv_dump (level, file, " TOP_GV", IoTOP_GV(sv)); |
| 1640 | if (IoFMT_NAME(sv)) |
| 1641 | Perl_dump_indent(aTHX_ level, file, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv)); |
| 1642 | do_gv_dump (level, file, " FMT_GV", IoFMT_GV(sv)); |
| 1643 | if (IoBOTTOM_NAME(sv)) |
| 1644 | Perl_dump_indent(aTHX_ level, file, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv)); |
| 1645 | do_gv_dump (level, file, " BOTTOM_GV", IoBOTTOM_GV(sv)); |
| 1646 | Perl_dump_indent(aTHX_ level, file, " SUBPROCESS = %"IVdf"\n", (IV)IoSUBPROCESS(sv)); |
| 1647 | if (isPRINT(IoTYPE(sv))) |
| 1648 | Perl_dump_indent(aTHX_ level, file, " TYPE = '%c'\n", IoTYPE(sv)); |
| 1649 | else |
| 1650 | Perl_dump_indent(aTHX_ level, file, " TYPE = '\\%o'\n", IoTYPE(sv)); |
| 1651 | Perl_dump_indent(aTHX_ level, file, " FLAGS = 0x%"UVxf"\n", (UV)IoFLAGS(sv)); |
| 1652 | break; |
| 1653 | } |
| 1654 | SvREFCNT_dec(d); |
| 1655 | } |
| 1656 | |
| 1657 | void |
| 1658 | Perl_sv_dump(pTHX_ SV *sv) |
| 1659 | { |
| 1660 | dVAR; |
| 1661 | do_sv_dump(0, Perl_debug_log, sv, 0, 0, 0, 0); |
| 1662 | } |
| 1663 | |
| 1664 | int |
| 1665 | Perl_runops_debug(pTHX) |
| 1666 | { |
| 1667 | dVAR; |
| 1668 | if (!PL_op) { |
| 1669 | if (ckWARN_d(WARN_DEBUGGING)) |
| 1670 | Perl_warner(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN"); |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
| 1674 | DEBUG_l(Perl_deb(aTHX_ "Entering new RUNOPS level\n")); |
| 1675 | do { |
| 1676 | PERL_ASYNC_CHECK(); |
| 1677 | if (PL_debug) { |
| 1678 | if (PL_watchaddr != 0 && *PL_watchaddr != PL_watchok) |
| 1679 | PerlIO_printf(Perl_debug_log, |
| 1680 | "WARNING: %"UVxf" changed from %"UVxf" to %"UVxf"\n", |
| 1681 | PTR2UV(PL_watchaddr), PTR2UV(PL_watchok), |
| 1682 | PTR2UV(*PL_watchaddr)); |
| 1683 | if (DEBUG_s_TEST_) { |
| 1684 | if (DEBUG_v_TEST_) { |
| 1685 | PerlIO_printf(Perl_debug_log, "\n"); |
| 1686 | deb_stack_all(); |
| 1687 | } |
| 1688 | else |
| 1689 | debstack(); |
| 1690 | } |
| 1691 | |
| 1692 | |
| 1693 | if (DEBUG_t_TEST_) debop(PL_op); |
| 1694 | if (DEBUG_P_TEST_) debprof(PL_op); |
| 1695 | } |
| 1696 | } while ((PL_op = CALL_FPTR(PL_op->op_ppaddr)(aTHX))); |
| 1697 | DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n")); |
| 1698 | |
| 1699 | TAINT_NOT; |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
| 1703 | I32 |
| 1704 | Perl_debop(pTHX_ const OP *o) |
| 1705 | { |
| 1706 | dVAR; |
| 1707 | if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_) |
| 1708 | return 0; |
| 1709 | |
| 1710 | Perl_deb(aTHX_ "%s", OP_NAME(o)); |
| 1711 | switch (o->op_type) { |
| 1712 | case OP_CONST: |
| 1713 | PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo_sv)); |
| 1714 | break; |
| 1715 | case OP_GVSV: |
| 1716 | case OP_GV: |
| 1717 | if (cGVOPo_gv) { |
| 1718 | SV *sv = newSV(0); |
| 1719 | #ifdef PERL_MAD |
| 1720 | /* FIXME - it this making unwarranted assumptions about the |
| 1721 | UTF-8 cleanliness of the dump file handle? */ |
| 1722 | SvUTF8_on(sv); |
| 1723 | #endif |
| 1724 | gv_fullname3(sv, cGVOPo_gv, NULL); |
| 1725 | PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv)); |
| 1726 | SvREFCNT_dec(sv); |
| 1727 | } |
| 1728 | else |
| 1729 | PerlIO_printf(Perl_debug_log, "(NULL)"); |
| 1730 | break; |
| 1731 | case OP_PADSV: |
| 1732 | case OP_PADAV: |
| 1733 | case OP_PADHV: |
| 1734 | { |
| 1735 | /* print the lexical's name */ |
| 1736 | CV *cv = deb_curcv(cxstack_ix); |
| 1737 | SV *sv; |
| 1738 | if (cv) { |
| 1739 | AV * const padlist = CvPADLIST(cv); |
| 1740 | AV * const comppad = (AV*)(*av_fetch(padlist, 0, FALSE)); |
| 1741 | sv = *av_fetch(comppad, o->op_targ, FALSE); |
| 1742 | } else |
| 1743 | sv = NULL; |
| 1744 | if (sv) |
| 1745 | PerlIO_printf(Perl_debug_log, "(%s)", SvPV_nolen_const(sv)); |
| 1746 | else |
| 1747 | PerlIO_printf(Perl_debug_log, "[%"UVuf"]", (UV)o->op_targ); |
| 1748 | } |
| 1749 | break; |
| 1750 | default: |
| 1751 | break; |
| 1752 | } |
| 1753 | PerlIO_printf(Perl_debug_log, "\n"); |
| 1754 | return 0; |
| 1755 | } |
| 1756 | |
| 1757 | STATIC CV* |
| 1758 | S_deb_curcv(pTHX_ I32 ix) |
| 1759 | { |
| 1760 | dVAR; |
| 1761 | const PERL_CONTEXT *cx = &cxstack[ix]; |
| 1762 | if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) |
| 1763 | return cx->blk_sub.cv; |
| 1764 | else if (CxTYPE(cx) == CXt_EVAL && !CxTRYBLOCK(cx)) |
| 1765 | return PL_compcv; |
| 1766 | else if (ix == 0 && PL_curstackinfo->si_type == PERLSI_MAIN) |
| 1767 | return PL_main_cv; |
| 1768 | else if (ix <= 0) |
| 1769 | return NULL; |
| 1770 | else |
| 1771 | return deb_curcv(ix - 1); |
| 1772 | } |
| 1773 | |
| 1774 | void |
| 1775 | Perl_watch(pTHX_ char **addr) |
| 1776 | { |
| 1777 | dVAR; |
| 1778 | PL_watchaddr = addr; |
| 1779 | PL_watchok = *addr; |
| 1780 | PerlIO_printf(Perl_debug_log, "WATCHING, %"UVxf" is currently %"UVxf"\n", |
| 1781 | PTR2UV(PL_watchaddr), PTR2UV(PL_watchok)); |
| 1782 | } |
| 1783 | |
| 1784 | STATIC void |
| 1785 | S_debprof(pTHX_ const OP *o) |
| 1786 | { |
| 1787 | dVAR; |
| 1788 | if (CopSTASH_eq(PL_curcop, PL_debstash) && !DEBUG_J_TEST_) |
| 1789 | return; |
| 1790 | if (!PL_profiledata) |
| 1791 | Newxz(PL_profiledata, MAXO, U32); |
| 1792 | ++PL_profiledata[o->op_type]; |
| 1793 | } |
| 1794 | |
| 1795 | void |
| 1796 | Perl_debprofdump(pTHX) |
| 1797 | { |
| 1798 | dVAR; |
| 1799 | unsigned i; |
| 1800 | if (!PL_profiledata) |
| 1801 | return; |
| 1802 | for (i = 0; i < MAXO; i++) { |
| 1803 | if (PL_profiledata[i]) |
| 1804 | PerlIO_printf(Perl_debug_log, |
| 1805 | "%5lu %s\n", (unsigned long)PL_profiledata[i], |
| 1806 | PL_op_name[i]); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | #ifdef PERL_MAD |
| 1811 | /* |
| 1812 | * XML variants of most of the above routines |
| 1813 | */ |
| 1814 | |
| 1815 | STATIC |
| 1816 | void |
| 1817 | S_xmldump_attr(pTHX_ I32 level, PerlIO *file, const char* pat, ...) |
| 1818 | { |
| 1819 | va_list args; |
| 1820 | PerlIO_printf(file, "\n "); |
| 1821 | va_start(args, pat); |
| 1822 | xmldump_vindent(level, file, pat, &args); |
| 1823 | va_end(args); |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | void |
| 1828 | Perl_xmldump_indent(pTHX_ I32 level, PerlIO *file, const char* pat, ...) |
| 1829 | { |
| 1830 | va_list args; |
| 1831 | va_start(args, pat); |
| 1832 | xmldump_vindent(level, file, pat, &args); |
| 1833 | va_end(args); |
| 1834 | } |
| 1835 | |
| 1836 | void |
| 1837 | Perl_xmldump_vindent(pTHX_ I32 level, PerlIO *file, const char* pat, va_list *args) |
| 1838 | { |
| 1839 | PerlIO_printf(file, "%*s", (int)(level*PL_dumpindent), ""); |
| 1840 | PerlIO_vprintf(file, pat, *args); |
| 1841 | } |
| 1842 | |
| 1843 | void |
| 1844 | Perl_xmldump_all(pTHX) |
| 1845 | { |
| 1846 | PerlIO_setlinebuf(PL_xmlfp); |
| 1847 | if (PL_main_root) |
| 1848 | op_xmldump(PL_main_root); |
| 1849 | if (PL_xmlfp != (PerlIO*)PerlIO_stdout()) |
| 1850 | PerlIO_close(PL_xmlfp); |
| 1851 | PL_xmlfp = 0; |
| 1852 | } |
| 1853 | |
| 1854 | void |
| 1855 | Perl_xmldump_packsubs(pTHX_ const HV *stash) |
| 1856 | { |
| 1857 | I32 i; |
| 1858 | HE *entry; |
| 1859 | |
| 1860 | if (!HvARRAY(stash)) |
| 1861 | return; |
| 1862 | for (i = 0; i <= (I32) HvMAX(stash); i++) { |
| 1863 | for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) { |
| 1864 | GV *gv = (GV*)HeVAL(entry); |
| 1865 | HV *hv; |
| 1866 | if (SvTYPE(gv) != SVt_PVGV || !GvGP(gv)) |
| 1867 | continue; |
| 1868 | if (GvCVu(gv)) |
| 1869 | xmldump_sub(gv); |
| 1870 | if (GvFORM(gv)) |
| 1871 | xmldump_form(gv); |
| 1872 | if (HeKEY(entry)[HeKLEN(entry)-1] == ':' |
| 1873 | && (hv = GvHV(gv)) && hv != PL_defstash) |
| 1874 | xmldump_packsubs(hv); /* nested package */ |
| 1875 | } |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | void |
| 1880 | Perl_xmldump_sub(pTHX_ const GV *gv) |
| 1881 | { |
| 1882 | SV *sv = sv_newmortal(); |
| 1883 | |
| 1884 | gv_fullname3(sv, gv, Nullch); |
| 1885 | Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nSUB %s = ", SvPVX(sv)); |
| 1886 | if (CvXSUB(GvCV(gv))) |
| 1887 | Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "(xsub 0x%"UVxf" %d)\n", |
| 1888 | PTR2UV(CvXSUB(GvCV(gv))), |
| 1889 | (int)CvXSUBANY(GvCV(gv)).any_i32); |
| 1890 | else if (CvROOT(GvCV(gv))) |
| 1891 | op_xmldump(CvROOT(GvCV(gv))); |
| 1892 | else |
| 1893 | Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n"); |
| 1894 | } |
| 1895 | |
| 1896 | void |
| 1897 | Perl_xmldump_form(pTHX_ const GV *gv) |
| 1898 | { |
| 1899 | SV *sv = sv_newmortal(); |
| 1900 | |
| 1901 | gv_fullname3(sv, gv, Nullch); |
| 1902 | Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "\nFORMAT %s = ", SvPVX(sv)); |
| 1903 | if (CvROOT(GvFORM(gv))) |
| 1904 | op_xmldump(CvROOT(GvFORM(gv))); |
| 1905 | else |
| 1906 | Perl_xmldump_indent(aTHX_ 0, PL_xmlfp, "<undef>\n"); |
| 1907 | } |
| 1908 | |
| 1909 | void |
| 1910 | Perl_xmldump_eval(pTHX) |
| 1911 | { |
| 1912 | op_xmldump(PL_eval_root); |
| 1913 | } |
| 1914 | |
| 1915 | char * |
| 1916 | Perl_sv_catxmlsv(pTHX_ SV *dsv, SV *ssv) |
| 1917 | { |
| 1918 | return sv_catxmlpvn(dsv, SvPVX(ssv), SvCUR(ssv), SvUTF8(ssv)); |
| 1919 | } |
| 1920 | |
| 1921 | char * |
| 1922 | Perl_sv_catxmlpvn(pTHX_ SV *dsv, char* pv, STRLEN len, int utf8) |
| 1923 | { |
| 1924 | unsigned int c; |
| 1925 | char *e = pv + len; |
| 1926 | char *start = pv; |
| 1927 | STRLEN dsvcur; |
| 1928 | STRLEN cl; |
| 1929 | |
| 1930 | sv_catpvn(dsv,"",0); |
| 1931 | dsvcur = SvCUR(dsv); /* in case we have to restart */ |
| 1932 | |
| 1933 | retry: |
| 1934 | while (pv < e) { |
| 1935 | if (utf8) { |
| 1936 | c = utf8_to_uvchr((U8*)pv, &cl); |
| 1937 | if (cl == 0) { |
| 1938 | SvCUR(dsv) = dsvcur; |
| 1939 | pv = start; |
| 1940 | utf8 = 0; |
| 1941 | goto retry; |
| 1942 | } |
| 1943 | } |
| 1944 | else |
| 1945 | c = (*pv & 255); |
| 1946 | |
| 1947 | switch (c) { |
| 1948 | case 0x00: |
| 1949 | case 0x01: |
| 1950 | case 0x02: |
| 1951 | case 0x03: |
| 1952 | case 0x04: |
| 1953 | case 0x05: |
| 1954 | case 0x06: |
| 1955 | case 0x07: |
| 1956 | case 0x08: |
| 1957 | case 0x0b: |
| 1958 | case 0x0c: |
| 1959 | case 0x0e: |
| 1960 | case 0x0f: |
| 1961 | case 0x10: |
| 1962 | case 0x11: |
| 1963 | case 0x12: |
| 1964 | case 0x13: |
| 1965 | case 0x14: |
| 1966 | case 0x15: |
| 1967 | case 0x16: |
| 1968 | case 0x17: |
| 1969 | case 0x18: |
| 1970 | case 0x19: |
| 1971 | case 0x1a: |
| 1972 | case 0x1b: |
| 1973 | case 0x1c: |
| 1974 | case 0x1d: |
| 1975 | case 0x1e: |
| 1976 | case 0x1f: |
| 1977 | case 0x7f: |
| 1978 | case 0x80: |
| 1979 | case 0x81: |
| 1980 | case 0x82: |
| 1981 | case 0x83: |
| 1982 | case 0x84: |
| 1983 | case 0x86: |
| 1984 | case 0x87: |
| 1985 | case 0x88: |
| 1986 | case 0x89: |
| 1987 | case 0x90: |
| 1988 | case 0x91: |
| 1989 | case 0x92: |
| 1990 | case 0x93: |
| 1991 | case 0x94: |
| 1992 | case 0x95: |
| 1993 | case 0x96: |
| 1994 | case 0x97: |
| 1995 | case 0x98: |
| 1996 | case 0x99: |
| 1997 | case 0x9a: |
| 1998 | case 0x9b: |
| 1999 | case 0x9c: |
| 2000 | case 0x9d: |
| 2001 | case 0x9e: |
| 2002 | case 0x9f: |
| 2003 | Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c); |
| 2004 | break; |
| 2005 | case '<': |
| 2006 | Perl_sv_catpvf(aTHX_ dsv, "<"); |
| 2007 | break; |
| 2008 | case '>': |
| 2009 | Perl_sv_catpvf(aTHX_ dsv, ">"); |
| 2010 | break; |
| 2011 | case '&': |
| 2012 | Perl_sv_catpvf(aTHX_ dsv, "&"); |
| 2013 | break; |
| 2014 | case '"': |
| 2015 | Perl_sv_catpvf(aTHX_ dsv, """); |
| 2016 | break; |
| 2017 | default: |
| 2018 | if (c < 0xD800) { |
| 2019 | if (c < 32 || c > 127) { |
| 2020 | Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c); |
| 2021 | } |
| 2022 | else { |
| 2023 | Perl_sv_catpvf(aTHX_ dsv, "%c", c); |
| 2024 | } |
| 2025 | break; |
| 2026 | } |
| 2027 | if ((c >= 0xD800 && c <= 0xDB7F) || |
| 2028 | (c >= 0xDC00 && c <= 0xDFFF) || |
| 2029 | (c >= 0xFFF0 && c <= 0xFFFF) || |
| 2030 | c > 0x10ffff) |
| 2031 | Perl_sv_catpvf(aTHX_ dsv, "STUPIDXML(#x%X)", c); |
| 2032 | else |
| 2033 | Perl_sv_catpvf(aTHX_ dsv, "&#x%X;", c); |
| 2034 | } |
| 2035 | |
| 2036 | if (utf8) |
| 2037 | pv += UTF8SKIP(pv); |
| 2038 | else |
| 2039 | pv++; |
| 2040 | } |
| 2041 | |
| 2042 | return SvPVX(dsv); |
| 2043 | } |
| 2044 | |
| 2045 | char * |
| 2046 | Perl_sv_xmlpeek(pTHX_ SV *sv) |
| 2047 | { |
| 2048 | SV *t = sv_newmortal(); |
| 2049 | STRLEN n_a; |
| 2050 | int unref = 0; |
| 2051 | |
| 2052 | sv_utf8_upgrade(t); |
| 2053 | sv_setpvn(t, "", 0); |
| 2054 | /* retry: */ |
| 2055 | if (!sv) { |
| 2056 | sv_catpv(t, "VOID=\"\""); |
| 2057 | goto finish; |
| 2058 | } |
| 2059 | else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') { |
| 2060 | sv_catpv(t, "WILD=\"\""); |
| 2061 | goto finish; |
| 2062 | } |
| 2063 | else if (sv == &PL_sv_undef || sv == &PL_sv_no || sv == &PL_sv_yes || sv == &PL_sv_placeholder) { |
| 2064 | if (sv == &PL_sv_undef) { |
| 2065 | sv_catpv(t, "SV_UNDEF=\"1\""); |
| 2066 | if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT| |
| 2067 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 2068 | SvREADONLY(sv)) |
| 2069 | goto finish; |
| 2070 | } |
| 2071 | else if (sv == &PL_sv_no) { |
| 2072 | sv_catpv(t, "SV_NO=\"1\""); |
| 2073 | if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT| |
| 2074 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 2075 | !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| |
| 2076 | SVp_POK|SVp_NOK)) && |
| 2077 | SvCUR(sv) == 0 && |
| 2078 | SvNVX(sv) == 0.0) |
| 2079 | goto finish; |
| 2080 | } |
| 2081 | else if (sv == &PL_sv_yes) { |
| 2082 | sv_catpv(t, "SV_YES=\"1\""); |
| 2083 | if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT| |
| 2084 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 2085 | !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY| |
| 2086 | SVp_POK|SVp_NOK)) && |
| 2087 | SvCUR(sv) == 1 && |
| 2088 | SvPVX(sv) && *SvPVX(sv) == '1' && |
| 2089 | SvNVX(sv) == 1.0) |
| 2090 | goto finish; |
| 2091 | } |
| 2092 | else { |
| 2093 | sv_catpv(t, "SV_PLACEHOLDER=\"1\""); |
| 2094 | if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT| |
| 2095 | SVs_GMG|SVs_SMG|SVs_RMG)) && |
| 2096 | SvREADONLY(sv)) |
| 2097 | goto finish; |
| 2098 | } |
| 2099 | sv_catpv(t, " XXX=\"\" "); |
| 2100 | } |
| 2101 | else if (SvREFCNT(sv) == 0) { |
| 2102 | sv_catpv(t, " refcnt=\"0\""); |
| 2103 | unref++; |
| 2104 | } |
| 2105 | else if (DEBUG_R_TEST_) { |
| 2106 | int is_tmp = 0; |
| 2107 | I32 ix; |
| 2108 | /* is this SV on the tmps stack? */ |
| 2109 | for (ix=PL_tmps_ix; ix>=0; ix--) { |
| 2110 | if (PL_tmps_stack[ix] == sv) { |
| 2111 | is_tmp = 1; |
| 2112 | break; |
| 2113 | } |
| 2114 | } |
| 2115 | if (SvREFCNT(sv) > 1) |
| 2116 | Perl_sv_catpvf(aTHX_ t, " DRT=\"<%"UVuf"%s>\"", (UV)SvREFCNT(sv), |
| 2117 | is_tmp ? "T" : ""); |
| 2118 | else if (is_tmp) |
| 2119 | sv_catpv(t, " DRT=\"<T>\""); |
| 2120 | } |
| 2121 | |
| 2122 | if (SvROK(sv)) { |
| 2123 | sv_catpv(t, " ROK=\"\""); |
| 2124 | } |
| 2125 | switch (SvTYPE(sv)) { |
| 2126 | default: |
| 2127 | sv_catpv(t, " FREED=\"1\""); |
| 2128 | goto finish; |
| 2129 | |
| 2130 | case SVt_NULL: |
| 2131 | sv_catpv(t, " UNDEF=\"1\""); |
| 2132 | goto finish; |
| 2133 | case SVt_IV: |
| 2134 | sv_catpv(t, " IV=\""); |
| 2135 | break; |
| 2136 | case SVt_NV: |
| 2137 | sv_catpv(t, " NV=\""); |
| 2138 | break; |
| 2139 | case SVt_RV: |
| 2140 | sv_catpv(t, " RV=\""); |
| 2141 | break; |
| 2142 | case SVt_PV: |
| 2143 | sv_catpv(t, " PV=\""); |
| 2144 | break; |
| 2145 | case SVt_PVIV: |
| 2146 | sv_catpv(t, " PVIV=\""); |
| 2147 | break; |
| 2148 | case SVt_PVNV: |
| 2149 | sv_catpv(t, " PVNV=\""); |
| 2150 | break; |
| 2151 | case SVt_PVMG: |
| 2152 | sv_catpv(t, " PVMG=\""); |
| 2153 | break; |
| 2154 | case SVt_PVLV: |
| 2155 | sv_catpv(t, " PVLV=\""); |
| 2156 | break; |
| 2157 | case SVt_PVAV: |
| 2158 | sv_catpv(t, " AV=\""); |
| 2159 | break; |
| 2160 | case SVt_PVHV: |
| 2161 | sv_catpv(t, " HV=\""); |
| 2162 | break; |
| 2163 | case SVt_PVCV: |
| 2164 | if (CvGV(sv)) |
| 2165 | Perl_sv_catpvf(aTHX_ t, " CV=\"(%s)\"", GvNAME(CvGV(sv))); |
| 2166 | else |
| 2167 | sv_catpv(t, " CV=\"()\""); |
| 2168 | goto finish; |
| 2169 | case SVt_PVGV: |
| 2170 | sv_catpv(t, " GV=\""); |
| 2171 | break; |
| 2172 | case SVt_PVBM: |
| 2173 | sv_catpv(t, " BM=\""); |
| 2174 | break; |
| 2175 | case SVt_PVFM: |
| 2176 | sv_catpv(t, " FM=\""); |
| 2177 | break; |
| 2178 | case SVt_PVIO: |
| 2179 | sv_catpv(t, " IO=\""); |
| 2180 | break; |
| 2181 | } |
| 2182 | |
| 2183 | if (SvPOKp(sv)) { |
| 2184 | if (SvPVX(sv)) { |
| 2185 | sv_catxmlsv(t, sv); |
| 2186 | } |
| 2187 | } |
| 2188 | else if (SvNOKp(sv)) { |
| 2189 | STORE_NUMERIC_LOCAL_SET_STANDARD(); |
| 2190 | Perl_sv_catpvf(aTHX_ t, "%"NVgf"",SvNVX(sv)); |
| 2191 | RESTORE_NUMERIC_LOCAL(); |
| 2192 | } |
| 2193 | else if (SvIOKp(sv)) { |
| 2194 | if (SvIsUV(sv)) |
| 2195 | Perl_sv_catpvf(aTHX_ t, "%"UVuf"", (UV)SvUVX(sv)); |
| 2196 | else |
| 2197 | Perl_sv_catpvf(aTHX_ t, "%"IVdf"", (IV)SvIVX(sv)); |
| 2198 | } |
| 2199 | else |
| 2200 | sv_catpv(t, ""); |
| 2201 | sv_catpv(t, "\""); |
| 2202 | |
| 2203 | finish: |
| 2204 | if (unref) { |
| 2205 | while (unref--) |
| 2206 | sv_catpv(t, ")"); |
| 2207 | } |
| 2208 | return SvPV(t, n_a); |
| 2209 | } |
| 2210 | |
| 2211 | void |
| 2212 | Perl_do_pmop_xmldump(pTHX_ I32 level, PerlIO *file, const PMOP *pm) |
| 2213 | { |
| 2214 | if (!pm) { |
| 2215 | Perl_xmldump_indent(aTHX_ level, file, "<pmop/>\n"); |
| 2216 | return; |
| 2217 | } |
| 2218 | Perl_xmldump_indent(aTHX_ level, file, "<pmop \n"); |
| 2219 | level++; |
| 2220 | if (PM_GETRE(pm)) { |
| 2221 | char *s = PM_GETRE(pm)->precomp; |
| 2222 | SV *tmpsv = newSV(0); |
| 2223 | SvUTF8_on(tmpsv); |
| 2224 | sv_catxmlpvn(tmpsv, s, strlen(s), 1); |
| 2225 | Perl_xmldump_indent(aTHX_ level, file, "pre=\"%s\"\n", |
| 2226 | SvPVX(tmpsv)); |
| 2227 | SvREFCNT_dec(tmpsv); |
| 2228 | Perl_xmldump_indent(aTHX_ level, file, "when=\"%s\"\n", |
| 2229 | (pm->op_private & OPpRUNTIME) ? "RUN" : "COMP"); |
| 2230 | } |
| 2231 | else |
| 2232 | Perl_xmldump_indent(aTHX_ level, file, "pre=\"\" when=\"RUN\"\n"); |
| 2233 | if (pm->op_pmflags || (PM_GETRE(pm) && PM_GETRE(pm)->check_substr)) { |
| 2234 | SV *tmpsv = newSVpvn("", 0); |
| 2235 | if (pm->op_pmdynflags & PMdf_USED) |
| 2236 | sv_catpv(tmpsv, ",USED"); |
| 2237 | if (pm->op_pmdynflags & PMdf_TAINTED) |
| 2238 | sv_catpv(tmpsv, ",TAINTED"); |
| 2239 | if (pm->op_pmflags & PMf_ONCE) |
| 2240 | sv_catpv(tmpsv, ",ONCE"); |
| 2241 | if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr |
| 2242 | && !(PM_GETRE(pm)->reganch & ROPT_NOSCAN)) |
| 2243 | sv_catpv(tmpsv, ",SCANFIRST"); |
| 2244 | if (PM_GETRE(pm) && PM_GETRE(pm)->check_substr |
| 2245 | && PM_GETRE(pm)->reganch & ROPT_CHECK_ALL) |
| 2246 | sv_catpv(tmpsv, ",ALL"); |
| 2247 | if (pm->op_pmflags & PMf_SKIPWHITE) |
| 2248 | sv_catpv(tmpsv, ",SKIPWHITE"); |
| 2249 | if (pm->op_pmflags & PMf_CONST) |
| 2250 | sv_catpv(tmpsv, ",CONST"); |
| 2251 | if (pm->op_pmflags & PMf_KEEP) |
| 2252 | sv_catpv(tmpsv, ",KEEP"); |
| 2253 | if (pm->op_pmflags & PMf_GLOBAL) |
| 2254 | sv_catpv(tmpsv, ",GLOBAL"); |
| 2255 | if (pm->op_pmflags & PMf_CONTINUE) |
| 2256 | sv_catpv(tmpsv, ",CONTINUE"); |
| 2257 | if (pm->op_pmflags & PMf_RETAINT) |
| 2258 | sv_catpv(tmpsv, ",RETAINT"); |
| 2259 | if (pm->op_pmflags & PMf_EVAL) |
| 2260 | sv_catpv(tmpsv, ",EVAL"); |
| 2261 | Perl_xmldump_indent(aTHX_ level, file, "pmflags=\"%s\"\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
| 2262 | SvREFCNT_dec(tmpsv); |
| 2263 | } |
| 2264 | |
| 2265 | level--; |
| 2266 | if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) { |
| 2267 | Perl_xmldump_indent(aTHX_ level, file, ">\n"); |
| 2268 | Perl_xmldump_indent(aTHX_ level+1, file, "<pm_repl>\n"); |
| 2269 | do_op_xmldump(level+2, file, pm->op_pmreplroot); |
| 2270 | Perl_xmldump_indent(aTHX_ level+1, file, "</pm_repl>\n"); |
| 2271 | Perl_xmldump_indent(aTHX_ level, file, "</pmop>\n"); |
| 2272 | } |
| 2273 | else |
| 2274 | Perl_xmldump_indent(aTHX_ level, file, "/>\n"); |
| 2275 | } |
| 2276 | |
| 2277 | void |
| 2278 | Perl_pmop_xmldump(pTHX_ const PMOP *pm) |
| 2279 | { |
| 2280 | do_pmop_xmldump(0, PL_xmlfp, pm); |
| 2281 | } |
| 2282 | |
| 2283 | void |
| 2284 | Perl_do_op_xmldump(pTHX_ I32 level, PerlIO *file, const OP *o) |
| 2285 | { |
| 2286 | UV seq; |
| 2287 | int contents = 0; |
| 2288 | if (!o) |
| 2289 | return; |
| 2290 | sequence(o); |
| 2291 | seq = sequence_num(o); |
| 2292 | Perl_xmldump_indent(aTHX_ level, file, |
| 2293 | "<op_%s seq=\"%"UVuf" -> ", |
| 2294 | OP_NAME(o), |
| 2295 | seq); |
| 2296 | level++; |
| 2297 | if (o->op_next) |
| 2298 | PerlIO_printf(file, seq ? "%"UVuf"\"" : "(%"UVuf")\"", |
| 2299 | sequence_num(o->op_next)); |
| 2300 | else |
| 2301 | PerlIO_printf(file, "DONE\""); |
| 2302 | |
| 2303 | if (o->op_targ) { |
| 2304 | if (o->op_type == OP_NULL) |
| 2305 | { |
| 2306 | PerlIO_printf(file, " was=\"%s\"", PL_op_name[o->op_targ]); |
| 2307 | if (o->op_targ == OP_NEXTSTATE) |
| 2308 | { |
| 2309 | if (CopLINE(cCOPo)) |
| 2310 | PerlIO_printf(file, " line=\"%"UVf"\"", |
| 2311 | (UV)CopLINE(cCOPo)); |
| 2312 | if (CopSTASHPV(cCOPo)) |
| 2313 | PerlIO_printf(file, " package=\"%s\"", |
| 2314 | CopSTASHPV(cCOPo)); |
| 2315 | if (cCOPo->cop_label) |
| 2316 | PerlIO_printf(file, " label=\"%s\"", |
| 2317 | cCOPo->cop_label); |
| 2318 | } |
| 2319 | } |
| 2320 | else |
| 2321 | PerlIO_printf(file, " targ=\"%ld\"", (long)o->op_targ); |
| 2322 | } |
| 2323 | #ifdef DUMPADDR |
| 2324 | PerlIO_printf(file, " addr=\"0x%"UVxf" => 0x%"UVxf"\"", (UV)o, (UV)o->op_next); |
| 2325 | #endif |
| 2326 | if (o->op_flags) { |
| 2327 | SV *tmpsv = newSVpvn("", 0); |
| 2328 | switch (o->op_flags & OPf_WANT) { |
| 2329 | case OPf_WANT_VOID: |
| 2330 | sv_catpv(tmpsv, ",VOID"); |
| 2331 | break; |
| 2332 | case OPf_WANT_SCALAR: |
| 2333 | sv_catpv(tmpsv, ",SCALAR"); |
| 2334 | break; |
| 2335 | case OPf_WANT_LIST: |
| 2336 | sv_catpv(tmpsv, ",LIST"); |
| 2337 | break; |
| 2338 | default: |
| 2339 | sv_catpv(tmpsv, ",UNKNOWN"); |
| 2340 | break; |
| 2341 | } |
| 2342 | if (o->op_flags & OPf_KIDS) |
| 2343 | sv_catpv(tmpsv, ",KIDS"); |
| 2344 | if (o->op_flags & OPf_PARENS) |
| 2345 | sv_catpv(tmpsv, ",PARENS"); |
| 2346 | if (o->op_flags & OPf_STACKED) |
| 2347 | sv_catpv(tmpsv, ",STACKED"); |
| 2348 | if (o->op_flags & OPf_REF) |
| 2349 | sv_catpv(tmpsv, ",REF"); |
| 2350 | if (o->op_flags & OPf_MOD) |
| 2351 | sv_catpv(tmpsv, ",MOD"); |
| 2352 | if (o->op_flags & OPf_SPECIAL) |
| 2353 | sv_catpv(tmpsv, ",SPECIAL"); |
| 2354 | PerlIO_printf(file, " flags=\"%s\"", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); |
| 2355 | SvREFCNT_dec(tmpsv); |
| 2356 | } |
| 2357 | if (o->op_private) { |
| 2358 | SV *tmpsv = newSVpvn("", 0); |
| 2359 | if (PL_opargs[o->op_type] & OA_TARGLEX) { |
| 2360 | if (o->op_private & OPpTARGET_MY) |
| 2361 | sv_catpv(tmpsv, ",TARGET_MY"); |
| 2362 | } |
| 2363 | else if (o->op_type == OP_LEAVESUB || |
| 2364 | o->op_type == OP_LEAVE || |
| 2365 | o->op_type == OP_LEAVESUBLV || |
| 2366 | o->op_type == OP_LEAVEWRITE) { |
| 2367 | if (o->op_private & OPpREFCOUNTED) |
| 2368 | sv_catpv(tmpsv, ",REFCOUNTED"); |
| 2369 | } |
| 2370 | else if (o->op_type == OP_AASSIGN) { |
| 2371 | if (o->op_private & OPpASSIGN_COMMON) |
| 2372 | sv_catpv(tmpsv, ",COMMON"); |
| 2373 | } |
| 2374 | else if (o->op_type == OP_SASSIGN) { |
| 2375 | if (o->op_private & OPpASSIGN_BACKWARDS) |
| 2376 | sv_catpv(tmpsv, ",BACKWARDS"); |
| 2377 | } |
| 2378 | else if (o->op_type == OP_TRANS) { |
| 2379 | if (o->op_private & OPpTRANS_SQUASH) |
| 2380 | sv_catpv(tmpsv, ",SQUASH"); |
| 2381 | if (o->op_private & OPpTRANS_DELETE) |
| 2382 | sv_catpv(tmpsv, ",DELETE"); |
| 2383 | if (o->op_private & OPpTRANS_COMPLEMENT) |
| 2384 | sv_catpv(tmpsv, ",COMPLEMENT"); |
| 2385 | if (o->op_private & OPpTRANS_IDENTICAL) |
| 2386 | sv_catpv(tmpsv, ",IDENTICAL"); |
| 2387 | if (o->op_private & OPpTRANS_GROWS) |
| 2388 | sv_catpv(tmpsv, ",GROWS"); |
| 2389 | } |
| 2390 | else if (o->op_type == OP_REPEAT) { |
| 2391 | if (o->op_private & OPpREPEAT_DOLIST) |
| 2392 | sv_catpv(tmpsv, ",DOLIST"); |
| 2393 | } |
| 2394 | else if (o->op_type == OP_ENTERSUB || |
| 2395 | o->op_type == OP_RV2SV || |
| 2396 | o->op_type == OP_GVSV || |
| 2397 | o->op_type == OP_RV2AV || |
| 2398 | o->op_type == OP_RV2HV || |
| 2399 | o->op_type == OP_RV2GV || |
| 2400 | o->op_type == OP_AELEM || |
| 2401 | o->op_type == OP_HELEM ) |
| 2402 | { |
| 2403 | if (o->op_type == OP_ENTERSUB) { |
| 2404 | if (o->op_private & OPpENTERSUB_AMPER) |
| 2405 | sv_catpv(tmpsv, ",AMPER"); |
| 2406 | if (o->op_private & OPpENTERSUB_DB) |
| 2407 | sv_catpv(tmpsv, ",DB"); |
| 2408 | if (o->op_private & OPpENTERSUB_HASTARG) |
| 2409 | sv_catpv(tmpsv, ",HASTARG"); |
| 2410 | if (o->op_private & OPpENTERSUB_NOPAREN) |
| 2411 | sv_catpv(tmpsv, ",NOPAREN"); |
| 2412 | if (o->op_private & OPpENTERSUB_INARGS) |
| 2413 | sv_catpv(tmpsv, ",INARGS"); |
| 2414 | if (o->op_private & OPpENTERSUB_NOMOD) |
| 2415 | sv_catpv(tmpsv, ",NOMOD"); |
| 2416 | } |
| 2417 | else { |
| 2418 | switch (o->op_private & OPpDEREF) { |
| 2419 | case OPpDEREF_SV: |
| 2420 | sv_catpv(tmpsv, ",SV"); |
| 2421 | break; |
| 2422 | case OPpDEREF_AV: |
| 2423 | sv_catpv(tmpsv, ",AV"); |
| 2424 | break; |
| 2425 | case OPpDEREF_HV: |
| 2426 | sv_catpv(tmpsv, ",HV"); |
| 2427 | break; |
| 2428 | } |
| 2429 | if (o->op_private & OPpMAYBE_LVSUB) |
| 2430 | sv_catpv(tmpsv, ",MAYBE_LVSUB"); |
| 2431 | } |
| 2432 | if (o->op_type == OP_AELEM || o->op_type == OP_HELEM) { |
| 2433 | if (o->op_private & OPpLVAL_DEFER) |
| 2434 | sv_catpv(tmpsv, ",LVAL_DEFER"); |
| 2435 | } |
| 2436 | else { |
| 2437 | if (o->op_private & HINT_STRICT_REFS) |
| 2438 | sv_catpv(tmpsv, ",STRICT_REFS"); |
| 2439 | if (o->op_private & OPpOUR_INTRO) |
| 2440 | sv_catpv(tmpsv, ",OUR_INTRO"); |
| 2441 | } |
| 2442 | } |
| 2443 | else if (o->op_type == OP_CONST) { |
| 2444 | if (o->op_private & OPpCONST_BARE) |
| 2445 | sv_catpv(tmpsv, ",BARE"); |
| 2446 | if (o->op_private & OPpCONST_STRICT) |
| 2447 | sv_catpv(tmpsv, ",STRICT"); |
| 2448 | if (o->op_private & OPpCONST_ARYBASE) |
| 2449 | sv_catpv(tmpsv, ",ARYBASE"); |
| 2450 | if (o->op_private & OPpCONST_WARNING) |
| 2451 | sv_catpv(tmpsv, ",WARNING"); |
| 2452 | if (o->op_private & OPpCONST_ENTERED) |
| 2453 | sv_catpv(tmpsv, ",ENTERED"); |
| 2454 | } |
| 2455 | else if (o->op_type == OP_FLIP) { |
| 2456 | if (o->op_private & OPpFLIP_LINENUM) |
| 2457 | sv_catpv(tmpsv, ",LINENUM"); |
| 2458 | } |
| 2459 | else if (o->op_type == OP_FLOP) { |
| 2460 | if (o->op_private & OPpFLIP_LINENUM) |
| 2461 | sv_catpv(tmpsv, ",LINENUM"); |
| 2462 | } |
| 2463 | else if (o->op_type == OP_RV2CV) { |
| 2464 | if (o->op_private & OPpLVAL_INTRO) |
| 2465 | sv_catpv(tmpsv, ",INTRO"); |
| 2466 | } |
| 2467 | else if (o->op_type == OP_GV) { |
| 2468 | if (o->op_private & OPpEARLY_CV) |
| 2469 | sv_catpv(tmpsv, ",EARLY_CV"); |
| 2470 | } |
| 2471 | else if (o->op_type == OP_LIST) { |
| 2472 | if (o->op_private & OPpLIST_GUESSED) |
| 2473 | sv_catpv(tmpsv, ",GUESSED"); |
| 2474 | } |
| 2475 | else if (o->op_type == OP_DELETE) { |
| 2476 | if (o->op_private & OPpSLICE) |
| 2477 | sv_catpv(tmpsv, ",SLICE"); |
| 2478 | } |
| 2479 | else if (o->op_type == OP_EXISTS) { |
| 2480 | if (o->op_private & OPpEXISTS_SUB) |
| 2481 | sv_catpv(tmpsv, ",EXISTS_SUB"); |
| 2482 | } |
| 2483 | else if (o->op_type == OP_SORT) { |
| 2484 | if (o->op_private & OPpSORT_NUMERIC) |
| 2485 | sv_catpv(tmpsv, ",NUMERIC"); |
| 2486 | if (o->op_private & OPpSORT_INTEGER) |
| 2487 | sv_catpv(tmpsv, ",INTEGER"); |
| 2488 | if (o->op_private & OPpSORT_REVERSE) |
| 2489 | sv_catpv(tmpsv, ",REVERSE"); |
| 2490 | } |
| 2491 | else if (o->op_type == OP_THREADSV) { |
| 2492 | if (o->op_private & OPpDONE_SVREF) |
| 2493 | sv_catpv(tmpsv, ",SVREF"); |
| 2494 | } |
| 2495 | else if (o->op_type == OP_OPEN || o->op_type == OP_BACKTICK) { |
| 2496 | if (o->op_private & OPpOPEN_IN_RAW) |
| 2497 | sv_catpv(tmpsv, ",IN_RAW"); |
| 2498 | if (o->op_private & OPpOPEN_IN_CRLF) |
| 2499 | sv_catpv(tmpsv, ",IN_CRLF"); |
| 2500 | if (o->op_private & OPpOPEN_OUT_RAW) |
| 2501 | sv_catpv(tmpsv, ",OUT_RAW"); |
| 2502 | if (o->op_private & OPpOPEN_OUT_CRLF) |
| 2503 | sv_catpv(tmpsv, ",OUT_CRLF"); |
| 2504 | } |
| 2505 | else if (o->op_type == OP_EXIT) { |
| 2506 | if (o->op_private & OPpEXIT_VMSISH) |
| 2507 | sv_catpv(tmpsv, ",EXIT_VMSISH"); |
| 2508 | if (o->op_private & OPpHUSH_VMSISH) |
| 2509 | sv_catpv(tmpsv, ",HUSH_VMSISH"); |
| 2510 | } |
| 2511 | else if (o->op_type == OP_DIE) { |
| 2512 | if (o->op_private & OPpHUSH_VMSISH) |
| 2513 | sv_catpv(tmpsv, ",HUSH_VMSISH"); |
| 2514 | } |
| 2515 | else if (PL_check[o->op_type] != MEMBER_TO_FPTR(Perl_ck_ftst)) { |
| 2516 | if (OP_IS_FILETEST_ACCESS(o) && o->op_private & OPpFT_ACCESS) |
| 2517 | sv_catpv(tmpsv, ",FT_ACCESS"); |
| 2518 | if (o->op_private & OPpFT_STACKED) |
| 2519 | sv_catpv(tmpsv, ",FT_STACKED"); |
| 2520 | } |
| 2521 | if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO) |
| 2522 | sv_catpv(tmpsv, ",INTRO"); |
| 2523 | if (SvCUR(tmpsv)) |
| 2524 | S_xmldump_attr(aTHX_ level, file, "private=\"%s\"", SvPVX(tmpsv) + 1); |
| 2525 | SvREFCNT_dec(tmpsv); |
| 2526 | } |
| 2527 | |
| 2528 | switch (o->op_type) { |
| 2529 | case OP_AELEMFAST: |
| 2530 | if (o->op_flags & OPf_SPECIAL) { |
| 2531 | break; |
| 2532 | } |
| 2533 | case OP_GVSV: |
| 2534 | case OP_GV: |
| 2535 | #ifdef USE_ITHREADS |
| 2536 | S_xmldump_attr(aTHX_ level, file, "padix=\"%" IVdf "\"", (IV)cPADOPo->op_padix); |
| 2537 | #else |
| 2538 | if (cSVOPo->op_sv) { |
| 2539 | SV *tmpsv1 = newSV(0); |
| 2540 | SV *tmpsv2 = newSV(0); |
| 2541 | char *s; |
| 2542 | STRLEN len; |
| 2543 | SvUTF8_on(tmpsv1); |
| 2544 | SvUTF8_on(tmpsv2); |
| 2545 | ENTER; |
| 2546 | SAVEFREESV(tmpsv1); |
| 2547 | SAVEFREESV(tmpsv2); |
| 2548 | gv_fullname3(tmpsv1, (GV*)cSVOPo->op_sv, Nullch); |
| 2549 | s = SvPV(tmpsv1,len); |
| 2550 | sv_catxmlpvn(tmpsv2, s, len, 1); |
| 2551 | S_xmldump_attr(aTHX_ level, file, "gv=\"%s\"", SvPV(tmpsv2, len)); |
| 2552 | LEAVE; |
| 2553 | } |
| 2554 | else |
| 2555 | S_xmldump_attr(aTHX_ level, file, "gv=\"NULL\""); |
| 2556 | #endif |
| 2557 | break; |
| 2558 | case OP_CONST: |
| 2559 | case OP_METHOD_NAMED: |
| 2560 | #ifndef USE_ITHREADS |
| 2561 | /* with ITHREADS, consts are stored in the pad, and the right pad |
| 2562 | * may not be active here, so skip */ |
| 2563 | S_xmldump_attr(aTHX_ level, file, "%s", sv_xmlpeek(cSVOPo_sv)); |
| 2564 | #endif |
| 2565 | break; |
| 2566 | case OP_ANONCODE: |
| 2567 | if (!contents) { |
| 2568 | contents = 1; |
| 2569 | PerlIO_printf(file, ">\n"); |
| 2570 | } |
| 2571 | do_op_xmldump(level+1, file, CvROOT(cSVOPo_sv)); |
| 2572 | break; |
| 2573 | case OP_SETSTATE: |
| 2574 | case OP_NEXTSTATE: |
| 2575 | case OP_DBSTATE: |
| 2576 | if (CopLINE(cCOPo)) |
| 2577 | S_xmldump_attr(aTHX_ level, file, "line=\"%"UVf"\"", |
| 2578 | (UV)CopLINE(cCOPo)); |
| 2579 | if (CopSTASHPV(cCOPo)) |
| 2580 | S_xmldump_attr(aTHX_ level, file, "package=\"%s\"", |
| 2581 | CopSTASHPV(cCOPo)); |
| 2582 | if (cCOPo->cop_label) |
| 2583 | S_xmldump_attr(aTHX_ level, file, "label=\"%s\"", |
| 2584 | cCOPo->cop_label); |
| 2585 | break; |
| 2586 | case OP_ENTERLOOP: |
| 2587 | S_xmldump_attr(aTHX_ level, file, "redo=\""); |
| 2588 | if (cLOOPo->op_redoop) |
| 2589 | PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_redoop)); |
| 2590 | else |
| 2591 | PerlIO_printf(file, "DONE\""); |
| 2592 | S_xmldump_attr(aTHX_ level, file, "next=\""); |
| 2593 | if (cLOOPo->op_nextop) |
| 2594 | PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_nextop)); |
| 2595 | else |
| 2596 | PerlIO_printf(file, "DONE\""); |
| 2597 | S_xmldump_attr(aTHX_ level, file, "last=\""); |
| 2598 | if (cLOOPo->op_lastop) |
| 2599 | PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOOPo->op_lastop)); |
| 2600 | else |
| 2601 | PerlIO_printf(file, "DONE\""); |
| 2602 | break; |
| 2603 | case OP_COND_EXPR: |
| 2604 | case OP_RANGE: |
| 2605 | case OP_MAPWHILE: |
| 2606 | case OP_GREPWHILE: |
| 2607 | case OP_OR: |
| 2608 | case OP_AND: |
| 2609 | S_xmldump_attr(aTHX_ level, file, "other=\""); |
| 2610 | if (cLOGOPo->op_other) |
| 2611 | PerlIO_printf(file, "%"UVuf"\"", sequence_num(cLOGOPo->op_other)); |
| 2612 | else |
| 2613 | PerlIO_printf(file, "DONE\""); |
| 2614 | break; |
| 2615 | case OP_LEAVE: |
| 2616 | case OP_LEAVEEVAL: |
| 2617 | case OP_LEAVESUB: |
| 2618 | case OP_LEAVESUBLV: |
| 2619 | case OP_LEAVEWRITE: |
| 2620 | case OP_SCOPE: |
| 2621 | if (o->op_private & OPpREFCOUNTED) |
| 2622 | S_xmldump_attr(aTHX_ level, file, "refcnt=\"%"UVuf"\"", (UV)o->op_targ); |
| 2623 | break; |
| 2624 | default: |
| 2625 | break; |
| 2626 | } |
| 2627 | |
| 2628 | if (PL_madskills && o->op_madprop) { |
| 2629 | SV *tmpsv = newSVpvn("", 0); |
| 2630 | MADPROP* mp = o->op_madprop; |
| 2631 | sv_utf8_upgrade(tmpsv); |
| 2632 | if (!contents) { |
| 2633 | contents = 1; |
| 2634 | PerlIO_printf(file, ">\n"); |
| 2635 | } |
| 2636 | Perl_xmldump_indent(aTHX_ level, file, "<madprops>\n"); |
| 2637 | level++; |
| 2638 | while (mp) { |
| 2639 | char tmp = mp->mad_key; |
| 2640 | sv_setpvn(tmpsv,"\"",1); |
| 2641 | if (tmp) |
| 2642 | sv_catxmlpvn(tmpsv, &tmp, 1, 0); |
| 2643 | sv_catpv(tmpsv, "\""); |
| 2644 | switch (mp->mad_type) { |
| 2645 | case MAD_NULL: |
| 2646 | sv_catpv(tmpsv, "NULL"); |
| 2647 | Perl_xmldump_indent(aTHX_ level, file, "<mad_null key=%s/>\n", SvPVX(tmpsv)); |
| 2648 | break; |
| 2649 | case MAD_PV: |
| 2650 | sv_catpv(tmpsv, " val=\""); |
| 2651 | sv_catxmlpvn(tmpsv, (char*)mp->mad_val, mp->mad_vlen,1); |
| 2652 | sv_catpv(tmpsv, "\""); |
| 2653 | Perl_xmldump_indent(aTHX_ level, file, "<mad_pv key=%s/>\n", SvPVX(tmpsv)); |
| 2654 | break; |
| 2655 | case MAD_SV: |
| 2656 | sv_catpv(tmpsv, " val=\""); |
| 2657 | sv_catxmlsv(tmpsv, (SV*)mp->mad_val); |
| 2658 | sv_catpv(tmpsv, "\""); |
| 2659 | Perl_xmldump_indent(aTHX_ level, file, "<mad_sv key=%s/>\n", SvPVX(tmpsv)); |
| 2660 | break; |
| 2661 | case MAD_OP: |
| 2662 | if ((OP*)mp->mad_val) { |
| 2663 | Perl_xmldump_indent(aTHX_ level, file, "<mad_op key=%s>\n", SvPVX(tmpsv)); |
| 2664 | do_op_xmldump(level+1, file, (OP*)mp->mad_val); |
| 2665 | Perl_xmldump_indent(aTHX_ level, file, "</mad_op>\n"); |
| 2666 | } |
| 2667 | break; |
| 2668 | default: |
| 2669 | Perl_xmldump_indent(aTHX_ level, file, "<mad_unk key=%s/>\n", SvPVX(tmpsv)); |
| 2670 | break; |
| 2671 | } |
| 2672 | mp = mp->mad_next; |
| 2673 | } |
| 2674 | level--; |
| 2675 | Perl_xmldump_indent(aTHX_ level, file, "</madprops>\n"); |
| 2676 | |
| 2677 | SvREFCNT_dec(tmpsv); |
| 2678 | } |
| 2679 | |
| 2680 | switch (o->op_type) { |
| 2681 | case OP_PUSHRE: |
| 2682 | case OP_MATCH: |
| 2683 | case OP_QR: |
| 2684 | case OP_SUBST: |
| 2685 | if (!contents) { |
| 2686 | contents = 1; |
| 2687 | PerlIO_printf(file, ">\n"); |
| 2688 | } |
| 2689 | do_pmop_xmldump(level, file, cPMOPo); |
| 2690 | break; |
| 2691 | default: |
| 2692 | break; |
| 2693 | } |
| 2694 | |
| 2695 | if (o->op_flags & OPf_KIDS) { |
| 2696 | OP *kid; |
| 2697 | if (!contents) { |
| 2698 | contents = 1; |
| 2699 | PerlIO_printf(file, ">\n"); |
| 2700 | } |
| 2701 | for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling) |
| 2702 | do_op_xmldump(level, file, kid); |
| 2703 | } |
| 2704 | |
| 2705 | if (contents) |
| 2706 | Perl_xmldump_indent(aTHX_ level-1, file, "</op_%s>\n", OP_NAME(o)); |
| 2707 | else |
| 2708 | PerlIO_printf(file, " />\n"); |
| 2709 | } |
| 2710 | |
| 2711 | void |
| 2712 | Perl_op_xmldump(pTHX_ const OP *o) |
| 2713 | { |
| 2714 | do_op_xmldump(0, PL_xmlfp, o); |
| 2715 | } |
| 2716 | #endif |
| 2717 | |
| 2718 | /* |
| 2719 | * Local variables: |
| 2720 | * c-indentation-style: bsd |
| 2721 | * c-basic-offset: 4 |
| 2722 | * indent-tabs-mode: t |
| 2723 | * End: |
| 2724 | * |
| 2725 | * ex: set ts=8 sts=4 sw=4 noet: |
| 2726 | */ |