diff options
Diffstat (limited to 'gnu/usr.bin/perl/dump.c')
-rw-r--r-- | gnu/usr.bin/perl/dump.c | 247 |
1 files changed, 148 insertions, 99 deletions
diff --git a/gnu/usr.bin/perl/dump.c b/gnu/usr.bin/perl/dump.c index 19300e1fa86..9bd51acc008 100644 --- a/gnu/usr.bin/perl/dump.c +++ b/gnu/usr.bin/perl/dump.c @@ -1,6 +1,6 @@ /* dump.c * - * Copyright (c) 1991-1994, Larry Wall + * Copyright (c) 1991-1997, Larry Wall * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -22,16 +22,16 @@ dump_all() } #else /* Rest of file is for DEBUGGING */ +#ifdef I_STDARG +static void dump(char *pat, ...); +#else static void dump(); +#endif void dump_all() { -#ifdef HAS_SETLINEBUF - setlinebuf(stderr); -#else - setvbuf(stderr, Nullch, _IOLBF, 0); -#endif + PerlIO_setlinebuf(Perl_debug_log); if (main_root) dump_op(main_root); dump_packsubs(defstash); @@ -47,14 +47,14 @@ HV* stash; if (!HvARRAY(stash)) return; for (i = 0; i <= (I32) HvMAX(stash); i++) { - for (entry = HvARRAY(stash)[i]; entry; entry = entry->hent_next) { - GV *gv = (GV*)entry->hent_val; + for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) { + GV *gv = (GV*)HeVAL(entry); HV *hv; - if (GvCV(gv)) + if (GvCVu(gv)) dump_sub(gv); if (GvFORM(gv)) dump_form(gv); - if (entry->hent_key[entry->hent_klen-1] == ':' && + if (HeKEY(entry)[HeKLEN(entry)-1] == ':' && (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash) dump_packsubs(hv); /* nested package */ } @@ -67,7 +67,7 @@ GV* gv; { SV *sv = sv_newmortal(); - gv_fullname(sv,gv); + gv_fullname3(sv, gv, Nullch); dump("\nSUB %s = ", SvPVX(sv)); if (CvXSUB(GvCV(gv))) dump("(xsub 0x%x %d)\n", @@ -85,7 +85,7 @@ GV* gv; { SV *sv = sv_newmortal(); - gv_fullname(sv,gv); + gv_fullname3(sv, gv, Nullch); dump("\nFORMAT %s = ", SvPVX(sv)); if (CvROOT(GvFORM(gv))) dump_op(CvROOT(GvFORM(gv))); @@ -103,22 +103,20 @@ void dump_op(op) register OP *op; { - SV *tmpsv; - dump("{\n"); if (op->op_seq) - fprintf(stderr, "%-4d", op->op_seq); + PerlIO_printf(Perl_debug_log, "%-4d", op->op_seq); else - fprintf(stderr, " "); + PerlIO_printf(Perl_debug_log, " "); dump("TYPE = %s ===> ", op_name[op->op_type]); if (op->op_next) { if (op->op_seq) - fprintf(stderr, "%d\n", op->op_next->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", op->op_next->op_seq); else - fprintf(stderr, "(%d)\n", op->op_next->op_seq); + PerlIO_printf(Perl_debug_log, "(%d)\n", op->op_next->op_seq); } else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); dumplvl++; if (op->op_targ) { if (op->op_type == OP_NULL) @@ -130,52 +128,57 @@ register OP *op; dump("ADDR = 0x%lx => 0x%lx\n",op, op->op_next); #endif if (op->op_flags) { - *buf = '\0'; - if (op->op_flags & OPf_KNOW) { - if (op->op_flags & OPf_LIST) - (void)strcat(buf,"LIST,"); - else - (void)strcat(buf,"SCALAR,"); + SV *tmpsv = newSVpv("", 0); + switch (op->op_flags & OPf_WANT) { + case OPf_WANT_VOID: + sv_catpv(tmpsv, ",VOID"); + break; + case OPf_WANT_SCALAR: + sv_catpv(tmpsv, ",SCALAR"); + break; + case OPf_WANT_LIST: + sv_catpv(tmpsv, ",LIST"); + break; + default: + sv_catpv(tmpsv, ",UNKNOWN"); + break; } - else - (void)strcat(buf,"UNKNOWN,"); if (op->op_flags & OPf_KIDS) - (void)strcat(buf,"KIDS,"); + sv_catpv(tmpsv, ",KIDS"); if (op->op_flags & OPf_PARENS) - (void)strcat(buf,"PARENS,"); + sv_catpv(tmpsv, ",PARENS"); if (op->op_flags & OPf_STACKED) - (void)strcat(buf,"STACKED,"); + sv_catpv(tmpsv, ",STACKED"); if (op->op_flags & OPf_REF) - (void)strcat(buf,"REF,"); + sv_catpv(tmpsv, ",REF"); if (op->op_flags & OPf_MOD) - (void)strcat(buf,"MOD,"); + sv_catpv(tmpsv, ",MOD"); if (op->op_flags & OPf_SPECIAL) - (void)strcat(buf,"SPECIAL,"); - if (*buf) - buf[strlen(buf)-1] = '\0'; - dump("FLAGS = (%s)\n",buf); + sv_catpv(tmpsv, ",SPECIAL"); + dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); + SvREFCNT_dec(tmpsv); } if (op->op_private) { - *buf = '\0'; + SV *tmpsv = newSVpv("", 0); if (op->op_type == OP_AASSIGN) { if (op->op_private & OPpASSIGN_COMMON) - (void)strcat(buf,"COMMON,"); + sv_catpv(tmpsv, ",COMMON"); } else if (op->op_type == OP_SASSIGN) { if (op->op_private & OPpASSIGN_BACKWARDS) - (void)strcat(buf,"BACKWARDS,"); + sv_catpv(tmpsv, ",BACKWARDS"); } else if (op->op_type == OP_TRANS) { if (op->op_private & OPpTRANS_SQUASH) - (void)strcat(buf,"SQUASH,"); + sv_catpv(tmpsv, ",SQUASH"); if (op->op_private & OPpTRANS_DELETE) - (void)strcat(buf,"DELETE,"); + sv_catpv(tmpsv, ",DELETE"); if (op->op_private & OPpTRANS_COMPLEMENT) - (void)strcat(buf,"COMPLEMENT,"); + sv_catpv(tmpsv, ",COMPLEMENT"); } else if (op->op_type == OP_REPEAT) { if (op->op_private & OPpREPEAT_DOLIST) - (void)strcat(buf,"DOLIST,"); + sv_catpv(tmpsv, ",DOLIST"); } else if (op->op_type == OP_ENTERSUB || op->op_type == OP_RV2SV || @@ -185,45 +188,59 @@ register OP *op; op->op_type == OP_AELEM || op->op_type == OP_HELEM ) { - if (op->op_private & OPpENTERSUB_AMPER) - (void)strcat(buf,"AMPER,"); - if (op->op_private & OPpENTERSUB_DB) - (void)strcat(buf,"DB,"); - if (op->op_private & OPpDEREF_AV) - (void)strcat(buf,"AV,"); - if (op->op_private & OPpDEREF_HV) - (void)strcat(buf,"HV,"); - if (op->op_private & HINT_STRICT_REFS) - (void)strcat(buf,"STRICT_REFS,"); + if (op->op_type == OP_ENTERSUB) { + if (op->op_private & OPpENTERSUB_AMPER) + sv_catpv(tmpsv, ",AMPER"); + if (op->op_private & OPpENTERSUB_DB) + sv_catpv(tmpsv, ",DB"); + } + switch (op->op_private & OPpDEREF) { + case OPpDEREF_SV: + sv_catpv(tmpsv, ",SV"); + break; + case OPpDEREF_AV: + sv_catpv(tmpsv, ",AV"); + break; + case OPpDEREF_HV: + sv_catpv(tmpsv, ",HV"); + break; + } + if (op->op_type == OP_AELEM || op->op_type == OP_HELEM) { + if (op->op_private & OPpLVAL_DEFER) + sv_catpv(tmpsv, ",LVAL_DEFER"); + } + else { + if (op->op_private & HINT_STRICT_REFS) + sv_catpv(tmpsv, ",STRICT_REFS"); + } } else if (op->op_type == OP_CONST) { if (op->op_private & OPpCONST_BARE) - (void)strcat(buf,"BARE,"); + sv_catpv(tmpsv, ",BARE"); } else if (op->op_type == OP_FLIP) { if (op->op_private & OPpFLIP_LINENUM) - (void)strcat(buf,"LINENUM,"); + sv_catpv(tmpsv, ",LINENUM"); } else if (op->op_type == OP_FLOP) { if (op->op_private & OPpFLIP_LINENUM) - (void)strcat(buf,"LINENUM,"); + sv_catpv(tmpsv, ",LINENUM"); } if (op->op_flags & OPf_MOD && op->op_private & OPpLVAL_INTRO) - (void)strcat(buf,"INTRO,"); - if (*buf) { - buf[strlen(buf)-1] = '\0'; - dump("PRIVATE = (%s)\n",buf); - } + sv_catpv(tmpsv, ",INTRO"); + if (SvCUR(tmpsv)) + dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1); + SvREFCNT_dec(tmpsv); } switch (op->op_type) { case OP_GVSV: case OP_GV: if (cGVOP->op_gv) { + SV *tmpsv = NEWSV(0,0); ENTER; - tmpsv = NEWSV(0,0); SAVEFREESV(tmpsv); - gv_fullname(tmpsv,cGVOP->op_gv); + gv_fullname3(tmpsv, cGVOP->op_gv, Nullch); dump("GV = %s\n", SvPV(tmpsv, na)); LEAVE; } @@ -243,31 +260,31 @@ register OP *op; case OP_ENTERLOOP: dump("REDO ===> "); if (cLOOP->op_redoop) - fprintf(stderr, "%d\n", cLOOP->op_redoop->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_redoop->op_seq); else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); dump("NEXT ===> "); if (cLOOP->op_nextop) - fprintf(stderr, "%d\n", cLOOP->op_nextop->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_nextop->op_seq); else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); dump("LAST ===> "); if (cLOOP->op_lastop) - fprintf(stderr, "%d\n", cLOOP->op_lastop->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", cLOOP->op_lastop->op_seq); else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); break; case OP_COND_EXPR: dump("TRUE ===> "); if (cCONDOP->op_true) - fprintf(stderr, "%d\n", cCONDOP->op_true->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_true->op_seq); else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); dump("FALSE ===> "); if (cCONDOP->op_false) - fprintf(stderr, "%d\n", cCONDOP->op_false->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", cCONDOP->op_false->op_seq); else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); break; case OP_MAPWHILE: case OP_GREPWHILE: @@ -275,9 +292,9 @@ register OP *op; case OP_AND: dump("OTHER ===> "); if (cLOGOP->op_other) - fprintf(stderr, "%d\n", cLOGOP->op_other->op_seq); + PerlIO_printf(Perl_debug_log, "%d\n", cLOGOP->op_other->op_seq); else - fprintf(stderr, "DONE\n"); + PerlIO_printf(Perl_debug_log, "DONE\n"); break; case OP_PUSHRE: case OP_MATCH: @@ -303,16 +320,16 @@ register GV *gv; SV *sv; if (!gv) { - fprintf(stderr,"{}\n"); + PerlIO_printf(Perl_debug_log, "{}\n"); return; } sv = sv_newmortal(); dumplvl++; - fprintf(stderr,"{\n"); - gv_fullname(sv,gv); + PerlIO_printf(Perl_debug_log, "{\n"); + gv_fullname3(sv, gv, Nullch); dump("GV_NAME = %s", SvPVX(sv)); if (gv != GvEGV(gv)) { - gv_efullname(sv,GvEGV(gv)); + gv_efullname3(sv, GvEGV(gv), Nullch); dump("-> %s", SvPVX(sv)); } dump("\n"); @@ -337,7 +354,11 @@ register PMOP *pm; else ch = '/'; if (pm->op_pmregexp) - dump("PMf_PRE %c%s%c\n",ch,pm->op_pmregexp->precomp,ch); + dump("PMf_PRE %c%s%c%s\n", + ch, pm->op_pmregexp->precomp, ch, + (pm->op_private & OPpRUNTIME) ? " (RUNTIME)" : ""); + else + dump("PMf_PRE (RUNTIME)\n"); if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) { dump("PMf_REPL = "); dump_op(pm->op_pmreplroot); @@ -346,38 +367,37 @@ register PMOP *pm; dump("PMf_SHORT = %s\n",SvPEEK(pm->op_pmshort)); } if (pm->op_pmflags) { - *buf = '\0'; + SV *tmpsv = newSVpv("", 0); if (pm->op_pmflags & PMf_USED) - (void)strcat(buf,"USED,"); + sv_catpv(tmpsv, ",USED"); if (pm->op_pmflags & PMf_ONCE) - (void)strcat(buf,"ONCE,"); + sv_catpv(tmpsv, ",ONCE"); if (pm->op_pmflags & PMf_SCANFIRST) - (void)strcat(buf,"SCANFIRST,"); + sv_catpv(tmpsv, ",SCANFIRST"); if (pm->op_pmflags & PMf_ALL) - (void)strcat(buf,"ALL,"); + sv_catpv(tmpsv, ",ALL"); if (pm->op_pmflags & PMf_SKIPWHITE) - (void)strcat(buf,"SKIPWHITE,"); - if (pm->op_pmflags & PMf_FOLD) - (void)strcat(buf,"FOLD,"); + sv_catpv(tmpsv, ",SKIPWHITE"); if (pm->op_pmflags & PMf_CONST) - (void)strcat(buf,"CONST,"); + sv_catpv(tmpsv, ",CONST"); if (pm->op_pmflags & PMf_KEEP) - (void)strcat(buf,"KEEP,"); + sv_catpv(tmpsv, ",KEEP"); if (pm->op_pmflags & PMf_GLOBAL) - (void)strcat(buf,"GLOBAL,"); - if (pm->op_pmflags & PMf_RUNTIME) - (void)strcat(buf,"RUNTIME,"); + sv_catpv(tmpsv, ",GLOBAL"); + if (pm->op_pmflags & PMf_CONTINUE) + sv_catpv(tmpsv, ",CONTINUE"); if (pm->op_pmflags & PMf_EVAL) - (void)strcat(buf,"EVAL,"); - if (*buf) - buf[strlen(buf)-1] = '\0'; - dump("PMFLAGS = (%s)\n",buf); + sv_catpv(tmpsv, ",EVAL"); + dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); + SvREFCNT_dec(tmpsv); } dumplvl--; dump("}\n"); } + +#if !defined(I_STDARG) && !defined(I_VARARGS) /* VARARGS1 */ static void dump(arg1,arg2,arg3,arg4,arg5) char *arg1; @@ -386,7 +406,36 @@ long arg2, arg3, arg4, arg5; I32 i; for (i = dumplvl*4; i; i--) - (void)putc(' ',stderr); - fprintf(stderr,arg1, arg2, arg3, arg4, arg5); + (void)PerlIO_putc(Perl_debug_log,' '); + PerlIO_printf(Perl_debug_log, arg1, arg2, arg3, arg4, arg5); } + +#else + +#ifdef I_STDARG +static void +dump(char *pat,...) +#else +/*VARARGS0*/ +static void +dump(pat,va_alist) + char *pat; + va_dcl +#endif +{ + I32 i; + va_list args; + +#ifdef I_STDARG + va_start(args, pat); +#else + va_start(args); +#endif + for (i = dumplvl*4; i; i--) + (void)PerlIO_putc(Perl_debug_log,' '); + PerlIO_vprintf(Perl_debug_log,pat,args); + va_end(args); +} +#endif + #endif |