X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/ffa66ed0d94d8fecaa2df218c279e88127f93da7..994e0ed0541fe0d586276964067173c7d6f1dc7d:/usr/src/old/dbx/printsym.c diff --git a/usr/src/old/dbx/printsym.c b/usr/src/old/dbx/printsym.c index b37d0348f1..3bf953132e 100644 --- a/usr/src/old/dbx/printsym.c +++ b/usr/src/old/dbx/printsym.c @@ -1,6 +1,14 @@ -/* Copyright (c) 1982 Regents of the University of California */ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#ifndef lint +static char sccsid[] = "@(#)printsym.c 5.5 (Berkeley) %G%"; +#endif not lint -static char sccsid[] = "@(#)printsym.c 1.12 %G%"; +static char rcsid[] = "$Header: printsym.c,v 1.4 87/04/15 00:23:35 donn Exp $"; /* * Printing of symbolic information. @@ -17,7 +25,9 @@ static char sccsid[] = "@(#)printsym.c 1.12 %G%"; #include "runtime.h" #include "machine.h" #include "names.h" +#include "keywords.h" #include "main.h" +#include #ifndef public #endif @@ -37,11 +47,12 @@ static char sccsid[] = "@(#)printsym.c 1.12 %G%"; */ private String clname[] = { - "bad use", "constant", "type", "variable", "array", "fileptr", - "record", "field", "procedure", "function", "funcvar", + "bad use", "constant", "type", "variable", "array", "array", + "dynarray", "subarray", "fileptr", "record", "field", + "procedure", "function", "funcvar", "ref", "pointer", "file", "set", "range", "label", "withptr", "scalar", "string", "program", "improper", "variant", - "procparam", "funcparam", "module", "tag", "common", "typeref" + "procparam", "funcparam", "module", "tag", "common", "extref", "typeref" }; public String classname(s) @@ -58,7 +69,9 @@ public printentry(s) Symbol s; { if (s != program) { - printf("\nentering %s %s\n", classname(s), symname(s)); + printf("\nentering %s ", classname(s)); + printname(stdout, s); + printf("\n"); } } @@ -70,7 +83,9 @@ public printexit(s) Symbol s; { if (s != program) { - printf("leaving %s %s\n\n", classname(s), symname(s)); + printf("leaving %s ", classname(s)); + printname(stdout, s); + printf("\n\n"); } } @@ -81,9 +96,12 @@ Symbol s; public printcall(s, t) Symbol s, t; { - printf("calling %s", symname(s)); + printf("calling "); + printname(stdout, s); printparams(s, nil); - printf(" from %s %s\n", classname(t), symname(t)); + printf(" from %s ", classname(t)); + printname(stdout, t); + printf("\n"); } /* @@ -112,12 +130,17 @@ Symbol s; printf("(value too large) "); } } - printf("from %s\n", symname(s)); + printf("from "); + printname(stdout, s); + printf("\n"); } /* * Print the values of the parameters of the given procedure or function. * The frame distinguishes recursive instances of a procedure. + * + * If the procedure or function is internal, the argument count is + * not valid so we ignore it. */ public printparams(f, frame) @@ -128,18 +151,25 @@ Frame frame; int n, m, s; n = nargspassed(frame); + if (isinternal(f)) { + n = 0; + } + printf("("); param = f->chain; if (param != nil or n > 0) { - printf("("); m = n; if (param != nil) { for (;;) { - s = size(param) div sizeof(Word); + s = psize(param) div sizeof(Word); if (s == 0) { s = 1; } m -= s; - printv(param, frame); + if (showaggrs) { + printv(param, frame); + } else { + printparamv(param, frame); + } param = param->chain; if (param == nil) break; printf(", "); @@ -159,8 +189,8 @@ Frame frame; printf(", "); } } - printf(")"); } + printf(")"); } /* @@ -207,6 +237,43 @@ Symbol s; return b; } +/* + * Print out a parameter value. + * + * Since this is intended to be printed on a single line with other information + * aggregate values are not printed. + */ + +public printparamv (p, frame) +Symbol p; +Frame frame; +{ + Symbol t; + + t = rtype(p->type); + switch (t->class) { + case ARRAY: + case OPENARRAY: + case DYNARRAY: + case SUBARRAY: + t = rtype(t->type); + if (compatible(t, t_char)) { + printv(p, frame); + } else { + printf("%s = (...)", symname(p)); + } + break; + + case RECORD: + printf("%s = (...)", symname(p)); + break; + + default: + printv(p, frame); + break; + } +} + /* * Print the name and value of a variable. */ @@ -224,24 +291,22 @@ Frame frame; } else { printf("%s = ", symname(s)); } - if(s->type->class == ARRAY && (! istypename(s->type->type,"char")) ) { - printf(" ARRAY "); + if (isvarparam(s) and not isopenarray(s)) { + rpush(address(s, frame), sizeof(Address)); + addr = pop(Address); } else { - if (isvarparam(s)) { - rpush(address(s, frame), sizeof(Address)); - addr = pop(Address); - len = size(s->type); - } else { - addr = address(s, frame); - len = size(s); - } - if (canpush(len)) { - rpush(addr, len); - printval(s->type); - } else { - printf("*** expression too large ***"); - } - } + addr = address(s, frame); + } + len = size(s); + if (not canpush(len)) { + printf("*** expression too large ***"); + } else if (isreg(s)) { + push(Address, addr); + printval(s->type); + } else { + rpush(addr, len); + printval(s->type); + } } /* @@ -254,6 +319,8 @@ Symbol s; { if (s == nil) { fprintf(f, "(noname)"); + } else if (s == program) { + fprintf(f, "."); } else if (isredirected() or isambiguous(s)) { printwhich(f, s); } else { @@ -318,8 +385,15 @@ Symbol s; public printdecl(s) Symbol s; { + Language lang; + checkref(s); - (*language_op(s->language, L_PRINTDECL))(s); + if (s->language == nil or s->language == primlang) { + lang = findlanguage(".s"); + } else { + lang = s->language; + } + (*language_op(lang, L_PRINTDECL))(s); } /* @@ -342,19 +416,31 @@ Symbol s; printf(" (%s)", symname(s->chain)); } printf("\nblock\t0x%x", s->block); - if (s->block->name != nil) { + if (s->block != nil and s->block->name != nil) { printf(" ("); printname(stdout, s->block); putchar(')'); } putchar('\n'); switch (s->class) { + case TYPE: + printf("size\t%d\n", size(s)); + break; + case VAR: case REF: - if (s->level >= 3) { - printf("address\t0x%x\n", s->symvalue.offset); - } else { - printf("offset\t%d\n", s->symvalue.offset); + switch (s->storage) { + case INREG: + printf("reg\t%d\n", s->symvalue.offset); + break; + + case STK: + printf("offset\t%d\n", s->symvalue.offset); + break; + + case EXT: + printf("address\t0x%x\n", s->symvalue.offset); + break; } printf("size\t%d\n", size(s)); break; @@ -384,7 +470,6 @@ Symbol s; break; case RANGE: - prangetype(s->symvalue.rangev.lowertype); printf("lower\t%d\n", s->symvalue.rangev.lower); prangetype(s->symvalue.rangev.uppertype); @@ -429,6 +514,9 @@ Symbol t; Symbol s; checkref(t); + if (t->class == TYPEREF) { + resolveRef(t); + } switch (t->class) { case PROC: case FUNC: @@ -437,8 +525,8 @@ Symbol t; break; default: - if (t->language == nil) { - error("unknown language"); + if (t->language == nil or t->language == primlang) { + (*language_op(findlanguage(".c"), L_PRINTVAL))(t); } else { (*language_op(t->language, L_PRINTVAL))(t); } @@ -453,33 +541,41 @@ Symbol t; public printrecord(s) Symbol s; { + Symbol f; + if (s->chain == nil) { error("record has no fields"); } printf("("); sp -= size(s); - printfield(s->chain); + f = s->chain; + if (f != nil) { + for (;;) { + printfield(f); + f = f->chain; + if (f == nil) break; + printf(", "); + } + } printf(")"); } /* - * Print out a field, first printing out other fields. - * This is done because the fields are chained together backwards. + * Print out a field. */ -private printfield(s) -Symbol s; +private printfield(f) +Symbol f; { Stack *savesp; + register int off, len; - if (s->chain != nil) { - printfield(s->chain); - printf(", "); - } - printf("%s = ", symname(s)); + printf("%s = ", symname(f)); savesp = sp; - sp += ((s->symvalue.field.offset div BITSPERBYTE) + size(s->type)); - printval(s); + off = f->symvalue.field.offset; + len = f->symvalue.field.length; + sp += ((off + len + BITSPERBYTE - 1) div BITSPERBYTE); + printval(f); sp = savesp; } @@ -538,7 +634,11 @@ double r; extern char *index(); char buf[256]; - sprintf(buf, "%g", r); +# ifdef IRIS + sprintf(buf, "%lg", r); +# else + sprintf(buf, "%g", r); +# endif if (buf[0] == '.') { printf("0%s", buf); } else if (buf[0] == '-' and buf[1] == '.') { @@ -567,7 +667,113 @@ char c; } else if (c > 0 and c < ' ') { putchar('^'); putchar(c - 1 + 'A'); - } else { + } else if (c >= ' ' && c <= '~') { putchar(c); + } else { + printf("\\0%o",c&0xff); + } +} + +/* + * Print out a value for a range type (integer, char, or boolean). + */ + +public printRangeVal (val, t) +long val; +Symbol t; +{ + if (t == t_boolean->type or istypename(t->type, "boolean")) { + if ((boolean) val) { + printf("true"); + } else { + printf("false"); + } + } else if (t == t_char->type or istypename(t->type, "char")) { + if (varIsSet("$hexchars")) { + printf("0x%lx", val); + } else { + putchar('\''); + printchar(val); + putchar('\''); + } + } else if (varIsSet("$hexints")) { + printf("0x%lx", val); + } else if (t->symvalue.rangev.lower >= 0) { + printf("%lu", val); + } else { + printf("%ld", val); + } +} + +/* + * Print out an enumerated value by finding the corresponding + * name in the enumeration list. + */ + +public printEnum (i, t) +integer i; +Symbol t; +{ + register Symbol e; + + e = t->chain; + while (e != nil and e->symvalue.constval->value.lcon != i) { + e = e->chain; + } + if (e != nil) { + printf("%s", symname(e)); + } else { + printf("%d", i); + } +} + +/* + * Print out a null-terminated string (pointer to char) + * starting at the given address. + */ + +public printString (addr, quotes) +Address addr; +boolean quotes; +{ + register Address a; + register integer i, len; + register boolean endofstring; + register int unprintables; +#define MAXGARBAGE 4 + union { + char ch[sizeof(Word)]; + int word; + } u; + + if (varIsSet("$hexstrings")) { + printf("0x%x", addr); + } else { + if (quotes) { + putchar('"'); + } + a = addr; + unprintables = 0; + endofstring = false; + while (not endofstring) { + dread(&u, a, sizeof(u)); + i = 0; + do { + if (u.ch[i] == '\0') { + endofstring = true; + } else { + printchar(u.ch[i]); + if (!isascii(u.ch[i]) and ++unprintables > MAXGARBAGE) { + endofstring = true; + printf("..."); + } + } + ++i; + } while (i < sizeof(Word) and not endofstring); + a += sizeof(Word); + } + if (quotes) { + putchar('"'); + } } }