1*25830Ssam #ifndef lint 2*25830Ssam static char sccsid[] = "@(#)stab.c 1.1 (Berkeley) 01/11/86"; 3*25830Ssam #endif 4*25830Ssam 5*25830Ssam #ifndef lint 6*25830Ssam static char *sccsid ="@(#)stab.c 1.9 (Berkeley) 8/11/83"; 7*25830Ssam #endif 8*25830Ssam /* 9*25830Ssam * Symbolic debugging info interface. 10*25830Ssam * 11*25830Ssam * Here we generate pseudo-ops that cause the assembler to put 12*25830Ssam * symbolic debugging information into the object file. 13*25830Ssam */ 14*25830Ssam 15*25830Ssam #include "mfile1" 16*25830Ssam 17*25830Ssam #include <sys/types.h> 18*25830Ssam #include <a.out.h> 19*25830Ssam #include <stab.h> 20*25830Ssam 21*25830Ssam #define private static 22*25830Ssam #define and && 23*25830Ssam #define or || 24*25830Ssam #define not ! 25*25830Ssam #define div / 26*25830Ssam #define mod % 27*25830Ssam #define nil 0 28*25830Ssam 29*25830Ssam #define bytes(bits) ((bits) / SZCHAR) 30*25830Ssam #define bsize(p) bytes(dimtab[p->sizoff]) /* size in bytes of a symbol */ 31*25830Ssam 32*25830Ssam #define NILINDEX -1 33*25830Ssam #define FORWARD -2 34*25830Ssam 35*25830Ssam typedef int Boolean; 36*25830Ssam 37*25830Ssam #define false 0 38*25830Ssam #define true 1 39*25830Ssam 40*25830Ssam extern int ddebug; 41*25830Ssam extern int gdebug; 42*25830Ssam extern char *malloc(); 43*25830Ssam 44*25830Ssam int stabLCSYM; 45*25830Ssam 46*25830Ssam /* 47*25830Ssam * Flag for producing either sdb or dbx symbol information. 48*25830Ssam */ 49*25830Ssam int oldway = false; 50*25830Ssam 51*25830Ssam /* 52*25830Ssam * Generate debugging info for a parameter. 53*25830Ssam * The offset isn't known when it is first entered into the symbol table 54*25830Ssam * since the types are read later. 55*25830Ssam */ 56*25830Ssam 57*25830Ssam fixarg(p) 58*25830Ssam struct symtab *p; 59*25830Ssam { 60*25830Ssam if (oldway) { 61*25830Ssam old_fixarg(p); 62*25830Ssam } else if (gdebug) { 63*25830Ssam printf("\t.stabs\t\"%s:p", p->sname); 64*25830Ssam gentype(p); 65*25830Ssam printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff)); 66*25830Ssam } 67*25830Ssam } 68*25830Ssam 69*25830Ssam /* 70*25830Ssam * Determine if the given symbol is a global array with dimension 0, 71*25830Ssam * which only makes sense if it's dimension is to be given later. 72*25830Ssam * We therefore currently do not generate symbol information for 73*25830Ssam * such entries. 74*25830Ssam */ 75*25830Ssam 76*25830Ssam #define isglobal(class) ( \ 77*25830Ssam class == EXTDEF or class == EXTERN or class == STATIC \ 78*25830Ssam ) 79*25830Ssam 80*25830Ssam private Boolean zero_length_array(p) 81*25830Ssam register struct symtab *p; 82*25830Ssam { 83*25830Ssam Boolean b; 84*25830Ssam int t; 85*25830Ssam 86*25830Ssam if (not isglobal(p->sclass)) { 87*25830Ssam b = false; 88*25830Ssam } else { 89*25830Ssam t = p->stype; 90*25830Ssam if (ISFTN(t)) { 91*25830Ssam t = DECREF(t); 92*25830Ssam } 93*25830Ssam b = (Boolean) (ISARY(t) and dimtab[p->dimoff] == 0); 94*25830Ssam } 95*25830Ssam return b; 96*25830Ssam } 97*25830Ssam 98*25830Ssam /* 99*25830Ssam * Generate debugging info for a given symbol. 100*25830Ssam */ 101*25830Ssam 102*25830Ssam outstab(sym) 103*25830Ssam struct symtab *sym; 104*25830Ssam { 105*25830Ssam register struct symtab *p; 106*25830Ssam char *classname; 107*25830Ssam int offset; 108*25830Ssam Boolean ignore; 109*25830Ssam static Boolean firsttime = true; 110*25830Ssam 111*25830Ssam if (oldway) { 112*25830Ssam old_outstab(sym); 113*25830Ssam } else if (gdebug and not zero_length_array(sym)) { 114*25830Ssam if (firsttime) { 115*25830Ssam firsttime = false; 116*25830Ssam inittypes(); 117*25830Ssam } 118*25830Ssam ignore = false; 119*25830Ssam p = sym; 120*25830Ssam offset = bytes(p->offset); 121*25830Ssam switch (p->sclass) { 122*25830Ssam case REGISTER: 123*25830Ssam classname = "r"; 124*25830Ssam offset = p->offset; 125*25830Ssam break; 126*25830Ssam 127*25830Ssam /* 128*25830Ssam * Locals are the default class. 129*25830Ssam */ 130*25830Ssam case AUTO: 131*25830Ssam classname = ""; 132*25830Ssam break; 133*25830Ssam 134*25830Ssam case STATIC: 135*25830Ssam if (ISFTN(p->stype)) { 136*25830Ssam ignore = true; 137*25830Ssam } else if (p->slevel <= 1) { 138*25830Ssam classname = "S"; 139*25830Ssam } else { 140*25830Ssam classname = "V"; 141*25830Ssam } 142*25830Ssam break; 143*25830Ssam 144*25830Ssam case EXTDEF: 145*25830Ssam case EXTERN: 146*25830Ssam if (ISFTN(p->stype)) { 147*25830Ssam ignore = true; 148*25830Ssam } else { 149*25830Ssam classname = "G"; 150*25830Ssam } 151*25830Ssam break; 152*25830Ssam 153*25830Ssam case TYPEDEF: 154*25830Ssam classname = "t"; 155*25830Ssam break; 156*25830Ssam 157*25830Ssam case PARAM: 158*25830Ssam case MOS: 159*25830Ssam case MOU: 160*25830Ssam case MOE: 161*25830Ssam ignore = true; 162*25830Ssam break; 163*25830Ssam 164*25830Ssam case ENAME: 165*25830Ssam case UNAME: 166*25830Ssam case STNAME: 167*25830Ssam entertype(p->stype, NILINDEX, FORWARD, dimtab[p->sizoff + 3]); 168*25830Ssam ignore = true; 169*25830Ssam break; 170*25830Ssam 171*25830Ssam default: 172*25830Ssam if ((p->sclass&FIELD) == 0) { 173*25830Ssam printf("/* no info for %s (%d) */\n", p->sname, p->sclass); 174*25830Ssam } 175*25830Ssam ignore = true; 176*25830Ssam break; 177*25830Ssam } 178*25830Ssam if (not ignore) { 179*25830Ssam printf("\t.stabs\t\"%s:%s", p->sname, classname); 180*25830Ssam gentype(p); 181*25830Ssam geninfo(p); 182*25830Ssam } 183*25830Ssam } 184*25830Ssam } 185*25830Ssam 186*25830Ssam /* 187*25830Ssam * Since type names are lost in the travels and because C has 188*25830Ssam * structural type equivalence we keep a table of type words that 189*25830Ssam * we've already seen. The first time we see a type, it is assigned 190*25830Ssam * (inline) a number and future references just list that number. 191*25830Ssam * Structures, unions, enums, and arrays must be handled carefully 192*25830Ssam * since not all the necessary information is in the type word. 193*25830Ssam */ 194*25830Ssam 195*25830Ssam typedef struct Typeid *Typeid; 196*25830Ssam 197*25830Ssam struct Typeid { 198*25830Ssam TWORD tword; 199*25830Ssam int tarray; 200*25830Ssam int tstruct; 201*25830Ssam int tstrtag; 202*25830Ssam int tnum; 203*25830Ssam Typeid chain; 204*25830Ssam }; 205*25830Ssam 206*25830Ssam #define TABLESIZE 2003 207*25830Ssam 208*25830Ssam private int tcount = 1; 209*25830Ssam private int t_int, t_char; 210*25830Ssam private Typeid typetable[TABLESIZE]; 211*25830Ssam 212*25830Ssam /* 213*25830Ssam * Look for the given type word in the type table. 214*25830Ssam */ 215*25830Ssam 216*25830Ssam private Typeid typelookup(type, arrindex, strindex, strtag) 217*25830Ssam TWORD type; 218*25830Ssam int arrindex; 219*25830Ssam int strindex; 220*25830Ssam int strtag; 221*25830Ssam { 222*25830Ssam register TWORD tword; 223*25830Ssam register int i1, i2; 224*25830Ssam Typeid t; 225*25830Ssam 226*25830Ssam t = typetable[type mod TABLESIZE]; 227*25830Ssam while (t != nil) { 228*25830Ssam if (t->tword == type and 229*25830Ssam strindex == t->tstruct and strtag == t->tstrtag) { 230*25830Ssam if (arrindex == NILINDEX) { 231*25830Ssam break; 232*25830Ssam } else { 233*25830Ssam tword = type; 234*25830Ssam i1 = arrindex; 235*25830Ssam i2 = t->tarray; 236*25830Ssam while (ISARY(tword) and dimtab[i1] == dimtab[i2]) { 237*25830Ssam ++i1; 238*25830Ssam ++i2; 239*25830Ssam tword >>= TSHIFT; 240*25830Ssam } 241*25830Ssam if (!ISARY(tword)) { 242*25830Ssam break; 243*25830Ssam } 244*25830Ssam } 245*25830Ssam } 246*25830Ssam t = t->chain; 247*25830Ssam } 248*25830Ssam return t; 249*25830Ssam } 250*25830Ssam 251*25830Ssam /* 252*25830Ssam * Enter a type word and associated symtab indices into the type table. 253*25830Ssam */ 254*25830Ssam 255*25830Ssam private int entertype(type, arrindex, strindex, strtag) 256*25830Ssam TWORD type; 257*25830Ssam int arrindex; 258*25830Ssam int strindex; 259*25830Ssam int strtag; 260*25830Ssam { 261*25830Ssam register Typeid t; 262*25830Ssam register int i; 263*25830Ssam 264*25830Ssam t = (Typeid) malloc(sizeof(struct Typeid)); 265*25830Ssam t->tword = type; 266*25830Ssam t->tarray = arrindex; 267*25830Ssam t->tstruct = strindex; 268*25830Ssam t->tstrtag = strtag; 269*25830Ssam t->tnum = tcount; 270*25830Ssam ++tcount; 271*25830Ssam i = type mod TABLESIZE; 272*25830Ssam t->chain = typetable[i]; 273*25830Ssam typetable[i] = t; 274*25830Ssam return t->tnum; 275*25830Ssam } 276*25830Ssam 277*25830Ssam /* 278*25830Ssam * Change the information associated with a type table entry. 279*25830Ssam * Since I'm lazy this just creates a new entry with the number 280*25830Ssam * as the old one. 281*25830Ssam */ 282*25830Ssam 283*25830Ssam private reentertype(typeid, type, arrindex, strindex, strtag) 284*25830Ssam Typeid typeid; 285*25830Ssam TWORD type; 286*25830Ssam int arrindex; 287*25830Ssam int strindex; 288*25830Ssam int strtag; 289*25830Ssam { 290*25830Ssam register Typeid t; 291*25830Ssam register int i; 292*25830Ssam 293*25830Ssam t = (Typeid) malloc(sizeof(struct Typeid)); 294*25830Ssam t->tword = type; 295*25830Ssam t->tarray = arrindex; 296*25830Ssam t->tstruct = strindex; 297*25830Ssam t->tstrtag = strtag; 298*25830Ssam t->tnum = typeid->tnum; 299*25830Ssam i = type mod TABLESIZE; 300*25830Ssam t->chain = typetable[i]; 301*25830Ssam typetable[i] = t; 302*25830Ssam } 303*25830Ssam 304*25830Ssam /* 305*25830Ssam * Initialize type table with predefined types. 306*25830Ssam */ 307*25830Ssam 308*25830Ssam #define builtintype(type) entertype(type, NILINDEX, NILINDEX, NILINDEX) 309*25830Ssam 310*25830Ssam private inittypes() 311*25830Ssam { 312*25830Ssam int t; 313*25830Ssam 314*25830Ssam t_int = builtintype(INT); 315*25830Ssam t_char = builtintype(CHAR); 316*25830Ssam maketype("int", t_int, t_int, 0x80000000L, 0x7fffffffL); 317*25830Ssam maketype("char", t_char, t_char, 0L, 127L); 318*25830Ssam maketype("long", builtintype(LONG), t_int, 0x80000000L, 0x7fffffffL); 319*25830Ssam maketype("short", builtintype(SHORT), t_int, 0xffff8000L, 0x7fffL); 320*25830Ssam maketype("unsigned char", builtintype(UCHAR), t_int, 0L, 255L); 321*25830Ssam maketype("unsigned short", builtintype(USHORT), t_int, 0L, 0xffffL); 322*25830Ssam maketype("unsigned long", builtintype(ULONG), t_int, 0L, 0xffffffffL); 323*25830Ssam maketype("unsigned int", builtintype(UNSIGNED), t_int, 0L, 0xffffffffL); 324*25830Ssam maketype("float", builtintype(FLOAT), t_int, 4L, 0L); 325*25830Ssam maketype("double", builtintype(DOUBLE), t_int, 8L, 0L); 326*25830Ssam t = builtintype(UNDEF); 327*25830Ssam printf("\t.stabs\t\"void:t%d=%d", t, t); 328*25830Ssam geninfo(nil); 329*25830Ssam t = builtintype(FARG); 330*25830Ssam printf("\t.stabs\t\"???:t%d=%d", t, t_int); 331*25830Ssam geninfo(nil); 332*25830Ssam } 333*25830Ssam 334*25830Ssam /* 335*25830Ssam * Generate info for a new range type. 336*25830Ssam */ 337*25830Ssam 338*25830Ssam private maketype(name, tnum, eqtnum, lower, upper) 339*25830Ssam char *name; 340*25830Ssam int tnum, eqtnum; 341*25830Ssam long lower, upper; 342*25830Ssam { 343*25830Ssam printf("\t.stabs\t\"%s:t%d=r%d;%d;%d;", name, tnum, eqtnum, lower, upper); 344*25830Ssam geninfo(nil); 345*25830Ssam } 346*25830Ssam 347*25830Ssam /* 348*25830Ssam * Generate debugging information for the given type of the given symbol. 349*25830Ssam */ 350*25830Ssam 351*25830Ssam private gentype(sym) 352*25830Ssam struct symtab *sym; 353*25830Ssam { 354*25830Ssam register struct symtab *p; 355*25830Ssam register TWORD t; 356*25830Ssam register TWORD basictype; 357*25830Ssam register Typeid typeid; 358*25830Ssam int i, arrindex, strindex, strtag; 359*25830Ssam 360*25830Ssam p = sym; 361*25830Ssam t = p->stype; 362*25830Ssam if (ISFTN(t)) { 363*25830Ssam t = DECREF(t); 364*25830Ssam } 365*25830Ssam basictype = BTYPE(t); 366*25830Ssam if (ISARY(t)) { 367*25830Ssam arrindex = p->dimoff; 368*25830Ssam } else { 369*25830Ssam arrindex = NILINDEX; 370*25830Ssam } 371*25830Ssam if (basictype == STRTY or basictype == UNIONTY or basictype == ENUMTY) { 372*25830Ssam strindex = dimtab[p->sizoff + 1]; 373*25830Ssam if (strindex == -1) { 374*25830Ssam strindex = FORWARD; 375*25830Ssam strtag = dimtab[p->sizoff + 3]; 376*25830Ssam } else { 377*25830Ssam strtag = NILINDEX; 378*25830Ssam } 379*25830Ssam } else { 380*25830Ssam strindex = NILINDEX; 381*25830Ssam strtag = NILINDEX; 382*25830Ssam } 383*25830Ssam i = arrindex; 384*25830Ssam typeid = typelookup(t, arrindex, strindex, strtag); 385*25830Ssam while (t != basictype and typeid == nil) { 386*25830Ssam printf("%d=", entertype(t, i, strindex, strtag)); 387*25830Ssam switch (t&TMASK) { 388*25830Ssam case PTR: 389*25830Ssam printf("*"); 390*25830Ssam break; 391*25830Ssam 392*25830Ssam case FTN: 393*25830Ssam printf("f"); 394*25830Ssam break; 395*25830Ssam 396*25830Ssam case ARY: 397*25830Ssam printf("ar%d;0;%d;", t_int, dimtab[i++] - 1); 398*25830Ssam break; 399*25830Ssam } 400*25830Ssam t = DECREF(t); 401*25830Ssam if (t == basictype) { 402*25830Ssam typeid = typelookup(t, NILINDEX, strindex, strtag); 403*25830Ssam } else { 404*25830Ssam typeid = typelookup(t, i, strindex, strtag); 405*25830Ssam } 406*25830Ssam } 407*25830Ssam if (typeid == nil) { 408*25830Ssam if (strindex == FORWARD) { 409*25830Ssam typeid = typelookup(t, NILINDEX, FORWARD, dimtab[p->sizoff + 3]); 410*25830Ssam if (typeid == nil) { 411*25830Ssam cerror("unbelievable forward reference"); 412*25830Ssam } 413*25830Ssam printf("%d", typeid->tnum); 414*25830Ssam } else { 415*25830Ssam genstruct(t, NILINDEX, strindex, p->sname, bsize(p)); 416*25830Ssam } 417*25830Ssam } else { 418*25830Ssam printf("%d", typeid->tnum); 419*25830Ssam } 420*25830Ssam } 421*25830Ssam 422*25830Ssam /* 423*25830Ssam * Generate type information for structures, unions, and enumerations. 424*25830Ssam */ 425*25830Ssam 426*25830Ssam private genstruct(t, structid, index, name, size) 427*25830Ssam TWORD t; 428*25830Ssam int structid; 429*25830Ssam int index; 430*25830Ssam char *name; 431*25830Ssam int size; 432*25830Ssam { 433*25830Ssam register int i; 434*25830Ssam register struct symtab *field; 435*25830Ssam int id; 436*25830Ssam 437*25830Ssam if (structid == NILINDEX) { 438*25830Ssam id = entertype(t, NILINDEX, index, NILINDEX); 439*25830Ssam } else { 440*25830Ssam id = structid; 441*25830Ssam } 442*25830Ssam switch (t) { 443*25830Ssam case STRTY: 444*25830Ssam case UNIONTY: 445*25830Ssam printf("%d=%c%d", id, t == STRTY ? 's' : 'u', size); 446*25830Ssam i = index; 447*25830Ssam while (dimtab[i] != -1) { 448*25830Ssam field = &stab[dimtab[i]]; 449*25830Ssam printf("%s:", field->sname); 450*25830Ssam gentype(field); 451*25830Ssam if (field->sclass > FIELD) { 452*25830Ssam printf(",%d,%d;", field->offset, field->sclass - FIELD); 453*25830Ssam } else { 454*25830Ssam printf(",%d,%d;", field->offset, 455*25830Ssam tsize(field->stype, field->dimoff, field->sizoff)); 456*25830Ssam } 457*25830Ssam ++i; 458*25830Ssam } 459*25830Ssam putchar(';'); 460*25830Ssam break; 461*25830Ssam 462*25830Ssam case ENUMTY: 463*25830Ssam printf("%d=e", id); 464*25830Ssam i = index; 465*25830Ssam while (dimtab[i] != -1) { 466*25830Ssam field = &stab[dimtab[i]]; 467*25830Ssam printf("%s:%d,", field->sname, field->offset); 468*25830Ssam i++; 469*25830Ssam } 470*25830Ssam break; 471*25830Ssam 472*25830Ssam default: 473*25830Ssam cerror("couldn't find basic type %d for %s\n", t, name); 474*25830Ssam break; 475*25830Ssam } 476*25830Ssam } 477*25830Ssam 478*25830Ssam /* 479*25830Ssam * Generate offset and size info. 480*25830Ssam */ 481*25830Ssam 482*25830Ssam private geninfo(p) 483*25830Ssam register struct symtab *p; 484*25830Ssam { 485*25830Ssam int stabtype; 486*25830Ssam 487*25830Ssam if (p == nil) { 488*25830Ssam printf("\",0x%x,0,0,0\n", N_LSYM); 489*25830Ssam } else { 490*25830Ssam switch (p->sclass) { 491*25830Ssam case EXTERN: 492*25830Ssam case EXTDEF: 493*25830Ssam if (ISFTN(p->stype)) { 494*25830Ssam printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname); 495*25830Ssam } else { 496*25830Ssam printf("\",0x%x,0,%d,0\n", N_GSYM, bsize(p)); 497*25830Ssam } 498*25830Ssam break; 499*25830Ssam 500*25830Ssam case STATIC: 501*25830Ssam stabtype = stabLCSYM ? N_LCSYM : N_STSYM; 502*25830Ssam if (ISFTN(p->stype)) { 503*25830Ssam printf("\",0x%x,0,%d,_%s\n", N_FUN, bsize(p), p->sname); 504*25830Ssam } else if (p->slevel > 1) { 505*25830Ssam printf("\",0x%x,0,%d,L%d\n", stabtype, bsize(p), p->offset); 506*25830Ssam } else { 507*25830Ssam printf("\",0x%x,0,%d,_%s\n", stabtype, bsize(p), p->sname); 508*25830Ssam } 509*25830Ssam break; 510*25830Ssam 511*25830Ssam case REGISTER: 512*25830Ssam printf("\",0x%x,0,%d,%d\n", N_RSYM, bsize(p), p->offset); 513*25830Ssam break; 514*25830Ssam 515*25830Ssam case PARAM: 516*25830Ssam printf("\",0x%x,0,%d,%d\n", N_PSYM, bsize(p), bytes(argoff)); 517*25830Ssam break; 518*25830Ssam 519*25830Ssam default: 520*25830Ssam printf("\",0x%x,0,%d,%d\n", N_LSYM, bsize(p), bytes(p->offset)); 521*25830Ssam break; 522*25830Ssam } 523*25830Ssam } 524*25830Ssam } 525*25830Ssam 526*25830Ssam /* 527*25830Ssam * Generate information for a newly-defined structure. 528*25830Ssam */ 529*25830Ssam 530*25830Ssam outstruct(szindex, paramindex) 531*25830Ssam int szindex, paramindex; 532*25830Ssam { 533*25830Ssam register Typeid typeid; 534*25830Ssam register struct symtab *p; 535*25830Ssam register int i, t, strindex; 536*25830Ssam 537*25830Ssam if (oldway) { 538*25830Ssam /* do nothing */; 539*25830Ssam } else if (gdebug) { 540*25830Ssam i = dimtab[szindex + 3]; 541*25830Ssam p = &stab[i]; 542*25830Ssam if (p->sname != nil) { 543*25830Ssam strindex = dimtab[p->sizoff + 1]; 544*25830Ssam typeid = typelookup(p->stype, NILINDEX, FORWARD, i); 545*25830Ssam if (typeid == nil) { 546*25830Ssam t = 0; 547*25830Ssam } else { 548*25830Ssam t = typeid->tnum; 549*25830Ssam reentertype(typeid, p->stype, NILINDEX, strindex, NILINDEX); 550*25830Ssam } 551*25830Ssam printf("\t.stabs\t\"%s:T", p->sname); 552*25830Ssam genstruct(p->stype, t, strindex, p->sname, bsize(p)); 553*25830Ssam geninfo(p); 554*25830Ssam } 555*25830Ssam } 556*25830Ssam } 557*25830Ssam 558*25830Ssam pstab(name, type) 559*25830Ssam char *name; 560*25830Ssam int type; 561*25830Ssam { 562*25830Ssam register int i; 563*25830Ssam register char c; 564*25830Ssam 565*25830Ssam if (!gdebug) { 566*25830Ssam return; 567*25830Ssam } else if (oldway) { 568*25830Ssam old_pstab(name, type); 569*25830Ssam return; 570*25830Ssam } 571*25830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */ 572*25830Ssam #ifdef ASSTRINGS 573*25830Ssam if ( name[0] == '\0') 574*25830Ssam printf("\t.stabn\t"); 575*25830Ssam else 576*25830Ssam #ifndef FLEXNAMES 577*25830Ssam printf("\t.stabs\t\"%.8s\",", name); 578*25830Ssam #else 579*25830Ssam printf("\t.stabs\t\"%s\",", name); 580*25830Ssam #endif 581*25830Ssam #else 582*25830Ssam printf(" .stab "); 583*25830Ssam for(i=0; i<8; i++) 584*25830Ssam if (c = name[i]) printf("'%c,", c); 585*25830Ssam else printf("0,"); 586*25830Ssam #endif 587*25830Ssam printf("0%o,", type); 588*25830Ssam } 589*25830Ssam 590*25830Ssam #ifdef STABDOT 591*25830Ssam pstabdot(type, value) 592*25830Ssam int type; 593*25830Ssam int value; 594*25830Ssam { 595*25830Ssam if ( ! gdebug) { 596*25830Ssam return; 597*25830Ssam } else if (oldway) { 598*25830Ssam old_pstabdot(type, value); 599*25830Ssam return; 600*25830Ssam } 601*25830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */ 602*25830Ssam printf("\t.stabd\t"); 603*25830Ssam printf("0%o,0,0%o\n",type, value); 604*25830Ssam } 605*25830Ssam #endif 606*25830Ssam 607*25830Ssam extern char NULLNAME[8]; 608*25830Ssam extern int labelno; 609*25830Ssam extern int fdefflag; 610*25830Ssam 611*25830Ssam psline() 612*25830Ssam { 613*25830Ssam static int lastlineno; 614*25830Ssam register char *cp, *cq; 615*25830Ssam register int i; 616*25830Ssam 617*25830Ssam if (!gdebug) { 618*25830Ssam return; 619*25830Ssam } else if (oldway) { 620*25830Ssam old_psline(); 621*25830Ssam return; 622*25830Ssam } 623*25830Ssam 624*25830Ssam cq = ititle; 625*25830Ssam cp = ftitle; 626*25830Ssam 627*25830Ssam while ( *cq ) if ( *cp++ != *cq++ ) goto neq; 628*25830Ssam if ( *cp == '\0' ) goto eq; 629*25830Ssam 630*25830Ssam neq: for (i=0; i<100; i++) 631*25830Ssam ititle[i] = '\0'; 632*25830Ssam cp = ftitle; 633*25830Ssam cq = ititle; 634*25830Ssam while ( *cp ) 635*25830Ssam *cq++ = *cp++; 636*25830Ssam *cq = '\0'; 637*25830Ssam *--cq = '\0'; 638*25830Ssam #ifndef FLEXNAMES 639*25830Ssam for ( cp = ititle+1; *(cp-1); cp += 8 ) { 640*25830Ssam pstab(cp, N_SOL); 641*25830Ssam if (gdebug) printf("0,0,LL%d\n", labelno); 642*25830Ssam } 643*25830Ssam #else 644*25830Ssam pstab(ititle+1, N_SOL); 645*25830Ssam if (gdebug) printf("0,0,LL%d\n", labelno); 646*25830Ssam #endif 647*25830Ssam *cq = '"'; 648*25830Ssam printf("LL%d:\n", labelno++); 649*25830Ssam 650*25830Ssam eq: if (lineno == lastlineno) return; 651*25830Ssam lastlineno = lineno; 652*25830Ssam 653*25830Ssam if (fdefflag) { 654*25830Ssam #ifdef STABDOT 655*25830Ssam pstabdot(N_SLINE, lineno); 656*25830Ssam #else 657*25830Ssam pstab(NULLNAME, N_SLINE); 658*25830Ssam printf("0,%d,LL%d\n", lineno, labelno); 659*25830Ssam printf("LL%d:\n", labelno++); 660*25830Ssam #endif 661*25830Ssam } 662*25830Ssam } 663*25830Ssam 664*25830Ssam plcstab(level) 665*25830Ssam int level; 666*25830Ssam { 667*25830Ssam if (!gdebug) { 668*25830Ssam return; 669*25830Ssam } else if (oldway) { 670*25830Ssam old_plcstab(level); 671*25830Ssam return; 672*25830Ssam } 673*25830Ssam #ifdef STABDOT 674*25830Ssam pstabdot(N_LBRAC, level); 675*25830Ssam #else 676*25830Ssam pstab(NULLNAME, N_LBRAC); 677*25830Ssam printf("0,%d,LL%d\n", level, labelno); 678*25830Ssam printf("LL%d:\n", labelno++); 679*25830Ssam #endif 680*25830Ssam } 681*25830Ssam 682*25830Ssam prcstab(level) 683*25830Ssam int level; 684*25830Ssam { 685*25830Ssam if (!gdebug) { 686*25830Ssam return; 687*25830Ssam } else if (oldway) { 688*25830Ssam old_prcstab(level); 689*25830Ssam return; 690*25830Ssam } 691*25830Ssam #ifdef STABDOT 692*25830Ssam pstabdot(N_RBRAC, level); 693*25830Ssam #else 694*25830Ssam pstab(NULLNAME, N_RBRAC); 695*25830Ssam printf("0,%d,LL%d\n", level, labelno); 696*25830Ssam printf("LL%d:\n", labelno++); 697*25830Ssam #endif 698*25830Ssam } 699*25830Ssam 700*25830Ssam pfstab(sname) 701*25830Ssam char *sname; 702*25830Ssam { 703*25830Ssam register struct symtab *p; 704*25830Ssam 705*25830Ssam if (gdebug) { 706*25830Ssam if (oldway) { 707*25830Ssam old_pfstab(sname); 708*25830Ssam } else { 709*25830Ssam p = &stab[lookup(sname, 0)]; 710*25830Ssam printf("\t.stabs\t\"%s:", p->sname); 711*25830Ssam putchar((p->sclass == STATIC) ? 'f' : 'F'); 712*25830Ssam gentype(p); 713*25830Ssam geninfo(p); 714*25830Ssam } 715*25830Ssam } 716*25830Ssam } 717*25830Ssam 718*25830Ssam /* 719*25830Ssam * Old way of doing things. 720*25830Ssam */ 721*25830Ssam 722*25830Ssam private old_fixarg(p) 723*25830Ssam struct symtab *p; { 724*25830Ssam if (gdebug) { 725*25830Ssam old_pstab(p->sname, N_PSYM); 726*25830Ssam if (gdebug) printf("0,%d,%d\n", p->stype, argoff/SZCHAR); 727*25830Ssam old_poffs(p); 728*25830Ssam } 729*25830Ssam } 730*25830Ssam 731*25830Ssam private old_outstab(p) 732*25830Ssam struct symtab *p; { 733*25830Ssam register TWORD ptype; 734*25830Ssam register char *pname; 735*25830Ssam register char pclass; 736*25830Ssam register int poffset; 737*25830Ssam 738*25830Ssam if (!gdebug) return; 739*25830Ssam 740*25830Ssam ptype = p->stype; 741*25830Ssam pname = p->sname; 742*25830Ssam pclass = p->sclass; 743*25830Ssam poffset = p->offset; 744*25830Ssam 745*25830Ssam if (ISFTN(ptype)) { 746*25830Ssam return; 747*25830Ssam } 748*25830Ssam 749*25830Ssam switch (pclass) { 750*25830Ssam 751*25830Ssam case AUTO: 752*25830Ssam old_pstab(pname, N_LSYM); 753*25830Ssam printf("0,%d,%d\n", ptype, (-poffset)/SZCHAR); 754*25830Ssam old_poffs(p); 755*25830Ssam return; 756*25830Ssam 757*25830Ssam case EXTDEF: 758*25830Ssam case EXTERN: 759*25830Ssam old_pstab(pname, N_GSYM); 760*25830Ssam printf("0,%d,0\n", ptype); 761*25830Ssam old_poffs(p); 762*25830Ssam return; 763*25830Ssam 764*25830Ssam case STATIC: 765*25830Ssam #ifdef LCOMM 766*25830Ssam /* stabLCSYM is 1 during nidcl so we can get stab type right */ 767*25830Ssam old_pstab(pname, stabLCSYM ? N_LCSYM : N_STSYM); 768*25830Ssam #else 769*25830Ssam old_pstab(pname, N_STSYM); 770*25830Ssam #endif 771*25830Ssam if (p->slevel > 1) { 772*25830Ssam printf("0,%d,L%d\n", ptype, poffset); 773*25830Ssam } else { 774*25830Ssam printf("0,%d,%s\n", ptype, exname(pname)); 775*25830Ssam } 776*25830Ssam old_poffs(p); 777*25830Ssam return; 778*25830Ssam 779*25830Ssam case REGISTER: 780*25830Ssam old_pstab(pname, N_RSYM); 781*25830Ssam printf("0,%d,%d\n", ptype, poffset); 782*25830Ssam old_poffs(p); 783*25830Ssam return; 784*25830Ssam 785*25830Ssam case MOS: 786*25830Ssam case MOU: 787*25830Ssam old_pstab(pname, N_SSYM); 788*25830Ssam printf("0,%d,%d\n", ptype, poffset/SZCHAR); 789*25830Ssam old_poffs(p); 790*25830Ssam return; 791*25830Ssam 792*25830Ssam case PARAM: 793*25830Ssam /* parameter stab entries are processed in dclargs() */ 794*25830Ssam return; 795*25830Ssam 796*25830Ssam default: 797*25830Ssam #ifndef FLEXNAMES 798*25830Ssam if (ddebug) printf(" No .stab for %.8s\n", pname); 799*25830Ssam #else 800*25830Ssam if (ddebug) printf(" No .stab for %s\n", pname); 801*25830Ssam #endif 802*25830Ssam 803*25830Ssam } 804*25830Ssam } 805*25830Ssam 806*25830Ssam private old_pstab(name, type) 807*25830Ssam char *name; 808*25830Ssam int type; { 809*25830Ssam register int i; 810*25830Ssam register char c; 811*25830Ssam if (!gdebug) return; 812*25830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */ 813*25830Ssam #ifdef ASSTRINGS 814*25830Ssam if ( name[0] == '\0') 815*25830Ssam printf("\t.stabn\t"); 816*25830Ssam else 817*25830Ssam #ifndef FLEXNAMES 818*25830Ssam printf("\t.stabs\t\"%.8s\", ", name); 819*25830Ssam #else 820*25830Ssam printf("\t.stabs\t\"%s\", ", name); 821*25830Ssam #endif 822*25830Ssam #else 823*25830Ssam printf(" .stab "); 824*25830Ssam for(i=0; i<8; i++) 825*25830Ssam if (c = name[i]) printf("'%c,", c); 826*25830Ssam else printf("0,"); 827*25830Ssam #endif 828*25830Ssam printf("0%o,", type); 829*25830Ssam } 830*25830Ssam 831*25830Ssam #ifdef STABDOT 832*25830Ssam private old_pstabdot(type, value) 833*25830Ssam int type; 834*25830Ssam int value; 835*25830Ssam { 836*25830Ssam if ( ! gdebug) return; 837*25830Ssam /* locctr(PROG); /* .stabs must appear in .text for c2 */ 838*25830Ssam printf("\t.stabd\t"); 839*25830Ssam printf("0%o,0,0%o\n",type, value); 840*25830Ssam } 841*25830Ssam #endif 842*25830Ssam 843*25830Ssam private old_poffs(p) 844*25830Ssam register struct symtab *p; { 845*25830Ssam int s; 846*25830Ssam if (!gdebug) return; 847*25830Ssam if ((s = dimtab[p->sizoff]/SZCHAR) > 1) { 848*25830Ssam old_pstab(p->sname, N_LENG); 849*25830Ssam printf("1,0,%d\n", s); 850*25830Ssam } 851*25830Ssam } 852*25830Ssam 853*25830Ssam private old_psline() { 854*25830Ssam static int lastlineno; 855*25830Ssam register char *cp, *cq; 856*25830Ssam register int i; 857*25830Ssam 858*25830Ssam if (!gdebug) return; 859*25830Ssam 860*25830Ssam cq = ititle; 861*25830Ssam cp = ftitle; 862*25830Ssam 863*25830Ssam while ( *cq ) if ( *cp++ != *cq++ ) goto neq; 864*25830Ssam if ( *cp == '\0' ) goto eq; 865*25830Ssam 866*25830Ssam neq: for (i=0; i<100; i++) 867*25830Ssam ititle[i] = '\0'; 868*25830Ssam cp = ftitle; 869*25830Ssam cq = ititle; 870*25830Ssam while ( *cp ) 871*25830Ssam *cq++ = *cp++; 872*25830Ssam *cq = '\0'; 873*25830Ssam *--cq = '\0'; 874*25830Ssam #ifndef FLEXNAMES 875*25830Ssam for ( cp = ititle+1; *(cp-1); cp += 8 ) { 876*25830Ssam old_pstab(cp, N_SOL); 877*25830Ssam if (gdebug) printf("0,0,LL%d\n", labelno); 878*25830Ssam } 879*25830Ssam #else 880*25830Ssam old_pstab(ititle+1, N_SOL); 881*25830Ssam if (gdebug) printf("0,0,LL%d\n", labelno); 882*25830Ssam #endif 883*25830Ssam *cq = '"'; 884*25830Ssam printf("LL%d:\n", labelno++); 885*25830Ssam 886*25830Ssam eq: if (lineno == lastlineno) return; 887*25830Ssam lastlineno = lineno; 888*25830Ssam 889*25830Ssam if (fdefflag) { 890*25830Ssam #ifdef STABDOT 891*25830Ssam old_pstabdot(N_SLINE, lineno); 892*25830Ssam #else 893*25830Ssam old_pstab(NULLNAME, N_SLINE); 894*25830Ssam printf("0,%d,LL%d\n", lineno, labelno); 895*25830Ssam printf("LL%d:\n", labelno++); 896*25830Ssam #endif 897*25830Ssam } 898*25830Ssam } 899*25830Ssam 900*25830Ssam private old_plcstab(level) { 901*25830Ssam if (!gdebug) return; 902*25830Ssam #ifdef STABDOT 903*25830Ssam old_pstabdot(N_LBRAC, level); 904*25830Ssam #else 905*25830Ssam old_pstab(NULLNAME, N_LBRAC); 906*25830Ssam printf("0,%d,LL%d\n", level, labelno); 907*25830Ssam printf("LL%d:\n", labelno++); 908*25830Ssam #endif 909*25830Ssam } 910*25830Ssam 911*25830Ssam private old_prcstab(level) { 912*25830Ssam if (!gdebug) return; 913*25830Ssam #ifdef STABDOT 914*25830Ssam pstabdot(N_RBRAC, level); 915*25830Ssam #else 916*25830Ssam pstab(NULLNAME, N_RBRAC); 917*25830Ssam printf("0,%d,LL%d\n", level, labelno); 918*25830Ssam printf("LL%d:\n", labelno++); 919*25830Ssam #endif 920*25830Ssam } 921*25830Ssam 922*25830Ssam private old_pfstab(sname) 923*25830Ssam char *sname; { 924*25830Ssam if (!gdebug) return; 925*25830Ssam pstab(sname, N_FUN); 926*25830Ssam #ifndef FLEXNAMES 927*25830Ssam printf("0,%d,_%.7s\n", lineno, sname); 928*25830Ssam #else 929*25830Ssam printf("0,%d,_%s\n", lineno, sname); 930*25830Ssam #endif 931*25830Ssam } 932