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