X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=dump.c;h=e74c8c4217e8cfcbedda24cd40568e6c30ead403;hb=e43cfa93c2ef6ac50be4121f06de5f795aa3fa62;hp=ea2e134f1673b5086ae8bee9ba101cfbb4978448;hpb=79072805bf63abe5b5978b5928ab00d360ea3e7f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/dump.c b/dump.c index ea2e134..e74c8c4 100644 --- a/dump.c +++ b/dump.c @@ -1,84 +1,101 @@ -/* $RCSfile: dump.c,v $$Revision: 4.1 $$Date: 92/08/07 17:20:03 $ +/* dump.c * - * Copyright (c) 1991, 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. * - * $Log: dump.c,v $ - * Revision 4.1 92/08/07 17:20:03 lwall - * Stage 6 Snapshot - * - * Revision 4.0.1.2 92/06/08 13:14:22 lwall - * patch20: removed implicit int declarations on funcions - * patch20: fixed confusion between a *var's real name and its effective name - * - * Revision 4.0.1.1 91/06/07 10:58:44 lwall - * patch4: new copyright notice - * - * Revision 4.0 91/03/20 01:08:25 lwall - * 4.0 baseline. - * + */ + +/* + * "'You have talked long in your sleep, Frodo,' said Gandalf gently, 'and + * it has not been hard for me to read your mind and memory.'" */ #include "EXTERN.h" #include "perl.h" -#ifdef DEBUGGING +#ifndef DEBUGGING +void +dump_all() +{ +} +#else /* Rest of file is for DEBUGGING */ +#ifdef I_STDARG +static void dump(char *pat, ...); +#else static void dump(); +#endif void -dump_sequence(op) -register OP *op; +dump_all() { - extern I32 op_seq; - - for (; op; op = op->op_next) { - if (op->op_seq) - return; - op->op_seq = ++op_seq; - } + PerlIO_setlinebuf(Perl_debug_log); + if (main_root) + dump_op(main_root); + dump_packsubs(defstash); } void -dump_all() +dump_packsubs(stash) +HV* stash; { - register I32 i; - register GV *gv; - register HE *entry; - SV *sv = sv_mortalcopy(&sv_undef); + I32 i; + HE *entry; - setlinebuf(stderr); - dump_sequence(main_start); - dump_op(main_root); - for (i = 0; i <= 127; i++) { - for (entry = HvARRAY(defstash)[i]; entry; entry = entry->hent_next) { - gv = (GV*)entry->hent_val; - if (GvCV(gv)) { - gv_fullname(sv,gv); - dump("\nSUB %s = ", SvPV(sv)); - if (CvUSERSUB(GvCV(gv))) - dump("(usersub 0x%x %d)\n", - (long)CvUSERSUB(GvCV(gv)), - CvUSERINDEX(GvCV(gv))); - else { - dump_sequence(CvSTART(GvCV(gv))); - dump_op(CvROOT(GvCV(gv))); - } - } + if (!HvARRAY(stash)) + return; + for (i = 0; i <= (I32) HvMAX(stash); i++) { + for (entry = HvARRAY(stash)[i]; entry; entry = HeNEXT(entry)) { + GV *gv = (GV*)HeVAL(entry); + HV *hv; + if (GvCVu(gv)) + dump_sub(gv); + if (GvFORM(gv)) + dump_form(gv); + if (HeKEY(entry)[HeKLEN(entry)-1] == ':' && + (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash) + dump_packsubs(hv); /* nested package */ } } } void -dump_eval() +dump_sub(gv) +GV* gv; { - register I32 i; - register GV *gv; - register HE *entry; + SV *sv = sv_newmortal(); - dump_sequence(eval_start); + gv_fullname3(sv, gv, Nullch); + dump("\nSUB %s = ", SvPVX(sv)); + if (CvXSUB(GvCV(gv))) + dump("(xsub 0x%x %d)\n", + (long)CvXSUB(GvCV(gv)), + CvXSUBANY(GvCV(gv)).any_i32); + else if (CvROOT(GvCV(gv))) + dump_op(CvROOT(GvCV(gv))); + else + dump("\n"); +} + +void +dump_form(gv) +GV* gv; +{ + SV *sv = sv_newmortal(); + + gv_fullname3(sv, gv, Nullch); + dump("\nFORMAT %s = ", SvPVX(sv)); + if (CvROOT(GvFORM(gv))) + dump_op(CvROOT(GvFORM(gv))); + else + dump("\n"); +} + +void +dump_eval() +{ dump_op(eval_root); } @@ -88,41 +105,56 @@ register OP *op; { SV *tmpsv; - if (!op->op_seq) - dump_sequence(op); dump("{\n"); - fprintf(stderr, "%-4d", op->op_seq); + if (op->op_seq) + PerlIO_printf(Perl_debug_log, "%-4d", op->op_seq); + else + PerlIO_printf(Perl_debug_log, " "); dump("TYPE = %s ===> ", op_name[op->op_type]); - if (op->op_next) - fprintf(stderr, "%d\n", op->op_next->op_seq); + if (op->op_next) { + if (op->op_seq) + PerlIO_printf(Perl_debug_log, "%d\n", op->op_next->op_seq); + else + 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) - dump("TARG = %d\n", op->op_targ); -#ifdef NOTDEF + if (op->op_targ) { + if (op->op_type == OP_NULL) + dump(" (was %s)\n", op_name[op->op_targ]); + else + dump("TARG = %d\n", op->op_targ); + } +#ifdef DUMPADDR 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,"); - } - else + switch (op->op_flags & OPf_WANT) { + case OPf_WANT_VOID: + (void)strcat(buf,"VOID,"); + break; + case OPf_WANT_SCALAR: + (void)strcat(buf,"SCALAR,"); + break; + case OPf_WANT_LIST: + (void)strcat(buf,"LIST,"); + break; + default: (void)strcat(buf,"UNKNOWN,"); + break; + } if (op->op_flags & OPf_KIDS) (void)strcat(buf,"KIDS,"); if (op->op_flags & OPf_PARENS) (void)strcat(buf,"PARENS,"); if (op->op_flags & OPf_STACKED) (void)strcat(buf,"STACKED,"); - if (op->op_flags & OPf_LVAL) - (void)strcat(buf,"LVAL,"); - if (op->op_flags & OPf_LOCAL) - (void)strcat(buf,"LOCAL,"); + if (op->op_flags & OPf_REF) + (void)strcat(buf,"REF,"); + if (op->op_flags & OPf_MOD) + (void)strcat(buf,"MOD,"); if (op->op_flags & OPf_SPECIAL) (void)strcat(buf,"SPECIAL,"); if (*buf) @@ -135,6 +167,10 @@ register OP *op; if (op->op_private & OPpASSIGN_COMMON) (void)strcat(buf,"COMMON,"); } + else if (op->op_type == OP_SASSIGN) { + if (op->op_private & OPpASSIGN_BACKWARDS) + (void)strcat(buf,"BACKWARDS,"); + } else if (op->op_type == OP_TRANS) { if (op->op_private & OPpTRANS_SQUASH) (void)strcat(buf,"SQUASH,"); @@ -147,9 +183,39 @@ register OP *op; if (op->op_private & OPpREPEAT_DOLIST) (void)strcat(buf,"DOLIST,"); } - else if (op->op_type == OP_ENTERSUBR) { - if (op->op_private & OPpSUBR_DB) - (void)strcat(buf,"DB,"); + else if (op->op_type == OP_ENTERSUB || + op->op_type == OP_RV2SV || + op->op_type == OP_RV2AV || + op->op_type == OP_RV2HV || + op->op_type == OP_RV2GV || + op->op_type == OP_AELEM || + op->op_type == OP_HELEM ) + { + if (op->op_type == OP_ENTERSUB) { + if (op->op_private & OPpENTERSUB_AMPER) + (void)strcat(buf,"AMPER,"); + if (op->op_private & OPpENTERSUB_DB) + (void)strcat(buf,"DB,"); + } + switch (op->op_private & OPpDEREF) { + case OPpDEREF_SV: + (void)strcat(buf, "SV,"); + break; + case OPpDEREF_AV: + (void)strcat(buf, "AV,"); + break; + case OPpDEREF_HV: + (void)strcat(buf, "HV,"); + break; + } + if (op->op_type == OP_AELEM || op->op_type == OP_HELEM) { + if (op->op_private & OPpLVAL_DEFER) + (void)strcat(buf,"LVAL_DEFER,"); + } + else { + if (op->op_private & HINT_STRICT_REFS) + (void)strcat(buf,"STRICT_REFS,"); + } } else if (op->op_type == OP_CONST) { if (op->op_private & OPpCONST_BARE) @@ -163,6 +229,8 @@ register OP *op; if (op->op_private & OPpFLIP_LINENUM) (void)strcat(buf,"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); @@ -170,12 +238,15 @@ register OP *op; } switch (op->op_type) { + case OP_GVSV: case OP_GV: if (cGVOP->op_gv) { + ENTER; tmpsv = NEWSV(0,0); - gv_fullname(tmpsv,cGVOP->op_gv); - dump("GV = %s\n", SvPVn(tmpsv)); - sv_free(tmpsv); + SAVEFREESV(tmpsv); + gv_fullname3(tmpsv, cGVOP->op_gv, Nullch); + dump("GV = %s\n", SvPV(tmpsv, na)); + LEAVE; } else dump("GV = NULL\n"); @@ -183,7 +254,8 @@ register OP *op; case OP_CONST: dump("SV = %s\n", SvPEEK(cSVOP->op_sv)); break; - case OP_CURCOP: + case OP_NEXTSTATE: + case OP_DBSTATE: if (cCOP->cop_line) dump("LINE = %d\n",cCOP->cop_line); if (cCOP->cop_label) @@ -191,59 +263,49 @@ register OP *op; break; case OP_ENTERLOOP: dump("REDO ===> "); - if (cLOOP->op_redoop) { - dump_sequence(cLOOP->op_redoop); - fprintf(stderr, "%d\n", cLOOP->op_redoop->op_seq); - } + if (cLOOP->op_redoop) + 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) { - dump_sequence(cLOOP->op_nextop); - fprintf(stderr, "%d\n", cLOOP->op_nextop->op_seq); - } + if (cLOOP->op_nextop) + 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) { - dump_sequence(cLOOP->op_lastop); - fprintf(stderr, "%d\n", cLOOP->op_lastop->op_seq); - } + if (cLOOP->op_lastop) + 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) { - dump_sequence(cCONDOP->op_true); - fprintf(stderr, "%d\n", cCONDOP->op_true->op_seq); - } + if (cCONDOP->op_true) + 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) { - dump_sequence(cCONDOP->op_false); - fprintf(stderr, "%d\n", cCONDOP->op_false->op_seq); - } + if (cCONDOP->op_false) + 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: case OP_OR: case OP_AND: - case OP_METHOD: dump("OTHER ===> "); - if (cLOGOP->op_other) { - dump_sequence(cLOGOP->op_other); - fprintf(stderr, "%d\n", cLOGOP->op_other->op_seq); - } + if (cLOGOP->op_other) + 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: case OP_SUBST: - dump_pm(op); + dump_pm((PMOP*)op); + break; + default: break; } if (op->op_flags & OPf_KIDS) { @@ -262,17 +324,17 @@ register GV *gv; SV *sv; if (!gv) { - fprintf(stderr,"{}\n"); + PerlIO_printf(Perl_debug_log, "{}\n"); return; } - sv = sv_mortalcopy(&sv_undef); + sv = sv_newmortal(); dumplvl++; - fprintf(stderr,"{\n"); - gv_fullname(sv,gv); - dump("GV_NAME = %s", SvPV(sv)); + 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)); - dump("-> %s", SvPV(sv)); + gv_efullname3(sv, GvEGV(gv), Nullch); + dump("-> %s", SvPVX(sv)); } dump("\n"); dumplvl--; @@ -316,8 +378,6 @@ register PMOP *pm; (void)strcat(buf,"ALL,"); if (pm->op_pmflags & PMf_SKIPWHITE) (void)strcat(buf,"SKIPWHITE,"); - if (pm->op_pmflags & PMf_FOLD) - (void)strcat(buf,"FOLD,"); if (pm->op_pmflags & PMf_CONST) (void)strcat(buf,"CONST,"); if (pm->op_pmflags & PMf_KEEP) @@ -337,6 +397,8 @@ register PMOP *pm; dump("}\n"); } + +#if !defined(I_STDARG) && !defined(I_VARARGS) /* VARARGS1 */ static void dump(arg1,arg2,arg3,arg4,arg5) char *arg1; @@ -345,7 +407,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