xref: /csrg-svn/old/pcc/ccom.vax/stab.c (revision 9703)
1*9703Slinton /*
2*9703Slinton  * Symbolic debugging info interface.
3*9703Slinton  *
4*9703Slinton  * Here we generate pseudo-ops that cause the assembler to put
5*9703Slinton  * symbolic debugging information into the object file.
6*9703Slinton  */
7*9703Slinton 
8*9703Slinton static char *sccsid ="@(#)stab.c	1.1 (Berkeley) 12/15/82";
9*9703Slinton 
10*9703Slinton #include "mfile1"
11*9703Slinton 
12*9703Slinton #include <sys/types.h>
13*9703Slinton #include <a.out.h>
14*9703Slinton #include <stab.h>
15*9703Slinton 
16*9703Slinton #define private static
17*9703Slinton #define and &&
18*9703Slinton #define or ||
19*9703Slinton #define not !
20*9703Slinton #define div /
21*9703Slinton #define mod %
22*9703Slinton #define nil 0
23*9703Slinton 
24*9703Slinton #define bytes(bits) ((bits) / SZCHAR)
25*9703Slinton #define bsize(p) bytes(dimtab[p->sizoff])	/* size in bytes of a symbol */
26*9703Slinton 
27*9703Slinton #define NILINDEX -1
28*9703Slinton #define FORWARD -2
29*9703Slinton 
30*9703Slinton typedef enum { false, true } Boolean;
31*9703Slinton 
32*9703Slinton extern int ddebug;
33*9703Slinton extern int gdebug;
34*9703Slinton extern char *malloc();
35*9703Slinton 
36*9703Slinton int stabLCSYM;
37*9703Slinton 
38*9703Slinton /*
39*9703Slinton  * Generate debugging info for a parameter.
40*9703Slinton  * The offset isn't known when it is first entered into the symbol table
41*9703Slinton  * since the types are read later.
42*9703Slinton  */
43*9703Slinton 
44*9703Slinton fixarg(p)
45*9703Slinton struct symtab *p;
46*9703Slinton {
47*9703Slinton     if (gdebug) {
48*9703Slinton 	printf("\t.stabs\t\"%s:p", p->sname);
49*9703Slinton 	gentype(p);
50*9703Slinton 	printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
51*9703Slinton     }
52*9703Slinton }
53*9703Slinton 
54*9703Slinton /*
55*9703Slinton  * Generate debugging info for a given symbol.
56*9703Slinton  */
57*9703Slinton 
58*9703Slinton outstab(sym)
59*9703Slinton struct symtab *sym;
60*9703Slinton {
61*9703Slinton     register struct symtab *p;
62*9703Slinton     char *classname;
63*9703Slinton     int offset;
64*9703Slinton     Boolean ignore;
65*9703Slinton     static Boolean firsttime = true;
66*9703Slinton 
67*9703Slinton     if (gdebug) {
68*9703Slinton 	if (firsttime) {
69*9703Slinton 	    firsttime = false;
70*9703Slinton 	    inittypes();
71*9703Slinton 	}
72*9703Slinton 	ignore = false;
73*9703Slinton 	p = sym;
74*9703Slinton 	offset = bytes(p->offset);
75*9703Slinton 	switch (p->sclass) {
76*9703Slinton 	case REGISTER:
77*9703Slinton 	    classname = "r";
78*9703Slinton 	    offset = p->offset;
79*9703Slinton 	    break;
80*9703Slinton 
81*9703Slinton 	/*
82*9703Slinton 	 * Locals are the default class.
83*9703Slinton 	 */
84*9703Slinton 	case AUTO:
85*9703Slinton 	    classname = "";
86*9703Slinton 	    break;
87*9703Slinton 
88*9703Slinton 	case STATIC:
89*9703Slinton 	    if (ISFTN(p->stype)) {
90*9703Slinton 		ignore = true;
91*9703Slinton 	    } else if (p->slevel <= 1) {
92*9703Slinton 		classname = "S";
93*9703Slinton 	    } else {
94*9703Slinton 		classname = "V";
95*9703Slinton 	    }
96*9703Slinton 	    break;
97*9703Slinton 
98*9703Slinton 	case EXTDEF:
99*9703Slinton 	case EXTERN:
100*9703Slinton 	    if (ISFTN(p->stype)) {
101*9703Slinton 		ignore = true;
102*9703Slinton 	    } else {
103*9703Slinton 		classname = "G";
104*9703Slinton 	    }
105*9703Slinton 	    break;
106*9703Slinton 
107*9703Slinton 	case TYPEDEF:
108*9703Slinton 	    classname = "t";
109*9703Slinton 	    break;
110*9703Slinton 
111*9703Slinton 	case PARAM:
112*9703Slinton 	case MOS:
113*9703Slinton 	case MOU:
114*9703Slinton 	case MOE:
115*9703Slinton 	    ignore = true;
116*9703Slinton 	    break;
117*9703Slinton 
118*9703Slinton 	case ENAME:
119*9703Slinton 	case UNAME:
120*9703Slinton 	case STNAME:
121*9703Slinton 	    entertype(p->stype, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
122*9703Slinton 	    ignore = true;
123*9703Slinton 	    break;
124*9703Slinton 
125*9703Slinton 	default:
126*9703Slinton 	    if ((p->sclass&FIELD) == 0) {
127*9703Slinton 		printf("/* no info for %s (%d) */\n", p->sname, p->sclass);
128*9703Slinton 	    }
129*9703Slinton 	    ignore = true;
130*9703Slinton 	    break;
131*9703Slinton 	}
132*9703Slinton 	if (not ignore) {
133*9703Slinton 	    printf("\t.stabs\t\"%s:%s", p->sname, classname);
134*9703Slinton 	    gentype(p);
135*9703Slinton 	    geninfo(p);
136*9703Slinton 	}
137*9703Slinton     }
138*9703Slinton }
139*9703Slinton 
140*9703Slinton /*
141*9703Slinton  * Since type names are lost in the travels and because C has
142*9703Slinton  * structural type equivalence we keep a table of type words that
143*9703Slinton  * we've already seen.  The first time we see a type, it is assigned
144*9703Slinton  * (inline) a number and future references just list that number.
145*9703Slinton  * Structures, unions, enums, and arrays must be handled carefully
146*9703Slinton  * since not all the necessary information is in the type word.
147*9703Slinton  */
148*9703Slinton 
149*9703Slinton typedef struct Typeid *Typeid;
150*9703Slinton 
151*9703Slinton struct Typeid {
152*9703Slinton     TWORD tword;
153*9703Slinton     int tarray;
154*9703Slinton     int tstruct;
155*9703Slinton     int tstrtag;
156*9703Slinton     int tnum;
157*9703Slinton     Typeid chain;
158*9703Slinton };
159*9703Slinton 
160*9703Slinton #define TABLESIZE 2003
161*9703Slinton 
162*9703Slinton private int tcount = 1;
163*9703Slinton private int t_int, t_char;
164*9703Slinton private Typeid typetable[TABLESIZE];
165*9703Slinton 
166*9703Slinton /*
167*9703Slinton  * Look for the given type word in the type table.
168*9703Slinton  */
169*9703Slinton 
170*9703Slinton private Typeid typelookup(type, arrindex, strindex, strtag)
171*9703Slinton TWORD type;
172*9703Slinton int arrindex;
173*9703Slinton int strindex;
174*9703Slinton int strtag;
175*9703Slinton {
176*9703Slinton     register TWORD tword;
177*9703Slinton     register int i1, i2;
178*9703Slinton     Typeid t;
179*9703Slinton 
180*9703Slinton     t = typetable[type mod TABLESIZE];
181*9703Slinton     while (t != nil) {
182*9703Slinton 	if (t->tword == type and
183*9703Slinton 	  strindex == t->tstruct and strtag == t->tstrtag) {
184*9703Slinton 	    if (arrindex == NILINDEX) {
185*9703Slinton 		break;
186*9703Slinton 	    } else {
187*9703Slinton 		tword = type >> TSHIFT;
188*9703Slinton 		i1 = arrindex;
189*9703Slinton 		i2 = t->tarray;
190*9703Slinton 		while (ISARY(tword) and dimtab[i1] == dimtab[i2]) {
191*9703Slinton 		    ++i1;
192*9703Slinton 		    ++i2;
193*9703Slinton 		    tword >>= TSHIFT;
194*9703Slinton 		}
195*9703Slinton 		if (!ISARY(tword)) {
196*9703Slinton 		    break;
197*9703Slinton 		}
198*9703Slinton 	    }
199*9703Slinton 	}
200*9703Slinton 	t = t->chain;
201*9703Slinton     }
202*9703Slinton     return t;
203*9703Slinton }
204*9703Slinton 
205*9703Slinton /*
206*9703Slinton  * Enter a type word and associated symtab indices into the type table.
207*9703Slinton  */
208*9703Slinton 
209*9703Slinton private int entertype(type, arrindex, strindex, strtag)
210*9703Slinton TWORD type;
211*9703Slinton int arrindex;
212*9703Slinton int strindex;
213*9703Slinton int strtag;
214*9703Slinton {
215*9703Slinton     register Typeid t;
216*9703Slinton     register int i;
217*9703Slinton 
218*9703Slinton     t = (Typeid) malloc(sizeof(struct Typeid));
219*9703Slinton     t->tword = type;
220*9703Slinton     t->tarray = arrindex;
221*9703Slinton     t->tstruct = strindex;
222*9703Slinton     t->tstrtag = strtag;
223*9703Slinton     t->tnum = tcount;
224*9703Slinton     ++tcount;
225*9703Slinton     i = type mod TABLESIZE;
226*9703Slinton     t->chain = typetable[i];
227*9703Slinton     typetable[i] = t;
228*9703Slinton     return t->tnum;
229*9703Slinton }
230*9703Slinton 
231*9703Slinton /*
232*9703Slinton  * Change the information associated with a type table entry.
233*9703Slinton  * Since I'm lazy this just creates a new entry with the number
234*9703Slinton  * as the old one.
235*9703Slinton  */
236*9703Slinton 
237*9703Slinton private reentertype(typeid, type, arrindex, strindex, strtag)
238*9703Slinton Typeid typeid;
239*9703Slinton TWORD type;
240*9703Slinton int arrindex;
241*9703Slinton int strindex;
242*9703Slinton int strtag;
243*9703Slinton {
244*9703Slinton     register Typeid t;
245*9703Slinton     register int i;
246*9703Slinton 
247*9703Slinton     t = (Typeid) malloc(sizeof(struct Typeid));
248*9703Slinton     t->tword = type;
249*9703Slinton     t->tarray = arrindex;
250*9703Slinton     t->tstruct = strindex;
251*9703Slinton     t->tstrtag = strtag;
252*9703Slinton     t->tnum = typeid->tnum;
253*9703Slinton     i = type mod TABLESIZE;
254*9703Slinton     t->chain = typetable[i];
255*9703Slinton     typetable[i] = t;
256*9703Slinton }
257*9703Slinton 
258*9703Slinton /*
259*9703Slinton  * Initialize type table with predefined types.
260*9703Slinton  */
261*9703Slinton 
262*9703Slinton #define builtintype(type) entertype(type, NILINDEX, NILINDEX, NILINDEX)
263*9703Slinton 
264*9703Slinton private inittypes()
265*9703Slinton {
266*9703Slinton     int t;
267*9703Slinton 
268*9703Slinton     t_int = builtintype(INT);
269*9703Slinton     t_char = builtintype(CHAR);
270*9703Slinton     maketype("int", t_int, t_int, 0x80000000L, 0x7fffffffL);
271*9703Slinton     maketype("char", t_char, t_char, 0L, 127L);
272*9703Slinton     maketype("long", builtintype(LONG), t_int, 0x80000000L, 0x7fffffffL);
273*9703Slinton     maketype("short", builtintype(SHORT), t_int, 0xffff8000L, 0x7fffL);
274*9703Slinton     maketype("unsigned char", builtintype(UCHAR), t_int, 0L, 255L);
275*9703Slinton     maketype("unsigned short", builtintype(USHORT), t_int, 0L, 0xffffL);
276*9703Slinton     maketype("unsigned long", builtintype(ULONG), t_int, 0L, 0xffffffffL);
277*9703Slinton     maketype("unsigned int", builtintype(UNSIGNED), t_int, 0L, 0xffffffffL);
278*9703Slinton     maketype("float", builtintype(FLOAT), t_int, 4L, 0L);
279*9703Slinton     maketype("double", builtintype(DOUBLE), t_int, 8L, 0L);
280*9703Slinton     t = builtintype(UNDEF);
281*9703Slinton     printf("\t.stabs\t\"void:t%d=%d", t, t);
282*9703Slinton     geninfo(nil);
283*9703Slinton }
284*9703Slinton 
285*9703Slinton /*
286*9703Slinton  * Generate info for a new range type.
287*9703Slinton  */
288*9703Slinton 
289*9703Slinton private maketype(name, tnum, eqtnum, lower, upper)
290*9703Slinton char *name;
291*9703Slinton int tnum, eqtnum;
292*9703Slinton long lower, upper;
293*9703Slinton {
294*9703Slinton     printf("\t.stabs\t\"%s:t%d=r%d;%d;%d;", name, tnum, eqtnum, lower, upper);
295*9703Slinton     geninfo(nil);
296*9703Slinton }
297*9703Slinton 
298*9703Slinton /*
299*9703Slinton  * Generate debugging information for the given type of the given symbol.
300*9703Slinton  */
301*9703Slinton 
302*9703Slinton private gentype(sym)
303*9703Slinton struct symtab *sym;
304*9703Slinton {
305*9703Slinton     register struct symtab *p;
306*9703Slinton     register TWORD t;
307*9703Slinton     register TWORD basictype;
308*9703Slinton     register Typeid typeid;
309*9703Slinton     int i, arrindex, strindex, strtag;
310*9703Slinton 
311*9703Slinton     p = sym;
312*9703Slinton     t = p->stype;
313*9703Slinton     if (ISFTN(t)) {
314*9703Slinton 	t = DECREF(t);
315*9703Slinton     }
316*9703Slinton     basictype = BTYPE(t);
317*9703Slinton     if (ISARY(t)) {
318*9703Slinton 	arrindex = p->dimoff;
319*9703Slinton     } else {
320*9703Slinton 	arrindex = NILINDEX;
321*9703Slinton     }
322*9703Slinton     if (basictype == STRTY or basictype == UNIONTY or basictype == ENUMTY) {
323*9703Slinton 	strindex = dimtab[p->sizoff + 1];
324*9703Slinton 	if (strindex == -1) {
325*9703Slinton 	    strindex = FORWARD;
326*9703Slinton 	    strtag = dimtab[p->sizoff + 3];
327*9703Slinton 	} else {
328*9703Slinton 	    strtag = NILINDEX;
329*9703Slinton 	}
330*9703Slinton     } else {
331*9703Slinton 	strindex = NILINDEX;
332*9703Slinton 	strtag = NILINDEX;
333*9703Slinton     }
334*9703Slinton     i = arrindex;
335*9703Slinton     typeid = typelookup(t, arrindex, strindex, strtag);
336*9703Slinton     while (t != basictype and typeid == nil) {
337*9703Slinton 	printf("%d=", entertype(t, i, strindex, strtag));
338*9703Slinton 	switch (t&TMASK) {
339*9703Slinton 	case PTR:
340*9703Slinton 	    printf("*");
341*9703Slinton 	    break;
342*9703Slinton 
343*9703Slinton 	case FTN:
344*9703Slinton 	    printf("f");
345*9703Slinton 	    break;
346*9703Slinton 
347*9703Slinton 	case ARY:
348*9703Slinton 	    printf("ar%d;0;%d;", t_int, dimtab[i++] - 1);
349*9703Slinton 	    break;
350*9703Slinton 	}
351*9703Slinton 	t = DECREF(t);
352*9703Slinton 	if (t == basictype) {
353*9703Slinton 	    typeid = typelookup(t, NILINDEX, strindex, strtag);
354*9703Slinton 	} else {
355*9703Slinton 	    typeid = typelookup(t, i, strindex, strtag);
356*9703Slinton 	}
357*9703Slinton     }
358*9703Slinton     if (typeid == nil) {
359*9703Slinton 	if (strindex == FORWARD) {
360*9703Slinton 	    typeid = typelookup(t, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
361*9703Slinton 	    if (typeid == nil) {
362*9703Slinton 		cerror("unbelievable forward reference");
363*9703Slinton 	    }
364*9703Slinton 	    printf("%d", typeid->tnum);
365*9703Slinton 	} else {
366*9703Slinton 	    genstruct(t, NILINDEX, strindex, p->sname, bsize(p));
367*9703Slinton 	}
368*9703Slinton     } else {
369*9703Slinton 	printf("%d", typeid->tnum);
370*9703Slinton     }
371*9703Slinton }
372*9703Slinton 
373*9703Slinton /*
374*9703Slinton  * Generate type information for structures, unions, and enumerations.
375*9703Slinton  */
376*9703Slinton 
377*9703Slinton private genstruct(t, structid, index, name, size)
378*9703Slinton TWORD t;
379*9703Slinton int structid;
380*9703Slinton int index;
381*9703Slinton char *name;
382*9703Slinton int size;
383*9703Slinton {
384*9703Slinton     register int i;
385*9703Slinton     register struct symtab *field;
386*9703Slinton     int id;
387*9703Slinton 
388*9703Slinton     if (structid == NILINDEX) {
389*9703Slinton 	id = entertype(t, NILINDEX, index, NILINDEX);
390*9703Slinton     } else {
391*9703Slinton 	id = structid;
392*9703Slinton     }
393*9703Slinton     switch (t) {
394*9703Slinton     case STRTY:
395*9703Slinton     case UNIONTY:
396*9703Slinton 	printf("%d=%c%d", id, t == STRTY ? 's' : 'u', size);
397*9703Slinton 	i = index;
398*9703Slinton 	while (dimtab[i] != -1) {
399*9703Slinton 	    field = &stab[dimtab[i]];
400*9703Slinton 	    printf("%s:", field->sname);
401*9703Slinton 	    gentype(field);
402*9703Slinton 	    if (field->sclass > FIELD) {
403*9703Slinton 		printf(",%d,%d;", field->offset, field->sclass - FIELD);
404*9703Slinton 	    } else {
405*9703Slinton 		printf(",%d,%d;", field->offset,
406*9703Slinton 		    tsize(field->stype, field->dimoff, field->sizoff));
407*9703Slinton 	    }
408*9703Slinton 	    ++i;
409*9703Slinton 	}
410*9703Slinton 	putchar(';');
411*9703Slinton 	break;
412*9703Slinton 
413*9703Slinton     case ENUMTY:
414*9703Slinton 	printf("%d=e", id);
415*9703Slinton 	i = index;
416*9703Slinton 	while (dimtab[i] != -1) {
417*9703Slinton 	    field = &stab[dimtab[i]];
418*9703Slinton 	    printf("%s:%d,", field->sname, field->offset);
419*9703Slinton 	    i++;
420*9703Slinton 	}
421*9703Slinton 	break;
422*9703Slinton 
423*9703Slinton     default:
424*9703Slinton 	cerror("couldn't find basic type %d for %s\n", t, name);
425*9703Slinton 	break;
426*9703Slinton     }
427*9703Slinton }
428*9703Slinton 
429*9703Slinton /*
430*9703Slinton  * Generate offset and size info.
431*9703Slinton  */
432*9703Slinton 
433*9703Slinton private geninfo(p)
434*9703Slinton register struct symtab *p;
435*9703Slinton {
436*9703Slinton     if (p == nil) {
437*9703Slinton 	printf("\",0x%x,0,0,0\n", N_LSYM);
438*9703Slinton     } else {
439*9703Slinton 	switch (p->sclass) {
440*9703Slinton 	    case EXTERN:
441*9703Slinton 	    case EXTDEF:
442*9703Slinton 		if (ISFTN(p->stype)) {
443*9703Slinton 		    printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
444*9703Slinton 		} else {
445*9703Slinton 		    printf("\",0x%x,0,%d,_%s\n", N_GSYM, bsize(p), p->sname);
446*9703Slinton 		}
447*9703Slinton 		break;
448*9703Slinton 
449*9703Slinton 	    case STATIC:
450*9703Slinton 		if (ISFTN(p->stype)) {
451*9703Slinton 		    printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
452*9703Slinton 		} else if (p->slevel > 1) {
453*9703Slinton 		    printf("\",0x%x,0,%d,L%d\n", N_STSYM, bsize(p), p->offset);
454*9703Slinton 		} else {
455*9703Slinton 		    printf("\",0x%x,0,%d,_%s\n", N_LCSYM, bsize(p), p->sname);
456*9703Slinton 		}
457*9703Slinton 		break;
458*9703Slinton 
459*9703Slinton 	    case REGISTER:
460*9703Slinton 		printf("\",0x%x,0,%d,%d\n", N_RSYM, bsize(p), p->offset);
461*9703Slinton 		break;
462*9703Slinton 
463*9703Slinton 	    case PARAM:
464*9703Slinton 		printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
465*9703Slinton 		break;
466*9703Slinton 
467*9703Slinton 	    default:
468*9703Slinton 		printf("\",0x%x,0,%d,%d\n", N_LSYM, bsize(p), bytes(p->offset));
469*9703Slinton 		break;
470*9703Slinton 	}
471*9703Slinton     }
472*9703Slinton }
473*9703Slinton 
474*9703Slinton /*
475*9703Slinton  * Generate information for a newly-defined structure.
476*9703Slinton  */
477*9703Slinton 
478*9703Slinton outstruct(szindex, paramindex)
479*9703Slinton int szindex, paramindex;
480*9703Slinton {
481*9703Slinton     register Typeid typeid;
482*9703Slinton     register struct symtab *p;
483*9703Slinton     register int i, t, strindex;
484*9703Slinton 
485*9703Slinton     if (gdebug) {
486*9703Slinton 	i = dimtab[szindex + 3];
487*9703Slinton 	p = &stab[i];
488*9703Slinton 	if (p->sname != nil) {
489*9703Slinton 	    strindex = dimtab[p->sizoff + 1];
490*9703Slinton 	    typeid = typelookup(p->stype, NILINDEX, FORWARD, i);
491*9703Slinton 	    if (typeid == nil) {
492*9703Slinton 		t = 0;
493*9703Slinton 	    } else {
494*9703Slinton 		t = typeid->tnum;
495*9703Slinton 		reentertype(typeid, p->stype, NILINDEX, strindex, NILINDEX);
496*9703Slinton 	    }
497*9703Slinton 	    printf("\t.stabs\t\"%s:T", p->sname);
498*9703Slinton 	    genstruct(p->stype, t, strindex, p->sname, bsize(p));
499*9703Slinton 	    geninfo(p);
500*9703Slinton 	}
501*9703Slinton     }
502*9703Slinton }
503*9703Slinton 
504*9703Slinton pstab(name, type)
505*9703Slinton char *name;
506*9703Slinton int type;
507*9703Slinton {
508*9703Slinton     register int i;
509*9703Slinton     register char c;
510*9703Slinton     if (!gdebug) return;
511*9703Slinton     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
512*9703Slinton #ifdef ASSTRINGS
513*9703Slinton     if ( name[0] == '\0')
514*9703Slinton 	printf("\t.stabn\t");
515*9703Slinton     else
516*9703Slinton #ifndef FLEXNAMES
517*9703Slinton 	printf("\t.stabs\t\"%.8s\",", name);
518*9703Slinton #else
519*9703Slinton 	printf("\t.stabs\t\"%s\",", name);
520*9703Slinton #endif
521*9703Slinton #else
522*9703Slinton     printf("    .stab   ");
523*9703Slinton     for(i=0; i<8; i++)
524*9703Slinton 	if (c = name[i]) printf("'%c,", c);
525*9703Slinton 	else printf("0,");
526*9703Slinton #endif
527*9703Slinton     printf("0%o,", type);
528*9703Slinton }
529*9703Slinton 
530*9703Slinton #ifdef STABDOT
531*9703Slinton pstabdot(type, value)
532*9703Slinton int type;
533*9703Slinton int value;
534*9703Slinton {
535*9703Slinton     if ( ! gdebug) return;
536*9703Slinton     /* locctr(PROG);  /* .stabs must appear in .text for c2 */
537*9703Slinton     printf("\t.stabd\t");
538*9703Slinton     printf("0%o,0,0%o\n",type, value);
539*9703Slinton }
540*9703Slinton #endif
541*9703Slinton 
542*9703Slinton extern char NULLNAME[8];
543*9703Slinton extern int  labelno;
544*9703Slinton extern int  fdefflag;
545*9703Slinton 
546*9703Slinton psline()
547*9703Slinton {
548*9703Slinton     static int lastlineno;
549*9703Slinton     register char *cp, *cq;
550*9703Slinton     register int i;
551*9703Slinton 
552*9703Slinton     if (!gdebug) return;
553*9703Slinton 
554*9703Slinton     cq = ititle;
555*9703Slinton     cp = ftitle;
556*9703Slinton 
557*9703Slinton     while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
558*9703Slinton     if ( *cp == '\0' ) goto eq;
559*9703Slinton 
560*9703Slinton neq:    for (i=0; i<100; i++)
561*9703Slinton 	ititle[i] = '\0';
562*9703Slinton     cp = ftitle;
563*9703Slinton     cq = ititle;
564*9703Slinton     while ( *cp )
565*9703Slinton 	*cq++ = *cp++;
566*9703Slinton     *cq = '\0';
567*9703Slinton     *--cq = '\0';
568*9703Slinton #ifndef FLEXNAMES
569*9703Slinton     for ( cp = ititle+1; *(cp-1); cp += 8 ) {
570*9703Slinton 	pstab(cp, N_SOL);
571*9703Slinton 	if (gdebug) printf("0,0,LL%d\n", labelno);
572*9703Slinton     }
573*9703Slinton #else
574*9703Slinton     pstab(ititle+1, N_SOL);
575*9703Slinton     if (gdebug) printf("0,0,LL%d\n", labelno);
576*9703Slinton #endif
577*9703Slinton     *cq = '"';
578*9703Slinton     printf("LL%d:\n", labelno++);
579*9703Slinton 
580*9703Slinton eq: if (lineno == lastlineno) return;
581*9703Slinton     lastlineno = lineno;
582*9703Slinton 
583*9703Slinton     if (fdefflag) {
584*9703Slinton #ifdef STABDOT
585*9703Slinton 	pstabdot(N_SLINE, lineno);
586*9703Slinton #else
587*9703Slinton 	pstab(NULLNAME, N_SLINE);
588*9703Slinton 	printf("0,%d,LL%d\n", lineno, labelno);
589*9703Slinton 	printf("LL%d:\n", labelno++);
590*9703Slinton #endif
591*9703Slinton     }
592*9703Slinton }
593*9703Slinton 
594*9703Slinton plcstab(level)
595*9703Slinton int level;
596*9703Slinton {
597*9703Slinton     if (!gdebug) return;
598*9703Slinton #ifdef STABDOT
599*9703Slinton     pstabdot(N_LBRAC, level);
600*9703Slinton #else
601*9703Slinton     pstab(NULLNAME, N_LBRAC);
602*9703Slinton     printf("0,%d,LL%d\n", level, labelno);
603*9703Slinton     printf("LL%d:\n", labelno++);
604*9703Slinton #endif
605*9703Slinton }
606*9703Slinton 
607*9703Slinton prcstab(level)
608*9703Slinton int level;
609*9703Slinton {
610*9703Slinton     if (!gdebug) return;
611*9703Slinton #ifdef STABDOT
612*9703Slinton     pstabdot(N_RBRAC, level);
613*9703Slinton #else
614*9703Slinton     pstab(NULLNAME, N_RBRAC);
615*9703Slinton     printf("0,%d,LL%d\n", level, labelno);
616*9703Slinton     printf("LL%d:\n", labelno++);
617*9703Slinton #endif
618*9703Slinton }
619*9703Slinton 
620*9703Slinton pfstab(sname)
621*9703Slinton char *sname;
622*9703Slinton {
623*9703Slinton     register struct symtab *p;
624*9703Slinton 
625*9703Slinton     if (gdebug) {
626*9703Slinton 	p = &stab[lookup(sname, 0)];
627*9703Slinton 	printf("\t.stabs\t\"%s:", p->sname);
628*9703Slinton 	putchar((p->sclass == STATIC) ? 'f' : 'F');
629*9703Slinton 	gentype(p);
630*9703Slinton 	geninfo(p);
631*9703Slinton     }
632*9703Slinton }
633