Annotation of 42BSD/ucb/dbx/debug.c, revision 1.1

1.1     ! root        1: 
        !             2: /* Copyright (c) 1982 Regents of the University of California */
        !             3: 
        !             4: static char sccsid[] = "@(#)debug.c    1.3     5/18/83";
        !             5: 
        !             6: /*
        !             7:  *  Debug routines
        !             8:  */
        !             9: 
        !            10: #include "defs.h"
        !            11: #include "tree.h"
        !            12: #include "operators.h"
        !            13: #include "eval.h"
        !            14: #include "events.h"
        !            15: #include "symbols.h"
        !            16: #include "scanner.h"
        !            17: #include "source.h"
        !            18: #include "object.h"
        !            19: #include "mappings.h"
        !            20: #include "process.h"
        !            21: #include "machine.h"
        !            22: #include <signal.h>
        !            23: 
        !            24: 
        !            25: public int debug_flag[20];
        !            26: 
        !            27: public debug(p)
        !            28: Node p;
        !            29: {
        !            30:    int code;
        !            31:    code = p->value.lcon;
        !            32: 
        !            33:    if ( (code >= 0) and (code < 10) ) {
        !            34:        switch(code)  {
        !            35:        case 2:   if(debug_flag[2])  debug_flag[2]=0;
        !            36:                  else debug_flag[2] =1;
        !            37:                   printf(" flag 2 is %d \n",debug_flag[2]);
        !            38:                  break;
        !            39: 
        !            40:        case 3:   if(debug_flag[3])  debug_flag[3]=0;
        !            41:                  else debug_flag[3] =1;
        !            42:                   printf(" flag 3 is %d \n",debug_flag[3]);
        !            43:                  break;
        !            44: 
        !            45:        case 4:   if(debug_flag[4])  debug_flag[4]=0;
        !            46:                  else debug_flag[4] =1;
        !            47:                   printf(" flag 4 is %d \n",debug_flag[4]);
        !            48:                  break;
        !            49: 
        !            50:        case 5:   if(debug_flag[5])  debug_flag[5]=0;
        !            51:                  else debug_flag[5] =1;
        !            52:                   printf(" flag 5 is %d \n",debug_flag[5]);
        !            53:                  break;
        !            54: 
        !            55:        case 6:   dumpfunctab();
        !            56:                  break;
        !            57: 
        !            58:        default:  printf(" unknown debug code %ld \n",p->value.lcon);
        !            59:                   break;
        !            60:         }
        !            61:    }
        !            62:    else if (debug_flag[3]) symbol_dump(code);
        !            63:    else if (debug_flag[4]) psym(code);
        !            64: }
        !            65: 
        !            66: public char *showoperator(op)
        !            67: Operator op;
        !            68: {
        !            69: static char *operator_str[] = {
        !            70: "O_NOP", "O_NAME", "O_SYM", "O_LCON", "O_FCON", "O_SCON", "O_RVAL", "O_INDEX",
        !            71: "O_INDIR", "O_DOT", "O_COMMA", "O_ITOF", "O_ADD", "O_ADDF", "O_SUB", "O_SUBF",
        !            72: "O_NEG", "O_NEGF", "O_MUL", "O_MULF", "O_DIVF", "O_DIV", "O_MOD", "O_AND",
        !            73: "O_OR", "O_LT", "O_LTF", "O_LE", "O_LEF", "O_GT", "O_GTF", "O_GE", "O_GEF",
        !            74: "O_EQ", "O_EQF", "O_NE", "O_NEF", "O_ALIAS", "O_ASSIGN", "O_CALL", "O_CATCH",
        !            75: "O_CHFILE", "O_CONT", "O_DEBUG", "O_DELETE", "O_DUMP", "O_EDIT", "O_FUNC",
        !            76: "O_GRIPE", "O_HELP", "O_IGNORE", "O_LIST", "O_PRINT", "O_PSYM", "O_RUN",
        !            77: "O_SKIP", "O_SOURCE", "O_STATUS", "O_STEP", "O_STOP", "O_STOPI", "O_TRACE",
        !            78: "O_TRACEI", "O_WHATIS", "O_WHERE", "O_WHEREIS", "O_WHICH", "O_EXAMINE",
        !            79: "O_ADDEVENT", "O_ENDX", "O_IF", "O_ONCE", "O_PRINTCALL", "O_PRINTIFCHANGED",
        !            80: "O_PRINTRTN", "O_PRINTSRCPOS", "O_PROCRTN", "O_QLINE", "O_STOPIFCHANGED",
        !            81: "O_STOPX", "O_TRACEON", "O_TRACEOFF", "O_TYPERENAME", "O_LASTOP" };
        !            82: return( operator_str[ord(op)] );
        !            83: }
        !            84: 
        !            85: /*
        !            86:  * Dump a tree recursively
        !            87:  */
        !            88: 
        !            89: public dumptree(f, p)
        !            90: File f;
        !            91: register Node p;
        !            92: {
        !            93:     register Node q;
        !            94:     Operator op;
        !            95:     static recurse  =0;
        !            96:     ++recurse;
        !            97: 
        !            98:     if (p != nil) {
        !            99:        op = p->op;
        !           100:        if (ord(op) > ord(O_LASTOP)) {
        !           101:            panic("bad op %d in dumptree", p->op);
        !           102:        }
        !           103:         { int n_args;
        !           104:          fprintf(f, "\n level %d op %s node %ld ",recurse,showoperator(op), p);
        !           105:           for(n_args=0;n_args < nargs(op); n_args++) 
        !           106:             fprintf(f," arg%d %ld ",n_args,p->value.arg[n_args]);
        !           107:           fprintf(f,"\n");
        !           108:         }
        !           109:         if(p->nodetype) {fprintf(f,"nodetype: "); psym(p->nodetype);}
        !           110:        switch (op) {
        !           111:            case O_NAME:
        !           112:                fprintf(f, "%s", ident(p->value.name));
        !           113:                break;
        !           114: 
        !           115:            case O_SYM:
        !           116:                printname(f, p->value.sym);
        !           117:                break;
        !           118: 
        !           119:            case O_QLINE:
        !           120:                if (nlhdr.nfiles > 1) {
        !           121:                    dumptree(f, p->value.arg[0]);
        !           122:                    fprintf(f, ":");
        !           123:                }
        !           124:                dumptree(f, p->value.arg[1]);
        !           125:                break;
        !           126: 
        !           127:            case O_LCON:
        !           128:                if (compatible(p->nodetype, t_char)) {
        !           129:                    fprintf(f, "'%c'", p->value.lcon);
        !           130:                } else {
        !           131:                    fprintf(f, "%d", p->value.lcon);
        !           132:                }
        !           133:                break;
        !           134: 
        !           135:            case O_FCON:
        !           136:                fprintf(f, "%g", p->value.fcon);
        !           137:                break;
        !           138: 
        !           139:            case O_SCON:
        !           140:                fprintf(f, "\"%s\"", p->value.scon);
        !           141:                break;
        !           142: 
        !           143:            case O_INDEX:
        !           144:                dumptree(f, p->value.arg[0]);
        !           145:                fprintf(f, "[");
        !           146:                dumptree(f, p->value.arg[1]);
        !           147:                fprintf(f, "]");
        !           148:                break;
        !           149: 
        !           150:            case O_COMMA:
        !           151:                dumptree(f, p->value.arg[0]);
        !           152:                if (p->value.arg[1] != nil) {
        !           153:                    fprintf(f, ", ");
        !           154:                    dumptree(f, p->value.arg[1]);
        !           155:                }
        !           156:                break;
        !           157: 
        !           158:            case O_RVAL:
        !           159:                if (p->value.arg[0]->op == O_SYM) {
        !           160:                    printname(f, p->value.arg[0]->value.sym);
        !           161:                } else {
        !           162:                    dumptree(f, p->value.arg[0]);
        !           163:                }
        !           164:                break;
        !           165: 
        !           166:            case O_ITOF:
        !           167:                dumptree(f, p->value.arg[0]);
        !           168:                break;
        !           169: 
        !           170:            case O_CALL:
        !           171:                dumptree(f, p->value.arg[0]);
        !           172:                if (p->value.arg[1]!= nil) {
        !           173:                    fprintf(f, "(");
        !           174:                    dumptree(f, p->value.arg[1]);
        !           175:                    fprintf(f, ")");
        !           176:                }
        !           177:                break;
        !           178: 
        !           179:            case O_INDIR:
        !           180:                q = p->value.arg[0];
        !           181:                if (isvarparam(q->nodetype)) {
        !           182:                    dumptree(f, q);
        !           183:                } else {
        !           184:                    if (q->op == O_SYM or q->op == O_LCON or q->op == O_DOT) {
        !           185:                        dumptree(f, q);
        !           186:                        fprintf(f, "^");
        !           187:                    } else {
        !           188:                        fprintf(f, "*(");
        !           189:                        dumptree(f, q);
        !           190:                        fprintf(f, ")");
        !           191:                    }
        !           192:                }
        !           193:                break;
        !           194: 
        !           195:            case O_DOT:
        !           196:                q = p->value.arg[0];
        !           197:                if (q->op == O_INDIR) {
        !           198:                    dumptree(f, q->value.arg[0]);
        !           199:                } else {
        !           200:                    dumptree(f, q);
        !           201:                }
        !           202:                fprintf(f, ".%s", symname(p->value.arg[1]->value.sym));
        !           203:                break;
        !           204: 
        !           205:            default:
        !           206:                switch (degree(op)) {
        !           207:                    case BINARY:
        !           208:                        dumptree(f, p->value.arg[0]);
        !           209:                        fprintf(f, "%s", opinfo[ord(op)].opstring);
        !           210:                        dumptree(f, p->value.arg[1]);
        !           211:                        break;
        !           212: 
        !           213:                    case UNARY:
        !           214:                        fprintf(f, "%s", opinfo[ord(op)].opstring);
        !           215:                        dumptree(f, p->value.arg[0]);
        !           216:                        break;
        !           217: 
        !           218:                    default:
        !           219:                         if(degree(op) < ord(O_LASTOP) )
        !           220:                         {      int i;
        !           221:                                if( nargs(op)  != 0) 
        !           222:                                  for(i=0;i<nargs(op);i++) 
        !           223:                                   dumptree(f, p->value.arg[i]);
        !           224:                        } 
        !           225:                        else
        !           226:                           error("internal error: bad op %d in dumptree", op);
        !           227:                }
        !           228:                break;
        !           229:        }
        !           230:     }
        !           231:    recurse--;
        !           232:    fflush(f);
        !           233: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.