| 1 | /* Support routines for decoding "stabs" debugging information format. |
| 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | /* Support routines for reading and decoding debugging information in |
| 22 | the "stabs" format. This format is used with many systems that use |
| 23 | the a.out object file format, as well as some systems that use |
| 24 | COFF or ELF where the stabs data is placed in a special section. |
| 25 | Avoid placing any object file format specific code in this file. */ |
| 26 | |
| 27 | #include "defs.h" |
| 28 | #include <string.h> |
| 29 | #include "bfd.h" |
| 30 | #include "obstack.h" |
| 31 | #include "symtab.h" |
| 32 | #include "gdbtypes.h" |
| 33 | #include "symfile.h" |
| 34 | #include "objfiles.h" |
| 35 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */ |
| 36 | #include "libaout.h" |
| 37 | #include "aout/aout64.h" |
| 38 | #include "gdb-stabs.h" |
| 39 | #include "buildsym.h" |
| 40 | #include "complaints.h" |
| 41 | #include "demangle.h" |
| 42 | |
| 43 | #include <ctype.h> |
| 44 | |
| 45 | /* Ask stabsread.h to define the vars it normally declares `extern'. */ |
| 46 | #define EXTERN /**/ |
| 47 | #include "stabsread.h" /* Our own declarations */ |
| 48 | #undef EXTERN |
| 49 | |
| 50 | /* The routines that read and process a complete stabs for a C struct or |
| 51 | C++ class pass lists of data member fields and lists of member function |
| 52 | fields in an instance of a field_info structure, as defined below. |
| 53 | This is part of some reorganization of low level C++ support and is |
| 54 | expected to eventually go away... (FIXME) */ |
| 55 | |
| 56 | struct field_info |
| 57 | { |
| 58 | struct nextfield |
| 59 | { |
| 60 | struct nextfield *next; |
| 61 | |
| 62 | /* This is the raw visibility from the stab. It is not checked |
| 63 | for being one of the visibilities we recognize, so code which |
| 64 | examines this field better be able to deal. */ |
| 65 | int visibility; |
| 66 | |
| 67 | struct field field; |
| 68 | } *list; |
| 69 | struct next_fnfieldlist |
| 70 | { |
| 71 | struct next_fnfieldlist *next; |
| 72 | struct fn_fieldlist fn_fieldlist; |
| 73 | } *fnlist; |
| 74 | }; |
| 75 | |
| 76 | static struct type * |
| 77 | dbx_alloc_type PARAMS ((int [2], struct objfile *)); |
| 78 | |
| 79 | static long read_huge_number PARAMS ((char **, int, int *)); |
| 80 | |
| 81 | static struct type *error_type PARAMS ((char **)); |
| 82 | |
| 83 | static void |
| 84 | patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *, |
| 85 | struct objfile *)); |
| 86 | |
| 87 | static void |
| 88 | fix_common_block PARAMS ((struct symbol *, int)); |
| 89 | |
| 90 | static int |
| 91 | read_type_number PARAMS ((char **, int *)); |
| 92 | |
| 93 | static struct type * |
| 94 | read_range_type PARAMS ((char **, int [2], struct objfile *)); |
| 95 | |
| 96 | static struct type * |
| 97 | read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *)); |
| 98 | |
| 99 | static struct type * |
| 100 | read_sun_floating_type PARAMS ((char **, int [2], struct objfile *)); |
| 101 | |
| 102 | static struct type * |
| 103 | read_enum_type PARAMS ((char **, struct type *, struct objfile *)); |
| 104 | |
| 105 | static struct type * |
| 106 | rs6000_builtin_type PARAMS ((int)); |
| 107 | |
| 108 | static int |
| 109 | read_member_functions PARAMS ((struct field_info *, char **, struct type *, |
| 110 | struct objfile *)); |
| 111 | |
| 112 | static int |
| 113 | read_struct_fields PARAMS ((struct field_info *, char **, struct type *, |
| 114 | struct objfile *)); |
| 115 | |
| 116 | static int |
| 117 | read_baseclasses PARAMS ((struct field_info *, char **, struct type *, |
| 118 | struct objfile *)); |
| 119 | |
| 120 | static int |
| 121 | read_tilde_fields PARAMS ((struct field_info *, char **, struct type *, |
| 122 | struct objfile *)); |
| 123 | |
| 124 | static int |
| 125 | attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *)); |
| 126 | |
| 127 | static int |
| 128 | attach_fields_to_type PARAMS ((struct field_info *, struct type *, |
| 129 | struct objfile *)); |
| 130 | |
| 131 | static struct type * |
| 132 | read_struct_type PARAMS ((char **, struct type *, struct objfile *)); |
| 133 | |
| 134 | static struct type * |
| 135 | read_array_type PARAMS ((char **, struct type *, struct objfile *)); |
| 136 | |
| 137 | static struct type ** |
| 138 | read_args PARAMS ((char **, int, struct objfile *)); |
| 139 | |
| 140 | static int |
| 141 | read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *, |
| 142 | struct objfile *)); |
| 143 | |
| 144 | static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' }; |
| 145 | static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' }; |
| 146 | |
| 147 | /* Define this as 1 if a pcc declaration of a char or short argument |
| 148 | gives the correct address. Otherwise assume pcc gives the |
| 149 | address of the corresponding int, which is not the same on a |
| 150 | big-endian machine. */ |
| 151 | |
| 152 | #ifndef BELIEVE_PCC_PROMOTION |
| 153 | #define BELIEVE_PCC_PROMOTION 0 |
| 154 | #endif |
| 155 | |
| 156 | struct complaint invalid_cpp_abbrev_complaint = |
| 157 | {"invalid C++ abbreviation `%s'", 0, 0}; |
| 158 | |
| 159 | struct complaint invalid_cpp_type_complaint = |
| 160 | {"C++ abbreviated type name unknown at symtab pos %d", 0, 0}; |
| 161 | |
| 162 | struct complaint member_fn_complaint = |
| 163 | {"member function type missing, got '%c'", 0, 0}; |
| 164 | |
| 165 | struct complaint const_vol_complaint = |
| 166 | {"const/volatile indicator missing, got '%c'", 0, 0}; |
| 167 | |
| 168 | struct complaint error_type_complaint = |
| 169 | {"debug info mismatch between compiler and debugger", 0, 0}; |
| 170 | |
| 171 | struct complaint invalid_member_complaint = |
| 172 | {"invalid (minimal) member type data format at symtab pos %d.", 0, 0}; |
| 173 | |
| 174 | struct complaint range_type_base_complaint = |
| 175 | {"base type %d of range type is not defined", 0, 0}; |
| 176 | |
| 177 | struct complaint reg_value_complaint = |
| 178 | {"register number too large in symbol %s", 0, 0}; |
| 179 | |
| 180 | struct complaint vtbl_notfound_complaint = |
| 181 | {"virtual function table pointer not found when defining class `%s'", 0, 0}; |
| 182 | |
| 183 | struct complaint unrecognized_cplus_name_complaint = |
| 184 | {"Unknown C++ symbol name `%s'", 0, 0}; |
| 185 | |
| 186 | struct complaint rs6000_builtin_complaint = |
| 187 | {"Unknown builtin type %d", 0, 0}; |
| 188 | |
| 189 | struct complaint stabs_general_complaint = |
| 190 | {"%s", 0, 0}; |
| 191 | |
| 192 | /* Make a list of forward references which haven't been defined. */ |
| 193 | |
| 194 | static struct type **undef_types; |
| 195 | static int undef_types_allocated; |
| 196 | static int undef_types_length; |
| 197 | |
| 198 | /* Check for and handle cretinous stabs symbol name continuation! */ |
| 199 | #define STABS_CONTINUE(pp) \ |
| 200 | do { \ |
| 201 | if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \ |
| 202 | *(pp) = next_symbol_text (); \ |
| 203 | } while (0) |
| 204 | \f |
| 205 | /* FIXME: These probably should be our own types (like rs6000_builtin_type |
| 206 | has its own types) rather than builtin_type_*. */ |
| 207 | static struct type **os9k_type_vector[] = { |
| 208 | 0, |
| 209 | &builtin_type_int, |
| 210 | &builtin_type_char, |
| 211 | &builtin_type_long, |
| 212 | &builtin_type_short, |
| 213 | &builtin_type_unsigned_char, |
| 214 | &builtin_type_unsigned_short, |
| 215 | &builtin_type_unsigned_long, |
| 216 | &builtin_type_unsigned_int, |
| 217 | &builtin_type_float, |
| 218 | &builtin_type_double, |
| 219 | &builtin_type_void, |
| 220 | &builtin_type_long_double |
| 221 | }; |
| 222 | |
| 223 | static void os9k_init_type_vector PARAMS ((struct type **)); |
| 224 | |
| 225 | static void |
| 226 | os9k_init_type_vector(tv) |
| 227 | struct type **tv; |
| 228 | { |
| 229 | int i; |
| 230 | for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++) |
| 231 | tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i])); |
| 232 | } |
| 233 | |
| 234 | /* Look up a dbx type-number pair. Return the address of the slot |
| 235 | where the type for that number-pair is stored. |
| 236 | The number-pair is in TYPENUMS. |
| 237 | |
| 238 | This can be used for finding the type associated with that pair |
| 239 | or for associating a new type with the pair. */ |
| 240 | |
| 241 | struct type ** |
| 242 | dbx_lookup_type (typenums) |
| 243 | int typenums[2]; |
| 244 | { |
| 245 | register int filenum = typenums[0]; |
| 246 | register int index = typenums[1]; |
| 247 | unsigned old_len; |
| 248 | register int real_filenum; |
| 249 | register struct header_file *f; |
| 250 | int f_orig_length; |
| 251 | |
| 252 | if (filenum == -1) /* -1,-1 is for temporary types. */ |
| 253 | return 0; |
| 254 | |
| 255 | if (filenum < 0 || filenum >= n_this_object_header_files) |
| 256 | { |
| 257 | static struct complaint msg = {"\ |
| 258 | Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", |
| 259 | 0, 0}; |
| 260 | complain (&msg, filenum, index, symnum); |
| 261 | goto error_return; |
| 262 | } |
| 263 | |
| 264 | if (filenum == 0) |
| 265 | { |
| 266 | if (index < 0) |
| 267 | { |
| 268 | /* Caller wants address of address of type. We think |
| 269 | that negative (rs6k builtin) types will never appear as |
| 270 | "lvalues", (nor should they), so we stuff the real type |
| 271 | pointer into a temp, and return its address. If referenced, |
| 272 | this will do the right thing. */ |
| 273 | static struct type *temp_type; |
| 274 | |
| 275 | temp_type = rs6000_builtin_type(index); |
| 276 | return &temp_type; |
| 277 | } |
| 278 | |
| 279 | /* Type is defined outside of header files. |
| 280 | Find it in this object file's type vector. */ |
| 281 | if (index >= type_vector_length) |
| 282 | { |
| 283 | old_len = type_vector_length; |
| 284 | if (old_len == 0) |
| 285 | { |
| 286 | type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; |
| 287 | type_vector = (struct type **) |
| 288 | malloc (type_vector_length * sizeof (struct type *)); |
| 289 | } |
| 290 | while (index >= type_vector_length) |
| 291 | { |
| 292 | type_vector_length *= 2; |
| 293 | } |
| 294 | type_vector = (struct type **) |
| 295 | xrealloc ((char *) type_vector, |
| 296 | (type_vector_length * sizeof (struct type *))); |
| 297 | memset (&type_vector[old_len], 0, |
| 298 | (type_vector_length - old_len) * sizeof (struct type *)); |
| 299 | |
| 300 | if (os9k_stabs) |
| 301 | /* Deal with OS9000 fundamental types. */ |
| 302 | os9k_init_type_vector (type_vector); |
| 303 | } |
| 304 | return (&type_vector[index]); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | real_filenum = this_object_header_files[filenum]; |
| 309 | |
| 310 | if (real_filenum >= n_header_files) |
| 311 | { |
| 312 | struct type *temp_type; |
| 313 | struct type **temp_type_p; |
| 314 | |
| 315 | warning ("GDB internal error: bad real_filenum"); |
| 316 | |
| 317 | error_return: |
| 318 | temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL); |
| 319 | temp_type_p = (struct type **) xmalloc (sizeof (struct type *)); |
| 320 | *temp_type_p = temp_type; |
| 321 | return temp_type_p; |
| 322 | } |
| 323 | |
| 324 | f = &header_files[real_filenum]; |
| 325 | |
| 326 | f_orig_length = f->length; |
| 327 | if (index >= f_orig_length) |
| 328 | { |
| 329 | while (index >= f->length) |
| 330 | { |
| 331 | f->length *= 2; |
| 332 | } |
| 333 | f->vector = (struct type **) |
| 334 | xrealloc ((char *) f->vector, f->length * sizeof (struct type *)); |
| 335 | memset (&f->vector[f_orig_length], 0, |
| 336 | (f->length - f_orig_length) * sizeof (struct type *)); |
| 337 | } |
| 338 | return (&f->vector[index]); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /* Make sure there is a type allocated for type numbers TYPENUMS |
| 343 | and return the type object. |
| 344 | This can create an empty (zeroed) type object. |
| 345 | TYPENUMS may be (-1, -1) to return a new type object that is not |
| 346 | put into the type vector, and so may not be referred to by number. */ |
| 347 | |
| 348 | static struct type * |
| 349 | dbx_alloc_type (typenums, objfile) |
| 350 | int typenums[2]; |
| 351 | struct objfile *objfile; |
| 352 | { |
| 353 | register struct type **type_addr; |
| 354 | |
| 355 | if (typenums[0] == -1) |
| 356 | { |
| 357 | return (alloc_type (objfile)); |
| 358 | } |
| 359 | |
| 360 | type_addr = dbx_lookup_type (typenums); |
| 361 | |
| 362 | /* If we are referring to a type not known at all yet, |
| 363 | allocate an empty type for it. |
| 364 | We will fill it in later if we find out how. */ |
| 365 | if (*type_addr == 0) |
| 366 | { |
| 367 | *type_addr = alloc_type (objfile); |
| 368 | } |
| 369 | |
| 370 | return (*type_addr); |
| 371 | } |
| 372 | |
| 373 | /* for all the stabs in a given stab vector, build appropriate types |
| 374 | and fix their symbols in given symbol vector. */ |
| 375 | |
| 376 | static void |
| 377 | patch_block_stabs (symbols, stabs, objfile) |
| 378 | struct pending *symbols; |
| 379 | struct pending_stabs *stabs; |
| 380 | struct objfile *objfile; |
| 381 | { |
| 382 | int ii; |
| 383 | char *name; |
| 384 | char *pp; |
| 385 | struct symbol *sym; |
| 386 | |
| 387 | if (stabs) |
| 388 | { |
| 389 | |
| 390 | /* for all the stab entries, find their corresponding symbols and |
| 391 | patch their types! */ |
| 392 | |
| 393 | for (ii = 0; ii < stabs->count; ++ii) |
| 394 | { |
| 395 | name = stabs->stab[ii]; |
| 396 | pp = (char*) strchr (name, ':'); |
| 397 | while (pp[1] == ':') |
| 398 | { |
| 399 | pp += 2; |
| 400 | pp = (char *)strchr(pp, ':'); |
| 401 | } |
| 402 | sym = find_symbol_in_list (symbols, name, pp-name); |
| 403 | if (!sym) |
| 404 | { |
| 405 | /* FIXME-maybe: it would be nice if we noticed whether |
| 406 | the variable was defined *anywhere*, not just whether |
| 407 | it is defined in this compilation unit. But neither |
| 408 | xlc or GCC seem to need such a definition, and until |
| 409 | we do psymtabs (so that the minimal symbols from all |
| 410 | compilation units are available now), I'm not sure |
| 411 | how to get the information. */ |
| 412 | |
| 413 | /* On xcoff, if a global is defined and never referenced, |
| 414 | ld will remove it from the executable. There is then |
| 415 | a N_GSYM stab for it, but no regular (C_EXT) symbol. */ |
| 416 | sym = (struct symbol *) |
| 417 | obstack_alloc (&objfile->symbol_obstack, |
| 418 | sizeof (struct symbol)); |
| 419 | |
| 420 | memset (sym, 0, sizeof (struct symbol)); |
| 421 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 422 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 423 | SYMBOL_NAME (sym) = |
| 424 | obstack_copy0 (&objfile->symbol_obstack, name, pp - name); |
| 425 | pp += 2; |
| 426 | if (*(pp-1) == 'F' || *(pp-1) == 'f') |
| 427 | { |
| 428 | /* I don't think the linker does this with functions, |
| 429 | so as far as I know this is never executed. |
| 430 | But it doesn't hurt to check. */ |
| 431 | SYMBOL_TYPE (sym) = |
| 432 | lookup_function_type (read_type (&pp, objfile)); |
| 433 | } |
| 434 | else |
| 435 | { |
| 436 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
| 437 | } |
| 438 | add_symbol_to_list (sym, &global_symbols); |
| 439 | } |
| 440 | else |
| 441 | { |
| 442 | pp += 2; |
| 443 | if (*(pp-1) == 'F' || *(pp-1) == 'f') |
| 444 | { |
| 445 | SYMBOL_TYPE (sym) = |
| 446 | lookup_function_type (read_type (&pp, objfile)); |
| 447 | } |
| 448 | else |
| 449 | { |
| 450 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | \f |
| 458 | /* Read a number by which a type is referred to in dbx data, |
| 459 | or perhaps read a pair (FILENUM, TYPENUM) in parentheses. |
| 460 | Just a single number N is equivalent to (0,N). |
| 461 | Return the two numbers by storing them in the vector TYPENUMS. |
| 462 | TYPENUMS will then be used as an argument to dbx_lookup_type. |
| 463 | |
| 464 | Returns 0 for success, -1 for error. */ |
| 465 | |
| 466 | static int |
| 467 | read_type_number (pp, typenums) |
| 468 | register char **pp; |
| 469 | register int *typenums; |
| 470 | { |
| 471 | int nbits; |
| 472 | if (**pp == '(') |
| 473 | { |
| 474 | (*pp)++; |
| 475 | typenums[0] = read_huge_number (pp, ',', &nbits); |
| 476 | if (nbits != 0) return -1; |
| 477 | typenums[1] = read_huge_number (pp, ')', &nbits); |
| 478 | if (nbits != 0) return -1; |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | typenums[0] = 0; |
| 483 | typenums[1] = read_huge_number (pp, 0, &nbits); |
| 484 | if (nbits != 0) return -1; |
| 485 | } |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | \f |
| 490 | /* To handle GNU C++ typename abbreviation, we need to be able to |
| 491 | fill in a type's name as soon as space for that type is allocated. |
| 492 | `type_synonym_name' is the name of the type being allocated. |
| 493 | It is cleared as soon as it is used (lest all allocated types |
| 494 | get this name). */ |
| 495 | |
| 496 | static char *type_synonym_name; |
| 497 | |
| 498 | #if !defined (REG_STRUCT_HAS_ADDR) |
| 499 | #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0 |
| 500 | #endif |
| 501 | |
| 502 | /* ARGSUSED */ |
| 503 | struct symbol * |
| 504 | define_symbol (valu, string, desc, type, objfile) |
| 505 | CORE_ADDR valu; |
| 506 | char *string; |
| 507 | int desc; |
| 508 | int type; |
| 509 | struct objfile *objfile; |
| 510 | { |
| 511 | register struct symbol *sym; |
| 512 | char *p = (char *) strchr (string, ':'); |
| 513 | int deftype; |
| 514 | int synonym = 0; |
| 515 | register int i; |
| 516 | |
| 517 | /* We would like to eliminate nameless symbols, but keep their types. |
| 518 | E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer |
| 519 | to type 2, but, should not create a symbol to address that type. Since |
| 520 | the symbol will be nameless, there is no way any user can refer to it. */ |
| 521 | |
| 522 | int nameless; |
| 523 | |
| 524 | /* Ignore syms with empty names. */ |
| 525 | if (string[0] == 0) |
| 526 | return 0; |
| 527 | |
| 528 | /* Ignore old-style symbols from cc -go */ |
| 529 | if (p == 0) |
| 530 | return 0; |
| 531 | |
| 532 | while (p[1] == ':') |
| 533 | { |
| 534 | p += 2; |
| 535 | p = strchr(p, ':'); |
| 536 | } |
| 537 | |
| 538 | /* If a nameless stab entry, all we need is the type, not the symbol. |
| 539 | e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */ |
| 540 | nameless = (p == string || ((string[0] == ' ') && (string[1] == ':'))); |
| 541 | |
| 542 | sym = (struct symbol *) |
| 543 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 544 | memset (sym, 0, sizeof (struct symbol)); |
| 545 | |
| 546 | switch (type & N_TYPE) |
| 547 | { |
| 548 | case N_TEXT: |
| 549 | SYMBOL_SECTION(sym) = SECT_OFF_TEXT; |
| 550 | break; |
| 551 | case N_DATA: |
| 552 | SYMBOL_SECTION(sym) = SECT_OFF_DATA; |
| 553 | break; |
| 554 | case N_BSS: |
| 555 | SYMBOL_SECTION(sym) = SECT_OFF_BSS; |
| 556 | break; |
| 557 | } |
| 558 | |
| 559 | if (processing_gcc_compilation) |
| 560 | { |
| 561 | /* GCC 2.x puts the line number in desc. SunOS apparently puts in the |
| 562 | number of bytes occupied by a type or object, which we ignore. */ |
| 563 | SYMBOL_LINE(sym) = desc; |
| 564 | } |
| 565 | else |
| 566 | { |
| 567 | SYMBOL_LINE(sym) = 0; /* unknown */ |
| 568 | } |
| 569 | |
| 570 | if (string[0] == CPLUS_MARKER) |
| 571 | { |
| 572 | /* Special GNU C++ names. */ |
| 573 | switch (string[1]) |
| 574 | { |
| 575 | case 't': |
| 576 | SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"), |
| 577 | &objfile -> symbol_obstack); |
| 578 | break; |
| 579 | |
| 580 | case 'v': /* $vtbl_ptr_type */ |
| 581 | /* Was: SYMBOL_NAME (sym) = "vptr"; */ |
| 582 | goto normal; |
| 583 | |
| 584 | case 'e': |
| 585 | SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"), |
| 586 | &objfile -> symbol_obstack); |
| 587 | break; |
| 588 | |
| 589 | case '_': |
| 590 | /* This was an anonymous type that was never fixed up. */ |
| 591 | goto normal; |
| 592 | |
| 593 | default: |
| 594 | complain (&unrecognized_cplus_name_complaint, string); |
| 595 | goto normal; /* Do *something* with it */ |
| 596 | } |
| 597 | } |
| 598 | else |
| 599 | { |
| 600 | normal: |
| 601 | SYMBOL_LANGUAGE (sym) = current_subfile -> language; |
| 602 | SYMBOL_NAME (sym) = (char *) |
| 603 | obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1)); |
| 604 | /* Open-coded memcpy--saves function call time. */ |
| 605 | /* FIXME: Does it really? Try replacing with simple strcpy and |
| 606 | try it on an executable with a large symbol table. */ |
| 607 | /* FIXME: considering that gcc can open code memcpy anyway, I |
| 608 | doubt it. xoxorich. */ |
| 609 | { |
| 610 | register char *p1 = string; |
| 611 | register char *p2 = SYMBOL_NAME (sym); |
| 612 | while (p1 != p) |
| 613 | { |
| 614 | *p2++ = *p1++; |
| 615 | } |
| 616 | *p2++ = '\0'; |
| 617 | } |
| 618 | |
| 619 | /* If this symbol is from a C++ compilation, then attempt to cache the |
| 620 | demangled form for future reference. This is a typical time versus |
| 621 | space tradeoff, that was decided in favor of time because it sped up |
| 622 | C++ symbol lookups by a factor of about 20. */ |
| 623 | |
| 624 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); |
| 625 | } |
| 626 | p++; |
| 627 | |
| 628 | /* Determine the type of name being defined. */ |
| 629 | #if 0 |
| 630 | /* Getting GDB to correctly skip the symbol on an undefined symbol |
| 631 | descriptor and not ever dump core is a very dodgy proposition if |
| 632 | we do things this way. I say the acorn RISC machine can just |
| 633 | fix their compiler. */ |
| 634 | /* The Acorn RISC machine's compiler can put out locals that don't |
| 635 | start with "234=" or "(3,4)=", so assume anything other than the |
| 636 | deftypes we know how to handle is a local. */ |
| 637 | if (!strchr ("cfFGpPrStTvVXCR", *p)) |
| 638 | #else |
| 639 | if (isdigit (*p) || *p == '(' || *p == '-') |
| 640 | #endif |
| 641 | deftype = 'l'; |
| 642 | else |
| 643 | deftype = *p++; |
| 644 | |
| 645 | switch (deftype) |
| 646 | { |
| 647 | case 'c': |
| 648 | /* c is a special case, not followed by a type-number. |
| 649 | SYMBOL:c=iVALUE for an integer constant symbol. |
| 650 | SYMBOL:c=rVALUE for a floating constant symbol. |
| 651 | SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. |
| 652 | e.g. "b:c=e6,0" for "const b = blob1" |
| 653 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ |
| 654 | if (*p != '=') |
| 655 | { |
| 656 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 657 | SYMBOL_TYPE (sym) = error_type (&p); |
| 658 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 659 | add_symbol_to_list (sym, &file_symbols); |
| 660 | return sym; |
| 661 | } |
| 662 | ++p; |
| 663 | switch (*p++) |
| 664 | { |
| 665 | case 'r': |
| 666 | { |
| 667 | double d = atof (p); |
| 668 | char *dbl_valu; |
| 669 | |
| 670 | /* FIXME-if-picky-about-floating-accuracy: Should be using |
| 671 | target arithmetic to get the value. real.c in GCC |
| 672 | probably has the necessary code. */ |
| 673 | |
| 674 | /* FIXME: lookup_fundamental_type is a hack. We should be |
| 675 | creating a type especially for the type of float constants. |
| 676 | Problem is, what type should it be? |
| 677 | |
| 678 | Also, what should the name of this type be? Should we |
| 679 | be using 'S' constants (see stabs.texinfo) instead? */ |
| 680 | |
| 681 | SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, |
| 682 | FT_DBL_PREC_FLOAT); |
| 683 | dbl_valu = (char *) |
| 684 | obstack_alloc (&objfile -> symbol_obstack, |
| 685 | TYPE_LENGTH (SYMBOL_TYPE (sym))); |
| 686 | store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d); |
| 687 | SYMBOL_VALUE_BYTES (sym) = dbl_valu; |
| 688 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 689 | } |
| 690 | break; |
| 691 | case 'i': |
| 692 | { |
| 693 | /* Defining integer constants this way is kind of silly, |
| 694 | since 'e' constants allows the compiler to give not |
| 695 | only the value, but the type as well. C has at least |
| 696 | int, long, unsigned int, and long long as constant |
| 697 | types; other languages probably should have at least |
| 698 | unsigned as well as signed constants. */ |
| 699 | |
| 700 | /* We just need one int constant type for all objfiles. |
| 701 | It doesn't depend on languages or anything (arguably its |
| 702 | name should be a language-specific name for a type of |
| 703 | that size, but I'm inclined to say that if the compiler |
| 704 | wants a nice name for the type, it can use 'e'). */ |
| 705 | static struct type *int_const_type; |
| 706 | |
| 707 | /* Yes, this is as long as a *host* int. That is because we |
| 708 | use atoi. */ |
| 709 | if (int_const_type == NULL) |
| 710 | int_const_type = |
| 711 | init_type (TYPE_CODE_INT, |
| 712 | sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0, |
| 713 | "integer constant", |
| 714 | (struct objfile *)NULL); |
| 715 | SYMBOL_TYPE (sym) = int_const_type; |
| 716 | SYMBOL_VALUE (sym) = atoi (p); |
| 717 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 718 | } |
| 719 | break; |
| 720 | case 'e': |
| 721 | /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value |
| 722 | can be represented as integral. |
| 723 | e.g. "b:c=e6,0" for "const b = blob1" |
| 724 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ |
| 725 | { |
| 726 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 727 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 728 | |
| 729 | if (*p != ',') |
| 730 | { |
| 731 | SYMBOL_TYPE (sym) = error_type (&p); |
| 732 | break; |
| 733 | } |
| 734 | ++p; |
| 735 | |
| 736 | /* If the value is too big to fit in an int (perhaps because |
| 737 | it is unsigned), or something like that, we silently get |
| 738 | a bogus value. The type and everything else about it is |
| 739 | correct. Ideally, we should be using whatever we have |
| 740 | available for parsing unsigned and long long values, |
| 741 | however. */ |
| 742 | SYMBOL_VALUE (sym) = atoi (p); |
| 743 | } |
| 744 | break; |
| 745 | default: |
| 746 | { |
| 747 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 748 | SYMBOL_TYPE (sym) = error_type (&p); |
| 749 | } |
| 750 | } |
| 751 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 752 | add_symbol_to_list (sym, &file_symbols); |
| 753 | return sym; |
| 754 | |
| 755 | case 'C': |
| 756 | /* The name of a caught exception. */ |
| 757 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 758 | SYMBOL_CLASS (sym) = LOC_LABEL; |
| 759 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 760 | SYMBOL_VALUE_ADDRESS (sym) = valu; |
| 761 | add_symbol_to_list (sym, &local_symbols); |
| 762 | break; |
| 763 | |
| 764 | case 'f': |
| 765 | /* A static function definition. */ |
| 766 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 767 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 768 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 769 | add_symbol_to_list (sym, &file_symbols); |
| 770 | /* fall into process_function_types. */ |
| 771 | |
| 772 | process_function_types: |
| 773 | /* Function result types are described as the result type in stabs. |
| 774 | We need to convert this to the function-returning-type-X type |
| 775 | in GDB. E.g. "int" is converted to "function returning int". */ |
| 776 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC) |
| 777 | { |
| 778 | #if 0 |
| 779 | /* This code doesn't work -- it needs to realloc and can't. */ |
| 780 | /* Attempt to set up to record a function prototype... */ |
| 781 | struct type *new = alloc_type (objfile); |
| 782 | |
| 783 | /* Generate a template for the type of this function. The |
| 784 | types of the arguments will be added as we read the symbol |
| 785 | table. */ |
| 786 | *new = *lookup_function_type (SYMBOL_TYPE(sym)); |
| 787 | SYMBOL_TYPE(sym) = new; |
| 788 | TYPE_OBJFILE (new) = objfile; |
| 789 | in_function_type = new; |
| 790 | #else |
| 791 | SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); |
| 792 | #endif |
| 793 | } |
| 794 | /* fall into process_prototype_types */ |
| 795 | |
| 796 | process_prototype_types: |
| 797 | /* Sun acc puts declared types of arguments here. We don't care |
| 798 | about their actual types (FIXME -- we should remember the whole |
| 799 | function prototype), but the list may define some new types |
| 800 | that we have to remember, so we must scan it now. */ |
| 801 | while (*p == ';') { |
| 802 | p++; |
| 803 | read_type (&p, objfile); |
| 804 | } |
| 805 | break; |
| 806 | |
| 807 | case 'F': |
| 808 | /* A global function definition. */ |
| 809 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 810 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 811 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 812 | add_symbol_to_list (sym, &global_symbols); |
| 813 | goto process_function_types; |
| 814 | |
| 815 | case 'G': |
| 816 | /* For a class G (global) symbol, it appears that the |
| 817 | value is not correct. It is necessary to search for the |
| 818 | corresponding linker definition to find the value. |
| 819 | These definitions appear at the end of the namelist. */ |
| 820 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 821 | i = hashname (SYMBOL_NAME (sym)); |
| 822 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; |
| 823 | global_sym_chain[i] = sym; |
| 824 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 825 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 826 | add_symbol_to_list (sym, &global_symbols); |
| 827 | break; |
| 828 | |
| 829 | /* This case is faked by a conditional above, |
| 830 | when there is no code letter in the dbx data. |
| 831 | Dbx data never actually contains 'l'. */ |
| 832 | case 's': |
| 833 | case 'l': |
| 834 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 835 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
| 836 | SYMBOL_VALUE (sym) = valu; |
| 837 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 838 | add_symbol_to_list (sym, &local_symbols); |
| 839 | break; |
| 840 | |
| 841 | case 'p': |
| 842 | if (*p == 'F') |
| 843 | /* pF is a two-letter code that means a function parameter in Fortran. |
| 844 | The type-number specifies the type of the return value. |
| 845 | Translate it into a pointer-to-function type. */ |
| 846 | { |
| 847 | p++; |
| 848 | SYMBOL_TYPE (sym) |
| 849 | = lookup_pointer_type |
| 850 | (lookup_function_type (read_type (&p, objfile))); |
| 851 | } |
| 852 | else |
| 853 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 854 | |
| 855 | /* Normally this is a parameter, a LOC_ARG. On the i960, it |
| 856 | can also be a LOC_LOCAL_ARG depending on symbol type. */ |
| 857 | #ifndef DBX_PARM_SYMBOL_CLASS |
| 858 | #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG |
| 859 | #endif |
| 860 | |
| 861 | SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type); |
| 862 | SYMBOL_VALUE (sym) = valu; |
| 863 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 864 | #if 0 |
| 865 | /* This doesn't work yet. */ |
| 866 | add_param_to_type (&in_function_type, sym); |
| 867 | #endif |
| 868 | add_symbol_to_list (sym, &local_symbols); |
| 869 | |
| 870 | if (TARGET_BYTE_ORDER != BIG_ENDIAN) |
| 871 | { |
| 872 | /* On little-endian machines, this crud is never necessary, |
| 873 | and, if the extra bytes contain garbage, is harmful. */ |
| 874 | break; |
| 875 | } |
| 876 | |
| 877 | /* If it's gcc-compiled, if it says `short', believe it. */ |
| 878 | if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION) |
| 879 | break; |
| 880 | |
| 881 | #if !BELIEVE_PCC_PROMOTION |
| 882 | { |
| 883 | /* This is the signed type which arguments get promoted to. */ |
| 884 | static struct type *pcc_promotion_type; |
| 885 | /* This is the unsigned type which arguments get promoted to. */ |
| 886 | static struct type *pcc_unsigned_promotion_type; |
| 887 | |
| 888 | /* Call it "int" because this is mainly C lossage. */ |
| 889 | if (pcc_promotion_type == NULL) |
| 890 | pcc_promotion_type = |
| 891 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 892 | 0, "int", NULL); |
| 893 | |
| 894 | if (pcc_unsigned_promotion_type == NULL) |
| 895 | pcc_unsigned_promotion_type = |
| 896 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 897 | TYPE_FLAG_UNSIGNED, "unsigned int", NULL); |
| 898 | |
| 899 | #if defined(BELIEVE_PCC_PROMOTION_TYPE) |
| 900 | /* This macro is defined on machines (e.g. sparc) where |
| 901 | we should believe the type of a PCC 'short' argument, |
| 902 | but shouldn't believe the address (the address is |
| 903 | the address of the corresponding int). |
| 904 | |
| 905 | My guess is that this correction, as opposed to changing |
| 906 | the parameter to an 'int' (as done below, for PCC |
| 907 | on most machines), is the right thing to do |
| 908 | on all machines, but I don't want to risk breaking |
| 909 | something that already works. On most PCC machines, |
| 910 | the sparc problem doesn't come up because the calling |
| 911 | function has to zero the top bytes (not knowing whether |
| 912 | the called function wants an int or a short), so there |
| 913 | is little practical difference between an int and a short |
| 914 | (except perhaps what happens when the GDB user types |
| 915 | "print short_arg = 0x10000;"). |
| 916 | |
| 917 | Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler |
| 918 | actually produces the correct address (we don't need to fix it |
| 919 | up). I made this code adapt so that it will offset the symbol |
| 920 | if it was pointing at an int-aligned location and not |
| 921 | otherwise. This way you can use the same gdb for 4.0.x and |
| 922 | 4.1 systems. |
| 923 | |
| 924 | If the parameter is shorter than an int, and is integral |
| 925 | (e.g. char, short, or unsigned equivalent), and is claimed to |
| 926 | be passed on an integer boundary, don't believe it! Offset the |
| 927 | parameter's address to the tail-end of that integer. */ |
| 928 | |
| 929 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) |
| 930 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT |
| 931 | && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type)) |
| 932 | { |
| 933 | SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type) |
| 934 | - TYPE_LENGTH (SYMBOL_TYPE (sym)); |
| 935 | } |
| 936 | break; |
| 937 | |
| 938 | #else /* no BELIEVE_PCC_PROMOTION_TYPE. */ |
| 939 | |
| 940 | /* If PCC says a parameter is a short or a char, |
| 941 | it is really an int. */ |
| 942 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) |
| 943 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT) |
| 944 | { |
| 945 | SYMBOL_TYPE (sym) = |
| 946 | TYPE_UNSIGNED (SYMBOL_TYPE (sym)) |
| 947 | ? pcc_unsigned_promotion_type |
| 948 | : pcc_promotion_type; |
| 949 | } |
| 950 | break; |
| 951 | |
| 952 | #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */ |
| 953 | } |
| 954 | #endif /* !BELIEVE_PCC_PROMOTION. */ |
| 955 | |
| 956 | case 'P': |
| 957 | /* acc seems to use P to delare the prototypes of functions that |
| 958 | are referenced by this file. gdb is not prepared to deal |
| 959 | with this extra information. FIXME, it ought to. */ |
| 960 | if (type == N_FUN) |
| 961 | { |
| 962 | read_type (&p, objfile); |
| 963 | goto process_prototype_types; |
| 964 | } |
| 965 | /*FALLTHROUGH*/ |
| 966 | |
| 967 | case 'R': |
| 968 | /* Parameter which is in a register. */ |
| 969 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 970 | SYMBOL_CLASS (sym) = LOC_REGPARM; |
| 971 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); |
| 972 | if (SYMBOL_VALUE (sym) >= NUM_REGS) |
| 973 | { |
| 974 | complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym)); |
| 975 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
| 976 | } |
| 977 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 978 | add_symbol_to_list (sym, &local_symbols); |
| 979 | break; |
| 980 | |
| 981 | case 'r': |
| 982 | /* Register variable (either global or local). */ |
| 983 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 984 | SYMBOL_CLASS (sym) = LOC_REGISTER; |
| 985 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); |
| 986 | if (SYMBOL_VALUE (sym) >= NUM_REGS) |
| 987 | { |
| 988 | complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym)); |
| 989 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
| 990 | } |
| 991 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 992 | if (within_function) |
| 993 | { |
| 994 | /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same |
| 995 | name to represent an argument passed in a register. |
| 996 | GCC uses 'P' for the same case. So if we find such a symbol pair |
| 997 | we combine it into one 'P' symbol. For Sun cc we need to do this |
| 998 | regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out |
| 999 | the 'p' symbol even if it never saves the argument onto the stack. |
| 1000 | |
| 1001 | On most machines, we want to preserve both symbols, so that |
| 1002 | we can still get information about what is going on with the |
| 1003 | stack (VAX for computing args_printed, using stack slots instead |
| 1004 | of saved registers in backtraces, etc.). |
| 1005 | |
| 1006 | Note that this code illegally combines |
| 1007 | main(argc) struct foo argc; { register struct foo argc; } |
| 1008 | but this case is considered pathological and causes a warning |
| 1009 | from a decent compiler. */ |
| 1010 | |
| 1011 | if (local_symbols |
| 1012 | && local_symbols->nsyms > 0 |
| 1013 | #ifndef USE_REGISTER_NOT_ARG |
| 1014 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
| 1015 | SYMBOL_TYPE (sym)) |
| 1016 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT |
| 1017 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) |
| 1018 | #endif |
| 1019 | ) |
| 1020 | { |
| 1021 | struct symbol *prev_sym; |
| 1022 | prev_sym = local_symbols->symbol[local_symbols->nsyms - 1]; |
| 1023 | if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG |
| 1024 | || SYMBOL_CLASS (prev_sym) == LOC_ARG) |
| 1025 | && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym))) |
| 1026 | { |
| 1027 | SYMBOL_CLASS (prev_sym) = LOC_REGPARM; |
| 1028 | /* Use the type from the LOC_REGISTER; that is the type |
| 1029 | that is actually in that register. */ |
| 1030 | SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym); |
| 1031 | SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym); |
| 1032 | sym = prev_sym; |
| 1033 | break; |
| 1034 | } |
| 1035 | } |
| 1036 | add_symbol_to_list (sym, &local_symbols); |
| 1037 | } |
| 1038 | else |
| 1039 | add_symbol_to_list (sym, &file_symbols); |
| 1040 | break; |
| 1041 | |
| 1042 | case 'S': |
| 1043 | /* Static symbol at top level of file */ |
| 1044 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1045 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 1046 | SYMBOL_VALUE_ADDRESS (sym) = valu; |
| 1047 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1048 | add_symbol_to_list (sym, &file_symbols); |
| 1049 | break; |
| 1050 | |
| 1051 | case 't': |
| 1052 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1053 | |
| 1054 | /* For a nameless type, we don't want a create a symbol, thus we |
| 1055 | did not use `sym'. Return without further processing. */ |
| 1056 | if (nameless) return NULL; |
| 1057 | |
| 1058 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 1059 | SYMBOL_VALUE (sym) = valu; |
| 1060 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1061 | /* C++ vagaries: we may have a type which is derived from |
| 1062 | a base type which did not have its name defined when the |
| 1063 | derived class was output. We fill in the derived class's |
| 1064 | base part member's name here in that case. */ |
| 1065 | if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL) |
| 1066 | if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT |
| 1067 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) |
| 1068 | && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) |
| 1069 | { |
| 1070 | int j; |
| 1071 | for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--) |
| 1072 | if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0) |
| 1073 | TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) = |
| 1074 | type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)); |
| 1075 | } |
| 1076 | |
| 1077 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL) |
| 1078 | { |
| 1079 | /* gcc-2.6 or later (when using -fvtable-thunks) |
| 1080 | emits a unique named type for a vtable entry. |
| 1081 | Some gdb code depends on that specific name. */ |
| 1082 | extern const char vtbl_ptr_name[]; |
| 1083 | |
| 1084 | if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR |
| 1085 | && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name)) |
| 1086 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC) |
| 1087 | { |
| 1088 | /* If we are giving a name to a type such as "pointer to |
| 1089 | foo" or "function returning foo", we better not set |
| 1090 | the TYPE_NAME. If the program contains "typedef char |
| 1091 | *caddr_t;", we don't want all variables of type char |
| 1092 | * to print as caddr_t. This is not just a |
| 1093 | consequence of GDB's type management; PCC and GCC (at |
| 1094 | least through version 2.4) both output variables of |
| 1095 | either type char * or caddr_t with the type number |
| 1096 | defined in the 't' symbol for caddr_t. If a future |
| 1097 | compiler cleans this up it GDB is not ready for it |
| 1098 | yet, but if it becomes ready we somehow need to |
| 1099 | disable this check (without breaking the PCC/GCC2.4 |
| 1100 | case). |
| 1101 | |
| 1102 | Sigh. |
| 1103 | |
| 1104 | Fortunately, this check seems not to be necessary |
| 1105 | for anything except pointers or functions. */ |
| 1106 | } |
| 1107 | else |
| 1108 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym); |
| 1109 | } |
| 1110 | |
| 1111 | add_symbol_to_list (sym, &file_symbols); |
| 1112 | break; |
| 1113 | |
| 1114 | case 'T': |
| 1115 | /* Struct, union, or enum tag. For GNU C++, this can be be followed |
| 1116 | by 't' which means we are typedef'ing it as well. */ |
| 1117 | synonym = *p == 't'; |
| 1118 | |
| 1119 | if (synonym) |
| 1120 | { |
| 1121 | p++; |
| 1122 | type_synonym_name = obsavestring (SYMBOL_NAME (sym), |
| 1123 | strlen (SYMBOL_NAME (sym)), |
| 1124 | &objfile -> symbol_obstack); |
| 1125 | } |
| 1126 | /* The semantics of C++ state that "struct foo { ... }" also defines |
| 1127 | a typedef for "foo". Unfortunately, cfront never makes the typedef |
| 1128 | when translating C++ into C. We make the typedef here so that |
| 1129 | "ptype foo" works as expected for cfront translated code. */ |
| 1130 | else if (current_subfile->language == language_cplus) |
| 1131 | { |
| 1132 | synonym = 1; |
| 1133 | type_synonym_name = obsavestring (SYMBOL_NAME (sym), |
| 1134 | strlen (SYMBOL_NAME (sym)), |
| 1135 | &objfile -> symbol_obstack); |
| 1136 | } |
| 1137 | |
| 1138 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1139 | |
| 1140 | /* For a nameless type, we don't want a create a symbol, thus we |
| 1141 | did not use `sym'. Return without further processing. */ |
| 1142 | if (nameless) return NULL; |
| 1143 | |
| 1144 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 1145 | SYMBOL_VALUE (sym) = valu; |
| 1146 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; |
| 1147 | if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0) |
| 1148 | TYPE_TAG_NAME (SYMBOL_TYPE (sym)) |
| 1149 | = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym)); |
| 1150 | add_symbol_to_list (sym, &file_symbols); |
| 1151 | |
| 1152 | if (synonym) |
| 1153 | { |
| 1154 | /* Clone the sym and then modify it. */ |
| 1155 | register struct symbol *typedef_sym = (struct symbol *) |
| 1156 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 1157 | *typedef_sym = *sym; |
| 1158 | SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; |
| 1159 | SYMBOL_VALUE (typedef_sym) = valu; |
| 1160 | SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; |
| 1161 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
| 1162 | TYPE_NAME (SYMBOL_TYPE (sym)) |
| 1163 | = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym)); |
| 1164 | add_symbol_to_list (typedef_sym, &file_symbols); |
| 1165 | } |
| 1166 | break; |
| 1167 | |
| 1168 | case 'V': |
| 1169 | /* Static symbol of local scope */ |
| 1170 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1171 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 1172 | SYMBOL_VALUE_ADDRESS (sym) = valu; |
| 1173 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1174 | if (os9k_stabs) |
| 1175 | add_symbol_to_list (sym, &global_symbols); |
| 1176 | else |
| 1177 | add_symbol_to_list (sym, &local_symbols); |
| 1178 | break; |
| 1179 | |
| 1180 | case 'v': |
| 1181 | /* Reference parameter */ |
| 1182 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1183 | SYMBOL_CLASS (sym) = LOC_REF_ARG; |
| 1184 | SYMBOL_VALUE (sym) = valu; |
| 1185 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1186 | add_symbol_to_list (sym, &local_symbols); |
| 1187 | break; |
| 1188 | |
| 1189 | case 'X': |
| 1190 | /* This is used by Sun FORTRAN for "function result value". |
| 1191 | Sun claims ("dbx and dbxtool interfaces", 2nd ed) |
| 1192 | that Pascal uses it too, but when I tried it Pascal used |
| 1193 | "x:3" (local symbol) instead. */ |
| 1194 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1195 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
| 1196 | SYMBOL_VALUE (sym) = valu; |
| 1197 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1198 | add_symbol_to_list (sym, &local_symbols); |
| 1199 | break; |
| 1200 | |
| 1201 | default: |
| 1202 | SYMBOL_TYPE (sym) = error_type (&p); |
| 1203 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 1204 | SYMBOL_VALUE (sym) = 0; |
| 1205 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1206 | add_symbol_to_list (sym, &file_symbols); |
| 1207 | break; |
| 1208 | } |
| 1209 | |
| 1210 | /* When passing structures to a function, some systems sometimes pass |
| 1211 | the address in a register, not the structure itself. |
| 1212 | |
| 1213 | If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM |
| 1214 | to LOC_REGPARM_ADDR for structures and unions. */ |
| 1215 | |
| 1216 | if (SYMBOL_CLASS (sym) == LOC_REGPARM |
| 1217 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
| 1218 | SYMBOL_TYPE (sym)) |
| 1219 | && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) |
| 1220 | || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))) |
| 1221 | SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; |
| 1222 | |
| 1223 | /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and |
| 1224 | subsequent arguments on the sparc, for example). */ |
| 1225 | if (SYMBOL_CLASS (sym) == LOC_ARG |
| 1226 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
| 1227 | SYMBOL_TYPE (sym)) |
| 1228 | && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT) |
| 1229 | || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))) |
| 1230 | SYMBOL_CLASS (sym) = LOC_REF_ARG; |
| 1231 | |
| 1232 | return sym; |
| 1233 | } |
| 1234 | |
| 1235 | \f |
| 1236 | /* Skip rest of this symbol and return an error type. |
| 1237 | |
| 1238 | General notes on error recovery: error_type always skips to the |
| 1239 | end of the symbol (modulo cretinous dbx symbol name continuation). |
| 1240 | Thus code like this: |
| 1241 | |
| 1242 | if (*(*pp)++ != ';') |
| 1243 | return error_type (pp); |
| 1244 | |
| 1245 | is wrong because if *pp starts out pointing at '\0' (typically as the |
| 1246 | result of an earlier error), it will be incremented to point to the |
| 1247 | start of the next symbol, which might produce strange results, at least |
| 1248 | if you run off the end of the string table. Instead use |
| 1249 | |
| 1250 | if (**pp != ';') |
| 1251 | return error_type (pp); |
| 1252 | ++*pp; |
| 1253 | |
| 1254 | or |
| 1255 | |
| 1256 | if (**pp != ';') |
| 1257 | foo = error_type (pp); |
| 1258 | else |
| 1259 | ++*pp; |
| 1260 | |
| 1261 | And in case it isn't obvious, the point of all this hair is so the compiler |
| 1262 | can define new types and new syntaxes, and old versions of the |
| 1263 | debugger will be able to read the new symbol tables. */ |
| 1264 | |
| 1265 | static struct type * |
| 1266 | error_type (pp) |
| 1267 | char **pp; |
| 1268 | { |
| 1269 | complain (&error_type_complaint); |
| 1270 | while (1) |
| 1271 | { |
| 1272 | /* Skip to end of symbol. */ |
| 1273 | while (**pp != '\0') |
| 1274 | { |
| 1275 | (*pp)++; |
| 1276 | } |
| 1277 | |
| 1278 | /* Check for and handle cretinous dbx symbol name continuation! */ |
| 1279 | if ((*pp)[-1] == '\\' || (*pp)[-1] == '?') |
| 1280 | { |
| 1281 | *pp = next_symbol_text (); |
| 1282 | } |
| 1283 | else |
| 1284 | { |
| 1285 | break; |
| 1286 | } |
| 1287 | } |
| 1288 | return (builtin_type_error); |
| 1289 | } |
| 1290 | |
| 1291 | \f |
| 1292 | /* Read type information or a type definition; return the type. Even |
| 1293 | though this routine accepts either type information or a type |
| 1294 | definition, the distinction is relevant--some parts of stabsread.c |
| 1295 | assume that type information starts with a digit, '-', or '(' in |
| 1296 | deciding whether to call read_type. */ |
| 1297 | |
| 1298 | struct type * |
| 1299 | read_type (pp, objfile) |
| 1300 | register char **pp; |
| 1301 | struct objfile *objfile; |
| 1302 | { |
| 1303 | register struct type *type = 0; |
| 1304 | struct type *type1; |
| 1305 | int typenums[2]; |
| 1306 | int xtypenums[2]; |
| 1307 | char type_descriptor; |
| 1308 | |
| 1309 | /* Size in bits of type if specified by a type attribute, or -1 if |
| 1310 | there is no size attribute. */ |
| 1311 | int type_size = -1; |
| 1312 | |
| 1313 | /* Used to distinguish string and bitstring from char-array and set. */ |
| 1314 | int is_string = 0; |
| 1315 | |
| 1316 | /* Read type number if present. The type number may be omitted. |
| 1317 | for instance in a two-dimensional array declared with type |
| 1318 | "ar1;1;10;ar1;1;10;4". */ |
| 1319 | if ((**pp >= '0' && **pp <= '9') |
| 1320 | || **pp == '(' |
| 1321 | || **pp == '-') |
| 1322 | { |
| 1323 | if (read_type_number (pp, typenums) != 0) |
| 1324 | return error_type (pp); |
| 1325 | |
| 1326 | /* Type is not being defined here. Either it already exists, |
| 1327 | or this is a forward reference to it. dbx_alloc_type handles |
| 1328 | both cases. */ |
| 1329 | if (**pp != '=') |
| 1330 | return dbx_alloc_type (typenums, objfile); |
| 1331 | |
| 1332 | /* Type is being defined here. */ |
| 1333 | /* Skip the '='. */ |
| 1334 | ++(*pp); |
| 1335 | |
| 1336 | while (**pp == '@') |
| 1337 | { |
| 1338 | char *p = *pp + 1; |
| 1339 | /* It might be a type attribute or a member type. */ |
| 1340 | if (isdigit (*p) || *p == '(' || *p == '-') |
| 1341 | /* Member type. */ |
| 1342 | break; |
| 1343 | else |
| 1344 | { |
| 1345 | /* Type attributes. */ |
| 1346 | char *attr = p; |
| 1347 | |
| 1348 | /* Skip to the semicolon. */ |
| 1349 | while (*p != ';' && *p != '\0') |
| 1350 | ++p; |
| 1351 | *pp = p; |
| 1352 | if (*p == '\0') |
| 1353 | return error_type (pp); |
| 1354 | else |
| 1355 | /* Skip the semicolon. */ |
| 1356 | ++*pp; |
| 1357 | |
| 1358 | switch (*attr) |
| 1359 | { |
| 1360 | case 's': |
| 1361 | type_size = atoi (attr + 1); |
| 1362 | if (type_size <= 0) |
| 1363 | type_size = -1; |
| 1364 | break; |
| 1365 | |
| 1366 | case 'S': |
| 1367 | is_string = 1; |
| 1368 | break; |
| 1369 | |
| 1370 | default: |
| 1371 | /* Ignore unrecognized type attributes, so future compilers |
| 1372 | can invent new ones. */ |
| 1373 | break; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | /* Skip the type descriptor, we get it below with (*pp)[-1]. */ |
| 1378 | ++(*pp); |
| 1379 | } |
| 1380 | else |
| 1381 | { |
| 1382 | /* 'typenums=' not present, type is anonymous. Read and return |
| 1383 | the definition, but don't put it in the type vector. */ |
| 1384 | typenums[0] = typenums[1] = -1; |
| 1385 | (*pp)++; |
| 1386 | } |
| 1387 | |
| 1388 | type_descriptor = (*pp)[-1]; |
| 1389 | switch (type_descriptor) |
| 1390 | { |
| 1391 | case 'x': |
| 1392 | { |
| 1393 | enum type_code code; |
| 1394 | |
| 1395 | /* Used to index through file_symbols. */ |
| 1396 | struct pending *ppt; |
| 1397 | int i; |
| 1398 | |
| 1399 | /* Name including "struct", etc. */ |
| 1400 | char *type_name; |
| 1401 | |
| 1402 | { |
| 1403 | char *from, *to, *p, *q1, *q2; |
| 1404 | |
| 1405 | /* Set the type code according to the following letter. */ |
| 1406 | switch ((*pp)[0]) |
| 1407 | { |
| 1408 | case 's': |
| 1409 | code = TYPE_CODE_STRUCT; |
| 1410 | break; |
| 1411 | case 'u': |
| 1412 | code = TYPE_CODE_UNION; |
| 1413 | break; |
| 1414 | case 'e': |
| 1415 | code = TYPE_CODE_ENUM; |
| 1416 | break; |
| 1417 | default: |
| 1418 | { |
| 1419 | /* Complain and keep going, so compilers can invent new |
| 1420 | cross-reference types. */ |
| 1421 | static struct complaint msg = |
| 1422 | {"Unrecognized cross-reference type `%c'", 0, 0}; |
| 1423 | complain (&msg, (*pp)[0]); |
| 1424 | code = TYPE_CODE_STRUCT; |
| 1425 | break; |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | q1 = strchr(*pp, '<'); |
| 1430 | p = strchr(*pp, ':'); |
| 1431 | if (p == NULL) |
| 1432 | return error_type (pp); |
| 1433 | while (q1 && p > q1 && p[1] == ':') |
| 1434 | { |
| 1435 | q2 = strchr(q1, '>'); |
| 1436 | if (!q2 || q2 < p) |
| 1437 | break; |
| 1438 | p += 2; |
| 1439 | p = strchr(p, ':'); |
| 1440 | if (p == NULL) |
| 1441 | return error_type (pp); |
| 1442 | } |
| 1443 | to = type_name = |
| 1444 | (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1); |
| 1445 | |
| 1446 | /* Copy the name. */ |
| 1447 | from = *pp + 1; |
| 1448 | while (from < p) |
| 1449 | *to++ = *from++; |
| 1450 | *to = '\0'; |
| 1451 | |
| 1452 | /* Set the pointer ahead of the name which we just read, and |
| 1453 | the colon. */ |
| 1454 | *pp = from + 1; |
| 1455 | } |
| 1456 | |
| 1457 | /* Now check to see whether the type has already been |
| 1458 | declared. This was written for arrays of cross-referenced |
| 1459 | types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty |
| 1460 | sure it is not necessary anymore. But it might be a good |
| 1461 | idea, to save a little memory. */ |
| 1462 | |
| 1463 | for (ppt = file_symbols; ppt; ppt = ppt->next) |
| 1464 | for (i = 0; i < ppt->nsyms; i++) |
| 1465 | { |
| 1466 | struct symbol *sym = ppt->symbol[i]; |
| 1467 | |
| 1468 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF |
| 1469 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE |
| 1470 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == code) |
| 1471 | && STREQ (SYMBOL_NAME (sym), type_name)) |
| 1472 | { |
| 1473 | obstack_free (&objfile -> type_obstack, type_name); |
| 1474 | type = SYMBOL_TYPE (sym); |
| 1475 | return type; |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | /* Didn't find the type to which this refers, so we must |
| 1480 | be dealing with a forward reference. Allocate a type |
| 1481 | structure for it, and keep track of it so we can |
| 1482 | fill in the rest of the fields when we get the full |
| 1483 | type. */ |
| 1484 | type = dbx_alloc_type (typenums, objfile); |
| 1485 | TYPE_CODE (type) = code; |
| 1486 | TYPE_TAG_NAME (type) = type_name; |
| 1487 | INIT_CPLUS_SPECIFIC(type); |
| 1488 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; |
| 1489 | |
| 1490 | add_undefined_type (type); |
| 1491 | return type; |
| 1492 | } |
| 1493 | |
| 1494 | case '-': /* RS/6000 built-in type */ |
| 1495 | case '0': |
| 1496 | case '1': |
| 1497 | case '2': |
| 1498 | case '3': |
| 1499 | case '4': |
| 1500 | case '5': |
| 1501 | case '6': |
| 1502 | case '7': |
| 1503 | case '8': |
| 1504 | case '9': |
| 1505 | case '(': |
| 1506 | |
| 1507 | { |
| 1508 | char *pp_saved; |
| 1509 | |
| 1510 | (*pp)--; |
| 1511 | pp_saved = *pp; |
| 1512 | |
| 1513 | /* Peek ahead at the number to detect void. */ |
| 1514 | if (read_type_number (pp, xtypenums) != 0) |
| 1515 | return error_type (pp); |
| 1516 | |
| 1517 | if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1]) |
| 1518 | /* It's being defined as itself. That means it is "void". */ |
| 1519 | type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
| 1520 | else |
| 1521 | { |
| 1522 | struct type *xtype; |
| 1523 | |
| 1524 | /* Go back to the number and have read_type get it. This means |
| 1525 | that we can deal with something like t(1,2)=(3,4)=... which |
| 1526 | the Lucid compiler uses. */ |
| 1527 | *pp = pp_saved; |
| 1528 | xtype = read_type (pp, objfile); |
| 1529 | |
| 1530 | /* The type is being defined to another type. So we copy the type. |
| 1531 | This loses if we copy a C++ class and so we lose track of how |
| 1532 | the names are mangled (but g++ doesn't output stabs like this |
| 1533 | now anyway). */ |
| 1534 | |
| 1535 | type = alloc_type (objfile); |
| 1536 | memcpy (type, xtype, sizeof (struct type)); |
| 1537 | |
| 1538 | /* The idea behind clearing the names is that the only purpose |
| 1539 | for defining a type to another type is so that the name of |
| 1540 | one can be different. So we probably don't need to worry much |
| 1541 | about the case where the compiler doesn't give a name to the |
| 1542 | new type. */ |
| 1543 | TYPE_NAME (type) = NULL; |
| 1544 | TYPE_TAG_NAME (type) = NULL; |
| 1545 | } |
| 1546 | if (typenums[0] != -1) |
| 1547 | *dbx_lookup_type (typenums) = type; |
| 1548 | break; |
| 1549 | } |
| 1550 | |
| 1551 | /* In the following types, we must be sure to overwrite any existing |
| 1552 | type that the typenums refer to, rather than allocating a new one |
| 1553 | and making the typenums point to the new one. This is because there |
| 1554 | may already be pointers to the existing type (if it had been |
| 1555 | forward-referenced), and we must change it to a pointer, function, |
| 1556 | reference, or whatever, *in-place*. */ |
| 1557 | |
| 1558 | case '*': |
| 1559 | type1 = read_type (pp, objfile); |
| 1560 | type = make_pointer_type (type1, dbx_lookup_type (typenums)); |
| 1561 | break; |
| 1562 | |
| 1563 | case '&': /* Reference to another type */ |
| 1564 | type1 = read_type (pp, objfile); |
| 1565 | type = make_reference_type (type1, dbx_lookup_type (typenums)); |
| 1566 | break; |
| 1567 | |
| 1568 | case 'f': /* Function returning another type */ |
| 1569 | if (os9k_stabs && **pp == '(') |
| 1570 | { |
| 1571 | /* Function prototype; parse it. |
| 1572 | We must conditionalize this on os9k_stabs because otherwise |
| 1573 | it could be confused with a Sun-style (1,3) typenumber |
| 1574 | (I think). */ |
| 1575 | struct type *t; |
| 1576 | ++*pp; |
| 1577 | while (**pp != ')') |
| 1578 | { |
| 1579 | t = read_type(pp, objfile); |
| 1580 | if (**pp == ',') ++*pp; |
| 1581 | } |
| 1582 | } |
| 1583 | type1 = read_type (pp, objfile); |
| 1584 | type = make_function_type (type1, dbx_lookup_type (typenums)); |
| 1585 | break; |
| 1586 | |
| 1587 | case 'k': /* Const qualifier on some type (Sun) */ |
| 1588 | case 'c': /* Const qualifier on some type (OS9000) */ |
| 1589 | /* Because 'c' means other things to AIX and 'k' is perfectly good, |
| 1590 | only accept 'c' in the os9k_stabs case. */ |
| 1591 | if (type_descriptor == 'c' && !os9k_stabs) |
| 1592 | return error_type (pp); |
| 1593 | type = read_type (pp, objfile); |
| 1594 | /* FIXME! For now, we ignore const and volatile qualifiers. */ |
| 1595 | break; |
| 1596 | |
| 1597 | case 'B': /* Volatile qual on some type (Sun) */ |
| 1598 | case 'i': /* Volatile qual on some type (OS9000) */ |
| 1599 | /* Because 'i' means other things to AIX and 'B' is perfectly good, |
| 1600 | only accept 'i' in the os9k_stabs case. */ |
| 1601 | if (type_descriptor == 'i' && !os9k_stabs) |
| 1602 | return error_type (pp); |
| 1603 | type = read_type (pp, objfile); |
| 1604 | /* FIXME! For now, we ignore const and volatile qualifiers. */ |
| 1605 | break; |
| 1606 | |
| 1607 | /* FIXME -- we should be doing smash_to_XXX types here. */ |
| 1608 | case '@': /* Member (class & variable) type */ |
| 1609 | { |
| 1610 | struct type *domain = read_type (pp, objfile); |
| 1611 | struct type *memtype; |
| 1612 | |
| 1613 | if (**pp != ',') |
| 1614 | /* Invalid member type data format. */ |
| 1615 | return error_type (pp); |
| 1616 | ++*pp; |
| 1617 | |
| 1618 | memtype = read_type (pp, objfile); |
| 1619 | type = dbx_alloc_type (typenums, objfile); |
| 1620 | smash_to_member_type (type, domain, memtype); |
| 1621 | } |
| 1622 | break; |
| 1623 | |
| 1624 | case '#': /* Method (class & fn) type */ |
| 1625 | if ((*pp)[0] == '#') |
| 1626 | { |
| 1627 | /* We'll get the parameter types from the name. */ |
| 1628 | struct type *return_type; |
| 1629 | |
| 1630 | (*pp)++; |
| 1631 | return_type = read_type (pp, objfile); |
| 1632 | if (*(*pp)++ != ';') |
| 1633 | complain (&invalid_member_complaint, symnum); |
| 1634 | type = allocate_stub_method (return_type); |
| 1635 | if (typenums[0] != -1) |
| 1636 | *dbx_lookup_type (typenums) = type; |
| 1637 | } |
| 1638 | else |
| 1639 | { |
| 1640 | struct type *domain = read_type (pp, objfile); |
| 1641 | struct type *return_type; |
| 1642 | struct type **args; |
| 1643 | |
| 1644 | if (**pp != ',') |
| 1645 | /* Invalid member type data format. */ |
| 1646 | return error_type (pp); |
| 1647 | else |
| 1648 | ++(*pp); |
| 1649 | |
| 1650 | return_type = read_type (pp, objfile); |
| 1651 | args = read_args (pp, ';', objfile); |
| 1652 | type = dbx_alloc_type (typenums, objfile); |
| 1653 | smash_to_method_type (type, domain, return_type, args); |
| 1654 | } |
| 1655 | break; |
| 1656 | |
| 1657 | case 'r': /* Range type */ |
| 1658 | type = read_range_type (pp, typenums, objfile); |
| 1659 | if (typenums[0] != -1) |
| 1660 | *dbx_lookup_type (typenums) = type; |
| 1661 | break; |
| 1662 | |
| 1663 | case 'b': |
| 1664 | if (os9k_stabs) |
| 1665 | /* Const and volatile qualified type. */ |
| 1666 | type = read_type (pp, objfile); |
| 1667 | else |
| 1668 | { |
| 1669 | /* Sun ACC builtin int type */ |
| 1670 | type = read_sun_builtin_type (pp, typenums, objfile); |
| 1671 | if (typenums[0] != -1) |
| 1672 | *dbx_lookup_type (typenums) = type; |
| 1673 | } |
| 1674 | break; |
| 1675 | |
| 1676 | case 'R': /* Sun ACC builtin float type */ |
| 1677 | type = read_sun_floating_type (pp, typenums, objfile); |
| 1678 | if (typenums[0] != -1) |
| 1679 | *dbx_lookup_type (typenums) = type; |
| 1680 | break; |
| 1681 | |
| 1682 | case 'e': /* Enumeration type */ |
| 1683 | type = dbx_alloc_type (typenums, objfile); |
| 1684 | type = read_enum_type (pp, type, objfile); |
| 1685 | if (typenums[0] != -1) |
| 1686 | *dbx_lookup_type (typenums) = type; |
| 1687 | break; |
| 1688 | |
| 1689 | case 's': /* Struct type */ |
| 1690 | case 'u': /* Union type */ |
| 1691 | type = dbx_alloc_type (typenums, objfile); |
| 1692 | if (!TYPE_NAME (type)) |
| 1693 | { |
| 1694 | TYPE_NAME (type) = type_synonym_name; |
| 1695 | } |
| 1696 | type_synonym_name = NULL; |
| 1697 | switch (type_descriptor) |
| 1698 | { |
| 1699 | case 's': |
| 1700 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
| 1701 | break; |
| 1702 | case 'u': |
| 1703 | TYPE_CODE (type) = TYPE_CODE_UNION; |
| 1704 | break; |
| 1705 | } |
| 1706 | type = read_struct_type (pp, type, objfile); |
| 1707 | break; |
| 1708 | |
| 1709 | case 'a': /* Array type */ |
| 1710 | if (**pp != 'r') |
| 1711 | return error_type (pp); |
| 1712 | ++*pp; |
| 1713 | |
| 1714 | type = dbx_alloc_type (typenums, objfile); |
| 1715 | type = read_array_type (pp, type, objfile); |
| 1716 | if (is_string) |
| 1717 | TYPE_CODE (type) = TYPE_CODE_STRING; |
| 1718 | break; |
| 1719 | |
| 1720 | case 'S': |
| 1721 | type1 = read_type (pp, objfile); |
| 1722 | type = create_set_type ((struct type*) NULL, type1); |
| 1723 | if (is_string) |
| 1724 | TYPE_CODE (type) = TYPE_CODE_BITSTRING; |
| 1725 | if (typenums[0] != -1) |
| 1726 | *dbx_lookup_type (typenums) = type; |
| 1727 | break; |
| 1728 | |
| 1729 | default: |
| 1730 | --*pp; /* Go back to the symbol in error */ |
| 1731 | /* Particularly important if it was \0! */ |
| 1732 | return error_type (pp); |
| 1733 | } |
| 1734 | |
| 1735 | if (type == 0) |
| 1736 | { |
| 1737 | warning ("GDB internal error, type is NULL in stabsread.c\n"); |
| 1738 | return error_type (pp); |
| 1739 | } |
| 1740 | |
| 1741 | /* Size specified in a type attribute overrides any other size. */ |
| 1742 | if (type_size != -1) |
| 1743 | TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; |
| 1744 | |
| 1745 | return type; |
| 1746 | } |
| 1747 | \f |
| 1748 | /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1. |
| 1749 | Return the proper type node for a given builtin type number. */ |
| 1750 | |
| 1751 | static struct type * |
| 1752 | rs6000_builtin_type (typenum) |
| 1753 | int typenum; |
| 1754 | { |
| 1755 | /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */ |
| 1756 | #define NUMBER_RECOGNIZED 30 |
| 1757 | /* This includes an empty slot for type number -0. */ |
| 1758 | static struct type *negative_types[NUMBER_RECOGNIZED + 1]; |
| 1759 | struct type *rettype = NULL; |
| 1760 | |
| 1761 | if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED) |
| 1762 | { |
| 1763 | complain (&rs6000_builtin_complaint, typenum); |
| 1764 | return builtin_type_error; |
| 1765 | } |
| 1766 | if (negative_types[-typenum] != NULL) |
| 1767 | return negative_types[-typenum]; |
| 1768 | |
| 1769 | #if TARGET_CHAR_BIT != 8 |
| 1770 | #error This code wrong for TARGET_CHAR_BIT not 8 |
| 1771 | /* These definitions all assume that TARGET_CHAR_BIT is 8. I think |
| 1772 | that if that ever becomes not true, the correct fix will be to |
| 1773 | make the size in the struct type to be in bits, not in units of |
| 1774 | TARGET_CHAR_BIT. */ |
| 1775 | #endif |
| 1776 | |
| 1777 | switch (-typenum) |
| 1778 | { |
| 1779 | case 1: |
| 1780 | /* The size of this and all the other types are fixed, defined |
| 1781 | by the debugging format. If there is a type called "int" which |
| 1782 | is other than 32 bits, then it should use a new negative type |
| 1783 | number (or avoid negative type numbers for that case). |
| 1784 | See stabs.texinfo. */ |
| 1785 | rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL); |
| 1786 | break; |
| 1787 | case 2: |
| 1788 | rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL); |
| 1789 | break; |
| 1790 | case 3: |
| 1791 | rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL); |
| 1792 | break; |
| 1793 | case 4: |
| 1794 | rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL); |
| 1795 | break; |
| 1796 | case 5: |
| 1797 | rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, |
| 1798 | "unsigned char", NULL); |
| 1799 | break; |
| 1800 | case 6: |
| 1801 | rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL); |
| 1802 | break; |
| 1803 | case 7: |
| 1804 | rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, |
| 1805 | "unsigned short", NULL); |
| 1806 | break; |
| 1807 | case 8: |
| 1808 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, |
| 1809 | "unsigned int", NULL); |
| 1810 | break; |
| 1811 | case 9: |
| 1812 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, |
| 1813 | "unsigned", NULL); |
| 1814 | case 10: |
| 1815 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, |
| 1816 | "unsigned long", NULL); |
| 1817 | break; |
| 1818 | case 11: |
| 1819 | rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL); |
| 1820 | break; |
| 1821 | case 12: |
| 1822 | /* IEEE single precision (32 bit). */ |
| 1823 | rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL); |
| 1824 | break; |
| 1825 | case 13: |
| 1826 | /* IEEE double precision (64 bit). */ |
| 1827 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL); |
| 1828 | break; |
| 1829 | case 14: |
| 1830 | /* This is an IEEE double on the RS/6000, and different machines with |
| 1831 | different sizes for "long double" should use different negative |
| 1832 | type numbers. See stabs.texinfo. */ |
| 1833 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL); |
| 1834 | break; |
| 1835 | case 15: |
| 1836 | rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL); |
| 1837 | break; |
| 1838 | case 16: |
| 1839 | rettype = init_type (TYPE_CODE_BOOL, 4, 0, "boolean", NULL); |
| 1840 | break; |
| 1841 | case 17: |
| 1842 | rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL); |
| 1843 | break; |
| 1844 | case 18: |
| 1845 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL); |
| 1846 | break; |
| 1847 | case 19: |
| 1848 | rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL); |
| 1849 | break; |
| 1850 | case 20: |
| 1851 | rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, |
| 1852 | "character", NULL); |
| 1853 | break; |
| 1854 | case 21: |
| 1855 | rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, |
| 1856 | "logical*1", NULL); |
| 1857 | break; |
| 1858 | case 22: |
| 1859 | rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED, |
| 1860 | "logical*2", NULL); |
| 1861 | break; |
| 1862 | case 23: |
| 1863 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
| 1864 | "logical*4", NULL); |
| 1865 | break; |
| 1866 | case 24: |
| 1867 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
| 1868 | "logical", NULL); |
| 1869 | break; |
| 1870 | case 25: |
| 1871 | /* Complex type consisting of two IEEE single precision values. */ |
| 1872 | rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL); |
| 1873 | break; |
| 1874 | case 26: |
| 1875 | /* Complex type consisting of two IEEE double precision values. */ |
| 1876 | rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL); |
| 1877 | break; |
| 1878 | case 27: |
| 1879 | rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL); |
| 1880 | break; |
| 1881 | case 28: |
| 1882 | rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL); |
| 1883 | break; |
| 1884 | case 29: |
| 1885 | rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL); |
| 1886 | break; |
| 1887 | case 30: |
| 1888 | rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL); |
| 1889 | break; |
| 1890 | } |
| 1891 | negative_types[-typenum] = rettype; |
| 1892 | return rettype; |
| 1893 | } |
| 1894 | \f |
| 1895 | /* This page contains subroutines of read_type. */ |
| 1896 | |
| 1897 | #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */ |
| 1898 | #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */ |
| 1899 | #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */ |
| 1900 | #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */ |
| 1901 | |
| 1902 | /* Read member function stabs info for C++ classes. The form of each member |
| 1903 | function data is: |
| 1904 | |
| 1905 | NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; |
| 1906 | |
| 1907 | An example with two member functions is: |
| 1908 | |
| 1909 | afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; |
| 1910 | |
| 1911 | For the case of overloaded operators, the format is op$::*.funcs, where |
| 1912 | $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator |
| 1913 | name (such as `+=') and `.' marks the end of the operator name. |
| 1914 | |
| 1915 | Returns 1 for success, 0 for failure. */ |
| 1916 | |
| 1917 | static int |
| 1918 | read_member_functions (fip, pp, type, objfile) |
| 1919 | struct field_info *fip; |
| 1920 | char **pp; |
| 1921 | struct type *type; |
| 1922 | struct objfile *objfile; |
| 1923 | { |
| 1924 | int nfn_fields = 0; |
| 1925 | int length = 0; |
| 1926 | /* Total number of member functions defined in this class. If the class |
| 1927 | defines two `f' functions, and one `g' function, then this will have |
| 1928 | the value 3. */ |
| 1929 | int total_length = 0; |
| 1930 | int i; |
| 1931 | struct next_fnfield |
| 1932 | { |
| 1933 | struct next_fnfield *next; |
| 1934 | struct fn_field fn_field; |
| 1935 | } *sublist; |
| 1936 | struct type *look_ahead_type; |
| 1937 | struct next_fnfieldlist *new_fnlist; |
| 1938 | struct next_fnfield *new_sublist; |
| 1939 | char *main_fn_name; |
| 1940 | register char *p; |
| 1941 | |
| 1942 | /* Process each list until we find something that is not a member function |
| 1943 | or find the end of the functions. */ |
| 1944 | |
| 1945 | while (**pp != ';') |
| 1946 | { |
| 1947 | /* We should be positioned at the start of the function name. |
| 1948 | Scan forward to find the first ':' and if it is not the |
| 1949 | first of a "::" delimiter, then this is not a member function. */ |
| 1950 | p = *pp; |
| 1951 | while (*p != ':') |
| 1952 | { |
| 1953 | p++; |
| 1954 | } |
| 1955 | if (p[1] != ':') |
| 1956 | { |
| 1957 | break; |
| 1958 | } |
| 1959 | |
| 1960 | sublist = NULL; |
| 1961 | look_ahead_type = NULL; |
| 1962 | length = 0; |
| 1963 | |
| 1964 | new_fnlist = (struct next_fnfieldlist *) |
| 1965 | xmalloc (sizeof (struct next_fnfieldlist)); |
| 1966 | make_cleanup (free, new_fnlist); |
| 1967 | memset (new_fnlist, 0, sizeof (struct next_fnfieldlist)); |
| 1968 | |
| 1969 | if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER) |
| 1970 | { |
| 1971 | /* This is a completely wierd case. In order to stuff in the |
| 1972 | names that might contain colons (the usual name delimiter), |
| 1973 | Mike Tiemann defined a different name format which is |
| 1974 | signalled if the identifier is "op$". In that case, the |
| 1975 | format is "op$::XXXX." where XXXX is the name. This is |
| 1976 | used for names like "+" or "=". YUUUUUUUK! FIXME! */ |
| 1977 | /* This lets the user type "break operator+". |
| 1978 | We could just put in "+" as the name, but that wouldn't |
| 1979 | work for "*". */ |
| 1980 | static char opname[32] = {'o', 'p', CPLUS_MARKER}; |
| 1981 | char *o = opname + 3; |
| 1982 | |
| 1983 | /* Skip past '::'. */ |
| 1984 | *pp = p + 2; |
| 1985 | |
| 1986 | STABS_CONTINUE (pp); |
| 1987 | p = *pp; |
| 1988 | while (*p != '.') |
| 1989 | { |
| 1990 | *o++ = *p++; |
| 1991 | } |
| 1992 | main_fn_name = savestring (opname, o - opname); |
| 1993 | /* Skip past '.' */ |
| 1994 | *pp = p + 1; |
| 1995 | } |
| 1996 | else |
| 1997 | { |
| 1998 | main_fn_name = savestring (*pp, p - *pp); |
| 1999 | /* Skip past '::'. */ |
| 2000 | *pp = p + 2; |
| 2001 | } |
| 2002 | new_fnlist -> fn_fieldlist.name = main_fn_name; |
| 2003 | |
| 2004 | do |
| 2005 | { |
| 2006 | new_sublist = |
| 2007 | (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield)); |
| 2008 | make_cleanup (free, new_sublist); |
| 2009 | memset (new_sublist, 0, sizeof (struct next_fnfield)); |
| 2010 | |
| 2011 | /* Check for and handle cretinous dbx symbol name continuation! */ |
| 2012 | if (look_ahead_type == NULL) |
| 2013 | { |
| 2014 | /* Normal case. */ |
| 2015 | STABS_CONTINUE (pp); |
| 2016 | |
| 2017 | new_sublist -> fn_field.type = read_type (pp, objfile); |
| 2018 | if (**pp != ':') |
| 2019 | { |
| 2020 | /* Invalid symtab info for member function. */ |
| 2021 | return 0; |
| 2022 | } |
| 2023 | } |
| 2024 | else |
| 2025 | { |
| 2026 | /* g++ version 1 kludge */ |
| 2027 | new_sublist -> fn_field.type = look_ahead_type; |
| 2028 | look_ahead_type = NULL; |
| 2029 | } |
| 2030 | |
| 2031 | (*pp)++; |
| 2032 | p = *pp; |
| 2033 | while (*p != ';') |
| 2034 | { |
| 2035 | p++; |
| 2036 | } |
| 2037 | |
| 2038 | /* If this is just a stub, then we don't have the real name here. */ |
| 2039 | |
| 2040 | if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB) |
| 2041 | { |
| 2042 | if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type)) |
| 2043 | TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type; |
| 2044 | new_sublist -> fn_field.is_stub = 1; |
| 2045 | } |
| 2046 | new_sublist -> fn_field.physname = savestring (*pp, p - *pp); |
| 2047 | *pp = p + 1; |
| 2048 | |
| 2049 | /* Set this member function's visibility fields. */ |
| 2050 | switch (*(*pp)++) |
| 2051 | { |
| 2052 | case VISIBILITY_PRIVATE: |
| 2053 | new_sublist -> fn_field.is_private = 1; |
| 2054 | break; |
| 2055 | case VISIBILITY_PROTECTED: |
| 2056 | new_sublist -> fn_field.is_protected = 1; |
| 2057 | break; |
| 2058 | } |
| 2059 | |
| 2060 | STABS_CONTINUE (pp); |
| 2061 | switch (**pp) |
| 2062 | { |
| 2063 | case 'A': /* Normal functions. */ |
| 2064 | new_sublist -> fn_field.is_const = 0; |
| 2065 | new_sublist -> fn_field.is_volatile = 0; |
| 2066 | (*pp)++; |
| 2067 | break; |
| 2068 | case 'B': /* `const' member functions. */ |
| 2069 | new_sublist -> fn_field.is_const = 1; |
| 2070 | new_sublist -> fn_field.is_volatile = 0; |
| 2071 | (*pp)++; |
| 2072 | break; |
| 2073 | case 'C': /* `volatile' member function. */ |
| 2074 | new_sublist -> fn_field.is_const = 0; |
| 2075 | new_sublist -> fn_field.is_volatile = 1; |
| 2076 | (*pp)++; |
| 2077 | break; |
| 2078 | case 'D': /* `const volatile' member function. */ |
| 2079 | new_sublist -> fn_field.is_const = 1; |
| 2080 | new_sublist -> fn_field.is_volatile = 1; |
| 2081 | (*pp)++; |
| 2082 | break; |
| 2083 | case '*': /* File compiled with g++ version 1 -- no info */ |
| 2084 | case '?': |
| 2085 | case '.': |
| 2086 | break; |
| 2087 | default: |
| 2088 | complain (&const_vol_complaint, **pp); |
| 2089 | break; |
| 2090 | } |
| 2091 | |
| 2092 | switch (*(*pp)++) |
| 2093 | { |
| 2094 | case '*': |
| 2095 | { |
| 2096 | int nbits; |
| 2097 | /* virtual member function, followed by index. |
| 2098 | The sign bit is set to distinguish pointers-to-methods |
| 2099 | from virtual function indicies. Since the array is |
| 2100 | in words, the quantity must be shifted left by 1 |
| 2101 | on 16 bit machine, and by 2 on 32 bit machine, forcing |
| 2102 | the sign bit out, and usable as a valid index into |
| 2103 | the array. Remove the sign bit here. */ |
| 2104 | new_sublist -> fn_field.voffset = |
| 2105 | (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2; |
| 2106 | if (nbits != 0) |
| 2107 | return 0; |
| 2108 | |
| 2109 | STABS_CONTINUE (pp); |
| 2110 | if (**pp == ';' || **pp == '\0') |
| 2111 | { |
| 2112 | /* Must be g++ version 1. */ |
| 2113 | new_sublist -> fn_field.fcontext = 0; |
| 2114 | } |
| 2115 | else |
| 2116 | { |
| 2117 | /* Figure out from whence this virtual function came. |
| 2118 | It may belong to virtual function table of |
| 2119 | one of its baseclasses. */ |
| 2120 | look_ahead_type = read_type (pp, objfile); |
| 2121 | if (**pp == ':') |
| 2122 | { |
| 2123 | /* g++ version 1 overloaded methods. */ |
| 2124 | } |
| 2125 | else |
| 2126 | { |
| 2127 | new_sublist -> fn_field.fcontext = look_ahead_type; |
| 2128 | if (**pp != ';') |
| 2129 | { |
| 2130 | return 0; |
| 2131 | } |
| 2132 | else |
| 2133 | { |
| 2134 | ++*pp; |
| 2135 | } |
| 2136 | look_ahead_type = NULL; |
| 2137 | } |
| 2138 | } |
| 2139 | break; |
| 2140 | } |
| 2141 | case '?': |
| 2142 | /* static member function. */ |
| 2143 | new_sublist -> fn_field.voffset = VOFFSET_STATIC; |
| 2144 | if (strncmp (new_sublist -> fn_field.physname, |
| 2145 | main_fn_name, strlen (main_fn_name))) |
| 2146 | { |
| 2147 | new_sublist -> fn_field.is_stub = 1; |
| 2148 | } |
| 2149 | break; |
| 2150 | |
| 2151 | default: |
| 2152 | /* error */ |
| 2153 | complain (&member_fn_complaint, (*pp)[-1]); |
| 2154 | /* Fall through into normal member function. */ |
| 2155 | |
| 2156 | case '.': |
| 2157 | /* normal member function. */ |
| 2158 | new_sublist -> fn_field.voffset = 0; |
| 2159 | new_sublist -> fn_field.fcontext = 0; |
| 2160 | break; |
| 2161 | } |
| 2162 | |
| 2163 | new_sublist -> next = sublist; |
| 2164 | sublist = new_sublist; |
| 2165 | length++; |
| 2166 | STABS_CONTINUE (pp); |
| 2167 | } |
| 2168 | while (**pp != ';' && **pp != '\0'); |
| 2169 | |
| 2170 | (*pp)++; |
| 2171 | |
| 2172 | new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *) |
| 2173 | obstack_alloc (&objfile -> type_obstack, |
| 2174 | sizeof (struct fn_field) * length); |
| 2175 | memset (new_fnlist -> fn_fieldlist.fn_fields, 0, |
| 2176 | sizeof (struct fn_field) * length); |
| 2177 | for (i = length; (i--, sublist); sublist = sublist -> next) |
| 2178 | { |
| 2179 | new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field; |
| 2180 | } |
| 2181 | |
| 2182 | new_fnlist -> fn_fieldlist.length = length; |
| 2183 | new_fnlist -> next = fip -> fnlist; |
| 2184 | fip -> fnlist = new_fnlist; |
| 2185 | nfn_fields++; |
| 2186 | total_length += length; |
| 2187 | STABS_CONTINUE (pp); |
| 2188 | } |
| 2189 | |
| 2190 | if (nfn_fields) |
| 2191 | { |
| 2192 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 2193 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 2194 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); |
| 2195 | memset (TYPE_FN_FIELDLISTS (type), 0, |
| 2196 | sizeof (struct fn_fieldlist) * nfn_fields); |
| 2197 | TYPE_NFN_FIELDS (type) = nfn_fields; |
| 2198 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; |
| 2199 | } |
| 2200 | |
| 2201 | return 1; |
| 2202 | } |
| 2203 | |
| 2204 | /* Special GNU C++ name. |
| 2205 | |
| 2206 | Returns 1 for success, 0 for failure. "failure" means that we can't |
| 2207 | keep parsing and it's time for error_type(). */ |
| 2208 | |
| 2209 | static int |
| 2210 | read_cpp_abbrev (fip, pp, type, objfile) |
| 2211 | struct field_info *fip; |
| 2212 | char **pp; |
| 2213 | struct type *type; |
| 2214 | struct objfile *objfile; |
| 2215 | { |
| 2216 | register char *p; |
| 2217 | char *name; |
| 2218 | char cpp_abbrev; |
| 2219 | struct type *context; |
| 2220 | |
| 2221 | p = *pp; |
| 2222 | if (*++p == 'v') |
| 2223 | { |
| 2224 | name = NULL; |
| 2225 | cpp_abbrev = *++p; |
| 2226 | |
| 2227 | *pp = p + 1; |
| 2228 | |
| 2229 | /* At this point, *pp points to something like "22:23=*22...", |
| 2230 | where the type number before the ':' is the "context" and |
| 2231 | everything after is a regular type definition. Lookup the |
| 2232 | type, find it's name, and construct the field name. */ |
| 2233 | |
| 2234 | context = read_type (pp, objfile); |
| 2235 | |
| 2236 | switch (cpp_abbrev) |
| 2237 | { |
| 2238 | case 'f': /* $vf -- a virtual function table pointer */ |
| 2239 | fip->list->field.name = |
| 2240 | obconcat (&objfile->type_obstack, vptr_name, "", ""); |
| 2241 | break; |
| 2242 | |
| 2243 | case 'b': /* $vb -- a virtual bsomethingorother */ |
| 2244 | name = type_name_no_tag (context); |
| 2245 | if (name == NULL) |
| 2246 | { |
| 2247 | complain (&invalid_cpp_type_complaint, symnum); |
| 2248 | name = "FOO"; |
| 2249 | } |
| 2250 | fip->list->field.name = |
| 2251 | obconcat (&objfile->type_obstack, vb_name, name, ""); |
| 2252 | break; |
| 2253 | |
| 2254 | default: |
| 2255 | complain (&invalid_cpp_abbrev_complaint, *pp); |
| 2256 | fip->list->field.name = |
| 2257 | obconcat (&objfile->type_obstack, |
| 2258 | "INVALID_CPLUSPLUS_ABBREV", "", ""); |
| 2259 | break; |
| 2260 | } |
| 2261 | |
| 2262 | /* At this point, *pp points to the ':'. Skip it and read the |
| 2263 | field type. */ |
| 2264 | |
| 2265 | p = ++(*pp); |
| 2266 | if (p[-1] != ':') |
| 2267 | { |
| 2268 | complain (&invalid_cpp_abbrev_complaint, *pp); |
| 2269 | return 0; |
| 2270 | } |
| 2271 | fip->list->field.type = read_type (pp, objfile); |
| 2272 | if (**pp == ',') |
| 2273 | (*pp)++; /* Skip the comma. */ |
| 2274 | else |
| 2275 | return 0; |
| 2276 | |
| 2277 | { |
| 2278 | int nbits; |
| 2279 | fip->list->field.bitpos = read_huge_number (pp, ';', &nbits); |
| 2280 | if (nbits != 0) |
| 2281 | return 0; |
| 2282 | } |
| 2283 | /* This field is unpacked. */ |
| 2284 | fip->list->field.bitsize = 0; |
| 2285 | fip->list->visibility = VISIBILITY_PRIVATE; |
| 2286 | } |
| 2287 | else |
| 2288 | { |
| 2289 | complain (&invalid_cpp_abbrev_complaint, *pp); |
| 2290 | /* We have no idea what syntax an unrecognized abbrev would have, so |
| 2291 | better return 0. If we returned 1, we would need to at least advance |
| 2292 | *pp to avoid an infinite loop. */ |
| 2293 | return 0; |
| 2294 | } |
| 2295 | return 1; |
| 2296 | } |
| 2297 | |
| 2298 | static void |
| 2299 | read_one_struct_field (fip, pp, p, type, objfile) |
| 2300 | struct field_info *fip; |
| 2301 | char **pp; |
| 2302 | char *p; |
| 2303 | struct type *type; |
| 2304 | struct objfile *objfile; |
| 2305 | { |
| 2306 | fip -> list -> field.name = |
| 2307 | obsavestring (*pp, p - *pp, &objfile -> type_obstack); |
| 2308 | *pp = p + 1; |
| 2309 | |
| 2310 | /* This means we have a visibility for a field coming. */ |
| 2311 | if (**pp == '/') |
| 2312 | { |
| 2313 | (*pp)++; |
| 2314 | fip -> list -> visibility = *(*pp)++; |
| 2315 | } |
| 2316 | else |
| 2317 | { |
| 2318 | /* normal dbx-style format, no explicit visibility */ |
| 2319 | fip -> list -> visibility = VISIBILITY_PUBLIC; |
| 2320 | } |
| 2321 | |
| 2322 | fip -> list -> field.type = read_type (pp, objfile); |
| 2323 | if (**pp == ':') |
| 2324 | { |
| 2325 | p = ++(*pp); |
| 2326 | #if 0 |
| 2327 | /* Possible future hook for nested types. */ |
| 2328 | if (**pp == '!') |
| 2329 | { |
| 2330 | fip -> list -> field.bitpos = (long)-2; /* nested type */ |
| 2331 | p = ++(*pp); |
| 2332 | } |
| 2333 | else |
| 2334 | #endif |
| 2335 | { |
| 2336 | /* Static class member. */ |
| 2337 | fip -> list -> field.bitpos = (long) -1; |
| 2338 | } |
| 2339 | while (*p != ';') |
| 2340 | { |
| 2341 | p++; |
| 2342 | } |
| 2343 | fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp); |
| 2344 | *pp = p + 1; |
| 2345 | return; |
| 2346 | } |
| 2347 | else if (**pp != ',') |
| 2348 | { |
| 2349 | /* Bad structure-type format. */ |
| 2350 | complain (&stabs_general_complaint, "bad structure-type format"); |
| 2351 | return; |
| 2352 | } |
| 2353 | |
| 2354 | (*pp)++; /* Skip the comma. */ |
| 2355 | |
| 2356 | { |
| 2357 | int nbits; |
| 2358 | fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits); |
| 2359 | if (nbits != 0) |
| 2360 | { |
| 2361 | complain (&stabs_general_complaint, "bad structure-type format"); |
| 2362 | return; |
| 2363 | } |
| 2364 | fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits); |
| 2365 | if (nbits != 0) |
| 2366 | { |
| 2367 | complain (&stabs_general_complaint, "bad structure-type format"); |
| 2368 | return; |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0) |
| 2373 | { |
| 2374 | /* This can happen in two cases: (1) at least for gcc 2.4.5 or so, |
| 2375 | it is a field which has been optimized out. The correct stab for |
| 2376 | this case is to use VISIBILITY_IGNORE, but that is a recent |
| 2377 | invention. (2) It is a 0-size array. For example |
| 2378 | union { int num; char str[0]; } foo. Printing "<no value>" for |
| 2379 | str in "p foo" is OK, since foo.str (and thus foo.str[3]) |
| 2380 | will continue to work, and a 0-size array as a whole doesn't |
| 2381 | have any contents to print. |
| 2382 | |
| 2383 | I suspect this probably could also happen with gcc -gstabs (not |
| 2384 | -gstabs+) for static fields, and perhaps other C++ extensions. |
| 2385 | Hopefully few people use -gstabs with gdb, since it is intended |
| 2386 | for dbx compatibility. */ |
| 2387 | |
| 2388 | /* Ignore this field. */ |
| 2389 | fip -> list-> visibility = VISIBILITY_IGNORE; |
| 2390 | } |
| 2391 | else |
| 2392 | { |
| 2393 | /* Detect an unpacked field and mark it as such. |
| 2394 | dbx gives a bit size for all fields. |
| 2395 | Note that forward refs cannot be packed, |
| 2396 | and treat enums as if they had the width of ints. */ |
| 2397 | |
| 2398 | if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT |
| 2399 | && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM) |
| 2400 | { |
| 2401 | fip -> list -> field.bitsize = 0; |
| 2402 | } |
| 2403 | if ((fip -> list -> field.bitsize |
| 2404 | == TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type) |
| 2405 | || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM |
| 2406 | && (fip -> list -> field.bitsize |
| 2407 | == TARGET_INT_BIT) |
| 2408 | ) |
| 2409 | ) |
| 2410 | && |
| 2411 | fip -> list -> field.bitpos % 8 == 0) |
| 2412 | { |
| 2413 | fip -> list -> field.bitsize = 0; |
| 2414 | } |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | |
| 2419 | /* Read struct or class data fields. They have the form: |
| 2420 | |
| 2421 | NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; |
| 2422 | |
| 2423 | At the end, we see a semicolon instead of a field. |
| 2424 | |
| 2425 | In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for |
| 2426 | a static field. |
| 2427 | |
| 2428 | The optional VISIBILITY is one of: |
| 2429 | |
| 2430 | '/0' (VISIBILITY_PRIVATE) |
| 2431 | '/1' (VISIBILITY_PROTECTED) |
| 2432 | '/2' (VISIBILITY_PUBLIC) |
| 2433 | '/9' (VISIBILITY_IGNORE) |
| 2434 | |
| 2435 | or nothing, for C style fields with public visibility. |
| 2436 | |
| 2437 | Returns 1 for success, 0 for failure. */ |
| 2438 | |
| 2439 | static int |
| 2440 | read_struct_fields (fip, pp, type, objfile) |
| 2441 | struct field_info *fip; |
| 2442 | char **pp; |
| 2443 | struct type *type; |
| 2444 | struct objfile *objfile; |
| 2445 | { |
| 2446 | register char *p; |
| 2447 | struct nextfield *new; |
| 2448 | |
| 2449 | /* We better set p right now, in case there are no fields at all... */ |
| 2450 | |
| 2451 | p = *pp; |
| 2452 | |
| 2453 | /* Read each data member type until we find the terminating ';' at the end of |
| 2454 | the data member list, or break for some other reason such as finding the |
| 2455 | start of the member function list. */ |
| 2456 | |
| 2457 | while (**pp != ';') |
| 2458 | { |
| 2459 | if (os9k_stabs && **pp == ',') break; |
| 2460 | STABS_CONTINUE (pp); |
| 2461 | /* Get space to record the next field's data. */ |
| 2462 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 2463 | make_cleanup (free, new); |
| 2464 | memset (new, 0, sizeof (struct nextfield)); |
| 2465 | new -> next = fip -> list; |
| 2466 | fip -> list = new; |
| 2467 | |
| 2468 | /* Get the field name. */ |
| 2469 | p = *pp; |
| 2470 | |
| 2471 | /* If is starts with CPLUS_MARKER it is a special abbreviation, |
| 2472 | unless the CPLUS_MARKER is followed by an underscore, in |
| 2473 | which case it is just the name of an anonymous type, which we |
| 2474 | should handle like any other type name. We accept either '$' |
| 2475 | or '.', because a field name can never contain one of these |
| 2476 | characters except as a CPLUS_MARKER (we probably should be |
| 2477 | doing that in most parts of GDB). */ |
| 2478 | |
| 2479 | if ((*p == '$' || *p == '.') && p[1] != '_') |
| 2480 | { |
| 2481 | if (!read_cpp_abbrev (fip, pp, type, objfile)) |
| 2482 | return 0; |
| 2483 | continue; |
| 2484 | } |
| 2485 | |
| 2486 | /* Look for the ':' that separates the field name from the field |
| 2487 | values. Data members are delimited by a single ':', while member |
| 2488 | functions are delimited by a pair of ':'s. When we hit the member |
| 2489 | functions (if any), terminate scan loop and return. */ |
| 2490 | |
| 2491 | while (*p != ':' && *p != '\0') |
| 2492 | { |
| 2493 | p++; |
| 2494 | } |
| 2495 | if (*p == '\0') |
| 2496 | return 0; |
| 2497 | |
| 2498 | /* Check to see if we have hit the member functions yet. */ |
| 2499 | if (p[1] == ':') |
| 2500 | { |
| 2501 | break; |
| 2502 | } |
| 2503 | read_one_struct_field (fip, pp, p, type, objfile); |
| 2504 | } |
| 2505 | if (p[0] == ':' && p[1] == ':') |
| 2506 | { |
| 2507 | /* chill the list of fields: the last entry (at the head) is a |
| 2508 | partially constructed entry which we now scrub. */ |
| 2509 | fip -> list = fip -> list -> next; |
| 2510 | } |
| 2511 | return 1; |
| 2512 | } |
| 2513 | |
| 2514 | /* The stabs for C++ derived classes contain baseclass information which |
| 2515 | is marked by a '!' character after the total size. This function is |
| 2516 | called when we encounter the baseclass marker, and slurps up all the |
| 2517 | baseclass information. |
| 2518 | |
| 2519 | Immediately following the '!' marker is the number of base classes that |
| 2520 | the class is derived from, followed by information for each base class. |
| 2521 | For each base class, there are two visibility specifiers, a bit offset |
| 2522 | to the base class information within the derived class, a reference to |
| 2523 | the type for the base class, and a terminating semicolon. |
| 2524 | |
| 2525 | A typical example, with two base classes, would be "!2,020,19;0264,21;". |
| 2526 | ^^ ^ ^ ^ ^ ^ ^ |
| 2527 | Baseclass information marker __________________|| | | | | | | |
| 2528 | Number of baseclasses __________________________| | | | | | | |
| 2529 | Visibility specifiers (2) ________________________| | | | | | |
| 2530 | Offset in bits from start of class _________________| | | | | |
| 2531 | Type number for base class ___________________________| | | | |
| 2532 | Visibility specifiers (2) _______________________________| | | |
| 2533 | Offset in bits from start of class ________________________| | |
| 2534 | Type number of base class ____________________________________| |
| 2535 | |
| 2536 | Return 1 for success, 0 for (error-type-inducing) failure. */ |
| 2537 | |
| 2538 | static int |
| 2539 | read_baseclasses (fip, pp, type, objfile) |
| 2540 | struct field_info *fip; |
| 2541 | char **pp; |
| 2542 | struct type *type; |
| 2543 | struct objfile *objfile; |
| 2544 | { |
| 2545 | int i; |
| 2546 | struct nextfield *new; |
| 2547 | |
| 2548 | if (**pp != '!') |
| 2549 | { |
| 2550 | return 1; |
| 2551 | } |
| 2552 | else |
| 2553 | { |
| 2554 | /* Skip the '!' baseclass information marker. */ |
| 2555 | (*pp)++; |
| 2556 | } |
| 2557 | |
| 2558 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 2559 | { |
| 2560 | int nbits; |
| 2561 | TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits); |
| 2562 | if (nbits != 0) |
| 2563 | return 0; |
| 2564 | } |
| 2565 | |
| 2566 | #if 0 |
| 2567 | /* Some stupid compilers have trouble with the following, so break |
| 2568 | it up into simpler expressions. */ |
| 2569 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) |
| 2570 | TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); |
| 2571 | #else |
| 2572 | { |
| 2573 | int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); |
| 2574 | char *pointer; |
| 2575 | |
| 2576 | pointer = (char *) TYPE_ALLOC (type, num_bytes); |
| 2577 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; |
| 2578 | } |
| 2579 | #endif /* 0 */ |
| 2580 | |
| 2581 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); |
| 2582 | |
| 2583 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
| 2584 | { |
| 2585 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 2586 | make_cleanup (free, new); |
| 2587 | memset (new, 0, sizeof (struct nextfield)); |
| 2588 | new -> next = fip -> list; |
| 2589 | fip -> list = new; |
| 2590 | new -> field.bitsize = 0; /* this should be an unpacked field! */ |
| 2591 | |
| 2592 | STABS_CONTINUE (pp); |
| 2593 | switch (**pp) |
| 2594 | { |
| 2595 | case '0': |
| 2596 | /* Nothing to do. */ |
| 2597 | break; |
| 2598 | case '1': |
| 2599 | SET_TYPE_FIELD_VIRTUAL (type, i); |
| 2600 | break; |
| 2601 | default: |
| 2602 | /* Unknown character. Complain and treat it as non-virtual. */ |
| 2603 | { |
| 2604 | static struct complaint msg = { |
| 2605 | "Unknown virtual character `%c' for baseclass", 0, 0}; |
| 2606 | complain (&msg, **pp); |
| 2607 | } |
| 2608 | } |
| 2609 | ++(*pp); |
| 2610 | |
| 2611 | new -> visibility = *(*pp)++; |
| 2612 | switch (new -> visibility) |
| 2613 | { |
| 2614 | case VISIBILITY_PRIVATE: |
| 2615 | case VISIBILITY_PROTECTED: |
| 2616 | case VISIBILITY_PUBLIC: |
| 2617 | break; |
| 2618 | default: |
| 2619 | /* Bad visibility format. Complain and treat it as |
| 2620 | public. */ |
| 2621 | { |
| 2622 | static struct complaint msg = { |
| 2623 | "Unknown visibility `%c' for baseclass", 0, 0}; |
| 2624 | complain (&msg, new -> visibility); |
| 2625 | new -> visibility = VISIBILITY_PUBLIC; |
| 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | { |
| 2630 | int nbits; |
| 2631 | |
| 2632 | /* The remaining value is the bit offset of the portion of the object |
| 2633 | corresponding to this baseclass. Always zero in the absence of |
| 2634 | multiple inheritance. */ |
| 2635 | |
| 2636 | new -> field.bitpos = read_huge_number (pp, ',', &nbits); |
| 2637 | if (nbits != 0) |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
| 2641 | /* The last piece of baseclass information is the type of the |
| 2642 | base class. Read it, and remember it's type name as this |
| 2643 | field's name. */ |
| 2644 | |
| 2645 | new -> field.type = read_type (pp, objfile); |
| 2646 | new -> field.name = type_name_no_tag (new -> field.type); |
| 2647 | |
| 2648 | /* skip trailing ';' and bump count of number of fields seen */ |
| 2649 | if (**pp == ';') |
| 2650 | (*pp)++; |
| 2651 | else |
| 2652 | return 0; |
| 2653 | } |
| 2654 | return 1; |
| 2655 | } |
| 2656 | |
| 2657 | /* The tail end of stabs for C++ classes that contain a virtual function |
| 2658 | pointer contains a tilde, a %, and a type number. |
| 2659 | The type number refers to the base class (possibly this class itself) which |
| 2660 | contains the vtable pointer for the current class. |
| 2661 | |
| 2662 | This function is called when we have parsed all the method declarations, |
| 2663 | so we can look for the vptr base class info. */ |
| 2664 | |
| 2665 | static int |
| 2666 | read_tilde_fields (fip, pp, type, objfile) |
| 2667 | struct field_info *fip; |
| 2668 | char **pp; |
| 2669 | struct type *type; |
| 2670 | struct objfile *objfile; |
| 2671 | { |
| 2672 | register char *p; |
| 2673 | |
| 2674 | STABS_CONTINUE (pp); |
| 2675 | |
| 2676 | /* If we are positioned at a ';', then skip it. */ |
| 2677 | if (**pp == ';') |
| 2678 | { |
| 2679 | (*pp)++; |
| 2680 | } |
| 2681 | |
| 2682 | if (**pp == '~') |
| 2683 | { |
| 2684 | (*pp)++; |
| 2685 | |
| 2686 | if (**pp == '=' || **pp == '+' || **pp == '-') |
| 2687 | { |
| 2688 | /* Obsolete flags that used to indicate the presence |
| 2689 | of constructors and/or destructors. */ |
| 2690 | (*pp)++; |
| 2691 | } |
| 2692 | |
| 2693 | /* Read either a '%' or the final ';'. */ |
| 2694 | if (*(*pp)++ == '%') |
| 2695 | { |
| 2696 | /* The next number is the type number of the base class |
| 2697 | (possibly our own class) which supplies the vtable for |
| 2698 | this class. Parse it out, and search that class to find |
| 2699 | its vtable pointer, and install those into TYPE_VPTR_BASETYPE |
| 2700 | and TYPE_VPTR_FIELDNO. */ |
| 2701 | |
| 2702 | struct type *t; |
| 2703 | int i; |
| 2704 | |
| 2705 | t = read_type (pp, objfile); |
| 2706 | p = (*pp)++; |
| 2707 | while (*p != '\0' && *p != ';') |
| 2708 | { |
| 2709 | p++; |
| 2710 | } |
| 2711 | if (*p == '\0') |
| 2712 | { |
| 2713 | /* Premature end of symbol. */ |
| 2714 | return 0; |
| 2715 | } |
| 2716 | |
| 2717 | TYPE_VPTR_BASETYPE (type) = t; |
| 2718 | if (type == t) /* Our own class provides vtbl ptr */ |
| 2719 | { |
| 2720 | for (i = TYPE_NFIELDS (t) - 1; |
| 2721 | i >= TYPE_N_BASECLASSES (t); |
| 2722 | --i) |
| 2723 | { |
| 2724 | if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name, |
| 2725 | sizeof (vptr_name) - 1)) |
| 2726 | { |
| 2727 | TYPE_VPTR_FIELDNO (type) = i; |
| 2728 | goto gotit; |
| 2729 | } |
| 2730 | } |
| 2731 | /* Virtual function table field not found. */ |
| 2732 | complain (&vtbl_notfound_complaint, TYPE_NAME (type)); |
| 2733 | return 0; |
| 2734 | } |
| 2735 | else |
| 2736 | { |
| 2737 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); |
| 2738 | } |
| 2739 | |
| 2740 | gotit: |
| 2741 | *pp = p + 1; |
| 2742 | } |
| 2743 | } |
| 2744 | return 1; |
| 2745 | } |
| 2746 | |
| 2747 | static int |
| 2748 | attach_fn_fields_to_type (fip, type) |
| 2749 | struct field_info *fip; |
| 2750 | register struct type *type; |
| 2751 | { |
| 2752 | register int n; |
| 2753 | |
| 2754 | for (n = TYPE_NFN_FIELDS (type); |
| 2755 | fip -> fnlist != NULL; |
| 2756 | fip -> fnlist = fip -> fnlist -> next) |
| 2757 | { |
| 2758 | --n; /* Circumvent Sun3 compiler bug */ |
| 2759 | TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist; |
| 2760 | } |
| 2761 | return 1; |
| 2762 | } |
| 2763 | |
| 2764 | /* Create the vector of fields, and record how big it is. |
| 2765 | We need this info to record proper virtual function table information |
| 2766 | for this class's virtual functions. */ |
| 2767 | |
| 2768 | static int |
| 2769 | attach_fields_to_type (fip, type, objfile) |
| 2770 | struct field_info *fip; |
| 2771 | register struct type *type; |
| 2772 | struct objfile *objfile; |
| 2773 | { |
| 2774 | register int nfields = 0; |
| 2775 | register int non_public_fields = 0; |
| 2776 | register struct nextfield *scan; |
| 2777 | |
| 2778 | /* Count up the number of fields that we have, as well as taking note of |
| 2779 | whether or not there are any non-public fields, which requires us to |
| 2780 | allocate and build the private_field_bits and protected_field_bits |
| 2781 | bitfields. */ |
| 2782 | |
| 2783 | for (scan = fip -> list; scan != NULL; scan = scan -> next) |
| 2784 | { |
| 2785 | nfields++; |
| 2786 | if (scan -> visibility != VISIBILITY_PUBLIC) |
| 2787 | { |
| 2788 | non_public_fields++; |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | /* Now we know how many fields there are, and whether or not there are any |
| 2793 | non-public fields. Record the field count, allocate space for the |
| 2794 | array of fields, and create blank visibility bitfields if necessary. */ |
| 2795 | |
| 2796 | TYPE_NFIELDS (type) = nfields; |
| 2797 | TYPE_FIELDS (type) = (struct field *) |
| 2798 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
| 2799 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); |
| 2800 | |
| 2801 | if (non_public_fields) |
| 2802 | { |
| 2803 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 2804 | |
| 2805 | TYPE_FIELD_PRIVATE_BITS (type) = |
| 2806 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 2807 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); |
| 2808 | |
| 2809 | TYPE_FIELD_PROTECTED_BITS (type) = |
| 2810 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 2811 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); |
| 2812 | |
| 2813 | TYPE_FIELD_IGNORE_BITS (type) = |
| 2814 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 2815 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); |
| 2816 | } |
| 2817 | |
| 2818 | /* Copy the saved-up fields into the field vector. Start from the head |
| 2819 | of the list, adding to the tail of the field array, so that they end |
| 2820 | up in the same order in the array in which they were added to the list. */ |
| 2821 | |
| 2822 | while (nfields-- > 0) |
| 2823 | { |
| 2824 | TYPE_FIELD (type, nfields) = fip -> list -> field; |
| 2825 | switch (fip -> list -> visibility) |
| 2826 | { |
| 2827 | case VISIBILITY_PRIVATE: |
| 2828 | SET_TYPE_FIELD_PRIVATE (type, nfields); |
| 2829 | break; |
| 2830 | |
| 2831 | case VISIBILITY_PROTECTED: |
| 2832 | SET_TYPE_FIELD_PROTECTED (type, nfields); |
| 2833 | break; |
| 2834 | |
| 2835 | case VISIBILITY_IGNORE: |
| 2836 | SET_TYPE_FIELD_IGNORE (type, nfields); |
| 2837 | break; |
| 2838 | |
| 2839 | case VISIBILITY_PUBLIC: |
| 2840 | break; |
| 2841 | |
| 2842 | default: |
| 2843 | /* Unknown visibility. Complain and treat it as public. */ |
| 2844 | { |
| 2845 | static struct complaint msg = { |
| 2846 | "Unknown visibility `%c' for field", 0, 0}; |
| 2847 | complain (&msg, fip -> list -> visibility); |
| 2848 | } |
| 2849 | break; |
| 2850 | } |
| 2851 | fip -> list = fip -> list -> next; |
| 2852 | } |
| 2853 | return 1; |
| 2854 | } |
| 2855 | |
| 2856 | /* Read the description of a structure (or union type) and return an object |
| 2857 | describing the type. |
| 2858 | |
| 2859 | PP points to a character pointer that points to the next unconsumed token |
| 2860 | in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", |
| 2861 | *PP will point to "4a:1,0,32;;". |
| 2862 | |
| 2863 | TYPE points to an incomplete type that needs to be filled in. |
| 2864 | |
| 2865 | OBJFILE points to the current objfile from which the stabs information is |
| 2866 | being read. (Note that it is redundant in that TYPE also contains a pointer |
| 2867 | to this same objfile, so it might be a good idea to eliminate it. FIXME). |
| 2868 | */ |
| 2869 | |
| 2870 | static struct type * |
| 2871 | read_struct_type (pp, type, objfile) |
| 2872 | char **pp; |
| 2873 | struct type *type; |
| 2874 | struct objfile *objfile; |
| 2875 | { |
| 2876 | struct cleanup *back_to; |
| 2877 | struct field_info fi; |
| 2878 | |
| 2879 | fi.list = NULL; |
| 2880 | fi.fnlist = NULL; |
| 2881 | |
| 2882 | back_to = make_cleanup (null_cleanup, 0); |
| 2883 | |
| 2884 | INIT_CPLUS_SPECIFIC (type); |
| 2885 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; |
| 2886 | |
| 2887 | /* First comes the total size in bytes. */ |
| 2888 | |
| 2889 | { |
| 2890 | int nbits; |
| 2891 | TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits); |
| 2892 | if (nbits != 0) |
| 2893 | return error_type (pp); |
| 2894 | } |
| 2895 | |
| 2896 | /* Now read the baseclasses, if any, read the regular C struct or C++ |
| 2897 | class member fields, attach the fields to the type, read the C++ |
| 2898 | member functions, attach them to the type, and then read any tilde |
| 2899 | field (baseclass specifier for the class holding the main vtable). */ |
| 2900 | |
| 2901 | if (!read_baseclasses (&fi, pp, type, objfile) |
| 2902 | || !read_struct_fields (&fi, pp, type, objfile) |
| 2903 | || !attach_fields_to_type (&fi, type, objfile) |
| 2904 | || !read_member_functions (&fi, pp, type, objfile) |
| 2905 | || !attach_fn_fields_to_type (&fi, type) |
| 2906 | || !read_tilde_fields (&fi, pp, type, objfile)) |
| 2907 | { |
| 2908 | do_cleanups (back_to); |
| 2909 | return (error_type (pp)); |
| 2910 | } |
| 2911 | |
| 2912 | do_cleanups (back_to); |
| 2913 | return (type); |
| 2914 | } |
| 2915 | |
| 2916 | /* Read a definition of an array type, |
| 2917 | and create and return a suitable type object. |
| 2918 | Also creates a range type which represents the bounds of that |
| 2919 | array. */ |
| 2920 | |
| 2921 | static struct type * |
| 2922 | read_array_type (pp, type, objfile) |
| 2923 | register char **pp; |
| 2924 | register struct type *type; |
| 2925 | struct objfile *objfile; |
| 2926 | { |
| 2927 | struct type *index_type, *element_type, *range_type; |
| 2928 | int lower, upper; |
| 2929 | int adjustable = 0; |
| 2930 | int nbits; |
| 2931 | |
| 2932 | /* Format of an array type: |
| 2933 | "ar<index type>;lower;upper;<array_contents_type>". |
| 2934 | OS9000: "arlower,upper;<array_contents_type>". |
| 2935 | |
| 2936 | Fortran adjustable arrays use Adigits or Tdigits for lower or upper; |
| 2937 | for these, produce a type like float[][]. */ |
| 2938 | |
| 2939 | if (os9k_stabs) |
| 2940 | index_type = builtin_type_int; |
| 2941 | else |
| 2942 | { |
| 2943 | index_type = read_type (pp, objfile); |
| 2944 | if (**pp != ';') |
| 2945 | /* Improper format of array type decl. */ |
| 2946 | return error_type (pp); |
| 2947 | ++*pp; |
| 2948 | } |
| 2949 | |
| 2950 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') |
| 2951 | { |
| 2952 | (*pp)++; |
| 2953 | adjustable = 1; |
| 2954 | } |
| 2955 | lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits); |
| 2956 | if (nbits != 0) |
| 2957 | return error_type (pp); |
| 2958 | |
| 2959 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') |
| 2960 | { |
| 2961 | (*pp)++; |
| 2962 | adjustable = 1; |
| 2963 | } |
| 2964 | upper = read_huge_number (pp, ';', &nbits); |
| 2965 | if (nbits != 0) |
| 2966 | return error_type (pp); |
| 2967 | |
| 2968 | element_type = read_type (pp, objfile); |
| 2969 | |
| 2970 | if (adjustable) |
| 2971 | { |
| 2972 | lower = 0; |
| 2973 | upper = -1; |
| 2974 | } |
| 2975 | |
| 2976 | range_type = |
| 2977 | create_range_type ((struct type *) NULL, index_type, lower, upper); |
| 2978 | type = create_array_type (type, element_type, range_type); |
| 2979 | |
| 2980 | /* If we have an array whose element type is not yet known, but whose |
| 2981 | bounds *are* known, record it to be adjusted at the end of the file. */ |
| 2982 | |
| 2983 | if ((TYPE_FLAGS (element_type) & TYPE_FLAG_STUB) && !adjustable) |
| 2984 | { |
| 2985 | TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB; |
| 2986 | add_undefined_type (type); |
| 2987 | } |
| 2988 | |
| 2989 | return type; |
| 2990 | } |
| 2991 | |
| 2992 | |
| 2993 | /* Read a definition of an enumeration type, |
| 2994 | and create and return a suitable type object. |
| 2995 | Also defines the symbols that represent the values of the type. */ |
| 2996 | |
| 2997 | static struct type * |
| 2998 | read_enum_type (pp, type, objfile) |
| 2999 | register char **pp; |
| 3000 | register struct type *type; |
| 3001 | struct objfile *objfile; |
| 3002 | { |
| 3003 | register char *p; |
| 3004 | char *name; |
| 3005 | register long n; |
| 3006 | register struct symbol *sym; |
| 3007 | int nsyms = 0; |
| 3008 | struct pending **symlist; |
| 3009 | struct pending *osyms, *syms; |
| 3010 | int o_nsyms; |
| 3011 | int nbits; |
| 3012 | |
| 3013 | #if 0 |
| 3014 | /* FIXME! The stabs produced by Sun CC merrily define things that ought |
| 3015 | to be file-scope, between N_FN entries, using N_LSYM. What's a mother |
| 3016 | to do? For now, force all enum values to file scope. */ |
| 3017 | if (within_function) |
| 3018 | symlist = &local_symbols; |
| 3019 | else |
| 3020 | #endif |
| 3021 | symlist = &file_symbols; |
| 3022 | osyms = *symlist; |
| 3023 | o_nsyms = osyms ? osyms->nsyms : 0; |
| 3024 | |
| 3025 | if (os9k_stabs) |
| 3026 | { |
| 3027 | /* Size. Perhaps this does not have to be conditionalized on |
| 3028 | os9k_stabs (assuming the name of an enum constant can't start |
| 3029 | with a digit). */ |
| 3030 | read_huge_number (pp, 0, &nbits); |
| 3031 | if (nbits != 0) |
| 3032 | return error_type (pp); |
| 3033 | } |
| 3034 | |
| 3035 | /* Read the value-names and their values. |
| 3036 | The input syntax is NAME:VALUE,NAME:VALUE, and so on. |
| 3037 | A semicolon or comma instead of a NAME means the end. */ |
| 3038 | while (**pp && **pp != ';' && **pp != ',') |
| 3039 | { |
| 3040 | STABS_CONTINUE (pp); |
| 3041 | p = *pp; |
| 3042 | while (*p != ':') p++; |
| 3043 | name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack); |
| 3044 | *pp = p + 1; |
| 3045 | n = read_huge_number (pp, ',', &nbits); |
| 3046 | if (nbits != 0) |
| 3047 | return error_type (pp); |
| 3048 | |
| 3049 | sym = (struct symbol *) |
| 3050 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 3051 | memset (sym, 0, sizeof (struct symbol)); |
| 3052 | SYMBOL_NAME (sym) = name; |
| 3053 | SYMBOL_LANGUAGE (sym) = current_subfile -> language; |
| 3054 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 3055 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 3056 | SYMBOL_VALUE (sym) = n; |
| 3057 | add_symbol_to_list (sym, symlist); |
| 3058 | nsyms++; |
| 3059 | } |
| 3060 | |
| 3061 | if (**pp == ';') |
| 3062 | (*pp)++; /* Skip the semicolon. */ |
| 3063 | |
| 3064 | /* Now fill in the fields of the type-structure. */ |
| 3065 | |
| 3066 | TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT; |
| 3067 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
| 3068 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; |
| 3069 | TYPE_NFIELDS (type) = nsyms; |
| 3070 | TYPE_FIELDS (type) = (struct field *) |
| 3071 | TYPE_ALLOC (type, sizeof (struct field) * nsyms); |
| 3072 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms); |
| 3073 | |
| 3074 | /* Find the symbols for the values and put them into the type. |
| 3075 | The symbols can be found in the symlist that we put them on |
| 3076 | to cause them to be defined. osyms contains the old value |
| 3077 | of that symlist; everything up to there was defined by us. */ |
| 3078 | /* Note that we preserve the order of the enum constants, so |
| 3079 | that in something like "enum {FOO, LAST_THING=FOO}" we print |
| 3080 | FOO, not LAST_THING. */ |
| 3081 | |
| 3082 | for (syms = *symlist, n = 0; syms; syms = syms->next) |
| 3083 | { |
| 3084 | int j = 0; |
| 3085 | if (syms == osyms) |
| 3086 | j = o_nsyms; |
| 3087 | for (; j < syms->nsyms; j++,n++) |
| 3088 | { |
| 3089 | struct symbol *xsym = syms->symbol[j]; |
| 3090 | SYMBOL_TYPE (xsym) = type; |
| 3091 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); |
| 3092 | TYPE_FIELD_VALUE (type, n) = 0; |
| 3093 | TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); |
| 3094 | TYPE_FIELD_BITSIZE (type, n) = 0; |
| 3095 | } |
| 3096 | if (syms == osyms) |
| 3097 | break; |
| 3098 | } |
| 3099 | |
| 3100 | return type; |
| 3101 | } |
| 3102 | |
| 3103 | /* Sun's ACC uses a somewhat saner method for specifying the builtin |
| 3104 | typedefs in every file (for int, long, etc): |
| 3105 | |
| 3106 | type = b <signed> <width>; <offset>; <nbits> |
| 3107 | signed = u or s. Possible c in addition to u or s (for char?). |
| 3108 | offset = offset from high order bit to start bit of type. |
| 3109 | width is # bytes in object of this type, nbits is # bits in type. |
| 3110 | |
| 3111 | The width/offset stuff appears to be for small objects stored in |
| 3112 | larger ones (e.g. `shorts' in `int' registers). We ignore it for now, |
| 3113 | FIXME. */ |
| 3114 | |
| 3115 | static struct type * |
| 3116 | read_sun_builtin_type (pp, typenums, objfile) |
| 3117 | char **pp; |
| 3118 | int typenums[2]; |
| 3119 | struct objfile *objfile; |
| 3120 | { |
| 3121 | int type_bits; |
| 3122 | int nbits; |
| 3123 | int signed_type; |
| 3124 | |
| 3125 | switch (**pp) |
| 3126 | { |
| 3127 | case 's': |
| 3128 | signed_type = 1; |
| 3129 | break; |
| 3130 | case 'u': |
| 3131 | signed_type = 0; |
| 3132 | break; |
| 3133 | default: |
| 3134 | return error_type (pp); |
| 3135 | } |
| 3136 | (*pp)++; |
| 3137 | |
| 3138 | /* For some odd reason, all forms of char put a c here. This is strange |
| 3139 | because no other type has this honor. We can safely ignore this because |
| 3140 | we actually determine 'char'acterness by the number of bits specified in |
| 3141 | the descriptor. */ |
| 3142 | |
| 3143 | if (**pp == 'c') |
| 3144 | (*pp)++; |
| 3145 | |
| 3146 | /* The first number appears to be the number of bytes occupied |
| 3147 | by this type, except that unsigned short is 4 instead of 2. |
| 3148 | Since this information is redundant with the third number, |
| 3149 | we will ignore it. */ |
| 3150 | read_huge_number (pp, ';', &nbits); |
| 3151 | if (nbits != 0) |
| 3152 | return error_type (pp); |
| 3153 | |
| 3154 | /* The second number is always 0, so ignore it too. */ |
| 3155 | read_huge_number (pp, ';', &nbits); |
| 3156 | if (nbits != 0) |
| 3157 | return error_type (pp); |
| 3158 | |
| 3159 | /* The third number is the number of bits for this type. */ |
| 3160 | type_bits = read_huge_number (pp, 0, &nbits); |
| 3161 | if (nbits != 0) |
| 3162 | return error_type (pp); |
| 3163 | /* The type *should* end with a semicolon. If it are embedded |
| 3164 | in a larger type the semicolon may be the only way to know where |
| 3165 | the type ends. If this type is at the end of the stabstring we |
| 3166 | can deal with the omitted semicolon (but we don't have to like |
| 3167 | it). Don't bother to complain(), Sun's compiler omits the semicolon |
| 3168 | for "void". */ |
| 3169 | if (**pp == ';') |
| 3170 | ++(*pp); |
| 3171 | |
| 3172 | if (type_bits == 0) |
| 3173 | return init_type (TYPE_CODE_VOID, 1, |
| 3174 | signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL, |
| 3175 | objfile); |
| 3176 | else |
| 3177 | return init_type (TYPE_CODE_INT, |
| 3178 | type_bits / TARGET_CHAR_BIT, |
| 3179 | signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL, |
| 3180 | objfile); |
| 3181 | } |
| 3182 | |
| 3183 | static struct type * |
| 3184 | read_sun_floating_type (pp, typenums, objfile) |
| 3185 | char **pp; |
| 3186 | int typenums[2]; |
| 3187 | struct objfile *objfile; |
| 3188 | { |
| 3189 | int nbits; |
| 3190 | int details; |
| 3191 | int nbytes; |
| 3192 | |
| 3193 | /* The first number has more details about the type, for example |
| 3194 | FN_COMPLEX. */ |
| 3195 | details = read_huge_number (pp, ';', &nbits); |
| 3196 | if (nbits != 0) |
| 3197 | return error_type (pp); |
| 3198 | |
| 3199 | /* The second number is the number of bytes occupied by this type */ |
| 3200 | nbytes = read_huge_number (pp, ';', &nbits); |
| 3201 | if (nbits != 0) |
| 3202 | return error_type (pp); |
| 3203 | |
| 3204 | if (details == NF_COMPLEX || details == NF_COMPLEX16 |
| 3205 | || details == NF_COMPLEX32) |
| 3206 | /* This is a type we can't handle, but we do know the size. |
| 3207 | We also will be able to give it a name. */ |
| 3208 | return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile); |
| 3209 | |
| 3210 | return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile); |
| 3211 | } |
| 3212 | |
| 3213 | /* Read a number from the string pointed to by *PP. |
| 3214 | The value of *PP is advanced over the number. |
| 3215 | If END is nonzero, the character that ends the |
| 3216 | number must match END, or an error happens; |
| 3217 | and that character is skipped if it does match. |
| 3218 | If END is zero, *PP is left pointing to that character. |
| 3219 | |
| 3220 | If the number fits in a long, set *BITS to 0 and return the value. |
| 3221 | If not, set *BITS to be the number of bits in the number and return 0. |
| 3222 | |
| 3223 | If encounter garbage, set *BITS to -1 and return 0. */ |
| 3224 | |
| 3225 | static long |
| 3226 | read_huge_number (pp, end, bits) |
| 3227 | char **pp; |
| 3228 | int end; |
| 3229 | int *bits; |
| 3230 | { |
| 3231 | char *p = *pp; |
| 3232 | int sign = 1; |
| 3233 | long n = 0; |
| 3234 | int radix = 10; |
| 3235 | char overflow = 0; |
| 3236 | int nbits = 0; |
| 3237 | int c; |
| 3238 | long upper_limit; |
| 3239 | |
| 3240 | if (*p == '-') |
| 3241 | { |
| 3242 | sign = -1; |
| 3243 | p++; |
| 3244 | } |
| 3245 | |
| 3246 | /* Leading zero means octal. GCC uses this to output values larger |
| 3247 | than an int (because that would be hard in decimal). */ |
| 3248 | if (*p == '0') |
| 3249 | { |
| 3250 | radix = 8; |
| 3251 | p++; |
| 3252 | } |
| 3253 | |
| 3254 | if (os9k_stabs) |
| 3255 | upper_limit = ULONG_MAX / radix; |
| 3256 | else |
| 3257 | upper_limit = LONG_MAX / radix; |
| 3258 | |
| 3259 | while ((c = *p++) >= '0' && c < ('0' + radix)) |
| 3260 | { |
| 3261 | if (n <= upper_limit) |
| 3262 | { |
| 3263 | n *= radix; |
| 3264 | n += c - '0'; /* FIXME this overflows anyway */ |
| 3265 | } |
| 3266 | else |
| 3267 | overflow = 1; |
| 3268 | |
| 3269 | /* This depends on large values being output in octal, which is |
| 3270 | what GCC does. */ |
| 3271 | if (radix == 8) |
| 3272 | { |
| 3273 | if (nbits == 0) |
| 3274 | { |
| 3275 | if (c == '0') |
| 3276 | /* Ignore leading zeroes. */ |
| 3277 | ; |
| 3278 | else if (c == '1') |
| 3279 | nbits = 1; |
| 3280 | else if (c == '2' || c == '3') |
| 3281 | nbits = 2; |
| 3282 | else |
| 3283 | nbits = 3; |
| 3284 | } |
| 3285 | else |
| 3286 | nbits += 3; |
| 3287 | } |
| 3288 | } |
| 3289 | if (end) |
| 3290 | { |
| 3291 | if (c && c != end) |
| 3292 | { |
| 3293 | if (bits != NULL) |
| 3294 | *bits = -1; |
| 3295 | return 0; |
| 3296 | } |
| 3297 | } |
| 3298 | else |
| 3299 | --p; |
| 3300 | |
| 3301 | *pp = p; |
| 3302 | if (overflow) |
| 3303 | { |
| 3304 | if (nbits == 0) |
| 3305 | { |
| 3306 | /* Large decimal constants are an error (because it is hard to |
| 3307 | count how many bits are in them). */ |
| 3308 | if (bits != NULL) |
| 3309 | *bits = -1; |
| 3310 | return 0; |
| 3311 | } |
| 3312 | |
| 3313 | /* -0x7f is the same as 0x80. So deal with it by adding one to |
| 3314 | the number of bits. */ |
| 3315 | if (sign == -1) |
| 3316 | ++nbits; |
| 3317 | if (bits) |
| 3318 | *bits = nbits; |
| 3319 | } |
| 3320 | else |
| 3321 | { |
| 3322 | if (bits) |
| 3323 | *bits = 0; |
| 3324 | return n * sign; |
| 3325 | } |
| 3326 | /* It's *BITS which has the interesting information. */ |
| 3327 | return 0; |
| 3328 | } |
| 3329 | |
| 3330 | static struct type * |
| 3331 | read_range_type (pp, typenums, objfile) |
| 3332 | char **pp; |
| 3333 | int typenums[2]; |
| 3334 | struct objfile *objfile; |
| 3335 | { |
| 3336 | int rangenums[2]; |
| 3337 | long n2, n3; |
| 3338 | int n2bits, n3bits; |
| 3339 | int self_subrange; |
| 3340 | struct type *result_type; |
| 3341 | struct type *index_type; |
| 3342 | |
| 3343 | /* First comes a type we are a subrange of. |
| 3344 | In C it is usually 0, 1 or the type being defined. */ |
| 3345 | /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id |
| 3346 | not just a type number. */ |
| 3347 | if (read_type_number (pp, rangenums) != 0) |
| 3348 | return error_type (pp); |
| 3349 | self_subrange = (rangenums[0] == typenums[0] && |
| 3350 | rangenums[1] == typenums[1]); |
| 3351 | |
| 3352 | /* A semicolon should now follow; skip it. */ |
| 3353 | if (**pp == ';') |
| 3354 | (*pp)++; |
| 3355 | |
| 3356 | /* The remaining two operands are usually lower and upper bounds |
| 3357 | of the range. But in some special cases they mean something else. */ |
| 3358 | n2 = read_huge_number (pp, ';', &n2bits); |
| 3359 | n3 = read_huge_number (pp, ';', &n3bits); |
| 3360 | |
| 3361 | if (n2bits == -1 || n3bits == -1) |
| 3362 | return error_type (pp); |
| 3363 | |
| 3364 | /* If limits are huge, must be large integral type. */ |
| 3365 | if (n2bits != 0 || n3bits != 0) |
| 3366 | { |
| 3367 | char got_signed = 0; |
| 3368 | char got_unsigned = 0; |
| 3369 | /* Number of bits in the type. */ |
| 3370 | int nbits = 0; |
| 3371 | |
| 3372 | /* Range from 0 to <large number> is an unsigned large integral type. */ |
| 3373 | if ((n2bits == 0 && n2 == 0) && n3bits != 0) |
| 3374 | { |
| 3375 | got_unsigned = 1; |
| 3376 | nbits = n3bits; |
| 3377 | } |
| 3378 | /* Range from <large number> to <large number>-1 is a large signed |
| 3379 | integral type. Take care of the case where <large number> doesn't |
| 3380 | fit in a long but <large number>-1 does. */ |
| 3381 | else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) |
| 3382 | || (n2bits != 0 && n3bits == 0 |
| 3383 | && (n2bits == sizeof (long) * HOST_CHAR_BIT) |
| 3384 | && n3 == LONG_MAX)) |
| 3385 | { |
| 3386 | got_signed = 1; |
| 3387 | nbits = n2bits; |
| 3388 | } |
| 3389 | |
| 3390 | if (got_signed || got_unsigned) |
| 3391 | { |
| 3392 | return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT, |
| 3393 | got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL, |
| 3394 | objfile); |
| 3395 | } |
| 3396 | else |
| 3397 | return error_type (pp); |
| 3398 | } |
| 3399 | |
| 3400 | /* A type defined as a subrange of itself, with bounds both 0, is void. */ |
| 3401 | if (self_subrange && n2 == 0 && n3 == 0) |
| 3402 | return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
| 3403 | |
| 3404 | /* If n3 is zero and n2 is not, we want a floating type, |
| 3405 | and n2 is the width in bytes. |
| 3406 | |
| 3407 | Fortran programs appear to use this for complex types also, |
| 3408 | and they give no way to distinguish between double and single-complex! |
| 3409 | |
| 3410 | GDB does not have complex types. |
| 3411 | |
| 3412 | Just return the complex as a float of that size. It won't work right |
| 3413 | for the complex values, but at least it makes the file loadable. */ |
| 3414 | |
| 3415 | if (n3 == 0 && n2 > 0) |
| 3416 | { |
| 3417 | return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile); |
| 3418 | } |
| 3419 | |
| 3420 | /* If the upper bound is -1, it must really be an unsigned int. */ |
| 3421 | |
| 3422 | else if (n2 == 0 && n3 == -1) |
| 3423 | { |
| 3424 | /* It is unsigned int or unsigned long. */ |
| 3425 | /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5 |
| 3426 | compatibility hack. */ |
| 3427 | return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 3428 | TYPE_FLAG_UNSIGNED, NULL, objfile); |
| 3429 | } |
| 3430 | |
| 3431 | /* Special case: char is defined (Who knows why) as a subrange of |
| 3432 | itself with range 0-127. */ |
| 3433 | else if (self_subrange && n2 == 0 && n3 == 127) |
| 3434 | return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); |
| 3435 | |
| 3436 | /* We used to do this only for subrange of self or subrange of int. */ |
| 3437 | else if (n2 == 0) |
| 3438 | { |
| 3439 | if (n3 < 0) |
| 3440 | /* n3 actually gives the size. */ |
| 3441 | return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED, |
| 3442 | NULL, objfile); |
| 3443 | if (n3 == 0xff) |
| 3444 | return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile); |
| 3445 | if (n3 == 0xffff) |
| 3446 | return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile); |
| 3447 | |
| 3448 | /* -1 is used for the upper bound of (4 byte) "unsigned int" and |
| 3449 | "unsigned long", and we already checked for that, |
| 3450 | so don't need to test for it here. */ |
| 3451 | } |
| 3452 | /* I think this is for Convex "long long". Since I don't know whether |
| 3453 | Convex sets self_subrange, I also accept that particular size regardless |
| 3454 | of self_subrange. */ |
| 3455 | else if (n3 == 0 && n2 < 0 |
| 3456 | && (self_subrange |
| 3457 | || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT)) |
| 3458 | return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile); |
| 3459 | else if (n2 == -n3 -1) |
| 3460 | { |
| 3461 | if (n3 == 0x7f) |
| 3462 | return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); |
| 3463 | if (n3 == 0x7fff) |
| 3464 | return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile); |
| 3465 | if (n3 == 0x7fffffff) |
| 3466 | return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile); |
| 3467 | } |
| 3468 | |
| 3469 | /* We have a real range type on our hands. Allocate space and |
| 3470 | return a real pointer. */ |
| 3471 | |
| 3472 | /* At this point I don't have the faintest idea how to deal with |
| 3473 | a self_subrange type; I'm going to assume that this is used |
| 3474 | as an idiom, and that all of them are special cases. So . . . */ |
| 3475 | if (self_subrange) |
| 3476 | return error_type (pp); |
| 3477 | |
| 3478 | index_type = *dbx_lookup_type (rangenums); |
| 3479 | if (index_type == NULL) |
| 3480 | { |
| 3481 | /* Does this actually ever happen? Is that why we are worrying |
| 3482 | about dealing with it rather than just calling error_type? */ |
| 3483 | |
| 3484 | static struct type *range_type_index; |
| 3485 | |
| 3486 | complain (&range_type_base_complaint, rangenums[1]); |
| 3487 | if (range_type_index == NULL) |
| 3488 | range_type_index = |
| 3489 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 3490 | 0, "range type index type", NULL); |
| 3491 | index_type = range_type_index; |
| 3492 | } |
| 3493 | |
| 3494 | result_type = create_range_type ((struct type *) NULL, index_type, n2, n3); |
| 3495 | return (result_type); |
| 3496 | } |
| 3497 | |
| 3498 | /* Read in an argument list. This is a list of types, separated by commas |
| 3499 | and terminated with END. Return the list of types read in, or (struct type |
| 3500 | **)-1 if there is an error. */ |
| 3501 | |
| 3502 | static struct type ** |
| 3503 | read_args (pp, end, objfile) |
| 3504 | char **pp; |
| 3505 | int end; |
| 3506 | struct objfile *objfile; |
| 3507 | { |
| 3508 | /* FIXME! Remove this arbitrary limit! */ |
| 3509 | struct type *types[1024], **rval; /* allow for fns of 1023 parameters */ |
| 3510 | int n = 0; |
| 3511 | |
| 3512 | while (**pp != end) |
| 3513 | { |
| 3514 | if (**pp != ',') |
| 3515 | /* Invalid argument list: no ','. */ |
| 3516 | return (struct type **)-1; |
| 3517 | (*pp)++; |
| 3518 | STABS_CONTINUE (pp); |
| 3519 | types[n++] = read_type (pp, objfile); |
| 3520 | } |
| 3521 | (*pp)++; /* get past `end' (the ':' character) */ |
| 3522 | |
| 3523 | if (n == 1) |
| 3524 | { |
| 3525 | rval = (struct type **) xmalloc (2 * sizeof (struct type *)); |
| 3526 | } |
| 3527 | else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID) |
| 3528 | { |
| 3529 | rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *)); |
| 3530 | memset (rval + n, 0, sizeof (struct type *)); |
| 3531 | } |
| 3532 | else |
| 3533 | { |
| 3534 | rval = (struct type **) xmalloc (n * sizeof (struct type *)); |
| 3535 | } |
| 3536 | memcpy (rval, types, n * sizeof (struct type *)); |
| 3537 | return rval; |
| 3538 | } |
| 3539 | \f |
| 3540 | /* Common block handling. */ |
| 3541 | |
| 3542 | /* List of symbols declared since the last BCOMM. This list is a tail |
| 3543 | of local_symbols. When ECOMM is seen, the symbols on the list |
| 3544 | are noted so their proper addresses can be filled in later, |
| 3545 | using the common block base address gotten from the assembler |
| 3546 | stabs. */ |
| 3547 | |
| 3548 | static struct pending *common_block; |
| 3549 | static int common_block_i; |
| 3550 | |
| 3551 | /* Name of the current common block. We get it from the BCOMM instead of the |
| 3552 | ECOMM to match IBM documentation (even though IBM puts the name both places |
| 3553 | like everyone else). */ |
| 3554 | static char *common_block_name; |
| 3555 | |
| 3556 | /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed |
| 3557 | to remain after this function returns. */ |
| 3558 | |
| 3559 | void |
| 3560 | common_block_start (name, objfile) |
| 3561 | char *name; |
| 3562 | struct objfile *objfile; |
| 3563 | { |
| 3564 | if (common_block_name != NULL) |
| 3565 | { |
| 3566 | static struct complaint msg = { |
| 3567 | "Invalid symbol data: common block within common block", |
| 3568 | 0, 0}; |
| 3569 | complain (&msg); |
| 3570 | } |
| 3571 | common_block = local_symbols; |
| 3572 | common_block_i = local_symbols ? local_symbols->nsyms : 0; |
| 3573 | common_block_name = obsavestring (name, strlen (name), |
| 3574 | &objfile -> symbol_obstack); |
| 3575 | } |
| 3576 | |
| 3577 | /* Process a N_ECOMM symbol. */ |
| 3578 | |
| 3579 | void |
| 3580 | common_block_end (objfile) |
| 3581 | struct objfile *objfile; |
| 3582 | { |
| 3583 | /* Symbols declared since the BCOMM are to have the common block |
| 3584 | start address added in when we know it. common_block and |
| 3585 | common_block_i point to the first symbol after the BCOMM in |
| 3586 | the local_symbols list; copy the list and hang it off the |
| 3587 | symbol for the common block name for later fixup. */ |
| 3588 | int i; |
| 3589 | struct symbol *sym; |
| 3590 | struct pending *new = 0; |
| 3591 | struct pending *next; |
| 3592 | int j; |
| 3593 | |
| 3594 | if (common_block_name == NULL) |
| 3595 | { |
| 3596 | static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0}; |
| 3597 | complain (&msg); |
| 3598 | return; |
| 3599 | } |
| 3600 | |
| 3601 | sym = (struct symbol *) |
| 3602 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 3603 | memset (sym, 0, sizeof (struct symbol)); |
| 3604 | SYMBOL_NAME (sym) = common_block_name; |
| 3605 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 3606 | |
| 3607 | /* Now we copy all the symbols which have been defined since the BCOMM. */ |
| 3608 | |
| 3609 | /* Copy all the struct pendings before common_block. */ |
| 3610 | for (next = local_symbols; |
| 3611 | next != NULL && next != common_block; |
| 3612 | next = next->next) |
| 3613 | { |
| 3614 | for (j = 0; j < next->nsyms; j++) |
| 3615 | add_symbol_to_list (next->symbol[j], &new); |
| 3616 | } |
| 3617 | |
| 3618 | /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is |
| 3619 | NULL, it means copy all the local symbols (which we already did |
| 3620 | above). */ |
| 3621 | |
| 3622 | if (common_block != NULL) |
| 3623 | for (j = common_block_i; j < common_block->nsyms; j++) |
| 3624 | add_symbol_to_list (common_block->symbol[j], &new); |
| 3625 | |
| 3626 | SYMBOL_TYPE (sym) = (struct type *) new; |
| 3627 | |
| 3628 | /* Should we be putting local_symbols back to what it was? |
| 3629 | Does it matter? */ |
| 3630 | |
| 3631 | i = hashname (SYMBOL_NAME (sym)); |
| 3632 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; |
| 3633 | global_sym_chain[i] = sym; |
| 3634 | common_block_name = NULL; |
| 3635 | } |
| 3636 | |
| 3637 | /* Add a common block's start address to the offset of each symbol |
| 3638 | declared to be in it (by being between a BCOMM/ECOMM pair that uses |
| 3639 | the common block name). */ |
| 3640 | |
| 3641 | static void |
| 3642 | fix_common_block (sym, valu) |
| 3643 | struct symbol *sym; |
| 3644 | int valu; |
| 3645 | { |
| 3646 | struct pending *next = (struct pending *) SYMBOL_TYPE (sym); |
| 3647 | for ( ; next; next = next->next) |
| 3648 | { |
| 3649 | register int j; |
| 3650 | for (j = next->nsyms - 1; j >= 0; j--) |
| 3651 | SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu; |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | |
| 3656 | \f |
| 3657 | /* What about types defined as forward references inside of a small lexical |
| 3658 | scope? */ |
| 3659 | /* Add a type to the list of undefined types to be checked through |
| 3660 | once this file has been read in. */ |
| 3661 | |
| 3662 | void |
| 3663 | add_undefined_type (type) |
| 3664 | struct type *type; |
| 3665 | { |
| 3666 | if (undef_types_length == undef_types_allocated) |
| 3667 | { |
| 3668 | undef_types_allocated *= 2; |
| 3669 | undef_types = (struct type **) |
| 3670 | xrealloc ((char *) undef_types, |
| 3671 | undef_types_allocated * sizeof (struct type *)); |
| 3672 | } |
| 3673 | undef_types[undef_types_length++] = type; |
| 3674 | } |
| 3675 | |
| 3676 | /* Go through each undefined type, see if it's still undefined, and fix it |
| 3677 | up if possible. We have two kinds of undefined types: |
| 3678 | |
| 3679 | TYPE_CODE_ARRAY: Array whose target type wasn't defined yet. |
| 3680 | Fix: update array length using the element bounds |
| 3681 | and the target type's length. |
| 3682 | TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not |
| 3683 | yet defined at the time a pointer to it was made. |
| 3684 | Fix: Do a full lookup on the struct/union tag. */ |
| 3685 | void |
| 3686 | cleanup_undefined_types () |
| 3687 | { |
| 3688 | struct type **type; |
| 3689 | |
| 3690 | for (type = undef_types; type < undef_types + undef_types_length; type++) |
| 3691 | { |
| 3692 | switch (TYPE_CODE (*type)) |
| 3693 | { |
| 3694 | |
| 3695 | case TYPE_CODE_STRUCT: |
| 3696 | case TYPE_CODE_UNION: |
| 3697 | case TYPE_CODE_ENUM: |
| 3698 | { |
| 3699 | /* Check if it has been defined since. Need to do this here |
| 3700 | as well as in check_stub_type to deal with the (legitimate in |
| 3701 | C though not C++) case of several types with the same name |
| 3702 | in different source files. */ |
| 3703 | if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB) |
| 3704 | { |
| 3705 | struct pending *ppt; |
| 3706 | int i; |
| 3707 | /* Name of the type, without "struct" or "union" */ |
| 3708 | char *typename = TYPE_TAG_NAME (*type); |
| 3709 | |
| 3710 | if (typename == NULL) |
| 3711 | { |
| 3712 | static struct complaint msg = {"need a type name", 0, 0}; |
| 3713 | complain (&msg); |
| 3714 | break; |
| 3715 | } |
| 3716 | for (ppt = file_symbols; ppt; ppt = ppt->next) |
| 3717 | { |
| 3718 | for (i = 0; i < ppt->nsyms; i++) |
| 3719 | { |
| 3720 | struct symbol *sym = ppt->symbol[i]; |
| 3721 | |
| 3722 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF |
| 3723 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE |
| 3724 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == |
| 3725 | TYPE_CODE (*type)) |
| 3726 | && STREQ (SYMBOL_NAME (sym), typename)) |
| 3727 | { |
| 3728 | memcpy (*type, SYMBOL_TYPE (sym), |
| 3729 | sizeof (struct type)); |
| 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | break; |
| 3736 | |
| 3737 | case TYPE_CODE_ARRAY: |
| 3738 | { |
| 3739 | /* This is a kludge which is here for historical reasons |
| 3740 | because I suspect that check_stub_type does not get |
| 3741 | called everywhere it needs to be called for arrays. Even |
| 3742 | with this kludge, those places are broken for the case |
| 3743 | where the stub type is defined in another compilation |
| 3744 | unit, but this kludge at least deals with it for the case |
| 3745 | in which it is the same compilation unit. |
| 3746 | |
| 3747 | Don't try to do this by calling check_stub_type; it might |
| 3748 | cause symbols to be read in lookup_symbol, and the symbol |
| 3749 | reader is not reentrant. */ |
| 3750 | |
| 3751 | struct type *range_type; |
| 3752 | int lower, upper; |
| 3753 | |
| 3754 | if (TYPE_LENGTH (*type) != 0) /* Better be unknown */ |
| 3755 | goto badtype; |
| 3756 | if (TYPE_NFIELDS (*type) != 1) |
| 3757 | goto badtype; |
| 3758 | range_type = TYPE_FIELD_TYPE (*type, 0); |
| 3759 | if (TYPE_CODE (range_type) != TYPE_CODE_RANGE) |
| 3760 | goto badtype; |
| 3761 | |
| 3762 | /* Now recompute the length of the array type, based on its |
| 3763 | number of elements and the target type's length. */ |
| 3764 | lower = TYPE_FIELD_BITPOS (range_type, 0); |
| 3765 | upper = TYPE_FIELD_BITPOS (range_type, 1); |
| 3766 | TYPE_LENGTH (*type) = (upper - lower + 1) |
| 3767 | * TYPE_LENGTH (TYPE_TARGET_TYPE (*type)); |
| 3768 | |
| 3769 | /* If the target type is not a stub, we could be clearing |
| 3770 | TYPE_FLAG_TARGET_STUB for *type. */ |
| 3771 | } |
| 3772 | break; |
| 3773 | |
| 3774 | default: |
| 3775 | badtype: |
| 3776 | { |
| 3777 | static struct complaint msg = {"\ |
| 3778 | GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0}; |
| 3779 | complain (&msg, TYPE_CODE (*type)); |
| 3780 | } |
| 3781 | break; |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | undef_types_length = 0; |
| 3786 | } |
| 3787 | |
| 3788 | /* Scan through all of the global symbols defined in the object file, |
| 3789 | assigning values to the debugging symbols that need to be assigned |
| 3790 | to. Get these symbols from the minimal symbol table. */ |
| 3791 | |
| 3792 | void |
| 3793 | scan_file_globals (objfile) |
| 3794 | struct objfile *objfile; |
| 3795 | { |
| 3796 | int hash; |
| 3797 | struct minimal_symbol *msymbol; |
| 3798 | struct symbol *sym, *prev; |
| 3799 | |
| 3800 | if (objfile->msymbols == 0) /* Beware the null file. */ |
| 3801 | return; |
| 3802 | |
| 3803 | for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++) |
| 3804 | { |
| 3805 | QUIT; |
| 3806 | |
| 3807 | /* Skip static symbols. */ |
| 3808 | switch (MSYMBOL_TYPE (msymbol)) |
| 3809 | { |
| 3810 | case mst_file_text: |
| 3811 | case mst_file_data: |
| 3812 | case mst_file_bss: |
| 3813 | continue; |
| 3814 | default: |
| 3815 | break; |
| 3816 | } |
| 3817 | |
| 3818 | prev = NULL; |
| 3819 | |
| 3820 | /* Get the hash index and check all the symbols |
| 3821 | under that hash index. */ |
| 3822 | |
| 3823 | hash = hashname (SYMBOL_NAME (msymbol)); |
| 3824 | |
| 3825 | for (sym = global_sym_chain[hash]; sym;) |
| 3826 | { |
| 3827 | if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] && |
| 3828 | STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1)) |
| 3829 | { |
| 3830 | /* Splice this symbol out of the hash chain and |
| 3831 | assign the value we have to it. */ |
| 3832 | if (prev) |
| 3833 | { |
| 3834 | SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); |
| 3835 | } |
| 3836 | else |
| 3837 | { |
| 3838 | global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); |
| 3839 | } |
| 3840 | |
| 3841 | /* Check to see whether we need to fix up a common block. */ |
| 3842 | /* Note: this code might be executed several times for |
| 3843 | the same symbol if there are multiple references. */ |
| 3844 | |
| 3845 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) |
| 3846 | { |
| 3847 | fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol)); |
| 3848 | } |
| 3849 | else |
| 3850 | { |
| 3851 | SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol); |
| 3852 | } |
| 3853 | |
| 3854 | SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol); |
| 3855 | |
| 3856 | if (prev) |
| 3857 | { |
| 3858 | sym = SYMBOL_VALUE_CHAIN (prev); |
| 3859 | } |
| 3860 | else |
| 3861 | { |
| 3862 | sym = global_sym_chain[hash]; |
| 3863 | } |
| 3864 | } |
| 3865 | else |
| 3866 | { |
| 3867 | prev = sym; |
| 3868 | sym = SYMBOL_VALUE_CHAIN (sym); |
| 3869 | } |
| 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | /* Initialize anything that needs initializing when starting to read |
| 3875 | a fresh piece of a symbol file, e.g. reading in the stuff corresponding |
| 3876 | to a psymtab. */ |
| 3877 | |
| 3878 | void |
| 3879 | stabsread_init () |
| 3880 | { |
| 3881 | } |
| 3882 | |
| 3883 | /* Initialize anything that needs initializing when a completely new |
| 3884 | symbol file is specified (not just adding some symbols from another |
| 3885 | file, e.g. a shared library). */ |
| 3886 | |
| 3887 | void |
| 3888 | stabsread_new_init () |
| 3889 | { |
| 3890 | /* Empty the hash table of global syms looking for values. */ |
| 3891 | memset (global_sym_chain, 0, sizeof (global_sym_chain)); |
| 3892 | } |
| 3893 | |
| 3894 | /* Initialize anything that needs initializing at the same time as |
| 3895 | start_symtab() is called. */ |
| 3896 | |
| 3897 | void start_stabs () |
| 3898 | { |
| 3899 | global_stabs = NULL; /* AIX COFF */ |
| 3900 | /* Leave FILENUM of 0 free for builtin types and this file's types. */ |
| 3901 | n_this_object_header_files = 1; |
| 3902 | type_vector_length = 0; |
| 3903 | type_vector = (struct type **) 0; |
| 3904 | |
| 3905 | /* FIXME: If common_block_name is not already NULL, we should complain(). */ |
| 3906 | common_block_name = NULL; |
| 3907 | |
| 3908 | os9k_stabs = 0; |
| 3909 | } |
| 3910 | |
| 3911 | /* Call after end_symtab() */ |
| 3912 | |
| 3913 | void end_stabs () |
| 3914 | { |
| 3915 | if (type_vector) |
| 3916 | { |
| 3917 | free ((char *) type_vector); |
| 3918 | } |
| 3919 | type_vector = 0; |
| 3920 | type_vector_length = 0; |
| 3921 | previous_stab_code = 0; |
| 3922 | } |
| 3923 | |
| 3924 | void |
| 3925 | finish_global_stabs (objfile) |
| 3926 | struct objfile *objfile; |
| 3927 | { |
| 3928 | if (global_stabs) |
| 3929 | { |
| 3930 | patch_block_stabs (global_symbols, global_stabs, objfile); |
| 3931 | free ((PTR) global_stabs); |
| 3932 | global_stabs = NULL; |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | /* Initializer for this module */ |
| 3937 | |
| 3938 | void |
| 3939 | _initialize_stabsread () |
| 3940 | { |
| 3941 | undef_types_allocated = 20; |
| 3942 | undef_types_length = 0; |
| 3943 | undef_types = (struct type **) |
| 3944 | xmalloc (undef_types_allocated * sizeof (struct type *)); |
| 3945 | } |