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