|
|
1.1 root 1: /*
2: * n3/dbgt3.c
3: * Print debug information.
4: * In VASM mode, we buffer DLABELS until their DLOCAT arrives.
5: */
6:
7: #ifdef vax
8: #include "INC$LIB:cc3.h"
9: #else
10: #include "cc3.h"
11: #endif
12:
13: struct dsave {
14: int d_ref;
15: struct dsave *d_next;
16: struct dsave *d_more;
17: char d_buf[];
18: };
19:
20: extern struct dsave *dbtget();
21: extern struct dsave *dbtmake();
22: extern struct dsave *dbtmore();
23: struct dsave *dsave = NULL;
24: int drefnum;
25: int dbtisline;
26:
27: /*
28: * Debug type, dim, class names.
29: */
30: char *dnames[] = {
31: NULL, /* No type (yet) */
32: "char", /* Char */
33: "uchar", /* Unsigned char */
34: "short", /* Short */
35: "ushort", /* Unsigned short */
36: "int", /* Int */
37: "uint", /* Unsigned int */
38: "long", /* Long */
39: "ulong", /* Unsigned long */
40: "float", /* Float */
41: "double", /* Double */
42: "void", /* void */
43: "struct", /* Struct */
44: "union", /* Union */
45: "enum", /* Enumeration */
46: "ptr", /* Pointer */
47: "func", /* Function returning */
48: "array", /* Array */
49: NULL, /* Structure member list */
50: NULL, /* Structure name */
51: NULL, /* Unused */
52: "static", /* Static external */
53: NULL, /* Global def. */
54: "extern", /* Global ref. */
55: "typedef", /* Typedef name */
56: "struct", /* Structure tag */
57: "union", /* Union tag */
58: "enum", /* Enumeration tag */
59: "source file", /* Source file name */
60: NULL, /* Line number item */
61: "label", /* Label */
62: "auto", /* Auto */
63: NULL, /* Parametric auto */
64: "register", /* Register */
65: "register", /* Parametric register */
66: "static", /* Static internal */
67: NULL, /* Member of enumeration */
68: NULL, /* Function call */
69: NULL, /* Member of structure */
70: NULL /* Member of union */
71: };
72:
73:
74:
75: /*
76: * Print out or save debug name and type information.
77: */
78: cc3dbug()
79: {
80: struct dsave *dp;
81:
82: dbtisline = 0;
83: dp = dbtget(1);
84: dp->d_ref = drefnum;
85: dbtnext(dp);
86: if (notvariant(VASM)
87: || (dbtisline==0 && dp == dsave))
88: dbtput(drefnum);
89: drefnum += 1;
90: }
91:
92: /*
93: * Report the location of a debug label
94: * or print the label information saved.
95: */
96: cc3dloc()
97: {
98: register int n;
99:
100: n = iget();
101: if (isvariant(VASM))
102: dbtput(n);
103: else
104: fprintf(ofp, " debug location #%d\n", n);
105: }
106:
107: char dbtbuf[2048]; /* Buffer for accumulating information */
108:
109: struct dsave *
110: dbtget(indent)
111: {
112: register char *p;
113: register int n;
114: struct dsave *dp;
115: int nline;
116: static char vstr[] = " " I_FMT;
117: static char sstr[] = " %s";
118: static char qstr[] = " '%s'";
119: static char fstr[] = ":%d";
120:
121: dp = NULL;
122: p = dbtbuf;
123: *p = 0;
124: /* Indent */
125: if (isvariant(VASM) || indent > 1)
126: for (n=0; n<indent; n+=1)
127: *p++ = '\t';
128: /* Get class */
129: n = bget();
130:
131: /* Get line number */
132: nline = iget();
133:
134: sprintf(p, "line %d:", nline);
135: p += strlen(p);
136: if (dnames[n] != NULL) {
137: sprintf(p, sstr, dnames[n]);
138: p += strlen(p);
139: }
140:
141: if (n==DC_LINE || n==DC_LAB)
142: dbtisline = 1;
143: /* Get value */
144: if (n < DC_AUTO)
145: ;
146: else if (n < DC_MOS) {
147: sprintf(p, vstr, iget());
148: p += strlen(p);
149: } else {
150: int w, s;
151:
152: w = bget(); /* Width */
153: s = bget(); /* Offset */
154: if (w != 0) {
155: sprintf(p, " (width:%d, shift:%d)", w, s);
156: p += strlen(p);
157: }
158: sprintf(p, fstr, iget()); /* Value */
159: p += strlen(p);
160: }
161:
162: /* Get name */
163: sget(id, NCSYMB);
164: sprintf(p, qstr, id);
165: p += strlen(p);
166:
167: /* Get type */
168: for (;;) {
169: n = bget();
170: if (n < DC_SEX) {
171: if (dnames[n] != NULL) {
172: sprintf(p, sstr, dnames[n]);
173: p += strlen(p);
174: }
175: if (n < DX_MEMBS) {
176: sizeof_t size;
177:
178: size = zget();
179: if (n != DT_NONE && n != DD_FUNC) {
180: sprintf(p, ":%ld", (long)size);
181: p += strlen(p);
182: }
183: }
184: if (n == DX_MEMBS) {
185: ++indent;
186: n = zget();
187: sprintf(p, " %d {\n", n);
188: dp = dbtmake();
189: for ( ; n > 0; n-=1)
190: dbtmore(dp, dbtget(indent));
191: --indent;
192: p = dbtbuf;
193: strcpy(p, "\t}");
194: p += strlen(p);
195: break;
196: } else if (n == DX_NAME) {
197: zget();
198: sget(id, NCSYMB);
199: sprintf(p, qstr, id);
200: p += strlen(p);
201: break;
202: } else if (n < DT_STRUCT)
203: break;
204: } else
205: cbotch("unrecognized type byte: %d", n);
206: }
207:
208: /* Done */
209: sprintf(p, "\n");
210: return (dbtmore(dp, dbtmake()));
211: }
212:
213: dbtnext(dp)
214: struct dsave *dp;
215: {
216: register struct dsave **dpp;
217:
218: dpp = &dsave;
219: while (*dpp != NULL)
220: dpp = &(*dpp)->d_next;
221: *dpp = dp;
222: }
223: dbtput(n)
224: {
225: register struct dsave *dp, *dp1;
226:
227: while ((dp = dsave) != NULL) {
228: if (dp->d_ref > n)
229: break;
230: dsave = dp->d_next;
231: if (isvariant(VASM))
232: fputs(CMTSTR, ofp);
233: fputs(dp->d_buf, ofp);
234: dp1 = dp->d_more;
235: free(dp);
236: while (dp1 != NULL) {
237: if (isvariant(VASM))
238: fputs(CMTSTR, ofp);
239: fputs(dp1->d_buf, ofp);
240: dp = dp1;
241: dp1 = dp->d_more;
242: free(dp);
243: }
244: }
245: }
246: struct dsave *
247: dbtmake()
248: {
249: register struct dsave *dp;
250:
251: dp = (struct dsave *)malloc(sizeof(*dp) + strlen(dbtbuf) + 1);
252: if (dp == NULL)
253: cnomem("dbtmake");
254: dp->d_ref = -1;
255: dp->d_next = dp->d_more = NULL;
256: strcpy(dp->d_buf, dbtbuf);
257: return (dp);
258: }
259:
260: struct dsave *
261: dbtmore(dp, mdp)
262: struct dsave *dp, *mdp;
263: {
264: register struct dsave **dpp;
265:
266: if (dp == NULL)
267: return (mdp);
268: for (dpp = &dp->d_more; *dpp != NULL; dpp = &(*dpp)->d_more)
269: ;
270: *dpp = mdp;
271: return (dp);
272: }
273:
274: /* end of n3/dbgt3.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.