125830Ssam #ifndef lint
2*32897Sdonn static char *sccsid ="@(#)stab.c 1.6 (Berkeley) 12/10/87";
325830Ssam #endif
425830Ssam /*
525830Ssam * Symbolic debugging info interface.
625830Ssam *
725830Ssam * Here we generate pseudo-ops that cause the assembler to put
825830Ssam * symbolic debugging information into the object file.
925830Ssam */
1025830Ssam
1126079Ssam #include "pass1.h"
1225830Ssam
1325830Ssam #include <sys/types.h>
1425830Ssam #include <a.out.h>
1525830Ssam #include <stab.h>
1625830Ssam
1725830Ssam #define private static
1825830Ssam #define and &&
1925830Ssam #define or ||
2025830Ssam #define not !
2125830Ssam #define div /
2225830Ssam #define mod %
2325830Ssam #define nil 0
2425830Ssam
2525830Ssam #define bytes(bits) ((bits) / SZCHAR)
2625830Ssam #define bsize(p) bytes(dimtab[p->sizoff]) /* size in bytes of a symbol */
2725830Ssam
2825830Ssam #define NILINDEX -1
2925830Ssam #define FORWARD -2
3025830Ssam
3125830Ssam typedef int Boolean;
3225830Ssam
3325830Ssam #define false 0
3425830Ssam #define true 1
3525830Ssam
3625830Ssam extern int ddebug;
3725830Ssam extern int gdebug;
3825830Ssam extern char *malloc();
3925830Ssam
4025830Ssam int stabLCSYM;
4125830Ssam
4225830Ssam /*
4325830Ssam * Flag for producing either sdb or dbx symbol information.
4425830Ssam */
4525830Ssam int oldway = false;
4625830Ssam
4725830Ssam /*
4825830Ssam * Generate debugging info for a parameter.
4925830Ssam * The offset isn't known when it is first entered into the symbol table
5025830Ssam * since the types are read later.
5125830Ssam */
5225830Ssam
5325830Ssam fixarg(p)
5425830Ssam struct symtab *p;
5525830Ssam {
5625830Ssam if (oldway) {
5725830Ssam old_fixarg(p);
5825830Ssam } else if (gdebug) {
5925830Ssam printf("\t.stabs\t\"%s:p", p->sname);
6025830Ssam gentype(p);
6125830Ssam printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
6225830Ssam }
6325830Ssam }
6425830Ssam
6525830Ssam /*
6625830Ssam * Determine if the given symbol is a global array with dimension 0,
6725830Ssam * which only makes sense if it's dimension is to be given later.
6825830Ssam * We therefore currently do not generate symbol information for
6925830Ssam * such entries.
7025830Ssam */
7125830Ssam
7225830Ssam #define isglobal(class) ( \
7325830Ssam class == EXTDEF or class == EXTERN or class == STATIC \
7425830Ssam )
7525830Ssam
zero_length_array(p)7625830Ssam private Boolean zero_length_array(p)
7725830Ssam register struct symtab *p;
7825830Ssam {
7925830Ssam Boolean b;
8025830Ssam int t;
8125830Ssam
8225830Ssam if (not isglobal(p->sclass)) {
8325830Ssam b = false;
8425830Ssam } else {
8525830Ssam t = p->stype;
8625830Ssam if (ISFTN(t)) {
8725830Ssam t = DECREF(t);
8825830Ssam }
8925830Ssam b = (Boolean) (ISARY(t) and dimtab[p->dimoff] == 0);
9025830Ssam }
9125830Ssam return b;
9225830Ssam }
9325830Ssam
9425830Ssam /*
9525830Ssam * Generate debugging info for a given symbol.
9625830Ssam */
9725830Ssam
9825830Ssam outstab(sym)
9925830Ssam struct symtab *sym;
10025830Ssam {
10125830Ssam register struct symtab *p;
10225830Ssam char *classname;
10325830Ssam Boolean ignore;
10425830Ssam static Boolean firsttime = true;
10525830Ssam
10625830Ssam if (oldway) {
10725830Ssam old_outstab(sym);
10825830Ssam } else if (gdebug and not zero_length_array(sym)) {
10925830Ssam if (firsttime) {
11025830Ssam firsttime = false;
11125830Ssam inittypes();
11225830Ssam }
11325830Ssam ignore = false;
11425830Ssam p = sym;
11525830Ssam switch (p->sclass) {
11625830Ssam case REGISTER:
11725830Ssam classname = "r";
11825830Ssam break;
11925830Ssam
12025830Ssam /*
12125830Ssam * Locals are the default class.
12225830Ssam */
12325830Ssam case AUTO:
12425830Ssam classname = "";
12525830Ssam break;
12625830Ssam
12725830Ssam case STATIC:
12825830Ssam if (ISFTN(p->stype)) {
12925830Ssam ignore = true;
13025830Ssam } else if (p->slevel <= 1) {
13125830Ssam classname = "S";
13225830Ssam } else {
13325830Ssam classname = "V";
13425830Ssam }
13525830Ssam break;
13625830Ssam
13725830Ssam case EXTDEF:
13825830Ssam case EXTERN:
13925830Ssam if (ISFTN(p->stype)) {
14025830Ssam ignore = true;
14125830Ssam } else {
14225830Ssam classname = "G";
14325830Ssam }
14425830Ssam break;
14525830Ssam
14625830Ssam case TYPEDEF:
14725830Ssam classname = "t";
14825830Ssam break;
14925830Ssam
15025830Ssam case PARAM:
15125830Ssam case MOS:
15225830Ssam case MOU:
15325830Ssam case MOE:
15425830Ssam ignore = true;
15525830Ssam break;
15625830Ssam
15725830Ssam case ENAME:
15825830Ssam case UNAME:
15925830Ssam case STNAME:
160*32897Sdonn (void) entertype(p->stype, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
16125830Ssam ignore = true;
16225830Ssam break;
16325830Ssam
16425830Ssam default:
16525830Ssam if ((p->sclass&FIELD) == 0) {
16625830Ssam printf("/* no info for %s (%d) */\n", p->sname, p->sclass);
16725830Ssam }
16825830Ssam ignore = true;
16925830Ssam break;
17025830Ssam }
17125830Ssam if (not ignore) {
17225830Ssam printf("\t.stabs\t\"%s:%s", p->sname, classname);
17325830Ssam gentype(p);
17425830Ssam geninfo(p);
17525830Ssam }
17625830Ssam }
17725830Ssam }
17825830Ssam
17925830Ssam /*
18025830Ssam * Since type names are lost in the travels and because C has
18125830Ssam * structural type equivalence we keep a table of type words that
18225830Ssam * we've already seen. The first time we see a type, it is assigned
18325830Ssam * (inline) a number and future references just list that number.
18425830Ssam * Structures, unions, enums, and arrays must be handled carefully
18525830Ssam * since not all the necessary information is in the type word.
18625830Ssam */
18725830Ssam
18825830Ssam typedef struct Typeid *Typeid;
18925830Ssam
19025830Ssam struct Typeid {
19125830Ssam TWORD tword;
19225830Ssam int tarray;
19325830Ssam int tstruct;
19425830Ssam int tstrtag;
19525830Ssam int tnum;
19625830Ssam Typeid chain;
19725830Ssam };
19825830Ssam
19925830Ssam #define TABLESIZE 2003
20025830Ssam
20125830Ssam private int tcount = 1;
20225830Ssam private int t_int, t_char;
20325830Ssam private Typeid typetable[TABLESIZE];
20425830Ssam
20525830Ssam /*
20625830Ssam * Look for the given type word in the type table.
20725830Ssam */
20825830Ssam
typelookup(type,arrindex,strindex,strtag)20925830Ssam private Typeid typelookup(type, arrindex, strindex, strtag)
21025830Ssam TWORD type;
21125830Ssam int arrindex;
21225830Ssam int strindex;
21325830Ssam int strtag;
21425830Ssam {
21525830Ssam register TWORD tword;
21625830Ssam register int i1, i2;
21725830Ssam Typeid t;
21825830Ssam
21925830Ssam t = typetable[type mod TABLESIZE];
22025830Ssam while (t != nil) {
22125830Ssam if (t->tword == type and
22225830Ssam strindex == t->tstruct and strtag == t->tstrtag) {
22325830Ssam if (arrindex == NILINDEX) {
22425830Ssam break;
22525830Ssam } else {
22625830Ssam tword = type;
22725830Ssam i1 = arrindex;
22825830Ssam i2 = t->tarray;
22925830Ssam while (ISARY(tword) and dimtab[i1] == dimtab[i2]) {
23025830Ssam ++i1;
23125830Ssam ++i2;
23225830Ssam tword >>= TSHIFT;
23325830Ssam }
23425830Ssam if (!ISARY(tword)) {
23525830Ssam break;
23625830Ssam }
23725830Ssam }
23825830Ssam }
23925830Ssam t = t->chain;
24025830Ssam }
24125830Ssam return t;
24225830Ssam }
24325830Ssam
24425830Ssam /*
24525830Ssam * Enter a type word and associated symtab indices into the type table.
24625830Ssam */
24725830Ssam
entertype(type,arrindex,strindex,strtag)24825830Ssam private int entertype(type, arrindex, strindex, strtag)
24925830Ssam TWORD type;
25025830Ssam int arrindex;
25125830Ssam int strindex;
25225830Ssam int strtag;
25325830Ssam {
25425830Ssam register Typeid t;
25525830Ssam register int i;
25625830Ssam
25725830Ssam t = (Typeid) malloc(sizeof(struct Typeid));
25825830Ssam t->tword = type;
25925830Ssam t->tarray = arrindex;
26025830Ssam t->tstruct = strindex;
26125830Ssam t->tstrtag = strtag;
26225830Ssam t->tnum = tcount;
26325830Ssam ++tcount;
26425830Ssam i = type mod TABLESIZE;
26525830Ssam t->chain = typetable[i];
26625830Ssam typetable[i] = t;
26725830Ssam return t->tnum;
26825830Ssam }
26925830Ssam
27025830Ssam /*
27125830Ssam * Change the information associated with a type table entry.
27225830Ssam * Since I'm lazy this just creates a new entry with the number
27325830Ssam * as the old one.
27425830Ssam */
27525830Ssam
reentertype(typeid,type,arrindex,strindex,strtag)27625830Ssam private reentertype(typeid, type, arrindex, strindex, strtag)
27725830Ssam Typeid typeid;
27825830Ssam TWORD type;
27925830Ssam int arrindex;
28025830Ssam int strindex;
28125830Ssam int strtag;
28225830Ssam {
28325830Ssam register Typeid t;
28425830Ssam register int i;
28525830Ssam
28625830Ssam t = (Typeid) malloc(sizeof(struct Typeid));
28725830Ssam t->tword = type;
28825830Ssam t->tarray = arrindex;
28925830Ssam t->tstruct = strindex;
29025830Ssam t->tstrtag = strtag;
29125830Ssam t->tnum = typeid->tnum;
29225830Ssam i = type mod TABLESIZE;
29325830Ssam t->chain = typetable[i];
29425830Ssam typetable[i] = t;
29525830Ssam }
29625830Ssam
29725830Ssam /*
29825830Ssam * Initialize type table with predefined types.
29925830Ssam */
30025830Ssam
30125830Ssam #define builtintype(type) entertype(type, NILINDEX, NILINDEX, NILINDEX)
30225830Ssam
inittypes()30325830Ssam private inittypes()
30425830Ssam {
30525830Ssam int t;
30625830Ssam
30725830Ssam t_int = builtintype(INT);
30825830Ssam t_char = builtintype(CHAR);
30925830Ssam maketype("int", t_int, t_int, 0x80000000L, 0x7fffffffL);
31025830Ssam maketype("char", t_char, t_char, 0L, 127L);
31125830Ssam maketype("long", builtintype(LONG), t_int, 0x80000000L, 0x7fffffffL);
31225830Ssam maketype("short", builtintype(SHORT), t_int, 0xffff8000L, 0x7fffL);
31325830Ssam maketype("unsigned char", builtintype(UCHAR), t_int, 0L, 255L);
31425830Ssam maketype("unsigned short", builtintype(USHORT), t_int, 0L, 0xffffL);
31525830Ssam maketype("unsigned long", builtintype(ULONG), t_int, 0L, 0xffffffffL);
31625830Ssam maketype("unsigned int", builtintype(UNSIGNED), t_int, 0L, 0xffffffffL);
31725830Ssam maketype("float", builtintype(FLOAT), t_int, 4L, 0L);
31825830Ssam maketype("double", builtintype(DOUBLE), t_int, 8L, 0L);
31925830Ssam t = builtintype(UNDEF);
32025830Ssam printf("\t.stabs\t\"void:t%d=%d", t, t);
321*32897Sdonn geninfo((struct symtab *)nil);
32225830Ssam t = builtintype(FARG);
32325830Ssam printf("\t.stabs\t\"???:t%d=%d", t, t_int);
324*32897Sdonn geninfo((struct symtab *)nil);
32525830Ssam }
32625830Ssam
32725830Ssam /*
32825830Ssam * Generate info for a new range type.
32925830Ssam */
33025830Ssam
maketype(name,tnum,eqtnum,lower,upper)33125830Ssam private maketype(name, tnum, eqtnum, lower, upper)
33225830Ssam char *name;
33325830Ssam int tnum, eqtnum;
33425830Ssam long lower, upper;
33525830Ssam {
33625830Ssam printf("\t.stabs\t\"%s:t%d=r%d;%d;%d;", name, tnum, eqtnum, lower, upper);
337*32897Sdonn geninfo((struct symtab *)nil);
33825830Ssam }
33925830Ssam
34025830Ssam /*
34125830Ssam * Generate debugging information for the given type of the given symbol.
34225830Ssam */
34325830Ssam
gentype(sym)34425830Ssam private gentype(sym)
34525830Ssam struct symtab *sym;
34625830Ssam {
34725830Ssam register struct symtab *p;
34825830Ssam register TWORD t;
34925830Ssam register TWORD basictype;
35025830Ssam register Typeid typeid;
35125830Ssam int i, arrindex, strindex, strtag;
35225830Ssam
35325830Ssam p = sym;
35425830Ssam t = p->stype;
35525830Ssam if (ISFTN(t)) {
35625830Ssam t = DECREF(t);
35725830Ssam }
35825830Ssam basictype = BTYPE(t);
35925830Ssam if (ISARY(t)) {
36025830Ssam arrindex = p->dimoff;
36125830Ssam } else {
36225830Ssam arrindex = NILINDEX;
36325830Ssam }
36425830Ssam if (basictype == STRTY or basictype == UNIONTY or basictype == ENUMTY) {
36525830Ssam strindex = dimtab[p->sizoff + 1];
36625830Ssam if (strindex == -1) {
36725830Ssam strindex = FORWARD;
36825830Ssam strtag = dimtab[p->sizoff + 3];
36925830Ssam } else {
37025830Ssam strtag = NILINDEX;
37125830Ssam }
37225830Ssam } else {
37325830Ssam strindex = NILINDEX;
37425830Ssam strtag = NILINDEX;
37525830Ssam }
37625830Ssam i = arrindex;
37725830Ssam typeid = typelookup(t, arrindex, strindex, strtag);
37825830Ssam while (t != basictype and typeid == nil) {
37925830Ssam printf("%d=", entertype(t, i, strindex, strtag));
38025830Ssam switch (t&TMASK) {
38125830Ssam case PTR:
38225830Ssam printf("*");
38325830Ssam break;
38425830Ssam
38525830Ssam case FTN:
38625830Ssam printf("f");
38725830Ssam break;
38825830Ssam
38925830Ssam case ARY:
39025830Ssam printf("ar%d;0;%d;", t_int, dimtab[i++] - 1);
39125830Ssam break;
39225830Ssam }
39325830Ssam t = DECREF(t);
39429684Ssam if (i == NILINDEX && ISARY(t)) {
39529684Ssam i = p->dimoff;
39629684Ssam }
39725830Ssam if (t == basictype) {
39825830Ssam typeid = typelookup(t, NILINDEX, strindex, strtag);
39925830Ssam } else {
40025830Ssam typeid = typelookup(t, i, strindex, strtag);
40125830Ssam }
40225830Ssam }
40325830Ssam if (typeid == nil) {
40425830Ssam if (strindex == FORWARD) {
40525830Ssam typeid = typelookup(t, NILINDEX, FORWARD, dimtab[p->sizoff + 3]);
40625830Ssam if (typeid == nil) {
40725830Ssam cerror("unbelievable forward reference");
40825830Ssam }
40925830Ssam printf("%d", typeid->tnum);
41025830Ssam } else {
41125830Ssam genstruct(t, NILINDEX, strindex, p->sname, bsize(p));
41225830Ssam }
41325830Ssam } else {
41425830Ssam printf("%d", typeid->tnum);
41525830Ssam }
41625830Ssam }
41725830Ssam
41825830Ssam /*
41925830Ssam * Generate type information for structures, unions, and enumerations.
42025830Ssam */
42125830Ssam
genstruct(t,structid,index,name,size)42225830Ssam private genstruct(t, structid, index, name, size)
42325830Ssam TWORD t;
42425830Ssam int structid;
42525830Ssam int index;
42625830Ssam char *name;
42725830Ssam int size;
42825830Ssam {
42925830Ssam register int i;
43025830Ssam register struct symtab *field;
43125830Ssam int id;
43225830Ssam
43325830Ssam if (structid == NILINDEX) {
43425830Ssam id = entertype(t, NILINDEX, index, NILINDEX);
43525830Ssam } else {
43625830Ssam id = structid;
43725830Ssam }
43825830Ssam switch (t) {
43925830Ssam case STRTY:
44025830Ssam case UNIONTY:
44125830Ssam printf("%d=%c%d", id, t == STRTY ? 's' : 'u', size);
44225830Ssam i = index;
44325830Ssam while (dimtab[i] != -1) {
44425830Ssam field = &stab[dimtab[i]];
44525830Ssam printf("%s:", field->sname);
44625830Ssam gentype(field);
44725830Ssam if (field->sclass > FIELD) {
44825830Ssam printf(",%d,%d;", field->offset, field->sclass - FIELD);
44925830Ssam } else {
45025830Ssam printf(",%d,%d;", field->offset,
45125830Ssam tsize(field->stype, field->dimoff, field->sizoff));
45225830Ssam }
45325830Ssam ++i;
45425830Ssam }
45525830Ssam putchar(';');
45625830Ssam break;
45725830Ssam
45825830Ssam case ENUMTY:
45925830Ssam printf("%d=e", id);
46025830Ssam i = index;
46125830Ssam while (dimtab[i] != -1) {
46225830Ssam field = &stab[dimtab[i]];
46325830Ssam printf("%s:%d,", field->sname, field->offset);
46425830Ssam i++;
46525830Ssam }
46626079Ssam putchar(';');
46725830Ssam break;
46825830Ssam
46925830Ssam default:
47025830Ssam cerror("couldn't find basic type %d for %s\n", t, name);
47125830Ssam break;
47225830Ssam }
47325830Ssam }
47425830Ssam
47525830Ssam /*
47625830Ssam * Generate offset and size info.
47725830Ssam */
47825830Ssam
geninfo(p)47925830Ssam private geninfo(p)
48025830Ssam register struct symtab *p;
48125830Ssam {
48225830Ssam int stabtype;
48325830Ssam
48425830Ssam if (p == nil) {
48525830Ssam printf("\",0x%x,0,0,0\n", N_LSYM);
48625830Ssam } else {
48725830Ssam switch (p->sclass) {
48825830Ssam case EXTERN:
48925830Ssam case EXTDEF:
49025830Ssam if (ISFTN(p->stype)) {
49125830Ssam printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
49225830Ssam } else {
49325830Ssam printf("\",0x%x,0,%d,0\n", N_GSYM, bsize(p));
49425830Ssam }
49525830Ssam break;
49625830Ssam
49725830Ssam case STATIC:
49825830Ssam stabtype = stabLCSYM ? N_LCSYM : N_STSYM;
49925830Ssam if (ISFTN(p->stype)) {
50025830Ssam printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname);
50125830Ssam } else if (p->slevel > 1) {
50225830Ssam printf("\",0x%x,0,%d,L%d\n", stabtype, bsize(p), p->offset);
50325830Ssam } else {
50425830Ssam printf("\",0x%x,0,%d,_%s\n", stabtype, bsize(p), p->sname);
50525830Ssam }
50625830Ssam break;
50725830Ssam
50825830Ssam case REGISTER:
50925830Ssam printf("\",0x%x,0,%d,%d\n", N_RSYM, bsize(p), p->offset);
51025830Ssam break;
51125830Ssam
51225830Ssam case PARAM:
51325830Ssam printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff));
51425830Ssam break;
51525830Ssam
51625830Ssam default:
51725830Ssam printf("\",0x%x,0,%d,%d\n", N_LSYM, bsize(p), bytes(p->offset));
51825830Ssam break;
51925830Ssam }
52025830Ssam }
52125830Ssam }
52225830Ssam
52325830Ssam /*
52425830Ssam * Generate information for a newly-defined structure.
52525830Ssam */
52625830Ssam
527*32897Sdonn /*ARGSUSED*/
outstruct(szindex,paramindex)52825830Ssam outstruct(szindex, paramindex)
52925830Ssam int szindex, paramindex;
53025830Ssam {
53125830Ssam register Typeid typeid;
53225830Ssam register struct symtab *p;
53325830Ssam register int i, t, strindex;
53425830Ssam
53525830Ssam if (oldway) {
53625830Ssam /* do nothing */;
53725830Ssam } else if (gdebug) {
538*32897Sdonn if ((i = dimtab[szindex + 3]) >= 0 && (p = &stab[i])->sname != nil) {
53925830Ssam strindex = dimtab[p->sizoff + 1];
54025830Ssam typeid = typelookup(p->stype, NILINDEX, FORWARD, i);
54125830Ssam if (typeid == nil) {
54225830Ssam t = 0;
54325830Ssam } else {
54425830Ssam t = typeid->tnum;
54525830Ssam reentertype(typeid, p->stype, NILINDEX, strindex, NILINDEX);
54625830Ssam }
54725830Ssam printf("\t.stabs\t\"%s:T", p->sname);
54825830Ssam genstruct(p->stype, t, strindex, p->sname, bsize(p));
54925830Ssam geninfo(p);
55025830Ssam }
55125830Ssam }
55225830Ssam }
55325830Ssam
pstab(name,type)55425830Ssam pstab(name, type)
55525830Ssam char *name;
55625830Ssam int type;
55725830Ssam {
558*32897Sdonn #ifndef ASSTRINGS
55925830Ssam register int i;
56025830Ssam register char c;
561*32897Sdonn #endif
56225830Ssam
56325830Ssam if (!gdebug) {
56425830Ssam return;
56525830Ssam } else if (oldway) {
56625830Ssam old_pstab(name, type);
56725830Ssam return;
56825830Ssam }
56925830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */
57025830Ssam #ifdef ASSTRINGS
57125830Ssam if ( name[0] == '\0')
57225830Ssam printf("\t.stabn\t");
57325830Ssam else
57425830Ssam #ifndef FLEXNAMES
57525830Ssam printf("\t.stabs\t\"%.8s\",", name);
57625830Ssam #else
57725830Ssam printf("\t.stabs\t\"%s\",", name);
57825830Ssam #endif
57925830Ssam #else
58025830Ssam printf(" .stab ");
58125830Ssam for(i=0; i<8; i++)
58225830Ssam if (c = name[i]) printf("'%c,", c);
58325830Ssam else printf("0,");
58425830Ssam #endif
58525830Ssam printf("0%o,", type);
58625830Ssam }
58725830Ssam
58825830Ssam #ifdef STABDOT
pstabdot(type,value)58925830Ssam pstabdot(type, value)
59025830Ssam int type;
59125830Ssam int value;
59225830Ssam {
59325830Ssam if ( ! gdebug) {
59425830Ssam return;
59525830Ssam } else if (oldway) {
59625830Ssam old_pstabdot(type, value);
59725830Ssam return;
59825830Ssam }
59925830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */
60025830Ssam printf("\t.stabd\t");
60125830Ssam printf("0%o,0,0%o\n",type, value);
60225830Ssam }
60325830Ssam #endif
60425830Ssam
605*32897Sdonn #ifndef STABDOT
60625830Ssam extern char NULLNAME[8];
607*32897Sdonn #endif
60825830Ssam extern int labelno;
60925830Ssam extern int fdefflag;
61025830Ssam
psline()61125830Ssam psline()
61225830Ssam {
61325830Ssam static int lastlineno;
61425830Ssam register char *cp, *cq;
61525830Ssam register int i;
61625830Ssam
61725830Ssam if (!gdebug) {
61825830Ssam return;
61925830Ssam } else if (oldway) {
62025830Ssam old_psline();
62125830Ssam return;
62225830Ssam }
62325830Ssam
62425830Ssam cq = ititle;
62525830Ssam cp = ftitle;
62625830Ssam
62725830Ssam while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
62825830Ssam if ( *cp == '\0' ) goto eq;
62925830Ssam
63025830Ssam neq: for (i=0; i<100; i++)
63125830Ssam ititle[i] = '\0';
63225830Ssam cp = ftitle;
63325830Ssam cq = ititle;
63425830Ssam while ( *cp )
63525830Ssam *cq++ = *cp++;
63625830Ssam *cq = '\0';
63725830Ssam *--cq = '\0';
63825830Ssam #ifndef FLEXNAMES
63925830Ssam for ( cp = ititle+1; *(cp-1); cp += 8 ) {
64025830Ssam pstab(cp, N_SOL);
64125830Ssam if (gdebug) printf("0,0,LL%d\n", labelno);
64225830Ssam }
64325830Ssam #else
64425830Ssam pstab(ititle+1, N_SOL);
64525830Ssam if (gdebug) printf("0,0,LL%d\n", labelno);
64625830Ssam #endif
64725830Ssam *cq = '"';
64825830Ssam printf("LL%d:\n", labelno++);
64925830Ssam
65025830Ssam eq: if (lineno == lastlineno) return;
65125830Ssam lastlineno = lineno;
65225830Ssam
65325830Ssam if (fdefflag) {
65425830Ssam #ifdef STABDOT
65525830Ssam pstabdot(N_SLINE, lineno);
65625830Ssam #else
65725830Ssam pstab(NULLNAME, N_SLINE);
65825830Ssam printf("0,%d,LL%d\n", lineno, labelno);
65925830Ssam printf("LL%d:\n", labelno++);
66025830Ssam #endif
66125830Ssam }
66225830Ssam }
66325830Ssam
plcstab(level)66425830Ssam plcstab(level)
66525830Ssam int level;
66625830Ssam {
66725830Ssam if (!gdebug) {
66825830Ssam return;
66925830Ssam } else if (oldway) {
67025830Ssam old_plcstab(level);
67125830Ssam return;
67225830Ssam }
67325830Ssam #ifdef STABDOT
67425830Ssam pstabdot(N_LBRAC, level);
67525830Ssam #else
67625830Ssam pstab(NULLNAME, N_LBRAC);
67725830Ssam printf("0,%d,LL%d\n", level, labelno);
67825830Ssam printf("LL%d:\n", labelno++);
67925830Ssam #endif
68025830Ssam }
68125830Ssam
prcstab(level)68225830Ssam prcstab(level)
68325830Ssam int level;
68425830Ssam {
68525830Ssam if (!gdebug) {
68625830Ssam return;
68725830Ssam } else if (oldway) {
68825830Ssam old_prcstab(level);
68925830Ssam return;
69025830Ssam }
69125830Ssam #ifdef STABDOT
69225830Ssam pstabdot(N_RBRAC, level);
69325830Ssam #else
69425830Ssam pstab(NULLNAME, N_RBRAC);
69525830Ssam printf("0,%d,LL%d\n", level, labelno);
69625830Ssam printf("LL%d:\n", labelno++);
69725830Ssam #endif
69825830Ssam }
69925830Ssam
pfstab(sname)70025830Ssam pfstab(sname)
70125830Ssam char *sname;
70225830Ssam {
70325830Ssam register struct symtab *p;
70425830Ssam
70525830Ssam if (gdebug) {
70625830Ssam if (oldway) {
70725830Ssam old_pfstab(sname);
70825830Ssam } else {
70925830Ssam p = &stab[lookup(sname, 0)];
71025830Ssam printf("\t.stabs\t\"%s:", p->sname);
71125830Ssam putchar((p->sclass == STATIC) ? 'f' : 'F');
71225830Ssam gentype(p);
71325830Ssam geninfo(p);
71425830Ssam }
71525830Ssam }
71625830Ssam }
71725830Ssam
71825830Ssam /*
71925830Ssam * Old way of doing things.
72025830Ssam */
72125830Ssam
old_fixarg(p)72225830Ssam private old_fixarg(p)
72325830Ssam struct symtab *p; {
72425830Ssam if (gdebug) {
72525830Ssam old_pstab(p->sname, N_PSYM);
72625830Ssam if (gdebug) printf("0,%d,%d\n", p->stype, argoff/SZCHAR);
72725830Ssam old_poffs(p);
72825830Ssam }
72925830Ssam }
73025830Ssam
old_outstab(p)73125830Ssam private old_outstab(p)
73225830Ssam struct symtab *p; {
73325830Ssam register TWORD ptype;
73425830Ssam register char *pname;
73525830Ssam register char pclass;
73625830Ssam register int poffset;
73725830Ssam
73825830Ssam if (!gdebug) return;
73925830Ssam
74025830Ssam ptype = p->stype;
74125830Ssam pname = p->sname;
74225830Ssam pclass = p->sclass;
74325830Ssam poffset = p->offset;
74425830Ssam
74525830Ssam if (ISFTN(ptype)) {
74625830Ssam return;
74725830Ssam }
74825830Ssam
74925830Ssam switch (pclass) {
75025830Ssam
75125830Ssam case AUTO:
75225830Ssam old_pstab(pname, N_LSYM);
75325830Ssam printf("0,%d,%d\n", ptype, (-poffset)/SZCHAR);
75425830Ssam old_poffs(p);
75525830Ssam return;
75625830Ssam
75725830Ssam case EXTDEF:
75825830Ssam case EXTERN:
75925830Ssam old_pstab(pname, N_GSYM);
76025830Ssam printf("0,%d,0\n", ptype);
76125830Ssam old_poffs(p);
76225830Ssam return;
76325830Ssam
76425830Ssam case STATIC:
76525830Ssam #ifdef LCOMM
76625830Ssam /* stabLCSYM is 1 during nidcl so we can get stab type right */
76725830Ssam old_pstab(pname, stabLCSYM ? N_LCSYM : N_STSYM);
76825830Ssam #else
76925830Ssam old_pstab(pname, N_STSYM);
77025830Ssam #endif
77125830Ssam if (p->slevel > 1) {
77225830Ssam printf("0,%d,L%d\n", ptype, poffset);
77325830Ssam } else {
77425830Ssam printf("0,%d,%s\n", ptype, exname(pname));
77525830Ssam }
77625830Ssam old_poffs(p);
77725830Ssam return;
77825830Ssam
77925830Ssam case REGISTER:
78025830Ssam old_pstab(pname, N_RSYM);
78125830Ssam printf("0,%d,%d\n", ptype, poffset);
78225830Ssam old_poffs(p);
78325830Ssam return;
78425830Ssam
78525830Ssam case MOS:
78625830Ssam case MOU:
78725830Ssam old_pstab(pname, N_SSYM);
78825830Ssam printf("0,%d,%d\n", ptype, poffset/SZCHAR);
78925830Ssam old_poffs(p);
79025830Ssam return;
79125830Ssam
79225830Ssam case PARAM:
79325830Ssam /* parameter stab entries are processed in dclargs() */
79425830Ssam return;
79525830Ssam
79625830Ssam default:
79725830Ssam #ifndef FLEXNAMES
79825830Ssam if (ddebug) printf(" No .stab for %.8s\n", pname);
79925830Ssam #else
80025830Ssam if (ddebug) printf(" No .stab for %s\n", pname);
80125830Ssam #endif
80225830Ssam
80325830Ssam }
80425830Ssam }
80525830Ssam
old_pstab(name,type)80625830Ssam private old_pstab(name, type)
80725830Ssam char *name;
80825830Ssam int type; {
809*32897Sdonn #ifndef ASSTRINGS
81025830Ssam register int i;
81125830Ssam register char c;
812*32897Sdonn #endif
81325830Ssam if (!gdebug) return;
81425830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */
81525830Ssam #ifdef ASSTRINGS
81625830Ssam if ( name[0] == '\0')
81725830Ssam printf("\t.stabn\t");
81825830Ssam else
81925830Ssam #ifndef FLEXNAMES
82025830Ssam printf("\t.stabs\t\"%.8s\", ", name);
82125830Ssam #else
82225830Ssam printf("\t.stabs\t\"%s\", ", name);
82325830Ssam #endif
82425830Ssam #else
82525830Ssam printf(" .stab ");
82625830Ssam for(i=0; i<8; i++)
82725830Ssam if (c = name[i]) printf("'%c,", c);
82825830Ssam else printf("0,");
82925830Ssam #endif
83025830Ssam printf("0%o,", type);
83125830Ssam }
83225830Ssam
83325830Ssam #ifdef STABDOT
old_pstabdot(type,value)83425830Ssam private old_pstabdot(type, value)
83525830Ssam int type;
83625830Ssam int value;
83725830Ssam {
83825830Ssam if ( ! gdebug) return;
83925830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */
84025830Ssam printf("\t.stabd\t");
84125830Ssam printf("0%o,0,0%o\n",type, value);
84225830Ssam }
84325830Ssam #endif
84425830Ssam
old_poffs(p)84525830Ssam private old_poffs(p)
84625830Ssam register struct symtab *p; {
84725830Ssam int s;
84825830Ssam if (!gdebug) return;
84925830Ssam if ((s = dimtab[p->sizoff]/SZCHAR) > 1) {
85025830Ssam old_pstab(p->sname, N_LENG);
85125830Ssam printf("1,0,%d\n", s);
85225830Ssam }
85325830Ssam }
85425830Ssam
old_psline()85525830Ssam private old_psline() {
85625830Ssam static int lastlineno;
85725830Ssam register char *cp, *cq;
85825830Ssam register int i;
85925830Ssam
86025830Ssam if (!gdebug) return;
86125830Ssam
86225830Ssam cq = ititle;
86325830Ssam cp = ftitle;
86425830Ssam
86525830Ssam while ( *cq ) if ( *cp++ != *cq++ ) goto neq;
86625830Ssam if ( *cp == '\0' ) goto eq;
86725830Ssam
86825830Ssam neq: for (i=0; i<100; i++)
86925830Ssam ititle[i] = '\0';
87025830Ssam cp = ftitle;
87125830Ssam cq = ititle;
87225830Ssam while ( *cp )
87325830Ssam *cq++ = *cp++;
87425830Ssam *cq = '\0';
87525830Ssam *--cq = '\0';
87625830Ssam #ifndef FLEXNAMES
87725830Ssam for ( cp = ititle+1; *(cp-1); cp += 8 ) {
87825830Ssam old_pstab(cp, N_SOL);
87925830Ssam if (gdebug) printf("0,0,LL%d\n", labelno);
88025830Ssam }
88125830Ssam #else
88225830Ssam old_pstab(ititle+1, N_SOL);
88325830Ssam if (gdebug) printf("0,0,LL%d\n", labelno);
88425830Ssam #endif
88525830Ssam *cq = '"';
88625830Ssam printf("LL%d:\n", labelno++);
88725830Ssam
88825830Ssam eq: if (lineno == lastlineno) return;
88925830Ssam lastlineno = lineno;
89025830Ssam
89125830Ssam if (fdefflag) {
89225830Ssam #ifdef STABDOT
89325830Ssam old_pstabdot(N_SLINE, lineno);
89425830Ssam #else
89525830Ssam old_pstab(NULLNAME, N_SLINE);
89625830Ssam printf("0,%d,LL%d\n", lineno, labelno);
89725830Ssam printf("LL%d:\n", labelno++);
89825830Ssam #endif
89925830Ssam }
90025830Ssam }
90125830Ssam
old_plcstab(level)90225830Ssam private old_plcstab(level) {
90325830Ssam if (!gdebug) return;
90425830Ssam #ifdef STABDOT
90525830Ssam old_pstabdot(N_LBRAC, level);
90625830Ssam #else
90725830Ssam old_pstab(NULLNAME, N_LBRAC);
90825830Ssam printf("0,%d,LL%d\n", level, labelno);
90925830Ssam printf("LL%d:\n", labelno++);
91025830Ssam #endif
91125830Ssam }
91225830Ssam
old_prcstab(level)91325830Ssam private old_prcstab(level) {
91425830Ssam if (!gdebug) return;
91525830Ssam #ifdef STABDOT
91625830Ssam pstabdot(N_RBRAC, level);
91725830Ssam #else
91825830Ssam pstab(NULLNAME, N_RBRAC);
91925830Ssam printf("0,%d,LL%d\n", level, labelno);
92025830Ssam printf("LL%d:\n", labelno++);
92125830Ssam #endif
92225830Ssam }
92325830Ssam
old_pfstab(sname)92425830Ssam private old_pfstab(sname)
92525830Ssam char *sname; {
92625830Ssam if (!gdebug) return;
92725830Ssam pstab(sname, N_FUN);
92825830Ssam #ifndef FLEXNAMES
92925830Ssam printf("0,%d,_%.7s\n", lineno, sname);
93025830Ssam #else
93125830Ssam printf("0,%d,_%s\n", lineno, sname);
93225830Ssam #endif
93325830Ssam }
934