|
|
1.1 root 1: /*
2: * Symbolic debugging info interface.
3: *
4: * Here we generate pseudo-ops that cause the assembler to put
5: * symbolic debugging information into the object file.
6: */
7: #include "cpass1.h"
8: #include <sys/types.h>
9: #include <a.out.h>
10: #include "stab.h"
11:
1.1.1.2 ! root 12: static int inastruct;
! 13: static int inafunc;
! 14: static int inbegfunc;
! 15: static int inaparam;
! 16: static char strvalfmt[] = " .stabs \"%s\",0x%x,0,%d,%d\n";
! 17: static char strsymfmt[] = " .stabs \"%s\",0x%x,0,%d,%s\n";
! 18: static char nulvalfmt[] = " .stabn 0x%x,0,%d,%d\n";
! 19: static char nulsymfmt[] = " .stabn 0x%x,0,%d,%s\n";
! 20: static char dotfmt[] = " .stabd 0x%x,0,%d\n";
1.1 root 21:
22: extern int gdebug;
23: extern char *strcpy();
24: int stabLCSYM;
25:
26: /*
1.1.1.2 ! root 27: * Old flag, not used anymore.
1.1 root 28: */
1.1.1.2 ! root 29: int oldway = 0;
1.1 root 30:
31: /*
32: * Generate information for a newly-defined structure.
33: */
34: outstruct(szindex, paramindex)
35: int szindex, paramindex;
36: {
1.1.1.2 ! root 37: register struct symtab *p;
! 38: register int i;
1.1 root 39:
1.1.1.2 ! root 40: if (!gdebug)
! 41: return;
! 42: inastruct = 1;
! 43: p = STP(dimtab[szindex + 3]);
! 44: printf(strvalfmt, p->sname, N_BSTR, p->stype, 0);
! 45: outstab(STP(dimtab[szindex + 3]));
! 46: for( i = dimtab[szindex + 1]; dimtab[i] > 0; i++)
! 47: outstab(STP(dimtab[i]));
! 48: printf(strvalfmt, p->sname, N_ESTR, p->stype, dimtab[p->sizoff]/SZCHAR);
! 49: inastruct = 0;
1.1 root 50: }
51:
52: psline(lineno)
53: int lineno;
54: {
1.1.1.2 ! root 55: if (gdebug && !dbfile(NULL))
! 56: printf(dotfmt, N_SLINE, lineno);
1.1 root 57: }
58:
59: plcstab(level)
60: int level;
61: {
1.1.1.2 ! root 62: if (gdebug)
! 63: printf(dotfmt, N_LBRAC, level);
1.1 root 64: }
65:
66: prcstab(level)
67: int level;
68: {
1.1.1.2 ! root 69: if (gdebug)
! 70: printf(dotfmt, N_RBRAC, level);
1.1 root 71: }
72:
73: pfstab(sname)
74: char *sname;
75: {
76: register struct symtab *p;
77:
1.1.1.2 ! root 78: if (!gdebug)
! 79: return;
! 80: p = STP(lookup(sname, 0));
! 81: inafunc = 1;
! 82: inbegfunc = 1;
! 83: /* dbfile(exname(p->sname));*/
! 84: locctr(PROG);
! 85: printf(strsymfmt, p->sname, N_BFUN, lineno, exname(p->sname));
! 86: outstab(p);
! 87: inbegfunc = 0;
1.1 root 88: }
89:
1.1.1.2 ! root 90: #define BYTOFF(p) (((off = (p)->offset) < 0 ? -off : off)/SZCHAR)
! 91:
1.1 root 92: /*
1.1.1.2 ! root 93: * Generate debugging info for a parameter.
! 94: * The offset isn't known when it is first entered into the symbol table
! 95: * since the types are read later.
1.1 root 96: */
1.1.1.2 ! root 97: fixarg(p)
! 98: struct symtab *p;
1.1 root 99: {
1.1.1.2 ! root 100: if (!gdebug)
1.1 root 101: return;
1.1.1.2 ! root 102: inaparam = 1;
! 103: outstab(p);
! 104: inaparam = 0;
1.1 root 105: }
106:
1.1.1.2 ! root 107: static char labstr[16];
1.1 root 108:
1.1.1.2 ! root 109: static char *
! 110: maklab(val)
! 111: {
! 112: sprintf(labstr, "L%d", val);
! 113: return labstr;
1.1 root 114: }
115:
1.1.1.2 ! root 116: # ifndef OUTREGNO
! 117: # define OUTREGNO(p) ((p)->offset)
! 118: # endif
! 119:
1.1 root 120: /*
1.1.1.2 ! root 121: * Generate debugging info for a given symbol.
1.1 root 122: */
1.1.1.2 ! root 123: outstab(p)
! 124: register struct symtab *p; {
1.1 root 125:
1.1.1.2 ! root 126: register TWORD t;
! 127: register off, i;
1.1 root 128:
1.1.1.2 ! root 129: if (!gdebug)
! 130: return;
! 131: if (ISFTN(p->stype) && !inbegfunc)
! 132: return;
! 133: if( p->sclass > FIELD ) {
! 134: if (!inastruct)
! 135: return;
! 136: printf(strvalfmt, p->sname, N_SFLD,
! 137: ((p->sclass - FIELD)<<BTSHIFT)|p->stype, p->offset);
1.1 root 138: return;
139: }
1.1.1.2 ! root 140:
! 141: switch( p->sclass )
! 142: {
1.1 root 143: case AUTO:
1.1.1.2 ! root 144: printf(strvalfmt, p->sname, N_LSYM, p->stype, BYTOFF(p));
! 145: break;
! 146: case REGISTER:
! 147: if (!inafunc)
! 148: return;
! 149: if (inaparam) {
! 150: p->sclass = PARAM;
! 151: outstab(p);
! 152: p->sclass = REGISTER;
! 153: }
! 154: printf(strvalfmt, p->sname, N_RSYM, p->stype, OUTREGNO(p));
! 155: break;
! 156: case PARAM:
! 157: if (!inaparam)
! 158: return;
! 159: printf(strvalfmt, p->sname, N_PSYM, p->stype, argoff/SZCHAR);
! 160: break;
1.1 root 161: case EXTERN:
1.1.1.2 ! root 162: case EXTDEF:
! 163: printf(strvalfmt, p->sname, N_GSYM, p->stype, 0);
! 164: break;
1.1 root 165: case STATIC:
1.1.1.2 ! root 166: if (ISFTN(p->stype))
! 167: printf(strvalfmt, p->sname, N_STFUN, p->stype, 0);
! 168: else
! 169: printf(strsymfmt, p->sname,
! 170: stabLCSYM ? N_LCSYM : N_STSYM, p->stype,
! 171: p->slevel ? maklab(p->offset) : exname(p->sname));
! 172: break;
1.1 root 173: case MOS:
174: case MOU:
1.1.1.2 ! root 175: if (!inastruct)
! 176: return;
! 177: printf(strvalfmt, p->sname, N_SSYM, p->stype, BYTOFF(p));
! 178: break;
! 179: case MOE:
! 180: if (!inastruct)
! 181: return;
! 182: printf(strvalfmt, p->sname, N_SSYM, p->stype, p->offset);
1.1 root 183: return;
184: default:
1.1.1.2 ! root 185: return;
! 186: }
! 187: /* make another entry to describe structs, unions, enums */
! 188: switch( BTYPE(p->stype) ) {
! 189: case STRTY:
! 190: case UNIONTY:
! 191: case ENUMTY:
! 192: printf(strvalfmt, STP(dimtab[p->sizoff+3])->sname,
! 193: N_TYID, 0, 0);
! 194: }
! 195:
! 196: /* make other entries with the dimensions */
! 197: for( t=p->stype, i=p->dimoff; t&TMASK; t = DECREF(t) )
! 198: {
! 199: if( ISARY(t) ) printf(nulvalfmt, N_DIM, 0, dimtab[i++]);
1.1 root 200: }
201:
202: }
203:
1.1.1.2 ! root 204: dbfunend( lab ) /* end of a function */
1.1 root 205: {
1.1.1.2 ! root 206: if (!gdebug)
! 207: return;
! 208: inafunc = 0;
! 209: printf(dotfmt, N_EFUN, lineno);
1.1 root 210: }
211:
1.1.1.2 ! root 212: beg_file() /* only used in cgram.y */
! 213: {
! 214: if (!gdebug)
! 215: return;
! 216: dbfile(NULL);
1.1 root 217: }
218:
1.1.1.2 ! root 219: static char orgfile[100], currfile[100], prtfile[100];
1.1 root 220:
1.1.1.2 ! root 221: static int srcfilop = N_SO;
1.1 root 222:
1.1.1.2 ! root 223: static char *
! 224: makstr(ip)
! 225: register char *ip;
! 226: {
! 227: register c; register char *jp = prtfile;
! 228: do {
! 229: if ((c = *ip++) != '"')
! 230: *jp++ = c;
! 231: } while (c);
! 232: return prtfile;
! 233: }
! 234:
! 235: dbfile(pname)
! 236: char *pname;
! 237: {
! 238: int seg;
! 239: if (!strcmp(currfile, ftitle))
! 240: return 0;
! 241: strcpy(currfile, ftitle);
! 242: seg = locctr(PROG);
! 243: if (pname == NULL)
! 244: printf("%s:", pname = maklab(getlab()));
! 245: printf(strsymfmt, makstr(currfile), srcfilop, lineno, pname);
! 246: if (srcfilop == N_SO) { /* first file */
! 247: strcpy(orgfile, ftitle);
! 248: srcfilop = N_SOL;
1.1 root 249: }
1.1.1.2 ! root 250: if (seg >= 0)
! 251: locctr(seg);
! 252: return 1;
1.1 root 253: }
254:
1.1.1.2 ! root 255: ejsdb()
1.1 root 256: {
1.1.1.2 ! root 257: /* called at the end of the entire file */
! 258: if (!gdebug)
! 259: return;
! 260: printf("\t.text\n");
! 261: printf("%s:", maklab(getlab()));
! 262: printf(strsymfmt, makstr(orgfile), N_ESO, lineno, labstr);
1.1 root 263: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.