| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#include "pass1.h" |
| 38 |
|
| 39 |
#ifdef STABS |
| 40 |
|
| 41 |
#include <sys/types.h> |
| 42 |
#include <stdarg.h> |
| 43 |
#include <string.h> |
| 44 |
|
| 45 |
#define STABHASH 256 |
| 46 |
#define INTNUM 1 |
| 47 |
#undef BIT2BYTE |
| 48 |
#define BIT2BYTE(x) ((x)/SZCHAR) |
| 49 |
|
| 50 |
#ifndef STABLBL |
| 51 |
#error macdefs.h must define STABLBL |
| 52 |
#endif |
| 53 |
|
| 54 |
|
| 55 |
#define N_GSYM 0x20 |
| 56 |
#define N_FUN 0x24 |
| 57 |
#define N_LCSYM 0x28 |
| 58 |
#define N_RSYM 0x40 |
| 59 |
#define N_SLINE 0x44 |
| 60 |
#define N_SO 0x64 |
| 61 |
#define N_LSYM 0x80 |
| 62 |
#define N_SOL 0x84 |
| 63 |
#define N_PSYM 0xa0 |
| 64 |
#define N_LBRAC 0xc0 |
| 65 |
#define N_RBRAC 0xe0 |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
static struct stabtype { |
| 74 |
struct stabtype *next; |
| 75 |
TWORD type; |
| 76 |
union dimfun *df; |
| 77 |
struct attr *ap; |
| 78 |
int num; |
| 79 |
} *stabhash[STABHASH]; |
| 80 |
static int ntypes; |
| 81 |
static char *curfun; |
| 82 |
static int stablbl = 10; |
| 83 |
extern int inftn; |
| 84 |
|
| 85 |
void ptype(char *name, int num, int inhnum, long long min, long long max); |
| 86 |
struct stabtype *addtype(TWORD, union dimfun *, struct attr *); |
| 87 |
struct stabtype *findtype(TWORD t, union dimfun *df, struct attr *sue); |
| 88 |
void printtype(struct symtab *s, char *str, int len); |
| 89 |
void cprint(int p2, char *fmt, ...); |
| 90 |
|
| 91 |
#define MAXPSTR 100 |
| 92 |
|
| 93 |
extern int isinlining; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
void |
| 100 |
stabs_init(void) |
| 101 |
{ |
| 102 |
struct stabtype *st; |
| 103 |
|
| 104 |
#define ADDTYPE(y) addtype(y, NULL, 0) |
| 105 |
|
| 106 |
ptype("int", ADDTYPE(INT)->num, INTNUM, MIN_INT, MAX_INT); |
| 107 |
|
| 108 |
st = ADDTYPE(CHAR); |
| 109 |
ptype("char", st->num, st->num, 0, MAX_CHAR); |
| 110 |
ptype("short", ADDTYPE(SHORT)->num, INTNUM, MIN_SHORT, MAX_SHORT); |
| 111 |
ptype("long", ADDTYPE(LONG)->num, INTNUM, MIN_LONG, MAX_LONG); |
| 112 |
ptype("long long", ADDTYPE(LONGLONG)->num, INTNUM, |
| 113 |
MIN_LONGLONG, MAX_LONGLONG); |
| 114 |
ptype("unsigned char", ADDTYPE(UCHAR)->num, INTNUM, 0, MAX_UCHAR); |
| 115 |
ptype("unsigned short", ADDTYPE(USHORT)->num, INTNUM, 0, MAX_USHORT); |
| 116 |
ptype("unsigned int", ADDTYPE(UNSIGNED)->num, INTNUM, 0, MAX_UNSIGNED); |
| 117 |
ptype("unsigned long", ADDTYPE(ULONG)->num, INTNUM, 0, MAX_ULONG); |
| 118 |
ptype("unsigned long long", ADDTYPE(ULONGLONG)->num, INTNUM, |
| 119 |
0, MAX_ULONGLONG); |
| 120 |
|
| 121 |
ptype("float", ADDTYPE(FLOAT)->num, INTNUM, 4, 0); |
| 122 |
ptype("double", ADDTYPE(DOUBLE)->num, INTNUM, 8, 0); |
| 123 |
ptype("long double", ADDTYPE(LDOUBLE)->num, INTNUM, 12, 0); |
| 124 |
st = ADDTYPE(VOID); |
| 125 |
cprint(0, "\t.stabs \"void:t%d=r%d\",%d,0,0,0\n", |
| 126 |
st->num, st->num, N_LSYM); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
void |
| 134 |
ptype(char *name, int num, int inhnum, long long min, long long max) |
| 135 |
{ |
| 136 |
cprint(0, "\t.stabs \"%s:t%d=r%d;%lld;%lld;\",%d,0,0,0\n", |
| 137 |
name, num, inhnum, min, max, N_LSYM); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
struct stabtype * |
| 145 |
addtype(TWORD t, union dimfun *df, struct attr *ap) |
| 146 |
{ |
| 147 |
struct stabtype *st; |
| 148 |
|
| 149 |
st = permalloc(sizeof(struct stabtype)); |
| 150 |
st->type = t; |
| 151 |
st->df = df; |
| 152 |
st->ap = ap; |
| 153 |
st->num = ++ntypes; |
| 154 |
st->next = stabhash[t & (STABHASH-1)]; |
| 155 |
stabhash[t & (STABHASH-1)] = st; |
| 156 |
return st; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
struct stabtype * |
| 163 |
findtype(TWORD t, union dimfun *df, struct attr *ap) |
| 164 |
{ |
| 165 |
struct stabtype *st; |
| 166 |
union dimfun *dw, *dx; |
| 167 |
TWORD tw; |
| 168 |
|
| 169 |
st = stabhash[t & (STABHASH-1)]; |
| 170 |
for (; st; st = st->next) { |
| 171 |
if (t != st->type || ap != st->ap) |
| 172 |
continue; |
| 173 |
|
| 174 |
if (st->df == NULL) |
| 175 |
return st; |
| 176 |
dw = st->df; |
| 177 |
dx = df; |
| 178 |
tw = t; |
| 179 |
for (; tw > BTMASK; tw = DECREF(tw)) { |
| 180 |
if (ISARY(tw)) { |
| 181 |
if (dw->ddim == dx->ddim) |
| 182 |
dw++, dx++; |
| 183 |
else |
| 184 |
break; |
| 185 |
} |
| 186 |
} |
| 187 |
if (tw <= BTMASK) |
| 188 |
return st; |
| 189 |
} |
| 190 |
return NULL; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
void |
| 197 |
stabs_line(int line) |
| 198 |
{ |
| 199 |
if (inftn == 0) |
| 200 |
return; |
| 201 |
#ifdef STAB_LINE_ABSOLUTE |
| 202 |
cprint(1, "\t.stabn %d,0,%d," STABLBL "\n" STABLBL ":\n", |
| 203 |
N_SLINE, line, stablbl, stablbl); |
| 204 |
#else |
| 205 |
cprint(1, "\t.stabn %d,0,%d," STABLBL "-%s\n" STABLBL ":\n", |
| 206 |
N_SLINE, line, stablbl, curfun, stablbl); |
| 207 |
#endif |
| 208 |
stablbl++; |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
void |
| 215 |
stabs_lbrac(int blklvl) |
| 216 |
{ |
| 217 |
#ifdef STAB_LINE_ABSOLUTE |
| 218 |
cprint(1, "\t.stabn %d,0,%d," STABLBL "\n" STABLBL ":\n", |
| 219 |
N_LBRAC, blklvl, stablbl, stablbl); |
| 220 |
#else |
| 221 |
cprint(1, "\t.stabn %d,0,%d," STABLBL "-%s\n" STABLBL ":\n", |
| 222 |
N_LBRAC, blklvl, stablbl, curfun, stablbl); |
| 223 |
#endif |
| 224 |
stablbl++; |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
void |
| 231 |
stabs_rbrac(int blklvl) |
| 232 |
{ |
| 233 |
#ifdef STAB_LINE_ABSOLUTE |
| 234 |
cprint(1, "\t.stabn %d,0,%d," STABLBL "\n" STABLBL ":\n", |
| 235 |
N_RBRAC, blklvl, stablbl, stablbl); |
| 236 |
#else |
| 237 |
cprint(1, "\t.stabn %d,0,%d," STABLBL "-%s\n" STABLBL ":\n", |
| 238 |
N_RBRAC, blklvl, stablbl, curfun, stablbl); |
| 239 |
#endif |
| 240 |
stablbl++; |
| 241 |
} |
| 242 |
|
| 243 |
static char *mainfile; |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
void |
| 249 |
stabs_file(char *fname) |
| 250 |
{ |
| 251 |
if (mainfile == NULL) |
| 252 |
mainfile = fname; |
| 253 |
cprint(inftn, "\t.stabs \"%s\",%d,0,0," STABLBL "\n" STABLBL ":\n", |
| 254 |
fname, fname == mainfile ? N_SO : N_SOL, stablbl, stablbl); |
| 255 |
stablbl++; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
void |
| 262 |
stabs_efile(char *fname) |
| 263 |
{ |
| 264 |
cprint(inftn, "\t.stabs \"\",%d,0,0," STABLBL "\n" STABLBL ":\n", |
| 265 |
fname == mainfile ? N_SO : N_SOL, stablbl, stablbl); |
| 266 |
stablbl++; |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
void |
| 273 |
stabs_func(struct symtab *s) |
| 274 |
{ |
| 275 |
char str[MAXPSTR]; |
| 276 |
|
| 277 |
curfun = getexname(s); |
| 278 |
printtype(s, str, sizeof(str)); |
| 279 |
cprint(1, "\t.stabs \"%s:%c%s\",%d,0,%d,%s\n", |
| 280 |
curfun, s->sclass == STATIC ? 'f' : 'F', str, |
| 281 |
N_FUN, 0, curfun); |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
void |
| 290 |
printtype(struct symtab *s, char *ostr, int len) |
| 291 |
{ |
| 292 |
struct stabtype *st; |
| 293 |
union dimfun *df = s->sdf; |
| 294 |
struct attr *ap = s->sap; |
| 295 |
TWORD t = s->stype; |
| 296 |
int op = 0; |
| 297 |
|
| 298 |
|
| 299 |
if (ISFTN(t)) |
| 300 |
t = DECREF(t); |
| 301 |
st = findtype(t, df, ap); |
| 302 |
while (st == NULL && t > BTMASK) { |
| 303 |
st = addtype(t, df, ap); |
| 304 |
op+=snprintf(ostr+op, len - op, "%d=", st->num); |
| 305 |
if (ISFTN(t)) |
| 306 |
ostr[op++] = 'f'; |
| 307 |
else if (ISPTR(t)) |
| 308 |
ostr[op++] = '*'; |
| 309 |
else if (ISARY(t)) { |
| 310 |
op+=snprintf(ostr+op, len - op, "ar%d;0;%d;", INTNUM, df->ddim-1); |
| 311 |
} else |
| 312 |
cerror("printtype: notype"); |
| 313 |
if (ISARY(t)) |
| 314 |
df++; |
| 315 |
t = DECREF(t); |
| 316 |
st = findtype(t, df, ap); |
| 317 |
if (op > MAXPSTR-10) |
| 318 |
cerror("printtype: too difficult expression"); |
| 319 |
} |
| 320 |
|
| 321 |
snprintf(ostr+op, len - op, "%d", st == NULL ? 1 : st->num); |
| 322 |
|
| 323 |
} |
| 324 |
|
| 325 |
void |
| 326 |
stabs_newsym(struct symtab *s) |
| 327 |
{ |
| 328 |
extern int fun_inline; |
| 329 |
char *sname; |
| 330 |
char ostr[MAXPSTR]; |
| 331 |
OFFSZ suesize, sz; |
| 332 |
|
| 333 |
if (ISFTN(s->stype)) |
| 334 |
return; |
| 335 |
|
| 336 |
if (s->sclass == STNAME || s->sclass == UNAME || s->sclass == MOS || |
| 337 |
s->sclass == ENAME || s->sclass == MOU || s->sclass == MOE || |
| 338 |
s->sclass == TYPEDEF || (s->sclass & FIELD) || ISSOU(s->stype)) |
| 339 |
return; |
| 340 |
|
| 341 |
sname = getexname(s); |
| 342 |
sz = tsize(s->stype, s->sdf, s->sap); |
| 343 |
suesize = BIT2BYTE(sz); |
| 344 |
if (suesize > 32767) |
| 345 |
suesize = 32767; |
| 346 |
else if (suesize < -32768) |
| 347 |
suesize = -32768; |
| 348 |
|
| 349 |
printtype(s, ostr, sizeof(ostr)); |
| 350 |
switch (s->sclass) { |
| 351 |
case PARAM: |
| 352 |
cprint(0, "\t.stabs \"%s:p%s\",%d,0," CONFMT ",%d\n", |
| 353 |
sname, ostr, N_PSYM, (CONSZ)suesize, BIT2BYTE(s->soffset)); |
| 354 |
break; |
| 355 |
|
| 356 |
case AUTO: |
| 357 |
cprint(0, "\t.stabs \"%s:%s\",%d,0," CONFMT ",%d\n", |
| 358 |
sname, ostr, N_LSYM, (CONSZ)suesize, BIT2BYTE(s->soffset)); |
| 359 |
break; |
| 360 |
|
| 361 |
case STATIC: |
| 362 |
if (blevel) |
| 363 |
cprint(0, "\t.stabs \"%s:V%s\",%d,0," CONFMT "," LABFMT "\n", |
| 364 |
sname, ostr, N_LCSYM, (CONSZ)suesize, s->soffset); |
| 365 |
else |
| 366 |
cprint(0, "\t.stabs \"%s:S%s\",%d,0," CONFMT ",%s\n", |
| 367 |
sname, ostr, N_LCSYM, (CONSZ)suesize, sname); |
| 368 |
break; |
| 369 |
|
| 370 |
case EXTERN: |
| 371 |
case EXTDEF: |
| 372 |
cprint(0, "\t.stabs \"%s:G%s\",%d,0," CONFMT ",0\n", |
| 373 |
sname, ostr, N_GSYM, (CONSZ)suesize); |
| 374 |
break; |
| 375 |
|
| 376 |
case REGISTER: |
| 377 |
cprint(0, "\t.stabs \"%s:r%s\",%d,0,%d,%d\n", |
| 378 |
sname, ostr, N_RSYM, 1, s->soffset); |
| 379 |
break; |
| 380 |
|
| 381 |
case SNULL: |
| 382 |
if (fun_inline) |
| 383 |
break; |
| 384 |
|
| 385 |
default: |
| 386 |
cerror("fix stab_newsym; class %d", s->sclass); |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
void |
| 391 |
stabs_chgsym(struct symtab *s) |
| 392 |
{ |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
void |
| 399 |
stabs_struct(struct symtab *p, struct attr *ap) |
| 400 |
{ |
| 401 |
} |
| 402 |
|
| 403 |
struct stabsv { |
| 404 |
SLIST_ENTRY(stabsv) next; |
| 405 |
char *str; |
| 406 |
} ; |
| 407 |
static SLIST_HEAD(, stabsv) stpole = { NULL, &stpole.q_forw }; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
void |
| 424 |
cprint(int p2, char *fmt, ...) |
| 425 |
{ |
| 426 |
#define CPBSZ 200 |
| 427 |
char buf[CPBSZ]; |
| 428 |
struct stabsv *w; |
| 429 |
va_list ap; |
| 430 |
char *str; |
| 431 |
|
| 432 |
if (isinlining) |
| 433 |
return; |
| 434 |
|
| 435 |
va_start(ap, fmt); |
| 436 |
if (p2) { |
| 437 |
if (vsnprintf(buf, CPBSZ, fmt, ap) >= CPBSZ) |
| 438 |
werror("stab symbol line too long, truncating"); |
| 439 |
str = tmpstrdup(buf); |
| 440 |
if (inftn == 0) { |
| 441 |
w = tmpalloc(sizeof(struct stabsv)); |
| 442 |
w->str = str; |
| 443 |
SLIST_INSERT_LAST(&stpole, w, next); |
| 444 |
} else { |
| 445 |
if (stpole.q_last != &stpole.q_forw) { |
| 446 |
SLIST_FOREACH(w, &stpole, next) { |
| 447 |
send_passt(IP_ASM, w->str); |
| 448 |
} |
| 449 |
SLIST_INIT(&stpole); |
| 450 |
} |
| 451 |
send_passt(IP_ASM, str); |
| 452 |
} |
| 453 |
} else |
| 454 |
vprintf(fmt, ap); |
| 455 |
va_end(ap); |
| 456 |
} |
| 457 |
|
| 458 |
#endif |