1 /*
2 * Copyright (c) 1983 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)debug.c 5.3 (Berkeley) 06/01/90";
10 #endif /* not lint */
11
12 /*
13 * Debug routines
14 */
15
16 #include "defs.h"
17 #include "tree.h"
18 #include "operators.h"
19 #include "eval.h"
20 #include "events.h"
21 #include "symbols.h"
22 #include "scanner.h"
23 #include "source.h"
24 #include "object.h"
25 #include "main.h"
26 #include "mappings.h"
27 #include "process.h"
28 #include "machine.h"
29 #include "debug.h"
30 #include <signal.h>
31
32 public boolean tracetree; /* trace building of parse trees */
33 public boolean traceeval; /* trace tree evaluation */
34
35 /*
36 * Dynamically turn on/off a debug flag, or display some information.
37 */
38
debug(p)39 public debug (p)
40 Node p;
41 {
42 int code;
43
44 code = p->value.lcon;
45 switch (code) {
46 case 0:
47 puts("debugging flags:");
48 puts(" 1 trace scanner return values");
49 puts(" 2 trace breakpoints");
50 puts(" 3 trace execution");
51 puts(" 4 trace tree building");
52 puts(" 5 trace tree evaluation");
53 puts(" -[12345] turns off corresponding flag");
54 puts(" 6 dump function table");
55 break;
56
57 case 1:
58 case -1:
59 # ifdef LEXDEBUG
60 lexdebug = (boolean) (code > 0);
61 # else
62 error("can't debug scanner (not compiled with LEXDEBUG)");
63 # endif
64 break;
65
66 case 2:
67 case -2:
68 tracebpts = (boolean) (code > 0);
69 break;
70
71 case 3:
72 case -3:
73 traceexec = (boolean) (code > 0);
74 break;
75
76 case 4:
77 case -4:
78 tracetree = (boolean) (code > 0);
79 break;
80
81 case 5:
82 case -5:
83 traceeval = (boolean) (code > 0);
84 break;
85
86 case 6:
87 dumpfunctab();
88 break;
89
90 default:
91 error("unknown debug flag");
92 break;
93 }
94 }
95
96 private String leafname[] = {
97 "nop", "name", "sym", "lcon", "fcon", "scon", "rval", "index"
98 };
99
opname(op)100 public String opname (op)
101 Operator op;
102 {
103 String s;
104 static char buf[100];
105
106 switch (op) {
107 case O_ITOF:
108 s = "itof";
109 break;
110
111 case O_ENDX:
112 s = "endx";
113 break;
114
115 case O_QLINE:
116 s = "qline";
117 break;
118
119 default:
120 if (ord(op) <= ord(O_INDEX)) {
121 s = leafname[ord(op)];
122 } else {
123 s = opinfo[ord(op)].opstring;
124 if (s == nil) {
125 sprintf(buf, "[op %d]", op);
126 s = buf;
127 }
128 }
129 break;
130 }
131 return s;
132 }
133