121628Sdist /*
238105Sbostic * Copyright (c) 1983 The Regents of the University of California.
338105Sbostic * All rights reserved.
438105Sbostic *
5*42683Sbostic * %sccs.include.redist.c%
621628Sdist */
712550Scsvaf
821628Sdist #ifndef lint
9*42683Sbostic static char sccsid[] = "@(#)debug.c 5.3 (Berkeley) 06/01/90";
1038105Sbostic #endif /* not lint */
1112550Scsvaf
1212550Scsvaf /*
1312550Scsvaf * Debug routines
1412550Scsvaf */
1512550Scsvaf
1612550Scsvaf #include "defs.h"
1712550Scsvaf #include "tree.h"
1812550Scsvaf #include "operators.h"
1912550Scsvaf #include "eval.h"
2012550Scsvaf #include "events.h"
2112550Scsvaf #include "symbols.h"
2212550Scsvaf #include "scanner.h"
2312550Scsvaf #include "source.h"
2412550Scsvaf #include "object.h"
2518216Slinton #include "main.h"
2612550Scsvaf #include "mappings.h"
2712550Scsvaf #include "process.h"
2812550Scsvaf #include "machine.h"
2918216Slinton #include "debug.h"
3012550Scsvaf #include <signal.h>
3112550Scsvaf
3218216Slinton public boolean tracetree; /* trace building of parse trees */
3318216Slinton public boolean traceeval; /* trace tree evaluation */
3412550Scsvaf
3518216Slinton /*
3618216Slinton * Dynamically turn on/off a debug flag, or display some information.
3718216Slinton */
3812550Scsvaf
debug(p)3918216Slinton public debug (p)
4012550Scsvaf Node p;
4112550Scsvaf {
4218216Slinton int code;
4312550Scsvaf
4418216Slinton code = p->value.lcon;
4518216Slinton switch (code) {
4618216Slinton case 0:
4718216Slinton puts("debugging flags:");
4818216Slinton puts(" 1 trace scanner return values");
4918216Slinton puts(" 2 trace breakpoints");
5018216Slinton puts(" 3 trace execution");
5118216Slinton puts(" 4 trace tree building");
5218216Slinton puts(" 5 trace tree evaluation");
5318216Slinton puts(" -[12345] turns off corresponding flag");
5418216Slinton puts(" 6 dump function table");
5518216Slinton break;
5612550Scsvaf
5718216Slinton case 1:
5818216Slinton case -1:
5918216Slinton # ifdef LEXDEBUG
6018216Slinton lexdebug = (boolean) (code > 0);
6118216Slinton # else
6218216Slinton error("can't debug scanner (not compiled with LEXDEBUG)");
6318216Slinton # endif
6418216Slinton break;
6512550Scsvaf
6618216Slinton case 2:
6718216Slinton case -2:
6818216Slinton tracebpts = (boolean) (code > 0);
6918216Slinton break;
7012550Scsvaf
7118216Slinton case 3:
7218216Slinton case -3:
7318216Slinton traceexec = (boolean) (code > 0);
7418216Slinton break;
7512550Scsvaf
7618216Slinton case 4:
7718216Slinton case -4:
7818216Slinton tracetree = (boolean) (code > 0);
7918216Slinton break;
8012550Scsvaf
8118216Slinton case 5:
8218216Slinton case -5:
8318216Slinton traceeval = (boolean) (code > 0);
8418216Slinton break;
8512550Scsvaf
8618216Slinton case 6:
8718216Slinton dumpfunctab();
8818216Slinton break;
8918216Slinton
9018216Slinton default:
9118216Slinton error("unknown debug flag");
9218216Slinton break;
9318216Slinton }
9412550Scsvaf }
9512550Scsvaf
9618216Slinton private String leafname[] = {
9718216Slinton "nop", "name", "sym", "lcon", "fcon", "scon", "rval", "index"
9818216Slinton };
9912550Scsvaf
opname(op)10018216Slinton public String opname (op)
10118216Slinton Operator op;
10212550Scsvaf {
10318216Slinton String s;
10418216Slinton static char buf[100];
10512550Scsvaf
10618216Slinton switch (op) {
10718216Slinton case O_ITOF:
10818216Slinton s = "itof";
10918216Slinton break;
11012550Scsvaf
11118216Slinton case O_ENDX:
11218216Slinton s = "endx";
11318216Slinton break;
11412550Scsvaf
11518216Slinton case O_QLINE:
11618216Slinton s = "qline";
11718216Slinton break;
11812550Scsvaf
11918216Slinton default:
12018216Slinton if (ord(op) <= ord(O_INDEX)) {
12118216Slinton s = leafname[ord(op)];
12218216Slinton } else {
12318216Slinton s = opinfo[ord(op)].opstring;
12418216Slinton if (s == nil) {
12518216Slinton sprintf(buf, "[op %d]", op);
12618216Slinton s = buf;
12712550Scsvaf }
12818216Slinton }
12918216Slinton break;
13012550Scsvaf }
13118216Slinton return s;
13212550Scsvaf }
133