1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/*
| 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/*
|
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms.
| 22 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
|
24 */ 25
| 23 */ 24
|
26#pragma ident "%Z%%M% %I% %E% SMI" 27
| |
28/* 29 * This file is a sewer. 30 */ 31 32#include <limits.h> 33#include <stdarg.h> 34#include <stdio.h> 35#include <assert.h> 36#include <strings.h> 37#include <setjmp.h> 38#include <ctype.h> 39#include <uts/common/sys/ctf.h> 40 41#include "ctftools.h" 42#include "memory.h" 43#include "list.h" 44 45#define HASH(NUM) ((int)(NUM & (BUCKETS - 1))) 46#define BUCKETS 128 47 48#define TYPEPAIRMULT 10000 49#define MAKETYPEID(file, num) ((file) * TYPEPAIRMULT + num) 50#define TYPEFILE(tid) ((tid) / TYPEPAIRMULT) 51#define TYPENUM(tid) ((tid) % TYPEPAIRMULT) 52 53#define expected(a, b, c) _expected(a, b, c, __LINE__) 54 55static int faketypenumber = 100000000; 56 57static tdesc_t *hash_table[BUCKETS]; 58static tdesc_t *name_table[BUCKETS]; 59 60list_t *typedbitfldmems; 61 62static void reset(void); 63static jmp_buf resetbuf; 64 65static char *soudef(char *cp, stabtype_t type, tdesc_t **rtdp); 66static void enumdef(char *cp, tdesc_t **rtdp); 67static int compute_sum(const char *w); 68 69static char *number(char *cp, int *n); 70static char *name(char *cp, char **w); 71static char *id(char *cp, int *h); 72static char *whitesp(char *cp); 73static void addhash(tdesc_t *tdp, int num); 74static int tagadd(char *w, int h, tdesc_t *tdp); 75static char *tdefdecl(char *cp, int h, tdesc_t **rtdp); 76static char *intrinsic(char *cp, tdesc_t **rtdp); 77static char *arraydef(char *cp, tdesc_t **rtdp); 78 79int debug_parse = DEBUG_PARSE; 80 81/*PRINTFLIKE3*/ 82static void 83parse_debug(int level, char *cp, const char *fmt, ...) 84{ 85 va_list ap; 86 char buf[1024]; 87 char tmp[32]; 88 int i; 89 90 if (level > debug_level || !debug_parse) 91 return; 92 93 if (cp != NULL) { 94 for (i = 0; i < 30; i++) { 95 if (cp[i] == '\0') 96 break; 97 if (!iscntrl(cp[i])) 98 tmp[i] = cp[i]; 99 } 100 tmp[i] = '\0'; 101 (void) snprintf(buf, sizeof (buf), "%s [cp='%s']\n", fmt, tmp); 102 } else { 103 strcpy(buf, fmt); 104 strcat(buf, "\n"); 105 } 106 107 va_start(ap, fmt); 108 vadebug(level, buf, ap); 109 va_end(ap); 110} 111 112/* Report unexpected syntax in stabs. */ 113static void 114_expected( 115 const char *who, /* what function, or part thereof, is reporting */ 116 const char *what, /* what was expected */ 117 const char *where, /* where we were in the line of input */ 118 int line) 119{ 120 fprintf(stderr, "%s, expecting \"%s\" at \"%s\"\n", who, what, where); 121 fprintf(stderr, "code line: %d, file %s\n", line, 122 (curhdr ? curhdr : "NO FILE")); 123 reset(); 124} 125 126/*ARGSUSED*/ 127void 128parse_init(tdata_t *td __unused) 129{ 130 int i; 131 132 for (i = 0; i < BUCKETS; i++) { 133 hash_table[i] = NULL; 134 name_table[i] = NULL; 135 } 136 137 if (typedbitfldmems != NULL) { 138 list_free(typedbitfldmems, NULL, NULL); 139 typedbitfldmems = NULL; 140 } 141} 142 143void 144parse_finish(tdata_t *td) 145{ 146 td->td_nextid = ++faketypenumber; 147} 148 149static tdesc_t * 150unres_new(int tid) 151{ 152 tdesc_t *tdp; 153 154 tdp = xcalloc(sizeof (*tdp)); 155 tdp->t_type = TYPEDEF_UNRES; 156 tdp->t_id = tid; 157 158 return (tdp); 159} 160 161static char * 162read_tid(char *cp, tdesc_t **tdpp) 163{ 164 tdesc_t *tdp; 165 int tid; 166 167 cp = id(cp, &tid); 168 169 assert(tid != 0); 170 171 if (*cp == '=') { 172 if (!(cp = tdefdecl(cp + 1, tid, &tdp))) 173 return (NULL); 174 if (tdp->t_id && tdp->t_id != tid) { 175 tdesc_t *ntdp = xcalloc(sizeof (*ntdp)); 176 177 ntdp->t_type = TYPEDEF; 178 ntdp->t_tdesc = tdp; 179 tdp = ntdp; 180 } 181 addhash(tdp, tid); 182 } else if ((tdp = lookup(tid)) == NULL) 183 tdp = unres_new(tid); 184 185 *tdpp = tdp; 186 return (cp); 187} 188 189static iitype_t 190parse_fun(char *cp, iidesc_t *ii) 191{ 192 iitype_t iitype = 0; 193 tdesc_t *tdp; 194 tdesc_t **args = NULL; 195 int nargs = 0; 196 int va = 0; 197 198 /* 199 * name:P prototype 200 * name:F global function 201 * name:f static function 202 */ 203 switch (*cp++) { 204 case 'P': 205 iitype = II_NOT; /* not interesting */ 206 break; 207 208 case 'F': 209 iitype = II_GFUN; 210 break; 211 212 case 'f': 213 iitype = II_SFUN; 214 break; 215 216 default: 217 expected("parse_nfun", "[PfF]", cp - 1); 218 } 219 220 if (!(cp = read_tid(cp, &tdp))) 221 return (-1); 222 223 if (*cp) 224 args = xmalloc(sizeof (tdesc_t *) * FUNCARG_DEF); 225 226 while (*cp && *++cp) { 227 if (*cp == '0') { 228 va = 1; 229 continue; 230 } 231 232 nargs++; 233 if (nargs > FUNCARG_DEF) 234 args = xrealloc(args, sizeof (tdesc_t *) * nargs); 235 if (!(cp = read_tid(cp, &args[nargs - 1]))) 236 return (-1); 237 } 238 239 ii->ii_type = iitype; 240 ii->ii_dtype = tdp; 241 ii->ii_nargs = nargs; 242 ii->ii_args = args; 243 ii->ii_vargs = va; 244 245 return (iitype); 246} 247 248static iitype_t 249parse_sym(char *cp, iidesc_t *ii) 250{ 251 tdesc_t *tdp; 252 iitype_t iitype = 0; 253 254 /* 255 * name:G global variable 256 * name:S static variable 257 */ 258 switch (*cp++) { 259 case 'G': 260 iitype = II_GVAR; 261 break; 262 case 'S': 263 iitype = II_SVAR; 264 break; 265 case 'p': 266 iitype = II_PSYM; 267 break; 268 case '(': 269 cp--; 270 /*FALLTHROUGH*/ 271 case 'r': 272 case 'V': 273 iitype = II_NOT; /* not interesting */ 274 break; 275 default: 276 expected("parse_sym", "[GprSV(]", cp - 1); 277 } 278 279 if (!(cp = read_tid(cp, &tdp))) 280 return (-1); 281 282 ii->ii_type = iitype; 283 ii->ii_dtype = tdp; 284 285 return (iitype); 286} 287 288static iitype_t 289parse_type(char *cp, iidesc_t *ii) 290{ 291 tdesc_t *tdp, *ntdp; 292 int tid; 293 294 if (*cp++ != 't') 295 expected("parse_type", "t (type)", cp - 1); 296 297 cp = id(cp, &tid); 298 if ((tdp = lookup(tid)) == NULL) { 299 if (*cp++ != '=') 300 expected("parse_type", "= (definition)", cp - 1); 301 302 (void) tdefdecl(cp, tid, &tdp); 303 304 if (tdp->t_id == tid) { 305 assert(tdp->t_type != TYPEDEF); 306 assert(!lookup(tdp->t_id)); 307 308 if (!streq(tdp->t_name, ii->ii_name)) { 309 ntdp = xcalloc(sizeof (*ntdp)); 310 ntdp->t_name = xstrdup(ii->ii_name); 311 ntdp->t_type = TYPEDEF; 312 ntdp->t_tdesc = tdp; 313 tdp->t_id = faketypenumber++; 314 tdp = ntdp; 315 } 316 } else if (tdp->t_id == 0) { 317 assert(tdp->t_type == FORWARD || 318 tdp->t_type == INTRINSIC); 319 320 if (tdp->t_name && !streq(tdp->t_name, ii->ii_name)) { 321 ntdp = xcalloc(sizeof (*ntdp)); 322 ntdp->t_name = xstrdup(ii->ii_name); 323 ntdp->t_type = TYPEDEF; 324 ntdp->t_tdesc = tdp; 325 tdp->t_id = faketypenumber++; 326 tdp = ntdp; 327 } 328 } else if (tdp->t_id != tid) { 329 ntdp = xcalloc(sizeof (*ntdp)); 330 ntdp->t_name = xstrdup(ii->ii_name); 331 ntdp->t_type = TYPEDEF; 332 ntdp->t_tdesc = tdp; 333 tdp = ntdp; 334 } 335 336 if (tagadd(ii->ii_name, tid, tdp) < 0) 337 return (-1); 338 } 339 340 ii->ii_type = II_TYPE; 341 ii->ii_dtype = tdp; 342 return (II_TYPE); 343} 344 345static iitype_t 346parse_sou(char *cp, iidesc_t *idp) 347{ 348 tdesc_t *rtdp; 349 int tid; 350 351 if (*cp++ != 'T') 352 expected("parse_sou", "T (sou)", cp - 1); 353 354 cp = id(cp, &tid); 355 if (*cp++ != '=') 356 expected("parse_sou", "= (definition)", cp - 1); 357 358 parse_debug(1, NULL, "parse_sou: declaring '%s'", idp->ii_name ? 359 idp->ii_name : "(anon)"); 360 if ((rtdp = lookup(tid)) != NULL) { 361 if (idp->ii_name != NULL) { 362 if (rtdp->t_name != NULL && 363 strcmp(rtdp->t_name, idp->ii_name) != 0) { 364 tdesc_t *tdp; 365 366 tdp = xcalloc(sizeof (*tdp)); 367 tdp->t_name = xstrdup(idp->ii_name); 368 tdp->t_type = TYPEDEF; 369 tdp->t_tdesc = rtdp; 370 addhash(tdp, tid); /* for *(x,y) types */ 371 parse_debug(3, NULL, " %s defined as %s(%d)", 372 idp->ii_name, tdesc_name(rtdp), tid); 373 } else if (rtdp->t_name == NULL) { 374 rtdp->t_name = xstrdup(idp->ii_name); 375 addhash(rtdp, tid); 376 } 377 } 378 } else { 379 rtdp = xcalloc(sizeof (*rtdp)); 380 rtdp->t_name = idp->ii_name ? xstrdup(idp->ii_name) : NULL; 381 addhash(rtdp, tid); 382 } 383 384 switch (*cp++) { 385 case 's': 386 (void) soudef(cp, STRUCT, &rtdp); 387 break; 388 case 'u': 389 (void) soudef(cp, UNION, &rtdp); 390 break; 391 case 'e': 392 enumdef(cp, &rtdp); 393 break; 394 default: 395 expected("parse_sou", "<tag type s/u/e>", cp - 1); 396 break; 397 } 398 399 idp->ii_type = II_SOU; 400 idp->ii_dtype = rtdp; 401 return (II_SOU); 402} 403 404int 405parse_stab(stab_t *stab, char *cp, iidesc_t **iidescp) 406{ 407 iidesc_t *ii = NULL; 408 iitype_t (*parse)(char *, iidesc_t *); 409 int rc; 410 411 /* 412 * set up for reset() 413 */ 414 if (setjmp(resetbuf)) 415 return (-1); 416 417 cp = whitesp(cp); 418 ii = iidesc_new(NULL); 419 cp = name(cp, &ii->ii_name); 420 421 switch (stab->n_type) { 422 case N_FUN: 423 parse = parse_fun; 424 break; 425 426 case N_LSYM: 427 if (*cp == 't') 428 parse = parse_type; 429 else if (*cp == 'T') 430 parse = parse_sou; 431 else 432 parse = parse_sym; 433 break; 434 435 case N_GSYM: 436 case N_LCSYM: 437 case N_PSYM: 438 case N_ROSYM: 439 case N_RSYM: 440 case N_STSYM: 441 parse = parse_sym; 442 break; 443 default: 444 parse_debug(1, cp, "Unknown stab type %#x", stab->n_type); 445 bzero(&resetbuf, sizeof (resetbuf)); 446 return (-1); 447 } 448 449 rc = parse(cp, ii); 450 bzero(&resetbuf, sizeof (resetbuf)); 451 452 if (rc < 0 || ii->ii_type == II_NOT) { 453 iidesc_free(ii, NULL); 454 return (rc); 455 } 456 457 *iidescp = ii; 458 459 return (1); 460} 461 462/* 463 * Check if we have this node in the hash table already 464 */ 465tdesc_t * 466lookup(int h) 467{ 468 int bucket = HASH(h); 469 tdesc_t *tdp = hash_table[bucket]; 470 471 while (tdp != NULL) { 472 if (tdp->t_id == h) 473 return (tdp); 474 tdp = tdp->t_hash; 475 } 476 return (NULL); 477} 478 479static char * 480whitesp(char *cp) 481{ 482 char c; 483
| 25/* 26 * This file is a sewer. 27 */ 28 29#include <limits.h> 30#include <stdarg.h> 31#include <stdio.h> 32#include <assert.h> 33#include <strings.h> 34#include <setjmp.h> 35#include <ctype.h> 36#include <uts/common/sys/ctf.h> 37 38#include "ctftools.h" 39#include "memory.h" 40#include "list.h" 41 42#define HASH(NUM) ((int)(NUM & (BUCKETS - 1))) 43#define BUCKETS 128 44 45#define TYPEPAIRMULT 10000 46#define MAKETYPEID(file, num) ((file) * TYPEPAIRMULT + num) 47#define TYPEFILE(tid) ((tid) / TYPEPAIRMULT) 48#define TYPENUM(tid) ((tid) % TYPEPAIRMULT) 49 50#define expected(a, b, c) _expected(a, b, c, __LINE__) 51 52static int faketypenumber = 100000000; 53 54static tdesc_t *hash_table[BUCKETS]; 55static tdesc_t *name_table[BUCKETS]; 56 57list_t *typedbitfldmems; 58 59static void reset(void); 60static jmp_buf resetbuf; 61 62static char *soudef(char *cp, stabtype_t type, tdesc_t **rtdp); 63static void enumdef(char *cp, tdesc_t **rtdp); 64static int compute_sum(const char *w); 65 66static char *number(char *cp, int *n); 67static char *name(char *cp, char **w); 68static char *id(char *cp, int *h); 69static char *whitesp(char *cp); 70static void addhash(tdesc_t *tdp, int num); 71static int tagadd(char *w, int h, tdesc_t *tdp); 72static char *tdefdecl(char *cp, int h, tdesc_t **rtdp); 73static char *intrinsic(char *cp, tdesc_t **rtdp); 74static char *arraydef(char *cp, tdesc_t **rtdp); 75 76int debug_parse = DEBUG_PARSE; 77 78/*PRINTFLIKE3*/ 79static void 80parse_debug(int level, char *cp, const char *fmt, ...) 81{ 82 va_list ap; 83 char buf[1024]; 84 char tmp[32]; 85 int i; 86 87 if (level > debug_level || !debug_parse) 88 return; 89 90 if (cp != NULL) { 91 for (i = 0; i < 30; i++) { 92 if (cp[i] == '\0') 93 break; 94 if (!iscntrl(cp[i])) 95 tmp[i] = cp[i]; 96 } 97 tmp[i] = '\0'; 98 (void) snprintf(buf, sizeof (buf), "%s [cp='%s']\n", fmt, tmp); 99 } else { 100 strcpy(buf, fmt); 101 strcat(buf, "\n"); 102 } 103 104 va_start(ap, fmt); 105 vadebug(level, buf, ap); 106 va_end(ap); 107} 108 109/* Report unexpected syntax in stabs. */ 110static void 111_expected( 112 const char *who, /* what function, or part thereof, is reporting */ 113 const char *what, /* what was expected */ 114 const char *where, /* where we were in the line of input */ 115 int line) 116{ 117 fprintf(stderr, "%s, expecting \"%s\" at \"%s\"\n", who, what, where); 118 fprintf(stderr, "code line: %d, file %s\n", line, 119 (curhdr ? curhdr : "NO FILE")); 120 reset(); 121} 122 123/*ARGSUSED*/ 124void 125parse_init(tdata_t *td __unused) 126{ 127 int i; 128 129 for (i = 0; i < BUCKETS; i++) { 130 hash_table[i] = NULL; 131 name_table[i] = NULL; 132 } 133 134 if (typedbitfldmems != NULL) { 135 list_free(typedbitfldmems, NULL, NULL); 136 typedbitfldmems = NULL; 137 } 138} 139 140void 141parse_finish(tdata_t *td) 142{ 143 td->td_nextid = ++faketypenumber; 144} 145 146static tdesc_t * 147unres_new(int tid) 148{ 149 tdesc_t *tdp; 150 151 tdp = xcalloc(sizeof (*tdp)); 152 tdp->t_type = TYPEDEF_UNRES; 153 tdp->t_id = tid; 154 155 return (tdp); 156} 157 158static char * 159read_tid(char *cp, tdesc_t **tdpp) 160{ 161 tdesc_t *tdp; 162 int tid; 163 164 cp = id(cp, &tid); 165 166 assert(tid != 0); 167 168 if (*cp == '=') { 169 if (!(cp = tdefdecl(cp + 1, tid, &tdp))) 170 return (NULL); 171 if (tdp->t_id && tdp->t_id != tid) { 172 tdesc_t *ntdp = xcalloc(sizeof (*ntdp)); 173 174 ntdp->t_type = TYPEDEF; 175 ntdp->t_tdesc = tdp; 176 tdp = ntdp; 177 } 178 addhash(tdp, tid); 179 } else if ((tdp = lookup(tid)) == NULL) 180 tdp = unres_new(tid); 181 182 *tdpp = tdp; 183 return (cp); 184} 185 186static iitype_t 187parse_fun(char *cp, iidesc_t *ii) 188{ 189 iitype_t iitype = 0; 190 tdesc_t *tdp; 191 tdesc_t **args = NULL; 192 int nargs = 0; 193 int va = 0; 194 195 /* 196 * name:P prototype 197 * name:F global function 198 * name:f static function 199 */ 200 switch (*cp++) { 201 case 'P': 202 iitype = II_NOT; /* not interesting */ 203 break; 204 205 case 'F': 206 iitype = II_GFUN; 207 break; 208 209 case 'f': 210 iitype = II_SFUN; 211 break; 212 213 default: 214 expected("parse_nfun", "[PfF]", cp - 1); 215 } 216 217 if (!(cp = read_tid(cp, &tdp))) 218 return (-1); 219 220 if (*cp) 221 args = xmalloc(sizeof (tdesc_t *) * FUNCARG_DEF); 222 223 while (*cp && *++cp) { 224 if (*cp == '0') { 225 va = 1; 226 continue; 227 } 228 229 nargs++; 230 if (nargs > FUNCARG_DEF) 231 args = xrealloc(args, sizeof (tdesc_t *) * nargs); 232 if (!(cp = read_tid(cp, &args[nargs - 1]))) 233 return (-1); 234 } 235 236 ii->ii_type = iitype; 237 ii->ii_dtype = tdp; 238 ii->ii_nargs = nargs; 239 ii->ii_args = args; 240 ii->ii_vargs = va; 241 242 return (iitype); 243} 244 245static iitype_t 246parse_sym(char *cp, iidesc_t *ii) 247{ 248 tdesc_t *tdp; 249 iitype_t iitype = 0; 250 251 /* 252 * name:G global variable 253 * name:S static variable 254 */ 255 switch (*cp++) { 256 case 'G': 257 iitype = II_GVAR; 258 break; 259 case 'S': 260 iitype = II_SVAR; 261 break; 262 case 'p': 263 iitype = II_PSYM; 264 break; 265 case '(': 266 cp--; 267 /*FALLTHROUGH*/ 268 case 'r': 269 case 'V': 270 iitype = II_NOT; /* not interesting */ 271 break; 272 default: 273 expected("parse_sym", "[GprSV(]", cp - 1); 274 } 275 276 if (!(cp = read_tid(cp, &tdp))) 277 return (-1); 278 279 ii->ii_type = iitype; 280 ii->ii_dtype = tdp; 281 282 return (iitype); 283} 284 285static iitype_t 286parse_type(char *cp, iidesc_t *ii) 287{ 288 tdesc_t *tdp, *ntdp; 289 int tid; 290 291 if (*cp++ != 't') 292 expected("parse_type", "t (type)", cp - 1); 293 294 cp = id(cp, &tid); 295 if ((tdp = lookup(tid)) == NULL) { 296 if (*cp++ != '=') 297 expected("parse_type", "= (definition)", cp - 1); 298 299 (void) tdefdecl(cp, tid, &tdp); 300 301 if (tdp->t_id == tid) { 302 assert(tdp->t_type != TYPEDEF); 303 assert(!lookup(tdp->t_id)); 304 305 if (!streq(tdp->t_name, ii->ii_name)) { 306 ntdp = xcalloc(sizeof (*ntdp)); 307 ntdp->t_name = xstrdup(ii->ii_name); 308 ntdp->t_type = TYPEDEF; 309 ntdp->t_tdesc = tdp; 310 tdp->t_id = faketypenumber++; 311 tdp = ntdp; 312 } 313 } else if (tdp->t_id == 0) { 314 assert(tdp->t_type == FORWARD || 315 tdp->t_type == INTRINSIC); 316 317 if (tdp->t_name && !streq(tdp->t_name, ii->ii_name)) { 318 ntdp = xcalloc(sizeof (*ntdp)); 319 ntdp->t_name = xstrdup(ii->ii_name); 320 ntdp->t_type = TYPEDEF; 321 ntdp->t_tdesc = tdp; 322 tdp->t_id = faketypenumber++; 323 tdp = ntdp; 324 } 325 } else if (tdp->t_id != tid) { 326 ntdp = xcalloc(sizeof (*ntdp)); 327 ntdp->t_name = xstrdup(ii->ii_name); 328 ntdp->t_type = TYPEDEF; 329 ntdp->t_tdesc = tdp; 330 tdp = ntdp; 331 } 332 333 if (tagadd(ii->ii_name, tid, tdp) < 0) 334 return (-1); 335 } 336 337 ii->ii_type = II_TYPE; 338 ii->ii_dtype = tdp; 339 return (II_TYPE); 340} 341 342static iitype_t 343parse_sou(char *cp, iidesc_t *idp) 344{ 345 tdesc_t *rtdp; 346 int tid; 347 348 if (*cp++ != 'T') 349 expected("parse_sou", "T (sou)", cp - 1); 350 351 cp = id(cp, &tid); 352 if (*cp++ != '=') 353 expected("parse_sou", "= (definition)", cp - 1); 354 355 parse_debug(1, NULL, "parse_sou: declaring '%s'", idp->ii_name ? 356 idp->ii_name : "(anon)"); 357 if ((rtdp = lookup(tid)) != NULL) { 358 if (idp->ii_name != NULL) { 359 if (rtdp->t_name != NULL && 360 strcmp(rtdp->t_name, idp->ii_name) != 0) { 361 tdesc_t *tdp; 362 363 tdp = xcalloc(sizeof (*tdp)); 364 tdp->t_name = xstrdup(idp->ii_name); 365 tdp->t_type = TYPEDEF; 366 tdp->t_tdesc = rtdp; 367 addhash(tdp, tid); /* for *(x,y) types */ 368 parse_debug(3, NULL, " %s defined as %s(%d)", 369 idp->ii_name, tdesc_name(rtdp), tid); 370 } else if (rtdp->t_name == NULL) { 371 rtdp->t_name = xstrdup(idp->ii_name); 372 addhash(rtdp, tid); 373 } 374 } 375 } else { 376 rtdp = xcalloc(sizeof (*rtdp)); 377 rtdp->t_name = idp->ii_name ? xstrdup(idp->ii_name) : NULL; 378 addhash(rtdp, tid); 379 } 380 381 switch (*cp++) { 382 case 's': 383 (void) soudef(cp, STRUCT, &rtdp); 384 break; 385 case 'u': 386 (void) soudef(cp, UNION, &rtdp); 387 break; 388 case 'e': 389 enumdef(cp, &rtdp); 390 break; 391 default: 392 expected("parse_sou", "<tag type s/u/e>", cp - 1); 393 break; 394 } 395 396 idp->ii_type = II_SOU; 397 idp->ii_dtype = rtdp; 398 return (II_SOU); 399} 400 401int 402parse_stab(stab_t *stab, char *cp, iidesc_t **iidescp) 403{ 404 iidesc_t *ii = NULL; 405 iitype_t (*parse)(char *, iidesc_t *); 406 int rc; 407 408 /* 409 * set up for reset() 410 */ 411 if (setjmp(resetbuf)) 412 return (-1); 413 414 cp = whitesp(cp); 415 ii = iidesc_new(NULL); 416 cp = name(cp, &ii->ii_name); 417 418 switch (stab->n_type) { 419 case N_FUN: 420 parse = parse_fun; 421 break; 422 423 case N_LSYM: 424 if (*cp == 't') 425 parse = parse_type; 426 else if (*cp == 'T') 427 parse = parse_sou; 428 else 429 parse = parse_sym; 430 break; 431 432 case N_GSYM: 433 case N_LCSYM: 434 case N_PSYM: 435 case N_ROSYM: 436 case N_RSYM: 437 case N_STSYM: 438 parse = parse_sym; 439 break; 440 default: 441 parse_debug(1, cp, "Unknown stab type %#x", stab->n_type); 442 bzero(&resetbuf, sizeof (resetbuf)); 443 return (-1); 444 } 445 446 rc = parse(cp, ii); 447 bzero(&resetbuf, sizeof (resetbuf)); 448 449 if (rc < 0 || ii->ii_type == II_NOT) { 450 iidesc_free(ii, NULL); 451 return (rc); 452 } 453 454 *iidescp = ii; 455 456 return (1); 457} 458 459/* 460 * Check if we have this node in the hash table already 461 */ 462tdesc_t * 463lookup(int h) 464{ 465 int bucket = HASH(h); 466 tdesc_t *tdp = hash_table[bucket]; 467 468 while (tdp != NULL) { 469 if (tdp->t_id == h) 470 return (tdp); 471 tdp = tdp->t_hash; 472 } 473 return (NULL); 474} 475 476static char * 477whitesp(char *cp) 478{ 479 char c; 480
|
484 for (c = *cp++; isspace(c); c = *cp++);
| 481 for (c = *cp++; isspace(c); c = *cp++) 482 ;
|
485 --cp; 486 return (cp); 487} 488 489static char * 490name(char *cp, char **w) 491{ 492 char *new, *orig, c; 493 int len; 494 495 orig = cp; 496 c = *cp++; 497 if (c == ':') 498 *w = NULL;
| 483 --cp; 484 return (cp); 485} 486 487static char * 488name(char *cp, char **w) 489{ 490 char *new, *orig, c; 491 int len; 492 493 orig = cp; 494 c = *cp++; 495 if (c == ':') 496 *w = NULL;
|
499 else if (isalpha(c) || strchr("_.$", c)) { 500 for (c = *cp++; isalnum(c) || strchr(" _.$", c); c = *cp++)
| 497 else if (isalpha(c) || strchr("_.$#", c)) { 498 for (c = *cp++; isalnum(c) || strchr(" _.$#", c); c = *cp++)
|
501 ; 502 if (c != ':') 503 reset(); 504 len = cp - orig; 505 new = xmalloc(len); 506 while (orig < cp - 1) 507 *new++ = *orig++; 508 *new = '\0'; 509 *w = new - (len - 1); 510 } else 511 reset(); 512 513 return (cp); 514} 515 516static char * 517number(char *cp, int *n) 518{ 519 char *next; 520 521 *n = (int)strtol(cp, &next, 10); 522 if (next == cp) 523 expected("number", "<number>", cp); 524 return (next); 525} 526 527static char * 528id(char *cp, int *h) 529{ 530 int n1, n2; 531 532 if (*cp == '(') { /* SunPro style */ 533 cp++; 534 cp = number(cp, &n1); 535 if (*cp++ != ',') 536 expected("id", ",", cp - 1); 537 cp = number(cp, &n2); 538 if (*cp++ != ')') 539 expected("id", ")", cp - 1); 540 *h = MAKETYPEID(n1, n2); 541 } else if (isdigit(*cp)) { /* gcc style */ 542 cp = number(cp, &n1); 543 *h = n1; 544 } else { 545 expected("id", "(/0-9", cp); 546 } 547 return (cp); 548} 549 550static int 551tagadd(char *w, int h, tdesc_t *tdp) 552{ 553 tdesc_t *otdp; 554 555 tdp->t_name = w; 556 if (!(otdp = lookup(h))) 557 addhash(tdp, h); 558 else if (otdp != tdp) { 559 warning("duplicate entry\n"); 560 warning(" old: %s %d (%d,%d)\n", tdesc_name(otdp), 561 otdp->t_type, TYPEFILE(otdp->t_id), TYPENUM(otdp->t_id)); 562 warning(" new: %s %d (%d,%d)\n", tdesc_name(tdp), 563 tdp->t_type, TYPEFILE(tdp->t_id), TYPENUM(tdp->t_id)); 564 return (-1); 565 } 566 567 return (0); 568} 569 570static char * 571tdefdecl(char *cp, int h, tdesc_t **rtdp) 572{ 573 tdesc_t *ntdp; 574 char *w; 575 int c, h2; 576 char type; 577 578 parse_debug(3, cp, "tdefdecl h=%d", h); 579 580 /* Type codes */ 581 switch (type = *cp) { 582 case 'b': /* integer */ 583 case 'R': /* fp */ 584 cp = intrinsic(cp, rtdp); 585 break; 586 case '(': /* equiv to another type */ 587 cp = id(cp, &h2); 588 ntdp = lookup(h2); 589 590 if (ntdp != NULL && *cp == '=') { 591 if (ntdp->t_type == FORWARD && *(cp + 1) == 'x') { 592 /* 593 * The 6.2 compiler, and possibly others, will 594 * sometimes emit the same stab for a forward 595 * declaration twice. That is, "(1,2)=xsfoo:" 596 * will sometimes show up in two different 597 * places. This is, of course, quite fun. We 598 * want CTF to work in spite of the compiler, 599 * so we'll let this one through. 600 */ 601 char *c2 = cp + 2; 602 char *nm; 603 604 if (!strchr("sue", *c2++)) { 605 expected("tdefdecl/x-redefine", "[sue]", 606 c2 - 1); 607 } 608 609 c2 = name(c2, &nm); 610 if (strcmp(nm, ntdp->t_name) != 0) { 611 terminate("Stabs error: Attempt to " 612 "redefine type (%d,%d) as " 613 "something else: %s\n", 614 TYPEFILE(h2), TYPENUM(h2), 615 c2 - 1); 616 } 617 free(nm); 618 619 h2 = faketypenumber++; 620 ntdp = NULL; 621 } else { 622 terminate("Stabs error: Attempting to " 623 "redefine type (%d,%d)\n", TYPEFILE(h2), 624 TYPENUM(h2)); 625 } 626 } 627 628 if (ntdp == NULL) { /* if that type isn't defined yet */ 629 if (*cp != '=') { 630 /* record it as unresolved */ 631 parse_debug(3, NULL, "tdefdecl unres type %d", 632 h2); 633 *rtdp = calloc(sizeof (**rtdp), 1); 634 (*rtdp)->t_type = TYPEDEF_UNRES; 635 (*rtdp)->t_id = h2; 636 break; 637 } else 638 cp++; 639 640 /* define a new type */ 641 cp = tdefdecl(cp, h2, rtdp); 642 if ((*rtdp)->t_id && (*rtdp)->t_id != h2) { 643 ntdp = calloc(sizeof (*ntdp), 1); 644 ntdp->t_type = TYPEDEF; 645 ntdp->t_tdesc = *rtdp; 646 *rtdp = ntdp; 647 } 648 649 addhash(*rtdp, h2); 650 651 } else { /* that type is already defined */ 652 if (ntdp->t_type != TYPEDEF || ntdp->t_name != NULL) { 653 *rtdp = ntdp; 654 } else { 655 parse_debug(3, NULL, 656 "No duplicate typedef anon for ref"); 657 *rtdp = ntdp; 658 } 659 } 660 break; 661 case '*': 662 ntdp = NULL; 663 cp = tdefdecl(cp + 1, h, &ntdp); 664 if (ntdp == NULL) 665 expected("tdefdecl/*", "id", cp); 666 667 if (!ntdp->t_id) 668 ntdp->t_id = faketypenumber++; 669 670 *rtdp = xcalloc(sizeof (**rtdp)); 671 (*rtdp)->t_type = POINTER; 672 (*rtdp)->t_size = 0; 673 (*rtdp)->t_id = h; 674 (*rtdp)->t_tdesc = ntdp; 675 break; 676 case 'f': 677 cp = tdefdecl(cp + 1, h, &ntdp); 678 *rtdp = xcalloc(sizeof (**rtdp)); 679 (*rtdp)->t_type = FUNCTION; 680 (*rtdp)->t_size = 0; 681 (*rtdp)->t_id = h; 682 (*rtdp)->t_fndef = xcalloc(sizeof (fndef_t)); 683 /* 684 * The 6.1 compiler will sometimes generate incorrect stabs for 685 * function pointers (it'll get the return type wrong). This 686 * causes merges to fail. We therefore treat function pointers 687 * as if they all point to functions that return int. When 688 * 4432549 is fixed, the lookupname() call below should be 689 * replaced with `ntdp'. 690 */ 691 (*rtdp)->t_fndef->fn_ret = lookupname("int"); 692 break; 693 case 'a': 694 case 'z': 695 cp++; 696 if (*cp++ != 'r') 697 expected("tdefdecl/[az]", "r", cp - 1); 698 *rtdp = xcalloc(sizeof (**rtdp)); 699 (*rtdp)->t_type = ARRAY; 700 (*rtdp)->t_id = h; 701 cp = arraydef(cp, rtdp); 702 break; 703 case 'x': 704 c = *++cp; 705 if (c != 's' && c != 'u' && c != 'e') 706 expected("tdefdecl/x", "[sue]", cp - 1); 707 cp = name(cp + 1, &w); 708 709 ntdp = xcalloc(sizeof (*ntdp)); 710 ntdp->t_type = FORWARD; 711 ntdp->t_name = w; 712 /* 713 * We explicitly don't set t_id here - the caller will do it. 714 * The caller may want to use a real type ID, or they may 715 * choose to make one up. 716 */ 717 718 *rtdp = ntdp; 719 break; 720 721 case 'B': /* volatile */ 722 cp = tdefdecl(cp + 1, h, &ntdp); 723 724 if (!ntdp->t_id) 725 ntdp->t_id = faketypenumber++; 726 727 *rtdp = xcalloc(sizeof (**rtdp)); 728 (*rtdp)->t_type = VOLATILE; 729 (*rtdp)->t_size = 0; 730 (*rtdp)->t_tdesc = ntdp; 731 (*rtdp)->t_id = h; 732 break; 733 734 case 'k': /* const */ 735 cp = tdefdecl(cp + 1, h, &ntdp); 736 737 if (!ntdp->t_id) 738 ntdp->t_id = faketypenumber++; 739 740 *rtdp = xcalloc(sizeof (**rtdp)); 741 (*rtdp)->t_type = CONST; 742 (*rtdp)->t_size = 0; 743 (*rtdp)->t_tdesc = ntdp; 744 (*rtdp)->t_id = h; 745 break; 746 747 case 'K': /* restricted */ 748 cp = tdefdecl(cp + 1, h, &ntdp); 749 750 if (!ntdp->t_id) 751 ntdp->t_id = faketypenumber++; 752 753 *rtdp = xcalloc(sizeof (**rtdp)); 754 (*rtdp)->t_type = RESTRICT; 755 (*rtdp)->t_size = 0; 756 (*rtdp)->t_tdesc = ntdp; 757 (*rtdp)->t_id = h; 758 break; 759 760 case 'u': 761 case 's': 762 cp++; 763 764 *rtdp = xcalloc(sizeof (**rtdp)); 765 (*rtdp)->t_name = NULL; 766 cp = soudef(cp, (type == 'u') ? UNION : STRUCT, rtdp); 767 break; 768 default: 769 expected("tdefdecl", "<type code>", cp); 770 } 771 return (cp); 772} 773 774static char * 775intrinsic(char *cp, tdesc_t **rtdp) 776{ 777 intr_t *intr = xcalloc(sizeof (intr_t)); 778 tdesc_t *tdp; 779 int width, fmt, i; 780 781 switch (*cp++) { 782 case 'b': 783 intr->intr_type = INTR_INT; 784 if (*cp == 's') 785 intr->intr_signed = 1; 786 else if (*cp != 'u') 787 expected("intrinsic/b", "[su]", cp); 788 cp++; 789 790 if (strchr("cbv", *cp)) 791 intr->intr_iformat = *cp++; 792 793 cp = number(cp, &width); 794 if (*cp++ != ';') 795 expected("intrinsic/b", "; (post-width)", cp - 1); 796 797 cp = number(cp, &intr->intr_offset); 798 if (*cp++ != ';') 799 expected("intrinsic/b", "; (post-offset)", cp - 1); 800 801 cp = number(cp, &intr->intr_nbits); 802 break; 803 804 case 'R': 805 intr->intr_type = INTR_REAL; 806 for (fmt = 0, i = 0; isdigit(*(cp + i)); i++) 807 fmt = fmt * 10 + (*(cp + i) - '0'); 808 809 if (fmt < 1 || fmt > CTF_FP_MAX) 810 expected("intrinsic/R", "number <= CTF_FP_MAX", cp); 811 812 intr->intr_fformat = fmt; 813 cp += i; 814 815 if (*cp++ != ';') 816 expected("intrinsic/R", ";", cp - 1); 817 cp = number(cp, &width); 818 819 intr->intr_nbits = width * 8; 820 break; 821 } 822 823 tdp = xcalloc(sizeof (*tdp)); 824 tdp->t_type = INTRINSIC; 825 tdp->t_size = width; 826 tdp->t_name = NULL; 827 tdp->t_intr = intr; 828 parse_debug(3, NULL, "intrinsic: size=%d", width); 829 *rtdp = tdp; 830 831 return (cp); 832} 833 834static tdesc_t * 835bitintrinsic(tdesc_t *template, int nbits) 836{ 837 tdesc_t *newtdp = xcalloc(sizeof (tdesc_t)); 838 839 newtdp->t_name = xstrdup(template->t_name); 840 newtdp->t_id = faketypenumber++; 841 newtdp->t_type = INTRINSIC; 842 newtdp->t_size = template->t_size; 843 newtdp->t_intr = xmalloc(sizeof (intr_t)); 844 bcopy(template->t_intr, newtdp->t_intr, sizeof (intr_t)); 845 newtdp->t_intr->intr_nbits = nbits; 846 847 return (newtdp); 848} 849 850static char * 851offsize(char *cp, mlist_t *mlp) 852{ 853 int offset, size; 854 855 if (*cp == ',') 856 cp++; 857 cp = number(cp, &offset); 858 if (*cp++ != ',') 859 expected("offsize/2", ",", cp - 1); 860 cp = number(cp, &size); 861 if (*cp++ != ';') 862 expected("offsize/3", ";", cp - 1); 863 mlp->ml_offset = offset; 864 mlp->ml_size = size; 865 return (cp); 866} 867 868static tdesc_t * 869find_intrinsic(tdesc_t *tdp) 870{ 871 for (;;) { 872 switch (tdp->t_type) { 873 case TYPEDEF: 874 case VOLATILE: 875 case CONST: 876 case RESTRICT: 877 tdp = tdp->t_tdesc; 878 break; 879 880 default: 881 return (tdp); 882 } 883 } 884} 885 886static char * 887soudef(char *cp, stabtype_t type, tdesc_t **rtdp) 888{ 889 mlist_t *mlp, **prev; 890 char *w; 891 int h; 892 int size; 893 tdesc_t *tdp, *itdp; 894 895 cp = number(cp, &size); 896 (*rtdp)->t_size = size; 897 (*rtdp)->t_type = type; /* s or u */ 898 899 /* 900 * An '@' here indicates a bitmask follows. This is so the 901 * compiler can pass information to debuggers about how structures 902 * are passed in the v9 world. We don't need this information 903 * so we skip over it. 904 */ 905 if (cp[0] == '@') { 906 cp += 3; 907 } 908 909 parse_debug(3, cp, "soudef: %s size=%d", tdesc_name(*rtdp), 910 (*rtdp)->t_size); 911 912 prev = &((*rtdp)->t_members); 913 /* now fill up the fields */ 914 while ((*cp != '\0') && (*cp != ';')) { /* signifies end of fields */ 915 mlp = xcalloc(sizeof (*mlp)); 916 *prev = mlp; 917 cp = name(cp, &w); 918 mlp->ml_name = w; 919 cp = id(cp, &h); 920 /* 921 * find the tdesc struct in the hash table for this type 922 * and stick a ptr in here 923 */ 924 tdp = lookup(h); 925 if (tdp == NULL) { /* not in hash list */ 926 parse_debug(3, NULL, " defines %s (%d)", w, h); 927 if (*cp++ != '=') { 928 tdp = unres_new(h); 929 parse_debug(3, NULL, 930 " refers to %s (unresolved %d)", 931 (w ? w : "anon"), h); 932 } else { 933 cp = tdefdecl(cp, h, &tdp); 934 935 if (tdp->t_id && tdp->t_id != h) { 936 tdesc_t *ntdp = xcalloc(sizeof (*ntdp)); 937 938 ntdp->t_type = TYPEDEF; 939 ntdp->t_tdesc = tdp; 940 tdp = ntdp; 941 } 942 943 addhash(tdp, h); 944 parse_debug(4, cp, 945 " soudef now looking at "); 946 cp++; 947 } 948 } else { 949 parse_debug(3, NULL, " refers to %s (%d, %s)", 950 w ? w : "anon", h, tdesc_name(tdp)); 951 } 952 953 cp = offsize(cp, mlp); 954 955 itdp = find_intrinsic(tdp); 956 if (itdp->t_type == INTRINSIC) { 957 if (mlp->ml_size != itdp->t_intr->intr_nbits) { 958 parse_debug(4, cp, "making %d bit intrinsic " 959 "from %s", mlp->ml_size, tdesc_name(itdp)); 960 mlp->ml_type = bitintrinsic(itdp, mlp->ml_size); 961 } else 962 mlp->ml_type = tdp; 963 } else if (itdp->t_type == TYPEDEF_UNRES) { 964 list_add(&typedbitfldmems, mlp); 965 mlp->ml_type = tdp; 966 } else { 967 mlp->ml_type = tdp; 968 } 969 970 /* cp is now pointing to next field */ 971 prev = &mlp->ml_next; 972 } 973 return (cp); 974} 975 976static char * 977arraydef(char *cp, tdesc_t **rtdp) 978{ 979 int start, end, h; 980 981 cp = id(cp, &h); 982 if (*cp++ != ';') 983 expected("arraydef/1", ";", cp - 1); 984 985 (*rtdp)->t_ardef = xcalloc(sizeof (ardef_t)); 986 (*rtdp)->t_ardef->ad_idxtype = lookup(h); 987 988 cp = number(cp, &start); /* lower */ 989 if (*cp++ != ';') 990 expected("arraydef/2", ";", cp - 1); 991 992 if (*cp == 'S') {
| 499 ; 500 if (c != ':') 501 reset(); 502 len = cp - orig; 503 new = xmalloc(len); 504 while (orig < cp - 1) 505 *new++ = *orig++; 506 *new = '\0'; 507 *w = new - (len - 1); 508 } else 509 reset(); 510 511 return (cp); 512} 513 514static char * 515number(char *cp, int *n) 516{ 517 char *next; 518 519 *n = (int)strtol(cp, &next, 10); 520 if (next == cp) 521 expected("number", "<number>", cp); 522 return (next); 523} 524 525static char * 526id(char *cp, int *h) 527{ 528 int n1, n2; 529 530 if (*cp == '(') { /* SunPro style */ 531 cp++; 532 cp = number(cp, &n1); 533 if (*cp++ != ',') 534 expected("id", ",", cp - 1); 535 cp = number(cp, &n2); 536 if (*cp++ != ')') 537 expected("id", ")", cp - 1); 538 *h = MAKETYPEID(n1, n2); 539 } else if (isdigit(*cp)) { /* gcc style */ 540 cp = number(cp, &n1); 541 *h = n1; 542 } else { 543 expected("id", "(/0-9", cp); 544 } 545 return (cp); 546} 547 548static int 549tagadd(char *w, int h, tdesc_t *tdp) 550{ 551 tdesc_t *otdp; 552 553 tdp->t_name = w; 554 if (!(otdp = lookup(h))) 555 addhash(tdp, h); 556 else if (otdp != tdp) { 557 warning("duplicate entry\n"); 558 warning(" old: %s %d (%d,%d)\n", tdesc_name(otdp), 559 otdp->t_type, TYPEFILE(otdp->t_id), TYPENUM(otdp->t_id)); 560 warning(" new: %s %d (%d,%d)\n", tdesc_name(tdp), 561 tdp->t_type, TYPEFILE(tdp->t_id), TYPENUM(tdp->t_id)); 562 return (-1); 563 } 564 565 return (0); 566} 567 568static char * 569tdefdecl(char *cp, int h, tdesc_t **rtdp) 570{ 571 tdesc_t *ntdp; 572 char *w; 573 int c, h2; 574 char type; 575 576 parse_debug(3, cp, "tdefdecl h=%d", h); 577 578 /* Type codes */ 579 switch (type = *cp) { 580 case 'b': /* integer */ 581 case 'R': /* fp */ 582 cp = intrinsic(cp, rtdp); 583 break; 584 case '(': /* equiv to another type */ 585 cp = id(cp, &h2); 586 ntdp = lookup(h2); 587 588 if (ntdp != NULL && *cp == '=') { 589 if (ntdp->t_type == FORWARD && *(cp + 1) == 'x') { 590 /* 591 * The 6.2 compiler, and possibly others, will 592 * sometimes emit the same stab for a forward 593 * declaration twice. That is, "(1,2)=xsfoo:" 594 * will sometimes show up in two different 595 * places. This is, of course, quite fun. We 596 * want CTF to work in spite of the compiler, 597 * so we'll let this one through. 598 */ 599 char *c2 = cp + 2; 600 char *nm; 601 602 if (!strchr("sue", *c2++)) { 603 expected("tdefdecl/x-redefine", "[sue]", 604 c2 - 1); 605 } 606 607 c2 = name(c2, &nm); 608 if (strcmp(nm, ntdp->t_name) != 0) { 609 terminate("Stabs error: Attempt to " 610 "redefine type (%d,%d) as " 611 "something else: %s\n", 612 TYPEFILE(h2), TYPENUM(h2), 613 c2 - 1); 614 } 615 free(nm); 616 617 h2 = faketypenumber++; 618 ntdp = NULL; 619 } else { 620 terminate("Stabs error: Attempting to " 621 "redefine type (%d,%d)\n", TYPEFILE(h2), 622 TYPENUM(h2)); 623 } 624 } 625 626 if (ntdp == NULL) { /* if that type isn't defined yet */ 627 if (*cp != '=') { 628 /* record it as unresolved */ 629 parse_debug(3, NULL, "tdefdecl unres type %d", 630 h2); 631 *rtdp = calloc(sizeof (**rtdp), 1); 632 (*rtdp)->t_type = TYPEDEF_UNRES; 633 (*rtdp)->t_id = h2; 634 break; 635 } else 636 cp++; 637 638 /* define a new type */ 639 cp = tdefdecl(cp, h2, rtdp); 640 if ((*rtdp)->t_id && (*rtdp)->t_id != h2) { 641 ntdp = calloc(sizeof (*ntdp), 1); 642 ntdp->t_type = TYPEDEF; 643 ntdp->t_tdesc = *rtdp; 644 *rtdp = ntdp; 645 } 646 647 addhash(*rtdp, h2); 648 649 } else { /* that type is already defined */ 650 if (ntdp->t_type != TYPEDEF || ntdp->t_name != NULL) { 651 *rtdp = ntdp; 652 } else { 653 parse_debug(3, NULL, 654 "No duplicate typedef anon for ref"); 655 *rtdp = ntdp; 656 } 657 } 658 break; 659 case '*': 660 ntdp = NULL; 661 cp = tdefdecl(cp + 1, h, &ntdp); 662 if (ntdp == NULL) 663 expected("tdefdecl/*", "id", cp); 664 665 if (!ntdp->t_id) 666 ntdp->t_id = faketypenumber++; 667 668 *rtdp = xcalloc(sizeof (**rtdp)); 669 (*rtdp)->t_type = POINTER; 670 (*rtdp)->t_size = 0; 671 (*rtdp)->t_id = h; 672 (*rtdp)->t_tdesc = ntdp; 673 break; 674 case 'f': 675 cp = tdefdecl(cp + 1, h, &ntdp); 676 *rtdp = xcalloc(sizeof (**rtdp)); 677 (*rtdp)->t_type = FUNCTION; 678 (*rtdp)->t_size = 0; 679 (*rtdp)->t_id = h; 680 (*rtdp)->t_fndef = xcalloc(sizeof (fndef_t)); 681 /* 682 * The 6.1 compiler will sometimes generate incorrect stabs for 683 * function pointers (it'll get the return type wrong). This 684 * causes merges to fail. We therefore treat function pointers 685 * as if they all point to functions that return int. When 686 * 4432549 is fixed, the lookupname() call below should be 687 * replaced with `ntdp'. 688 */ 689 (*rtdp)->t_fndef->fn_ret = lookupname("int"); 690 break; 691 case 'a': 692 case 'z': 693 cp++; 694 if (*cp++ != 'r') 695 expected("tdefdecl/[az]", "r", cp - 1); 696 *rtdp = xcalloc(sizeof (**rtdp)); 697 (*rtdp)->t_type = ARRAY; 698 (*rtdp)->t_id = h; 699 cp = arraydef(cp, rtdp); 700 break; 701 case 'x': 702 c = *++cp; 703 if (c != 's' && c != 'u' && c != 'e') 704 expected("tdefdecl/x", "[sue]", cp - 1); 705 cp = name(cp + 1, &w); 706 707 ntdp = xcalloc(sizeof (*ntdp)); 708 ntdp->t_type = FORWARD; 709 ntdp->t_name = w; 710 /* 711 * We explicitly don't set t_id here - the caller will do it. 712 * The caller may want to use a real type ID, or they may 713 * choose to make one up. 714 */ 715 716 *rtdp = ntdp; 717 break; 718 719 case 'B': /* volatile */ 720 cp = tdefdecl(cp + 1, h, &ntdp); 721 722 if (!ntdp->t_id) 723 ntdp->t_id = faketypenumber++; 724 725 *rtdp = xcalloc(sizeof (**rtdp)); 726 (*rtdp)->t_type = VOLATILE; 727 (*rtdp)->t_size = 0; 728 (*rtdp)->t_tdesc = ntdp; 729 (*rtdp)->t_id = h; 730 break; 731 732 case 'k': /* const */ 733 cp = tdefdecl(cp + 1, h, &ntdp); 734 735 if (!ntdp->t_id) 736 ntdp->t_id = faketypenumber++; 737 738 *rtdp = xcalloc(sizeof (**rtdp)); 739 (*rtdp)->t_type = CONST; 740 (*rtdp)->t_size = 0; 741 (*rtdp)->t_tdesc = ntdp; 742 (*rtdp)->t_id = h; 743 break; 744 745 case 'K': /* restricted */ 746 cp = tdefdecl(cp + 1, h, &ntdp); 747 748 if (!ntdp->t_id) 749 ntdp->t_id = faketypenumber++; 750 751 *rtdp = xcalloc(sizeof (**rtdp)); 752 (*rtdp)->t_type = RESTRICT; 753 (*rtdp)->t_size = 0; 754 (*rtdp)->t_tdesc = ntdp; 755 (*rtdp)->t_id = h; 756 break; 757 758 case 'u': 759 case 's': 760 cp++; 761 762 *rtdp = xcalloc(sizeof (**rtdp)); 763 (*rtdp)->t_name = NULL; 764 cp = soudef(cp, (type == 'u') ? UNION : STRUCT, rtdp); 765 break; 766 default: 767 expected("tdefdecl", "<type code>", cp); 768 } 769 return (cp); 770} 771 772static char * 773intrinsic(char *cp, tdesc_t **rtdp) 774{ 775 intr_t *intr = xcalloc(sizeof (intr_t)); 776 tdesc_t *tdp; 777 int width, fmt, i; 778 779 switch (*cp++) { 780 case 'b': 781 intr->intr_type = INTR_INT; 782 if (*cp == 's') 783 intr->intr_signed = 1; 784 else if (*cp != 'u') 785 expected("intrinsic/b", "[su]", cp); 786 cp++; 787 788 if (strchr("cbv", *cp)) 789 intr->intr_iformat = *cp++; 790 791 cp = number(cp, &width); 792 if (*cp++ != ';') 793 expected("intrinsic/b", "; (post-width)", cp - 1); 794 795 cp = number(cp, &intr->intr_offset); 796 if (*cp++ != ';') 797 expected("intrinsic/b", "; (post-offset)", cp - 1); 798 799 cp = number(cp, &intr->intr_nbits); 800 break; 801 802 case 'R': 803 intr->intr_type = INTR_REAL; 804 for (fmt = 0, i = 0; isdigit(*(cp + i)); i++) 805 fmt = fmt * 10 + (*(cp + i) - '0'); 806 807 if (fmt < 1 || fmt > CTF_FP_MAX) 808 expected("intrinsic/R", "number <= CTF_FP_MAX", cp); 809 810 intr->intr_fformat = fmt; 811 cp += i; 812 813 if (*cp++ != ';') 814 expected("intrinsic/R", ";", cp - 1); 815 cp = number(cp, &width); 816 817 intr->intr_nbits = width * 8; 818 break; 819 } 820 821 tdp = xcalloc(sizeof (*tdp)); 822 tdp->t_type = INTRINSIC; 823 tdp->t_size = width; 824 tdp->t_name = NULL; 825 tdp->t_intr = intr; 826 parse_debug(3, NULL, "intrinsic: size=%d", width); 827 *rtdp = tdp; 828 829 return (cp); 830} 831 832static tdesc_t * 833bitintrinsic(tdesc_t *template, int nbits) 834{ 835 tdesc_t *newtdp = xcalloc(sizeof (tdesc_t)); 836 837 newtdp->t_name = xstrdup(template->t_name); 838 newtdp->t_id = faketypenumber++; 839 newtdp->t_type = INTRINSIC; 840 newtdp->t_size = template->t_size; 841 newtdp->t_intr = xmalloc(sizeof (intr_t)); 842 bcopy(template->t_intr, newtdp->t_intr, sizeof (intr_t)); 843 newtdp->t_intr->intr_nbits = nbits; 844 845 return (newtdp); 846} 847 848static char * 849offsize(char *cp, mlist_t *mlp) 850{ 851 int offset, size; 852 853 if (*cp == ',') 854 cp++; 855 cp = number(cp, &offset); 856 if (*cp++ != ',') 857 expected("offsize/2", ",", cp - 1); 858 cp = number(cp, &size); 859 if (*cp++ != ';') 860 expected("offsize/3", ";", cp - 1); 861 mlp->ml_offset = offset; 862 mlp->ml_size = size; 863 return (cp); 864} 865 866static tdesc_t * 867find_intrinsic(tdesc_t *tdp) 868{ 869 for (;;) { 870 switch (tdp->t_type) { 871 case TYPEDEF: 872 case VOLATILE: 873 case CONST: 874 case RESTRICT: 875 tdp = tdp->t_tdesc; 876 break; 877 878 default: 879 return (tdp); 880 } 881 } 882} 883 884static char * 885soudef(char *cp, stabtype_t type, tdesc_t **rtdp) 886{ 887 mlist_t *mlp, **prev; 888 char *w; 889 int h; 890 int size; 891 tdesc_t *tdp, *itdp; 892 893 cp = number(cp, &size); 894 (*rtdp)->t_size = size; 895 (*rtdp)->t_type = type; /* s or u */ 896 897 /* 898 * An '@' here indicates a bitmask follows. This is so the 899 * compiler can pass information to debuggers about how structures 900 * are passed in the v9 world. We don't need this information 901 * so we skip over it. 902 */ 903 if (cp[0] == '@') { 904 cp += 3; 905 } 906 907 parse_debug(3, cp, "soudef: %s size=%d", tdesc_name(*rtdp), 908 (*rtdp)->t_size); 909 910 prev = &((*rtdp)->t_members); 911 /* now fill up the fields */ 912 while ((*cp != '\0') && (*cp != ';')) { /* signifies end of fields */ 913 mlp = xcalloc(sizeof (*mlp)); 914 *prev = mlp; 915 cp = name(cp, &w); 916 mlp->ml_name = w; 917 cp = id(cp, &h); 918 /* 919 * find the tdesc struct in the hash table for this type 920 * and stick a ptr in here 921 */ 922 tdp = lookup(h); 923 if (tdp == NULL) { /* not in hash list */ 924 parse_debug(3, NULL, " defines %s (%d)", w, h); 925 if (*cp++ != '=') { 926 tdp = unres_new(h); 927 parse_debug(3, NULL, 928 " refers to %s (unresolved %d)", 929 (w ? w : "anon"), h); 930 } else { 931 cp = tdefdecl(cp, h, &tdp); 932 933 if (tdp->t_id && tdp->t_id != h) { 934 tdesc_t *ntdp = xcalloc(sizeof (*ntdp)); 935 936 ntdp->t_type = TYPEDEF; 937 ntdp->t_tdesc = tdp; 938 tdp = ntdp; 939 } 940 941 addhash(tdp, h); 942 parse_debug(4, cp, 943 " soudef now looking at "); 944 cp++; 945 } 946 } else { 947 parse_debug(3, NULL, " refers to %s (%d, %s)", 948 w ? w : "anon", h, tdesc_name(tdp)); 949 } 950 951 cp = offsize(cp, mlp); 952 953 itdp = find_intrinsic(tdp); 954 if (itdp->t_type == INTRINSIC) { 955 if (mlp->ml_size != itdp->t_intr->intr_nbits) { 956 parse_debug(4, cp, "making %d bit intrinsic " 957 "from %s", mlp->ml_size, tdesc_name(itdp)); 958 mlp->ml_type = bitintrinsic(itdp, mlp->ml_size); 959 } else 960 mlp->ml_type = tdp; 961 } else if (itdp->t_type == TYPEDEF_UNRES) { 962 list_add(&typedbitfldmems, mlp); 963 mlp->ml_type = tdp; 964 } else { 965 mlp->ml_type = tdp; 966 } 967 968 /* cp is now pointing to next field */ 969 prev = &mlp->ml_next; 970 } 971 return (cp); 972} 973 974static char * 975arraydef(char *cp, tdesc_t **rtdp) 976{ 977 int start, end, h; 978 979 cp = id(cp, &h); 980 if (*cp++ != ';') 981 expected("arraydef/1", ";", cp - 1); 982 983 (*rtdp)->t_ardef = xcalloc(sizeof (ardef_t)); 984 (*rtdp)->t_ardef->ad_idxtype = lookup(h); 985 986 cp = number(cp, &start); /* lower */ 987 if (*cp++ != ';') 988 expected("arraydef/2", ";", cp - 1); 989 990 if (*cp == 'S') {
|
993 /* variable length array - treat as null dimensioned */
| 991 /* 992 * variable length array - treat as null dimensioned 993 * 994 * For VLA variables on sparc, SS12 generated stab entry 995 * looks as follows: 996 * .stabs "buf:(0,28)=zr(0,4);0;S-12;(0,1)", 0x80, 0, 0, -16 997 * Whereas SS12u1 generated stab entry looks like this: 998 * .stabs "buf:(0,28)=zr(0,4);0;S0;(0,1)", 0x80, 0, 0, 0 999 * On x86, both versions generate the first type of entry. 1000 * We should be able to parse both. 1001 */
|
994 cp++;
| 1002 cp++;
|
995 if (*cp++ != '-') 996 expected("arraydef/fpoff-sep", "-", cp - 1);
| 1003 if (*cp == '-') 1004 cp++;
|
997 cp = number(cp, &end); 998 end = start; 999 } else {
| 1005 cp = number(cp, &end); 1006 end = start; 1007 } else {
|
1000 /* normal fixed-dimension array */
| 1008 /* 1009 * normal fixed-dimension array 1010 * Stab entry for this looks as follows : 1011 * .stabs "x:(0,28)=ar(0,4);0;9;(0,3)", 0x80, 0, 40, 0 1012 */
|
1001 cp = number(cp, &end); /* upper */ 1002 } 1003 1004 if (*cp++ != ';') 1005 expected("arraydef/3", ";", cp - 1); 1006 (*rtdp)->t_ardef->ad_nelems = end - start + 1; 1007 cp = tdefdecl(cp, h, &((*rtdp)->t_ardef->ad_contents)); 1008 1009 parse_debug(3, cp, "defined array idx type %d %d-%d next ", 1010 h, start, end); 1011 1012 return (cp); 1013} 1014 1015static void 1016enumdef(char *cp, tdesc_t **rtdp) 1017{ 1018 elist_t *elp, **prev; 1019 char *w; 1020 1021 (*rtdp)->t_type = ENUM; 1022 (*rtdp)->t_emem = NULL; 1023 1024 prev = &((*rtdp)->t_emem); 1025 while (*cp != ';') { 1026 elp = xcalloc(sizeof (*elp)); 1027 elp->el_next = NULL; 1028 *prev = elp; 1029 cp = name(cp, &w); 1030 elp->el_name = w; 1031 cp = number(cp, &elp->el_number); 1032 parse_debug(3, NULL, "enum %s: %s=%d", tdesc_name(*rtdp), 1033 elp->el_name, elp->el_number); 1034 prev = &elp->el_next; 1035 if (*cp++ != ',') 1036 expected("enumdef", ",", cp - 1); 1037 } 1038} 1039 1040static tdesc_t * 1041lookup_name(tdesc_t **hash, const char *name1) 1042{ 1043 int bucket = compute_sum(name1); 1044 tdesc_t *tdp, *ttdp = NULL; 1045 1046 for (tdp = hash[bucket]; tdp != NULL; tdp = tdp->t_next) { 1047 if (tdp->t_name != NULL && strcmp(tdp->t_name, name1) == 0) { 1048 if (tdp->t_type == STRUCT || tdp->t_type == UNION || 1049 tdp->t_type == ENUM || tdp->t_type == INTRINSIC) 1050 return (tdp); 1051 if (tdp->t_type == TYPEDEF) 1052 ttdp = tdp; 1053 } 1054 } 1055 return (ttdp); 1056} 1057 1058tdesc_t * 1059lookupname(const char *name1) 1060{ 1061 return (lookup_name(name_table, name1)); 1062} 1063 1064/* 1065 * Add a node to the hash queues. 1066 */ 1067static void 1068addhash(tdesc_t *tdp, int num) 1069{ 1070 int hash = HASH(num); 1071 tdesc_t *ttdp; 1072 char added_num = 0, added_name = 0; 1073 1074 /* 1075 * If it already exists in the hash table don't add it again 1076 * (but still check to see if the name should be hashed). 1077 */ 1078 ttdp = lookup(num); 1079 1080 if (ttdp == NULL) { 1081 tdp->t_id = num; 1082 tdp->t_hash = hash_table[hash]; 1083 hash_table[hash] = tdp; 1084 added_num = 1; 1085 } 1086 1087 if (tdp->t_name != NULL) { 1088 ttdp = lookupname(tdp->t_name); 1089 if (ttdp == NULL) { 1090 hash = compute_sum(tdp->t_name); 1091 tdp->t_next = name_table[hash]; 1092 name_table[hash] = tdp; 1093 added_name = 1; 1094 } 1095 } 1096 if (!added_num && !added_name) { 1097 terminate("stabs: broken hash\n"); 1098 } 1099} 1100 1101static int 1102compute_sum(const char *w) 1103{ 1104 char c; 1105 int sum; 1106 1107 for (sum = 0; (c = *w) != '\0'; sum += c, w++) 1108 ; 1109 return (HASH(sum)); 1110} 1111 1112static void 1113reset(void) 1114{ 1115 longjmp(resetbuf, 1); 1116} 1117 1118void 1119check_hash(void) 1120{ 1121 tdesc_t *tdp; 1122 int i; 1123 1124 printf("checking hash\n"); 1125 for (i = 0; i < BUCKETS; i++) { 1126 if (hash_table[i]) { 1127 for (tdp = hash_table[i]->t_hash; 1128 tdp && tdp != hash_table[i]; 1129 tdp = tdp->t_hash) 1130 continue; 1131 if (tdp) { 1132 terminate("cycle in hash bucket %d\n", i); 1133 return; 1134 } 1135 } 1136 1137 if (name_table[i]) { 1138 for (tdp = name_table[i]->t_next; 1139 tdp && tdp != name_table[i]; 1140 tdp = tdp->t_next) 1141 continue; 1142 if (tdp) { 1143 terminate("cycle in name bucket %d\n", i); 1144 return; 1145 } 1146 } 1147 } 1148 printf("done\n"); 1149} 1150 1151/*ARGSUSED1*/ 1152static int 1153resolve_typed_bitfields_cb(void *arg, void *private __unused) 1154{ 1155 mlist_t *ml = arg; 1156 tdesc_t *tdp = ml->ml_type; 1157 1158 debug(3, "Resolving typed bitfields (member %s)\n", 1159 (ml->ml_name ? ml->ml_name : "(anon)")); 1160 1161 while (tdp) { 1162 switch (tdp->t_type) { 1163 case INTRINSIC: 1164 if (ml->ml_size != tdp->t_intr->intr_nbits) { 1165 debug(3, "making %d bit intrinsic from %s", 1166 ml->ml_size, tdesc_name(tdp)); 1167 ml->ml_type = bitintrinsic(tdp, ml->ml_size); 1168 } else { 1169 debug(3, "using existing %d bit %s intrinsic", 1170 ml->ml_size, tdesc_name(tdp)); 1171 ml->ml_type = tdp; 1172 } 1173 return (1); 1174 1175 case POINTER: 1176 case TYPEDEF: 1177 case VOLATILE: 1178 case CONST: 1179 case RESTRICT: 1180 tdp = tdp->t_tdesc; 1181 break; 1182 1183 default: 1184 return (1); 1185 } 1186 } 1187 1188 terminate("type chain for bitfield member %s has a NULL", ml->ml_name); 1189 /*NOTREACHED*/ 1190 return (0); 1191} 1192 1193void 1194resolve_typed_bitfields(void) 1195{ 1196 (void) list_iter(typedbitfldmems, 1197 resolve_typed_bitfields_cb, NULL); 1198}
| 1013 cp = number(cp, &end); /* upper */ 1014 } 1015 1016 if (*cp++ != ';') 1017 expected("arraydef/3", ";", cp - 1); 1018 (*rtdp)->t_ardef->ad_nelems = end - start + 1; 1019 cp = tdefdecl(cp, h, &((*rtdp)->t_ardef->ad_contents)); 1020 1021 parse_debug(3, cp, "defined array idx type %d %d-%d next ", 1022 h, start, end); 1023 1024 return (cp); 1025} 1026 1027static void 1028enumdef(char *cp, tdesc_t **rtdp) 1029{ 1030 elist_t *elp, **prev; 1031 char *w; 1032 1033 (*rtdp)->t_type = ENUM; 1034 (*rtdp)->t_emem = NULL; 1035 1036 prev = &((*rtdp)->t_emem); 1037 while (*cp != ';') { 1038 elp = xcalloc(sizeof (*elp)); 1039 elp->el_next = NULL; 1040 *prev = elp; 1041 cp = name(cp, &w); 1042 elp->el_name = w; 1043 cp = number(cp, &elp->el_number); 1044 parse_debug(3, NULL, "enum %s: %s=%d", tdesc_name(*rtdp), 1045 elp->el_name, elp->el_number); 1046 prev = &elp->el_next; 1047 if (*cp++ != ',') 1048 expected("enumdef", ",", cp - 1); 1049 } 1050} 1051 1052static tdesc_t * 1053lookup_name(tdesc_t **hash, const char *name1) 1054{ 1055 int bucket = compute_sum(name1); 1056 tdesc_t *tdp, *ttdp = NULL; 1057 1058 for (tdp = hash[bucket]; tdp != NULL; tdp = tdp->t_next) { 1059 if (tdp->t_name != NULL && strcmp(tdp->t_name, name1) == 0) { 1060 if (tdp->t_type == STRUCT || tdp->t_type == UNION || 1061 tdp->t_type == ENUM || tdp->t_type == INTRINSIC) 1062 return (tdp); 1063 if (tdp->t_type == TYPEDEF) 1064 ttdp = tdp; 1065 } 1066 } 1067 return (ttdp); 1068} 1069 1070tdesc_t * 1071lookupname(const char *name1) 1072{ 1073 return (lookup_name(name_table, name1)); 1074} 1075 1076/* 1077 * Add a node to the hash queues. 1078 */ 1079static void 1080addhash(tdesc_t *tdp, int num) 1081{ 1082 int hash = HASH(num); 1083 tdesc_t *ttdp; 1084 char added_num = 0, added_name = 0; 1085 1086 /* 1087 * If it already exists in the hash table don't add it again 1088 * (but still check to see if the name should be hashed). 1089 */ 1090 ttdp = lookup(num); 1091 1092 if (ttdp == NULL) { 1093 tdp->t_id = num; 1094 tdp->t_hash = hash_table[hash]; 1095 hash_table[hash] = tdp; 1096 added_num = 1; 1097 } 1098 1099 if (tdp->t_name != NULL) { 1100 ttdp = lookupname(tdp->t_name); 1101 if (ttdp == NULL) { 1102 hash = compute_sum(tdp->t_name); 1103 tdp->t_next = name_table[hash]; 1104 name_table[hash] = tdp; 1105 added_name = 1; 1106 } 1107 } 1108 if (!added_num && !added_name) { 1109 terminate("stabs: broken hash\n"); 1110 } 1111} 1112 1113static int 1114compute_sum(const char *w) 1115{ 1116 char c; 1117 int sum; 1118 1119 for (sum = 0; (c = *w) != '\0'; sum += c, w++) 1120 ; 1121 return (HASH(sum)); 1122} 1123 1124static void 1125reset(void) 1126{ 1127 longjmp(resetbuf, 1); 1128} 1129 1130void 1131check_hash(void) 1132{ 1133 tdesc_t *tdp; 1134 int i; 1135 1136 printf("checking hash\n"); 1137 for (i = 0; i < BUCKETS; i++) { 1138 if (hash_table[i]) { 1139 for (tdp = hash_table[i]->t_hash; 1140 tdp && tdp != hash_table[i]; 1141 tdp = tdp->t_hash) 1142 continue; 1143 if (tdp) { 1144 terminate("cycle in hash bucket %d\n", i); 1145 return; 1146 } 1147 } 1148 1149 if (name_table[i]) { 1150 for (tdp = name_table[i]->t_next; 1151 tdp && tdp != name_table[i]; 1152 tdp = tdp->t_next) 1153 continue; 1154 if (tdp) { 1155 terminate("cycle in name bucket %d\n", i); 1156 return; 1157 } 1158 } 1159 } 1160 printf("done\n"); 1161} 1162 1163/*ARGSUSED1*/ 1164static int 1165resolve_typed_bitfields_cb(void *arg, void *private __unused) 1166{ 1167 mlist_t *ml = arg; 1168 tdesc_t *tdp = ml->ml_type; 1169 1170 debug(3, "Resolving typed bitfields (member %s)\n", 1171 (ml->ml_name ? ml->ml_name : "(anon)")); 1172 1173 while (tdp) { 1174 switch (tdp->t_type) { 1175 case INTRINSIC: 1176 if (ml->ml_size != tdp->t_intr->intr_nbits) { 1177 debug(3, "making %d bit intrinsic from %s", 1178 ml->ml_size, tdesc_name(tdp)); 1179 ml->ml_type = bitintrinsic(tdp, ml->ml_size); 1180 } else { 1181 debug(3, "using existing %d bit %s intrinsic", 1182 ml->ml_size, tdesc_name(tdp)); 1183 ml->ml_type = tdp; 1184 } 1185 return (1); 1186 1187 case POINTER: 1188 case TYPEDEF: 1189 case VOLATILE: 1190 case CONST: 1191 case RESTRICT: 1192 tdp = tdp->t_tdesc; 1193 break; 1194 1195 default: 1196 return (1); 1197 } 1198 } 1199 1200 terminate("type chain for bitfield member %s has a NULL", ml->ml_name); 1201 /*NOTREACHED*/ 1202 return (0); 1203} 1204 1205void 1206resolve_typed_bitfields(void) 1207{ 1208 (void) list_iter(typedbitfldmems, 1209 resolve_typed_bitfields_cb, NULL); 1210}
|