Annotation of coherent/b/bin/db_400/trace3.c, revision 1.1

1.1     ! root        1: /* $Header: /src386/bin/db/RCS/trace3.c,v 1.2 93/03/11 07:46:06 bin Exp Locker: bin $
        !             2:  *
        !             3:  *     The information contained herein is a trade secret of Mark Williams
        !             4:  *     Company, and  is confidential information.  It is provided  under a
        !             5:  *     license agreement,  and may be  copied or disclosed  only under the
        !             6:  *     terms of  that agreement.  Any  reproduction or disclosure  of this
        !             7:  *     material without the express written authorization of Mark Williams
        !             8:  *     Company or persuant to the license agreement is unlawful.
        !             9:  *
        !            10:  *     COHERENT Version 2.3.35
        !            11:  *     Copyright (c) 1982, 1983, 1984.
        !            12:  *     An unpublished work by Mark Williams Company, Chicago.
        !            13:  *     All rights reserved.
        !            14:  */
        !            15: /*
        !            16:  * A debugger.
        !            17:  * Display.
        !            18:  *
        !            19:  * $Log:       trace3.c,v $
        !            20:  * Revision 1.2  93/03/11  07:46:06  bin
        !            21:  * Hal: post NDP update that at least
        !            22:  * can st breakpoints.
        !            23:  * 
        !            24:  * Revision 1.1  92/06/10  14:36:59  bin
        !            25:  * Initial revision
        !            26:  * 
        !            27:  * Revision 1.1        88/10/17  04:05:31      src
        !            28:  * Initial revision
        !            29:  * 
        !            30:  *
        !            31:  * Revision: 386 version 92/05/01 
        !            32:  * Bernard Wald, Wald Software Consulting, Germany
        !            33:  *
        !            34:  */
        !            35: #include <stdio.h>
        !            36: #include <ctype.h>
        !            37: #include <l.out.h>
        !            38: #include "trace.h"
        !            39: 
        !            40: /*
        !            41:  * Execute a command string.
        !            42:  */
        !            43: execute(cp)
        !            44: char *cp;
        !            45: {
        !            46:        register INP *ip;
        !            47: 
        !            48:        /* Delete list starting at "inpp" */
        !            49:        while (ip=inpp) {
        !            50:                inpp = ip->i_st1.i_next;
        !            51:                nfree(ip);
        !            52:        }
        !            53: 
        !            54:        /* muck with some globals */
        !            55:        modsize = sizeof(int);
        !            56:        sincmod = SNULL;
        !            57:        dot = getpc();
        !            58:        lastc = '\0';
        !            59: 
        !            60:        /* put string "cp" in first node at "inpp" list */
        !            61:        if (cp) {
        !            62:                addstrp(cp);
        !            63:                request();
        !            64:        }
        !            65: 
        !            66:        /* print if interrupt occurred - mess with more globals */
        !            67:        testint();
        !            68: }
        !            69: 
        !            70: /*
        !            71:  * Parse requests and execute them.
        !            72:  */
        !            73: request(arg)
        !            74: {
        !            75:        register int c;
        !            76:        register char *cp;
        !            77:        register unsigned segn;
        !            78:        register long l;
        !            79:        register long d;
        !            80:        VAL val[VALSIZE];
        !            81: 
        !            82:        while ((c=getn()) != EOF) {
        !            83:                if (c == '!') {
        !            84:                        syscall();
        !            85:                        continue;
        !            86:                }
        !            87:                if (c == '?') {
        !            88:                        if ((c=getn()) != '\n') {
        !            89:                                printe("Syntax error");
        !            90:                                goto next;
        !            91:                        }
        !            92:                        if (errrstr == NULL)
        !            93:                                printx("No error\n");
        !            94:                        else
        !            95:                                printx("%s\n", errrstr);
        !            96:                        continue;
        !            97:                }
        !            98:                ungetn(c);
        !            99:                if (explist(val) == 0)
        !           100:                        goto next;
        !           101:                switch (c=getn()) {
        !           102:                case ':':
        !           103:                        sincmod = SNULL;
        !           104:                        if (command(val) == 0)
        !           105:                                return;
        !           106:                        continue;
        !           107:                case '\n':
        !           108:                        if (nvalue(&val[0]) && sincmod!=SNULL) {
        !           109:                                if (excflag == 0) {
        !           110:                                        sincmod = SNULL;
        !           111:                                        printe("Cannot single step");
        !           112:                                        continue;
        !           113:                                }
        !           114:                                sinmode = sincmod;
        !           115:                                sindecr = rvalue(&val[1], (long)1);
        !           116:                                return;
        !           117:                        }
        !           118:                case '=':
        !           119:                        ungetn(c);
        !           120:                case '?':
        !           121:                        sincmod = SNULL;
        !           122:                        segn = vsegno(&val[0], cseg);
        !           123:                        if ((c=getn()) == '=') {
        !           124:                                l = lvalue(&val[0], (long)dot);
        !           125:                                if ((c=getn()) == '\n') {
        !           126:                                        printx(DAFMT, l);
        !           127:                                        printx("\n");
        !           128:                                        continue;
        !           129:                                }
        !           130:                                ungetn(c);
        !           131:                                if (setdata(segn, l) == 0)
        !           132:                                        break;
        !           133:                                continue;
        !           134:                        }
        !           135:                        if (c != '\n') {
        !           136:                                cp = &segform[segn][0];
        !           137:                                while (c != '\n') {
        !           138:                                        *cp++ = c;
        !           139:                                        c = getn();
        !           140:                                }
        !           141:                                *cp++ = '\0';
        !           142:                        }
        !           143:                        d = dot;
        !           144:                        l = lad;
        !           145:                        dot = lvalue(&val[0], (long)lad);
        !           146:                        dispfmt(segn, segform[segn],
        !           147:                                (int)rvalue(&val[1], (long)1));
        !           148:                        if (segn != 2)
        !           149:                                cseg = segn;
        !           150:                        else {
        !           151:                                dot = d;
        !           152:                                lad = l;
        !           153:                        }
        !           154:                        continue;
        !           155:                default:
        !           156:                        sincmod = SNULL;
        !           157:                        printe("Syntax error");
        !           158:                        break;
        !           159:                }
        !           160:        next:
        !           161:                while ((c=getn()) != '\n')
        !           162:                        ;
        !           163:        }
        !           164: }
        !           165: 
        !           166: /*
        !           167:  * Change the value of a location.
        !           168:  */
        !           169: setdata(segn, a)
        !           170: long a;
        !           171: {
        !           172:        register char *cp;
        !           173:        register int n;
        !           174:        register int c;
        !           175:        char b[1];
        !           176:        char l3[3];
        !           177:        int i[1];
        !           178:        long l[1];
        !           179:        VAL val[VALSIZE];
        !           180: 
        !           181:        if (explist(val) == 0)
        !           182:                return (0);
        !           183:        if ((c=getn()) != '\n')
        !           184:                return (0);
        !           185:        for (n=0; n<VALSIZE; n++, a+=modsize) {
        !           186:                if (nvalue(&val[n]))
        !           187:                        continue;
        !           188:                l[0] = rvalue(&val[n], (long)0);
        !           189:                switch (modsize) {
        !           190:                case (sizeof(char)):
        !           191:                        b[0] = l[0];
        !           192:                        cp = b;
        !           193:                        break;
        !           194:                case (sizeof(short)):
        !           195:                        i[0] = l[0];
        !           196:                        cp = i;
        !           197:                        break;
        !           198:                case (sizeof(l3)):
        !           199:                        ltol3(l3, l, 1);
        !           200:                        cp = l3;
        !           201:                        break;
        !           202:                case (sizeof(long)):
        !           203:                        cp = l;
        !           204:                        break;
        !           205:                default:
        !           206:                        printe("Bad change type");
        !           207:                        return (1);
        !           208:                }
        !           209:                add = a;
        !           210:                if (putb(segn, cp, modsize) == 0) {
        !           211:                        printe("Cannot change value");
        !           212:                        return (1);
        !           213:                }
        !           214:        }
        !           215:        if (segn == 2)
        !           216:                setregs();
        !           217:        return (1);
        !           218: }
        !           219: 
        !           220: /*
        !           221:  * Send a command to the shell.
        !           222:  */
        !           223: syscall()
        !           224: {
        !           225:        register int c;
        !           226:        register char *cp;
        !           227: 
        !           228:        cp = miscbuf;
        !           229:        while ((c=getn()) != '\n')
        !           230:                *cp++ = c;
        !           231:        *cp++ = '\0';
        !           232:        system(miscbuf);
        !           233:        testint();
        !           234:        printf("!\n");
        !           235: }
        !           236: 
        !           237: /*
        !           238:  * Print out data according to a format string.  `n' is the number
        !           239:  * of times this is done.  Segment number is 's'.
        !           240:  */
        !           241: dispfmt(s, fs, n)
        !           242: char *fs;
        !           243: {
        !           244:        register char *sp1;
        !           245:        register char *sp2;
        !           246:        register int c;
        !           247:        register int r;
        !           248:        register int t1;
        !           249:        register int t2;
        !           250:        register char *sp3;
        !           251:        register char *fp;
        !           252:        register long nad;
        !           253:        register long pad;
        !           254:        register long uad;
        !           255: 
        !           256:        r = 1;
        !           257:        t2 = '\0';
        !           258:        add = dot;
        !           259:        nad = dot;
        !           260:        pad = dot;
        !           261:        uad = dot;
        !           262:        sp1 = miscbuf;
        !           263:        sp3 = &sp1[DISSIZE];
        !           264:        while (n--) {
        !           265:                fp = fs;
        !           266:                for (;;) {
        !           267:                        c = *fp++;
        !           268:                        if (isascii(c) && isdigit(c)) {
        !           269:                                r = 0;
        !           270:                                do {
        !           271:                                        r = r*10 + c-'0';
        !           272:                                        c = *fp++;
        !           273:                                } while (isascii(c) && isdigit(c));
        !           274:                                --fp;
        !           275:                                continue;
        !           276:                        }
        !           277:                        switch (c) {
        !           278:                        case '^':
        !           279:                                add = uad;
        !           280:                                continue;
        !           281:                        case '+':
        !           282:                                add += r;
        !           283:                                r = 1;
        !           284:                                continue;
        !           285:                        case '-':
        !           286:                                add -= r;
        !           287:                                r = 1;
        !           288:                                continue;
        !           289:                        case 'n':
        !           290:                                *sp1 = '\0';
        !           291:                                flushb((long)nad);
        !           292:                                sp1 = miscbuf;
        !           293:                                nad = add;
        !           294:                                continue;
        !           295:                        case 'd':
        !           296:                        case 'o':
        !           297:                        case 'u':
        !           298:                        case 'x':
        !           299:                                t2 = c;
        !           300:                                continue;
        !           301:                        default:
        !           302:                                t1 = c;
        !           303:                                if (t1=='\0' && t2=='\0')
        !           304:                                        break;
        !           305:                                if (t1 == '\0')
        !           306:                                        t1 = 'w';
        !           307:                                if (t2 == '\0')
        !           308:                                        t2 = DDCHR;
        !           309:                                uad = add;
        !           310:                                while (r--) {
        !           311:                                        if (testint())
        !           312:                                                return (1);
        !           313:                                        *sp1++ = ' ';
        !           314:                                        pad = add;
        !           315:                                        sp2 = conform(sp1, s, t1, t2, getb);
        !           316:                                        if (sp2 == NULL) {
        !           317:                                                *--sp1 = '\0';
        !           318:                                                if (sp1 != miscbuf)
        !           319:                                                        flushb((long)nad);
        !           320:                                                printe("Addressing error");
        !           321:                                                return (0);
        !           322:                                        }
        !           323:                                        if (sp2 <= sp3)
        !           324:                                                sp1 = sp2;
        !           325:                                        else {
        !           326:                                                *--sp1 = '\0';
        !           327:                                                flushb((long)nad);
        !           328:                                                *sp2 = '\0';
        !           329:                                                *sp1 = ' ';
        !           330:                                                sp2 = sp1;
        !           331:                                                sp1 = miscbuf;
        !           332:                                                while (*sp2)
        !           333:                                                        *sp1++ = *sp2++;
        !           334:                                                nad = pad;
        !           335:                                        }
        !           336:                                        if (c == 'i') {
        !           337:                                                *sp1++ = '\0';
        !           338:                                                flushb((long)nad);
        !           339:                                                sp1 = miscbuf;
        !           340:                                                nad = add;
        !           341:                                        }
        !           342:                                }
        !           343:                                r = 1;
        !           344:                                t2 = '\0';
        !           345:                                if (c != '\0')
        !           346:                                        continue;
        !           347:                        }
        !           348:                        break;
        !           349:                }
        !           350:                lad = add;
        !           351:        }
        !           352:        if (sp1 != miscbuf) {
        !           353:                *sp1 = '\0';
        !           354:                flushb((long)nad);
        !           355:        }
        !           356:        return (1);
        !           357: }
        !           358: 
        !           359: /*
        !           360:  * Flush the output buffer.  The given address `a' is printed before the
        !           361:  * contents of the buffer and dot is set to it.
        !           362:  */
        !           363: flushb(a)
        !           364: long a;
        !           365: {
        !           366:        dot = a;
        !           367:        printx(DAFMT, (long)dot);
        !           368:        printx("  %s\n", miscbuf);
        !           369: }
        !           370: 
        !           371: /*
        !           372:  * Given a format character `f' and a function `func', print out
        !           373:  * data according to the given format.  The function `get' is
        !           374:  * called to read characters.  Segment number is 's'.
        !           375:  */
        !           376: char *
        !           377: conform(sp, s, t1, t2, get)
        !           378: register char *sp;
        !           379: int (*get)();
        !           380: {
        !           381:        register char *lp;
        !           382:        unsigned char c[1];
        !           383:        unsigned char v[3];
        !           384:        unsigned short h[1];
        !           385:        char *p[1];
        !           386:        int  i[1];
        !           387:        long l[1];
        !           388: #ifndef        NFP
        !           389:        float f[1];
        !           390:        double d[1];
        !           391: #endif
        !           392:        switch (t1) {
        !           393:        case 'b':
        !           394:                if ((*get)(s, c, sizeof(c)) == 0)
        !           395:                        return (NULL);
        !           396:                modsize = sizeof(c);
        !           397: 
        !           398:                /*
        !           399:                 * There should be a better way to do this.
        !           400:                 */
        !           401:                if (t2 != 'd')
        !           402:                        i[0] = c[0];
        !           403:                else {
        !           404:                        char x[1];
        !           405: 
        !           406:                        x[0] = c[0];
        !           407:                        i[0] = x[0];
        !           408:                }
        !           409:                sprintf(sp, getform(t1, t2), i[0]);
        !           410:                break;
        !           411:        case 'c':
        !           412:                if ((*get)(s, c, sizeof(c)) == 0)
        !           413:                        return (NULL);
        !           414:                modsize = sizeof(c);
        !           415:                sp = conescs(sp, c[0]);
        !           416:                return (sp);
        !           417:        case 'C':
        !           418:                if ((*get)(s, c, sizeof(c)) == 0)
        !           419:                        return (NULL);
        !           420:                modsize = sizeof(c);
        !           421:                *sp++ = (c[0]>=040&&c[0]<0177) ? c[0] : '.';
        !           422:                return (sp);
        !           423: #ifndef        NFP
        !           424:        case 'f':
        !           425:                if ((*get)(s, (char *)f, sizeof(f)) == 0)
        !           426:                        return (NULL);
        !           427:                modsize = sizeof(f);
        !           428:                sprintf(sp, getform(t1, t2), f[0]);
        !           429:                break;
        !           430:        case 'F':
        !           431:                if ((*get)(s, (char *)d, sizeof(d)) == 0)
        !           432:                        return (NULL);
        !           433:                modsize = sizeof(d);
        !           434:                sprintf(sp, getform(t1, t2), d[0]);
        !           435:                break;
        !           436: #endif
        !           437:        case 'h':
        !           438:                if ((*get)(s, h, sizeof(h)) == 0)
        !           439:                        return (NULL);
        !           440:                modsize = sizeof(h);
        !           441: 
        !           442:                /*
        !           443:                 * Oh well.
        !           444:                 */
        !           445:                if (t2 != 'd')
        !           446:                        i[0] = h[0];
        !           447:                else {
        !           448:                        short x[1];
        !           449: 
        !           450:                        x[0] = h[0];
        !           451:                        i[0] = x[0];
        !           452:                }
        !           453:                sprintf(sp, getform(t1, t2), i[0]);
        !           454:                break;
        !           455:        case 'i':
        !           456:                sp = newconinst(sp, s);
        !           457:                modsize = INLEN;
        !           458:                return (sp);
        !           459:        case 'l':
        !           460:                if ((*get)(s, (char *)l, sizeof(l)) == 0)
        !           461:                        return (NULL);
        !           462:                modsize = sizeof(l);
        !           463:                sprintf(sp, getform(t1, t2), l[0]);
        !           464:                break;
        !           465:        case 'p':
        !           466:                if ((*get)(s, (char *)p, sizeof(p)) == 0)
        !           467:                        return (NULL);
        !           468:                modsize = sizeof(p);
        !           469:                sp = conaddr(sp, 0, (long)p[0], I);
        !           470:                return (sp);
        !           471:        case 's':
        !           472:        case 'S':
        !           473:                lp = &sp[DISSIZE];
        !           474:                c[0] = '\0';
        !           475:                for (;;) {
        !           476:                        if ((*get)(s, c, sizeof(c)) == 0)
        !           477:                                return (NULL);
        !           478:                        if (c[0] == '\0')
        !           479:                                break;
        !           480:                        if (t1 == 's')
        !           481:                                sp = conescs(sp, c[0]);
        !           482:                        else
        !           483:                                *sp++ = c[0];
        !           484:                        if (sp > lp)
        !           485:                                return (NULL);
        !           486:                }
        !           487:                modsize = sizeof(i);
        !           488:                return (sp);
        !           489:        case 'v':
        !           490:                if ((*get)(s, (char *)v, sizeof(v)) == 0)
        !           491:                        return (NULL);
        !           492:                modsize = sizeof(v);
        !           493:                l3tol(l, v, 1);
        !           494:                sprintf(sp, getform(t1, t2), l[0]);
        !           495:                break;
        !           496:        case 'w':
        !           497:                if ((*get)(s, (char *)i, hdrinfo.magic == L_MAGIC 
        !           498:                                        ? sizeof(short) : sizeof(int)) == 0)
        !           499:                        return (NULL);
        !           500:                modsize = hdrinfo.magic == L_MAGIC 
        !           501:                                        ? sizeof(short) : sizeof(int);
        !           502:                sprintf(sp, getform(t1, t2), hdrinfo.magic == L_MAGIC 
        !           503:                                        ? (unsigned short)i[0] : i[0]);
        !           504:                break;
        !           505:        case 'Y':
        !           506:                sp = gettime(sp, cseg, get);
        !           507:                modsize = sizeof(i);
        !           508:                return (sp);
        !           509:        default:
        !           510:                return (NULL);
        !           511:        }
        !           512:        while (*sp)
        !           513:                sp++;
        !           514:        return (sp);
        !           515: }
        !           516: 
        !           517: /*
        !           518:  * If the given character is unprintable, convert it into
        !           519:  * an escape sequence.
        !           520:  */
        !           521: conescs(sp, c)
        !           522: register char *sp;
        !           523: register int c;
        !           524: {
        !           525:        *sp++ = '\\';
        !           526:        switch (c) {
        !           527:        case '\0':
        !           528:                *sp++ = '0';
        !           529:                break;
        !           530:        case '\b':
        !           531:                *sp++ = 'b';
        !           532:                break;
        !           533:        case '\n':
        !           534:                *sp++ = 'n';
        !           535:                break;
        !           536:        case '\f':
        !           537:                *sp++ = 'f';
        !           538:                break;
        !           539:        case '\r':
        !           540:                *sp++ = 'r';
        !           541:                break;
        !           542:        case '\\':
        !           543:                *sp++ = '\\';
        !           544:                break;
        !           545:        default:
        !           546:                if (c<040 || c>=0177) {
        !           547:                        sprintf(sp, "%03o", c);
        !           548:                        while (*sp)
        !           549:                                sp++;
        !           550:                        break;
        !           551:                }
        !           552:                sp[-1] = c;
        !           553:        }
        !           554:        return (sp);
        !           555: }
        !           556: 
        !           557: /*
        !           558:  * Get the current time.
        !           559:  */
        !           560: char *
        !           561: gettime(sp, s, get)
        !           562: register char *sp;
        !           563: int (*get)();
        !           564: {
        !           565:        long l;
        !           566:        register int n;
        !           567:        register char *cp;
        !           568: 
        !           569:        if ((*get)(s, (char *) &l, sizeof(l)) == 0)
        !           570:                return (NULL);
        !           571:        cp = ctime(&l);
        !           572:        n = 24;
        !           573:        do {
        !           574:                *sp++ = *cp++;
        !           575:        } while (--n);
        !           576:        return (sp);
        !           577: }

unix.superglobalmegacorp.com

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