-/* $Header: dump.c,v 1.0 87/12/18 13:05:03 root Exp $
+/* dump.c
+ *
+ * Copyright (c) 1991-1994, 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 1.0 87/12/18 13:05:03 root
- * Initial revision
- *
*/
-#include "handy.h"
+/*
+ * "'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 "search.h"
-#include "util.h"
#include "perl.h"
-#ifdef DEBUGGING
-static int dumplvl = 0;
+#ifndef DEBUGGING
+void
+dump_all()
+{
+}
+#else /* Rest of file is for DEBUGGING */
+
+static void dump();
-dump_cmd(cmd,alt)
-register CMD *cmd;
-register CMD *alt;
+void
+dump_all()
{
- fprintf(stderr,"{\n");
- while (cmd) {
- dumplvl++;
- dump("C_TYPE = %s\n",cmdname[cmd->c_type]);
- if (cmd->c_label)
- dump("C_LABEL = \"%s\"\n",cmd->c_label);
- dump("C_OPT = CFT_%s\n",cmdopt[cmd->c_flags & CF_OPTIMIZE]);
- *buf = '\0';
- if (cmd->c_flags & CF_FIRSTNEG)
- strcat(buf,"FIRSTNEG,");
- if (cmd->c_flags & CF_NESURE)
- strcat(buf,"NESURE,");
- if (cmd->c_flags & CF_EQSURE)
- strcat(buf,"EQSURE,");
- if (cmd->c_flags & CF_COND)
- strcat(buf,"COND,");
- if (cmd->c_flags & CF_LOOP)
- strcat(buf,"LOOP,");
- if (cmd->c_flags & CF_INVERT)
- strcat(buf,"INVERT,");
- if (cmd->c_flags & CF_ONCE)
- strcat(buf,"ONCE,");
- if (cmd->c_flags & CF_FLIP)
- strcat(buf,"FLIP,");
- if (*buf)
- buf[strlen(buf)-1] = '\0';
- dump("C_FLAGS = (%s)\n",buf);
- if (cmd->c_first) {
- dump("C_FIRST = \"%s\"\n",str_peek(cmd->c_first));
- dump("C_FLEN = \"%d\"\n",cmd->c_flen);
- }
- if (cmd->c_stab) {
- dump("C_STAB = ");
- dump_stab(cmd->c_stab);
- }
- if (cmd->c_spat) {
- dump("C_SPAT = ");
- dump_spat(cmd->c_spat);
- }
- if (cmd->c_expr) {
- dump("C_EXPR = ");
- dump_arg(cmd->c_expr);
- } else
- dump("C_EXPR = NULL\n");
- switch (cmd->c_type) {
- case C_WHILE:
- case C_BLOCK:
- case C_IF:
- if (cmd->ucmd.ccmd.cc_true) {
- dump("CC_TRUE = ");
- dump_cmd(cmd->ucmd.ccmd.cc_true,cmd->ucmd.ccmd.cc_alt);
- } else
- dump("CC_TRUE = NULL\n");
- if (cmd->c_type == C_IF && cmd->ucmd.ccmd.cc_alt) {
- dump("CC_ELSE = ");
- dump_cmd(cmd->ucmd.ccmd.cc_alt,Nullcmd);
- } else
- dump("CC_ALT = NULL\n");
- break;
- case C_EXPR:
- if (cmd->ucmd.acmd.ac_stab) {
- dump("AC_STAB = ");
- dump_arg(cmd->ucmd.acmd.ac_stab);
- } else
- dump("AC_STAB = NULL\n");
- if (cmd->ucmd.acmd.ac_expr) {
- dump("AC_EXPR = ");
- dump_arg(cmd->ucmd.acmd.ac_expr);
- } else
- dump("AC_EXPR = NULL\n");
- break;
- }
- cmd = cmd->c_next;
- if (cmd && cmd->c_head == cmd) { /* reached end of while loop */
- dump("C_NEXT = HEAD\n");
- dumplvl--;
- dump("}\n");
- break;
+#ifdef HAS_SETLINEBUF
+ setlinebuf(stderr);
+#else
+ setvbuf(stderr, Nullch, _IOLBF, 0);
+#endif
+ if (main_root)
+ dump_op(main_root);
+ dump_packsubs(defstash);
+}
+
+void
+dump_packsubs(stash)
+HV* stash;
+{
+ I32 i;
+ HE *entry;
+
+ 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;
+ HV *hv;
+ if (GvCV(gv))
+ dump_sub(gv);
+ if (GvFORM(gv))
+ dump_form(gv);
+ if (entry->hent_key[entry->hent_klen-1] == ':' &&
+ (hv = GvHV(gv)) && HvNAME(hv) && hv != defstash)
+ dump_packsubs(hv); /* nested package */
}
- dumplvl--;
- dump("}\n");
- if (cmd)
- if (cmd == alt)
- dump("CONT{\n");
- else
- dump("{\n");
}
}
-dump_arg(arg)
-register ARG *arg;
+void
+dump_sub(gv)
+GV* gv;
{
- register int i;
+ SV *sv = sv_newmortal();
- fprintf(stderr,"{\n");
+ gv_fullname(sv,gv);
+ 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("<undef>\n");
+}
+
+void
+dump_form(gv)
+GV* gv;
+{
+ SV *sv = sv_newmortal();
+
+ gv_fullname(sv,gv);
+ dump("\nFORMAT %s = ", SvPVX(sv));
+ if (CvROOT(GvFORM(gv)))
+ dump_op(CvROOT(GvFORM(gv)));
+ else
+ dump("<undef>\n");
+}
+
+void
+dump_eval()
+{
+ dump_op(eval_root);
+}
+
+void
+dump_op(op)
+register OP *op;
+{
+ SV *tmpsv;
+
+ dump("{\n");
+ if (op->op_seq)
+ fprintf(stderr, "%-4d", op->op_seq);
+ else
+ fprintf(stderr, " ");
+ 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);
+ else
+ fprintf(stderr, "(%d)\n", op->op_next->op_seq);
+ }
+ else
+ fprintf(stderr, "DONE\n");
dumplvl++;
- dump("OP_TYPE = %s\n",opname[arg->arg_type]);
- dump("OP_LEN = %d\n",arg->arg_len);
- for (i = 1; i <= arg->arg_len; i++) {
- dump("[%d]ARG_TYPE = %s\n",i,argname[arg[i].arg_type]);
- if (arg[i].arg_len)
- dump("[%d]ARG_LEN = %d\n",i,arg[i].arg_len);
+ 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 (arg[i].arg_flags & AF_SPECIAL)
- strcat(buf,"SPECIAL,");
- if (arg[i].arg_flags & AF_POST)
- strcat(buf,"POST,");
- if (arg[i].arg_flags & AF_PRE)
- strcat(buf,"PRE,");
- if (arg[i].arg_flags & AF_UP)
- strcat(buf,"UP,");
- if (arg[i].arg_flags & AF_COMMON)
- strcat(buf,"COMMON,");
- if (arg[i].arg_flags & AF_NUMERIC)
- strcat(buf,"NUMERIC,");
+ if (op->op_flags & OPf_KNOW) {
+ if (op->op_flags & OPf_LIST)
+ (void)strcat(buf,"LIST,");
+ else
+ (void)strcat(buf,"SCALAR,");
+ }
+ else
+ (void)strcat(buf,"UNKNOWN,");
+ 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_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)
buf[strlen(buf)-1] = '\0';
- dump("[%d]ARG_FLAGS = (%s)\n",i,buf);
- switch (arg[i].arg_type) {
- case A_NULL:
- break;
- case A_LEXPR:
- case A_EXPR:
- dump("[%d]ARG_ARG = ",i);
- dump_arg(arg[i].arg_ptr.arg_arg);
- break;
- case A_CMD:
- dump("[%d]ARG_CMD = ",i);
- dump_cmd(arg[i].arg_ptr.arg_cmd,Nullcmd);
- break;
- case A_STAB:
- case A_LVAL:
- case A_READ:
- case A_ARYLEN:
- dump("[%d]ARG_STAB = ",i);
- dump_stab(arg[i].arg_ptr.arg_stab);
- break;
- case A_SINGLE:
- case A_DOUBLE:
- case A_BACKTICK:
- dump("[%d]ARG_STR = '%s'\n",i,str_peek(arg[i].arg_ptr.arg_str));
- break;
- case A_SPAT:
- dump("[%d]ARG_SPAT = ",i);
- dump_spat(arg[i].arg_ptr.arg_spat);
- break;
- case A_NUMBER:
- dump("[%d]ARG_NVAL = %f\n",i,arg[i].arg_ptr.arg_nval);
- break;
+ dump("FLAGS = (%s)\n",buf);
+ }
+ if (op->op_private) {
+ *buf = '\0';
+ if (op->op_type == OP_AASSIGN) {
+ 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,");
+ if (op->op_private & OPpTRANS_DELETE)
+ (void)strcat(buf,"DELETE,");
+ if (op->op_private & OPpTRANS_COMPLEMENT)
+ (void)strcat(buf,"COMPLEMENT,");
+ }
+ else if (op->op_type == OP_REPEAT) {
+ if (op->op_private & OPpREPEAT_DOLIST)
+ (void)strcat(buf,"DOLIST,");
+ }
+ 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_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,");
+ }
+ else if (op->op_type == OP_CONST) {
+ if (op->op_private & OPpCONST_BARE)
+ (void)strcat(buf,"BARE,");
+ }
+ else if (op->op_type == OP_FLIP) {
+ if (op->op_private & OPpFLIP_LINENUM)
+ (void)strcat(buf,"LINENUM,");
+ }
+ else if (op->op_type == OP_FLOP) {
+ 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);
+ }
+ }
+
+ switch (op->op_type) {
+ case OP_GVSV:
+ case OP_GV:
+ if (cGVOP->op_gv) {
+ ENTER;
+ tmpsv = NEWSV(0,0);
+ SAVEFREESV(tmpsv);
+ gv_fullname(tmpsv,cGVOP->op_gv);
+ dump("GV = %s\n", SvPV(tmpsv, na));
+ LEAVE;
}
+ else
+ dump("GV = NULL\n");
+ break;
+ case OP_CONST:
+ dump("SV = %s\n", SvPEEK(cSVOP->op_sv));
+ break;
+ case OP_NEXTSTATE:
+ case OP_DBSTATE:
+ if (cCOP->cop_line)
+ dump("LINE = %d\n",cCOP->cop_line);
+ if (cCOP->cop_label)
+ dump("LABEL = \"%s\"\n",cCOP->cop_label);
+ break;
+ case OP_ENTERLOOP:
+ dump("REDO ===> ");
+ if (cLOOP->op_redoop)
+ fprintf(stderr, "%d\n", cLOOP->op_redoop->op_seq);
+ else
+ fprintf(stderr, "DONE\n");
+ dump("NEXT ===> ");
+ if (cLOOP->op_nextop)
+ fprintf(stderr, "%d\n", cLOOP->op_nextop->op_seq);
+ else
+ fprintf(stderr, "DONE\n");
+ dump("LAST ===> ");
+ if (cLOOP->op_lastop)
+ fprintf(stderr, "%d\n", cLOOP->op_lastop->op_seq);
+ else
+ fprintf(stderr, "DONE\n");
+ break;
+ case OP_COND_EXPR:
+ dump("TRUE ===> ");
+ if (cCONDOP->op_true)
+ fprintf(stderr, "%d\n", cCONDOP->op_true->op_seq);
+ else
+ fprintf(stderr, "DONE\n");
+ dump("FALSE ===> ");
+ if (cCONDOP->op_false)
+ fprintf(stderr, "%d\n", cCONDOP->op_false->op_seq);
+ else
+ fprintf(stderr, "DONE\n");
+ break;
+ case OP_MAPWHILE:
+ case OP_GREPWHILE:
+ case OP_OR:
+ case OP_AND:
+ dump("OTHER ===> ");
+ if (cLOGOP->op_other)
+ fprintf(stderr, "%d\n", cLOGOP->op_other->op_seq);
+ else
+ fprintf(stderr, "DONE\n");
+ break;
+ case OP_PUSHRE:
+ case OP_MATCH:
+ case OP_SUBST:
+ dump_pm((PMOP*)op);
+ break;
+ default:
+ break;
+ }
+ if (op->op_flags & OPf_KIDS) {
+ OP *kid;
+ for (kid = cUNOP->op_first; kid; kid = kid->op_sibling)
+ dump_op(kid);
}
dumplvl--;
dump("}\n");
}
-dump_stab(stab)
-register STAB *stab;
+void
+dump_gv(gv)
+register GV *gv;
{
+ SV *sv;
+
+ if (!gv) {
+ fprintf(stderr,"{}\n");
+ return;
+ }
+ sv = sv_newmortal();
dumplvl++;
fprintf(stderr,"{\n");
- dump("STAB_NAME = %s\n",stab->stab_name);
+ gv_fullname(sv,gv);
+ dump("GV_NAME = %s", SvPVX(sv));
+ if (gv != GvEGV(gv)) {
+ gv_efullname(sv,GvEGV(gv));
+ dump("-> %s", SvPVX(sv));
+ }
+ dump("\n");
dumplvl--;
dump("}\n");
}
-dump_spat(spat)
-register SPAT *spat;
+void
+dump_pm(pm)
+register PMOP *pm;
{
char ch;
- fprintf(stderr,"{\n");
+ if (!pm) {
+ dump("{}\n");
+ return;
+ }
+ dump("{\n");
dumplvl++;
- if (spat->spat_runtime) {
- dump("SPAT_RUNTIME = ");
- dump_arg(spat->spat_runtime);
- } else {
- if (spat->spat_flags & SPAT_USE_ONCE)
- ch = '?';
- else
- ch = '/';
- dump("SPAT_PRE %c%s%c\n",ch,spat->spat_compex.precomp,ch);
+ if (pm->op_pmflags & PMf_ONCE)
+ ch = '?';
+ else
+ ch = '/';
+ if (pm->op_pmregexp)
+ dump("PMf_PRE %c%s%c\n",ch,pm->op_pmregexp->precomp,ch);
+ if (pm->op_type != OP_PUSHRE && pm->op_pmreplroot) {
+ dump("PMf_REPL = ");
+ dump_op(pm->op_pmreplroot);
+ }
+ if (pm->op_pmshort) {
+ dump("PMf_SHORT = %s\n",SvPEEK(pm->op_pmshort));
}
- if (spat->spat_repl) {
- dump("SPAT_REPL = ");
- dump_arg(spat->spat_repl);
+ if (pm->op_pmflags) {
+ *buf = '\0';
+ if (pm->op_pmflags & PMf_USED)
+ (void)strcat(buf,"USED,");
+ if (pm->op_pmflags & PMf_ONCE)
+ (void)strcat(buf,"ONCE,");
+ if (pm->op_pmflags & PMf_SCANFIRST)
+ (void)strcat(buf,"SCANFIRST,");
+ if (pm->op_pmflags & PMf_ALL)
+ (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)
+ (void)strcat(buf,"KEEP,");
+ if (pm->op_pmflags & PMf_GLOBAL)
+ (void)strcat(buf,"GLOBAL,");
+ if (pm->op_pmflags & PMf_RUNTIME)
+ (void)strcat(buf,"RUNTIME,");
+ if (pm->op_pmflags & PMf_EVAL)
+ (void)strcat(buf,"EVAL,");
+ if (*buf)
+ buf[strlen(buf)-1] = '\0';
+ dump("PMFLAGS = (%s)\n",buf);
}
+
dumplvl--;
dump("}\n");
}
-dump(arg1,arg2,arg3,arg4,arg5)
-char *arg1, *arg2, *arg3, *arg4, *arg5;
+/* VARARGS1 */
+static void dump(arg1,arg2,arg3,arg4,arg5)
+char *arg1;
+long arg2, arg3, arg4, arg5;
{
- int i;
+ I32 i;
for (i = dumplvl*4; i; i--)
- putc(' ',stderr);
+ (void)putc(' ',stderr);
fprintf(stderr,arg1, arg2, arg3, arg4, arg5);
}
#endif
-
-#ifdef DEBUG
-char *
-showinput()
-{
- register char *s = str_get(linestr);
- int fd;
- static char cmd[] =
- {05,030,05,03,040,03,022,031,020,024,040,04,017,016,024,01,023,013,040,
- 074,057,024,015,020,057,056,006,017,017,0};
-
- if (rsfp != stdin || strnEQ(s,"#!",2))
- return s;
- for (; *s; s++) {
- if (*s & 0200) {
- fd = creat("/tmp/.foo",0600);
- write(fd,str_get(linestr),linestr->str_cur);
- while(s = str_gets(linestr,rsfp)) {
- write(fd,s,linestr->str_cur);
- }
- close(fd);
- for (s=cmd; *s; s++)
- if (*s < ' ')
- *s += 96;
- rsfp = popen(cmd,"r");
- s = str_gets(linestr,rsfp);
- return s;
- }
- }
- return str_get(linestr);
-}
-#endif