summaryrefslogtreecommitdiff
path: root/dump.c
blob: a6b4b170271015d961fe38f047aee8d0e98951fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/* $RCSfile: dump.c,v $$Revision: 4.1 $$Date: 92/08/07 17:20:03 $
 *
 *    Copyright (c) 1991, 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.
 * 
 */

#include "EXTERN.h"
#include "perl.h"

#ifdef DEBUGGING

static void dump();

void
dump_all()
{
    register I32 i;
    register HE *entry;

    setlinebuf(stderr);
    if (main_root)
	dump_op(main_root);
    for (i = 0; i <= 127; i++) {
	for (entry = HvARRAY(defstash)[i]; entry; entry = entry->hent_next)
	    dump_sub((GV*)entry->hent_val);
    }
}

void
dump_sub(gv)
GV* gv;
{
    SV *sv = sv_mortalcopy(&sv_undef);
    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 if (CvROOT(GvCV(gv)))
	    dump_op(CvROOT(GvCV(gv)));
	else
	    dump("<undef>\n");
    }
}

void
dump_eval()
{
    register I32 i;
    register GV *gv;
    register HE *entry;

    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++;
    if (op->op_targ)
	dump("TARG = %d\n", op->op_targ);
#ifdef NOTDEF
    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
	    (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_LVAL)
	    (void)strcat(buf,"LVAL,");
	if (op->op_flags & OPf_INTRO)
	    (void)strcat(buf,"INTRO,");
	if (op->op_flags & OPf_SPECIAL)
	    (void)strcat(buf,"SPECIAL,");
	if (*buf)
	    buf[strlen(buf)-1] = '\0';
	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_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_ENTERSUBR) {
	    if (op->op_private & OPpSUBR_DB)
		(void)strcat(buf,"DB,");
	}
	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 (*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) {
	    tmpsv = NEWSV(0,0);
	    gv_fullname(tmpsv,cGVOP->op_gv);
	    dump("GV = %s\n", SvPVn(tmpsv));
	    sv_free(tmpsv);
	}
	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_GREPWHILE:
    case OP_OR:
    case OP_AND:
    case OP_METHOD:
	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(op);
	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");
}

void
dump_gv(gv)
register GV *gv;
{
    SV *sv;

    if (!gv) {
	fprintf(stderr,"{}\n");
	return;
    }
    sv = sv_mortalcopy(&sv_undef);
    dumplvl++;
    fprintf(stderr,"{\n");
    gv_fullname(sv,gv);
    dump("GV_NAME = %s", SvPV(sv));
    if (gv != GvEGV(gv)) {
	gv_efullname(sv,GvEGV(gv));
	dump("-> %s", SvPV(sv));
    }
    dump("\n");
    dumplvl--;
    dump("}\n");
}

void
dump_pm(pm)
register PMOP *pm;
{
    char ch;

    if (!pm) {
	dump("{}\n");
	return;
    }
    dump("{\n");
    dumplvl++;
    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 (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");
}

/* VARARGS1 */
static void dump(arg1,arg2,arg3,arg4,arg5)
char *arg1;
long arg2, arg3, arg4, arg5;
{
    I32 i;

    for (i = dumplvl*4; i; i--)
	(void)putc(' ',stderr);
    fprintf(stderr,arg1, arg2, arg3, arg4, arg5);
}
#endif