1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)debug.c 5.2 (Berkeley) 05/23/89"; 20 #endif /* not lint */ 21 22 /* 23 * Debug routines 24 */ 25 26 #include "defs.h" 27 #include "tree.h" 28 #include "operators.h" 29 #include "eval.h" 30 #include "events.h" 31 #include "symbols.h" 32 #include "scanner.h" 33 #include "source.h" 34 #include "object.h" 35 #include "main.h" 36 #include "mappings.h" 37 #include "process.h" 38 #include "machine.h" 39 #include "debug.h" 40 #include <signal.h> 41 42 public boolean tracetree; /* trace building of parse trees */ 43 public boolean traceeval; /* trace tree evaluation */ 44 45 /* 46 * Dynamically turn on/off a debug flag, or display some information. 47 */ 48 49 public debug (p) 50 Node p; 51 { 52 int code; 53 54 code = p->value.lcon; 55 switch (code) { 56 case 0: 57 puts("debugging flags:"); 58 puts(" 1 trace scanner return values"); 59 puts(" 2 trace breakpoints"); 60 puts(" 3 trace execution"); 61 puts(" 4 trace tree building"); 62 puts(" 5 trace tree evaluation"); 63 puts(" -[12345] turns off corresponding flag"); 64 puts(" 6 dump function table"); 65 break; 66 67 case 1: 68 case -1: 69 # ifdef LEXDEBUG 70 lexdebug = (boolean) (code > 0); 71 # else 72 error("can't debug scanner (not compiled with LEXDEBUG)"); 73 # endif 74 break; 75 76 case 2: 77 case -2: 78 tracebpts = (boolean) (code > 0); 79 break; 80 81 case 3: 82 case -3: 83 traceexec = (boolean) (code > 0); 84 break; 85 86 case 4: 87 case -4: 88 tracetree = (boolean) (code > 0); 89 break; 90 91 case 5: 92 case -5: 93 traceeval = (boolean) (code > 0); 94 break; 95 96 case 6: 97 dumpfunctab(); 98 break; 99 100 default: 101 error("unknown debug flag"); 102 break; 103 } 104 } 105 106 private String leafname[] = { 107 "nop", "name", "sym", "lcon", "fcon", "scon", "rval", "index" 108 }; 109 110 public String opname (op) 111 Operator op; 112 { 113 String s; 114 static char buf[100]; 115 116 switch (op) { 117 case O_ITOF: 118 s = "itof"; 119 break; 120 121 case O_ENDX: 122 s = "endx"; 123 break; 124 125 case O_QLINE: 126 s = "qline"; 127 break; 128 129 default: 130 if (ord(op) <= ord(O_INDEX)) { 131 s = leafname[ord(op)]; 132 } else { 133 s = opinfo[ord(op)].opstring; 134 if (s == nil) { 135 sprintf(buf, "[op %d]", op); 136 s = buf; 137 } 138 } 139 break; 140 } 141 return s; 142 } 143