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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
/* dump.c
*
* 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.
*
*/
/*
* "'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"
#ifndef PERL_OBJECT
#ifdef I_STDARG
static void dump(char *pat, ...);
#else
static void dump();
#endif
#endif /* PERL_OBJECT */
void
dump_all(void)
{
#ifdef DEBUGGING
dTHR;
PerlIO_setlinebuf(Perl_debug_log);
if (main_root)
dump_op(main_root);
dump_packsubs(defstash);
#endif /* DEBUGGING */
}
void
dump_packsubs(HV *stash)
{
#ifdef DEBUGGING
dTHR;
I32 i;
HE *entry;
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 */
}
}
#endif /* DEBUGGING */
}
void
dump_sub(GV *gv)
{
#ifdef DEBUGGING
SV *sv = sv_newmortal();
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("<undef>\n");
#endif /* DEBUGGING */
}
void
dump_form(GV *gv)
{
#ifdef DEBUGGING
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("<undef>\n");
#endif /* DEBUGGING */
}
void
dump_eval(void)
{
#ifdef DEBUGGING
dump_op(eval_root);
#endif /* DEBUGGING */
}
void
dump_op(OP *o)
{
#ifdef DEBUGGING
dump("{\n");
if (o->op_seq)
PerlIO_printf(Perl_debug_log, "%-4d", o->op_seq);
else
PerlIO_printf(Perl_debug_log, " ");
dump("TYPE = %s ===> ", op_name[o->op_type]);
if (o->op_next) {
if (o->op_seq)
PerlIO_printf(Perl_debug_log, "%d\n", o->op_next->op_seq);
else
PerlIO_printf(Perl_debug_log, "(%d)\n", o->op_next->op_seq);
}
else
PerlIO_printf(Perl_debug_log, "DONE\n");
dumplvl++;
if (o->op_targ) {
if (o->op_type == OP_NULL)
dump(" (was %s)\n", op_name[o->op_targ]);
else
dump("TARG = %d\n", o->op_targ);
}
#ifdef DUMPADDR
dump("ADDR = 0x%lx => 0x%lx\n",o, o->op_next);
#endif
if (o->op_flags) {
SV *tmpsv = newSVpv("", 0);
switch (o->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;
}
if (o->op_flags & OPf_KIDS)
sv_catpv(tmpsv, ",KIDS");
if (o->op_flags & OPf_PARENS)
sv_catpv(tmpsv, ",PARENS");
if (o->op_flags & OPf_STACKED)
sv_catpv(tmpsv, ",STACKED");
if (o->op_flags & OPf_REF)
sv_catpv(tmpsv, ",REF");
if (o->op_flags & OPf_MOD)
sv_catpv(tmpsv, ",MOD");
if (o->op_flags & OPf_SPECIAL)
sv_catpv(tmpsv, ",SPECIAL");
dump("FLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
SvREFCNT_dec(tmpsv);
}
if (o->op_private) {
SV *tmpsv = newSVpv("", 0);
if (o->op_type == OP_AASSIGN) {
if (o->op_private & OPpASSIGN_COMMON)
sv_catpv(tmpsv, ",COMMON");
}
else if (o->op_type == OP_SASSIGN) {
if (o->op_private & OPpASSIGN_BACKWARDS)
sv_catpv(tmpsv, ",BACKWARDS");
}
else if (o->op_type == OP_TRANS) {
if (o->op_private & OPpTRANS_SQUASH)
sv_catpv(tmpsv, ",SQUASH");
if (o->op_private & OPpTRANS_DELETE)
sv_catpv(tmpsv, ",DELETE");
if (o->op_private & OPpTRANS_COMPLEMENT)
sv_catpv(tmpsv, ",COMPLEMENT");
}
else if (o->op_type == OP_REPEAT) {
if (o->op_private & OPpREPEAT_DOLIST)
sv_catpv(tmpsv, ",DOLIST");
}
else if (o->op_type == OP_ENTERSUB ||
o->op_type == OP_RV2SV ||
o->op_type == OP_RV2AV ||
o->op_type == OP_RV2HV ||
o->op_type == OP_RV2GV ||
o->op_type == OP_AELEM ||
o->op_type == OP_HELEM )
{
if (o->op_type == OP_ENTERSUB) {
if (o->op_private & OPpENTERSUB_AMPER)
sv_catpv(tmpsv, ",AMPER");
if (o->op_private & OPpENTERSUB_DB)
sv_catpv(tmpsv, ",DB");
}
switch (o->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 (o->op_type == OP_AELEM || o->op_type == OP_HELEM) {
if (o->op_private & OPpLVAL_DEFER)
sv_catpv(tmpsv, ",LVAL_DEFER");
}
else {
if (o->op_private & HINT_STRICT_REFS)
sv_catpv(tmpsv, ",STRICT_REFS");
}
}
else if (o->op_type == OP_CONST) {
if (o->op_private & OPpCONST_BARE)
sv_catpv(tmpsv, ",BARE");
}
else if (o->op_type == OP_FLIP) {
if (o->op_private & OPpFLIP_LINENUM)
sv_catpv(tmpsv, ",LINENUM");
}
else if (o->op_type == OP_FLOP) {
if (o->op_private & OPpFLIP_LINENUM)
sv_catpv(tmpsv, ",LINENUM");
}
if (o->op_flags & OPf_MOD && o->op_private & OPpLVAL_INTRO)
sv_catpv(tmpsv, ",INTRO");
if (SvCUR(tmpsv))
dump("PRIVATE = (%s)\n", SvPVX(tmpsv) + 1);
SvREFCNT_dec(tmpsv);
}
switch (o->op_type) {
case OP_GVSV:
case OP_GV:
if (cGVOPo->op_gv) {
SV *tmpsv = NEWSV(0,0);
ENTER;
SAVEFREESV(tmpsv);
gv_fullname3(tmpsv, cGVOPo->op_gv, Nullch);
dump("GV = %s\n", SvPV(tmpsv, na));
LEAVE;
}
else
dump("GV = NULL\n");
break;
case OP_CONST:
dump("SV = %s\n", SvPEEK(cSVOPo->op_sv));
break;
case OP_NEXTSTATE:
case OP_DBSTATE:
if (cCOPo->cop_line)
dump("LINE = %d\n",cCOPo->cop_line);
if (cCOPo->cop_label)
dump("LABEL = \"%s\"\n",cCOPo->cop_label);
break;
case OP_ENTERLOOP:
dump("REDO ===> ");
if (cLOOPo->op_redoop)
PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_redoop->op_seq);
else
PerlIO_printf(Perl_debug_log, "DONE\n");
dump("NEXT ===> ");
if (cLOOPo->op_nextop)
PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_nextop->op_seq);
else
PerlIO_printf(Perl_debug_log, "DONE\n");
dump("LAST ===> ");
if (cLOOPo->op_lastop)
PerlIO_printf(Perl_debug_log, "%d\n", cLOOPo->op_lastop->op_seq);
else
PerlIO_printf(Perl_debug_log, "DONE\n");
break;
case OP_COND_EXPR:
dump("TRUE ===> ");
if (cCONDOPo->op_true)
PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_true->op_seq);
else
PerlIO_printf(Perl_debug_log, "DONE\n");
dump("FALSE ===> ");
if (cCONDOPo->op_false)
PerlIO_printf(Perl_debug_log, "%d\n", cCONDOPo->op_false->op_seq);
else
PerlIO_printf(Perl_debug_log, "DONE\n");
break;
case OP_MAPWHILE:
case OP_GREPWHILE:
case OP_OR:
case OP_AND:
dump("OTHER ===> ");
if (cLOGOPo->op_other)
PerlIO_printf(Perl_debug_log, "%d\n", cLOGOPo->op_other->op_seq);
else
PerlIO_printf(Perl_debug_log, "DONE\n");
break;
case OP_PUSHRE:
case OP_MATCH:
case OP_SUBST:
dump_pm(cPMOPo);
break;
default:
break;
}
if (o->op_flags & OPf_KIDS) {
OP *kid;
for (kid = cUNOPo->op_first; kid; kid = kid->op_sibling)
dump_op(kid);
}
dumplvl--;
dump("}\n");
#endif /* DEBUGGING */
}
void
dump_gv(GV *gv)
{
#ifdef DEBUGGING
SV *sv;
if (!gv) {
PerlIO_printf(Perl_debug_log, "{}\n");
return;
}
sv = sv_newmortal();
dumplvl++;
PerlIO_printf(Perl_debug_log, "{\n");
gv_fullname3(sv, gv, Nullch);
dump("GV_NAME = %s", SvPVX(sv));
if (gv != GvEGV(gv)) {
gv_efullname3(sv, GvEGV(gv), Nullch);
dump("-> %s", SvPVX(sv));
}
dump("\n");
dumplvl--;
dump("}\n");
#endif /* DEBUGGING */
}
void
dump_pm(PMOP *pm)
{
#ifdef DEBUGGING
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%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);
}
if (pm->op_pmflags || (pm->op_pmregexp && pm->op_pmregexp->check_substr)) {
SV *tmpsv = newSVpv("", 0);
if (pm->op_pmdynflags & PMdf_USED)
sv_catpv(tmpsv, ",USED");
if (pm->op_pmflags & PMf_ONCE)
sv_catpv(tmpsv, ",ONCE");
if (pm->op_pmregexp && pm->op_pmregexp->check_substr
&& !(pm->op_pmregexp->reganch & ROPT_NOSCAN))
sv_catpv(tmpsv, ",SCANFIRST");
if (pm->op_pmregexp && pm->op_pmregexp->check_substr
&& pm->op_pmregexp->reganch & ROPT_CHECK_ALL)
sv_catpv(tmpsv, ",ALL");
if (pm->op_pmflags & PMf_SKIPWHITE)
sv_catpv(tmpsv, ",SKIPWHITE");
if (pm->op_pmflags & PMf_CONST)
sv_catpv(tmpsv, ",CONST");
if (pm->op_pmflags & PMf_KEEP)
sv_catpv(tmpsv, ",KEEP");
if (pm->op_pmflags & PMf_GLOBAL)
sv_catpv(tmpsv, ",GLOBAL");
if (pm->op_pmflags & PMf_CONTINUE)
sv_catpv(tmpsv, ",CONTINUE");
if (pm->op_pmflags & PMf_TAINTMEM)
sv_catpv(tmpsv, ",TAINTMEM");
if (pm->op_pmflags & PMf_EVAL)
sv_catpv(tmpsv, ",EVAL");
dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : "");
SvREFCNT_dec(tmpsv);
}
dumplvl--;
dump("}\n");
#endif /* DEBUGGING */
}
#if !defined(I_STDARG) && !defined(I_VARARGS)
/* VARARGS1 */
static void dump(arg1,arg2,arg3,arg4,arg5)
char *arg1;
long arg2, arg3, arg4, arg5;
{
#ifdef DEBUGGING
I32 i;
for (i = dumplvl*4; i; i--)
(void)PerlIO_putc(Perl_debug_log,' ');
PerlIO_printf(Perl_debug_log, arg1, arg2, arg3, arg4, arg5);
#endif /* DEBUGGING */
}
#else
#ifdef I_STDARG
STATIC void
dump(char *pat,...)
#else
/*VARARGS0*/
static void
dump(pat,va_alist)
char *pat;
va_dcl
#endif
{
#ifdef DEBUGGING
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 /* DEBUGGING */
}
#endif
|