Start merge with maint-5.004 branch by creating an ancestral
[p5sagit/p5-mst-13.2.git] / run.c
1 /*    run.c
2  *
3  *    Copyright (c) 1991-1997, Larry Wall
4  *
5  *    You may distribute under the terms of either the GNU General Public
6  *    License or the Artistic License, as specified in the README file.
7  *
8  */
9
10 #include "EXTERN.h"
11 #include "perl.h"
12
13 /*
14  * "Away now, Shadowfax!  Run, greatheart, run as you have never run before!
15  * Now we are come to the lands where you were foaled, and every stone you
16  * know.  Run now!  Hope is in speed!"  --Gandalf
17  */
18
19 dEXT char **watchaddr = 0;
20 dEXT char *watchok;
21
22 #ifndef DEBUGGING
23
24 int
25 runops() {
26     dTHR;
27     SAVEI32(runlevel);
28     runlevel++;
29
30     while ( op = (*op->op_ppaddr)(ARGS) ) ;
31
32     TAINT_NOT;
33     return 0;
34 }
35
36 #else
37
38 static void debprof _((OP*o));
39
40 int
41 runops() {
42     dTHR;
43     if (!op) {
44         warn("NULL OP IN RUN");
45         return 0;
46     }
47
48     SAVEI32(runlevel);
49     runlevel++;
50
51     do {
52         if (debug) {
53             if (watchaddr != 0 && *watchaddr != watchok)
54                 PerlIO_printf(Perl_debug_log, "WARNING: %lx changed from %lx to %lx\n",
55                     (long)watchaddr, (long)watchok, (long)*watchaddr);
56             DEBUG_s(debstack());
57             DEBUG_t(debop(op));
58             DEBUG_P(debprof(op));
59         }
60     } while ( op = (*op->op_ppaddr)(ARGS) );
61
62     TAINT_NOT;
63     return 0;
64 }
65
66 I32
67 debop(o)
68 OP *o;
69 {
70     SV *sv;
71     deb("%s", op_name[o->op_type]);
72     switch (o->op_type) {
73     case OP_CONST:
74         PerlIO_printf(Perl_debug_log, "(%s)", SvPEEK(cSVOPo->op_sv));
75         break;
76     case OP_GVSV:
77     case OP_GV:
78         if (cGVOPo->op_gv) {
79             sv = NEWSV(0,0);
80             gv_fullname3(sv, cGVOPo->op_gv, Nullch);
81             PerlIO_printf(Perl_debug_log, "(%s)", SvPV(sv, na));
82             SvREFCNT_dec(sv);
83         }
84         else
85             PerlIO_printf(Perl_debug_log, "(NULL)");
86         break;
87     default:
88         break;
89     }
90     PerlIO_printf(Perl_debug_log, "\n");
91     return 0;
92 }
93
94 void
95 watch(addr)
96 char **addr;
97 {
98     watchaddr = addr;
99     watchok = *addr;
100     PerlIO_printf(Perl_debug_log, "WATCHING, %lx is currently %lx\n",
101         (long)watchaddr, (long)watchok);
102 }
103
104 static void
105 debprof(o)
106 OP* o;
107 {
108     if (!profiledata)
109         New(000, profiledata, MAXO, U32);
110     ++profiledata[o->op_type];
111 }
112
113 void
114 debprofdump()
115 {
116     unsigned i;
117     if (!profiledata)
118         return;
119     for (i = 0; i < MAXO; i++) {
120         if (profiledata[i])
121             PerlIO_printf(Perl_debug_log,
122                           "%u\t%lu\n", i, (unsigned long)profiledata[i]);
123     }
124 }
125
126 #endif
127