121628Sdist /* 2*38105Sbostic * Copyright (c) 1983 The Regents of the University of California. 3*38105Sbostic * All rights reserved. 4*38105Sbostic * 5*38105Sbostic * Redistribution and use in source and binary forms are permitted 6*38105Sbostic * provided that the above copyright notice and this paragraph are 7*38105Sbostic * duplicated in all such forms and that any documentation, 8*38105Sbostic * advertising materials, and other materials related to such 9*38105Sbostic * distribution and use acknowledge that the software was developed 10*38105Sbostic * by the University of California, Berkeley. The name of the 11*38105Sbostic * University may not be used to endorse or promote products derived 12*38105Sbostic * from this software without specific prior written permission. 13*38105Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*38105Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*38105Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1621628Sdist */ 1712550Scsvaf 1821628Sdist #ifndef lint 19*38105Sbostic static char sccsid[] = "@(#)debug.c 5.2 (Berkeley) 05/23/89"; 20*38105Sbostic #endif /* not lint */ 2112550Scsvaf 2212550Scsvaf /* 2312550Scsvaf * Debug routines 2412550Scsvaf */ 2512550Scsvaf 2612550Scsvaf #include "defs.h" 2712550Scsvaf #include "tree.h" 2812550Scsvaf #include "operators.h" 2912550Scsvaf #include "eval.h" 3012550Scsvaf #include "events.h" 3112550Scsvaf #include "symbols.h" 3212550Scsvaf #include "scanner.h" 3312550Scsvaf #include "source.h" 3412550Scsvaf #include "object.h" 3518216Slinton #include "main.h" 3612550Scsvaf #include "mappings.h" 3712550Scsvaf #include "process.h" 3812550Scsvaf #include "machine.h" 3918216Slinton #include "debug.h" 4012550Scsvaf #include <signal.h> 4112550Scsvaf 4218216Slinton public boolean tracetree; /* trace building of parse trees */ 4318216Slinton public boolean traceeval; /* trace tree evaluation */ 4412550Scsvaf 4518216Slinton /* 4618216Slinton * Dynamically turn on/off a debug flag, or display some information. 4718216Slinton */ 4812550Scsvaf 4918216Slinton public debug (p) 5012550Scsvaf Node p; 5112550Scsvaf { 5218216Slinton int code; 5312550Scsvaf 5418216Slinton code = p->value.lcon; 5518216Slinton switch (code) { 5618216Slinton case 0: 5718216Slinton puts("debugging flags:"); 5818216Slinton puts(" 1 trace scanner return values"); 5918216Slinton puts(" 2 trace breakpoints"); 6018216Slinton puts(" 3 trace execution"); 6118216Slinton puts(" 4 trace tree building"); 6218216Slinton puts(" 5 trace tree evaluation"); 6318216Slinton puts(" -[12345] turns off corresponding flag"); 6418216Slinton puts(" 6 dump function table"); 6518216Slinton break; 6612550Scsvaf 6718216Slinton case 1: 6818216Slinton case -1: 6918216Slinton # ifdef LEXDEBUG 7018216Slinton lexdebug = (boolean) (code > 0); 7118216Slinton # else 7218216Slinton error("can't debug scanner (not compiled with LEXDEBUG)"); 7318216Slinton # endif 7418216Slinton break; 7512550Scsvaf 7618216Slinton case 2: 7718216Slinton case -2: 7818216Slinton tracebpts = (boolean) (code > 0); 7918216Slinton break; 8012550Scsvaf 8118216Slinton case 3: 8218216Slinton case -3: 8318216Slinton traceexec = (boolean) (code > 0); 8418216Slinton break; 8512550Scsvaf 8618216Slinton case 4: 8718216Slinton case -4: 8818216Slinton tracetree = (boolean) (code > 0); 8918216Slinton break; 9012550Scsvaf 9118216Slinton case 5: 9218216Slinton case -5: 9318216Slinton traceeval = (boolean) (code > 0); 9418216Slinton break; 9512550Scsvaf 9618216Slinton case 6: 9718216Slinton dumpfunctab(); 9818216Slinton break; 9918216Slinton 10018216Slinton default: 10118216Slinton error("unknown debug flag"); 10218216Slinton break; 10318216Slinton } 10412550Scsvaf } 10512550Scsvaf 10618216Slinton private String leafname[] = { 10718216Slinton "nop", "name", "sym", "lcon", "fcon", "scon", "rval", "index" 10818216Slinton }; 10912550Scsvaf 11018216Slinton public String opname (op) 11118216Slinton Operator op; 11212550Scsvaf { 11318216Slinton String s; 11418216Slinton static char buf[100]; 11512550Scsvaf 11618216Slinton switch (op) { 11718216Slinton case O_ITOF: 11818216Slinton s = "itof"; 11918216Slinton break; 12012550Scsvaf 12118216Slinton case O_ENDX: 12218216Slinton s = "endx"; 12318216Slinton break; 12412550Scsvaf 12518216Slinton case O_QLINE: 12618216Slinton s = "qline"; 12718216Slinton break; 12812550Scsvaf 12918216Slinton default: 13018216Slinton if (ord(op) <= ord(O_INDEX)) { 13118216Slinton s = leafname[ord(op)]; 13218216Slinton } else { 13318216Slinton s = opinfo[ord(op)].opstring; 13418216Slinton if (s == nil) { 13518216Slinton sprintf(buf, "[op %d]", op); 13618216Slinton s = buf; 13712550Scsvaf } 13818216Slinton } 13918216Slinton break; 14012550Scsvaf } 14118216Slinton return s; 14212550Scsvaf } 143