| 1 | /* Support routines for decoding "stabs" debugging information format. |
| 2 | Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998 |
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "gdb_string.h" |
| 29 | #include "bfd.h" |
| 30 | #include "obstack.h" |
| 31 | #include "symtab.h" |
| 32 | #include "gdbtypes.h" |
| 33 | #include "expression.h" |
| 34 | #include "symfile.h" |
| 35 | #include "objfiles.h" |
| 36 | #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */ |
| 37 | #include "libaout.h" |
| 38 | #include "aout/aout64.h" |
| 39 | #include "gdb-stabs.h" |
| 40 | #include "buildsym.h" |
| 41 | #include "complaints.h" |
| 42 | #include "demangle.h" |
| 43 | #include "language.h" |
| 44 | |
| 45 | #include <ctype.h> |
| 46 | |
| 47 | /* Ask stabsread.h to define the vars it normally declares `extern'. */ |
| 48 | #define EXTERN /**/ |
| 49 | #include "stabsread.h" /* Our own declarations */ |
| 50 | #undef EXTERN |
| 51 | |
| 52 | /* The routines that read and process a complete stabs for a C struct or |
| 53 | C++ class pass lists of data member fields and lists of member function |
| 54 | fields in an instance of a field_info structure, as defined below. |
| 55 | This is part of some reorganization of low level C++ support and is |
| 56 | expected to eventually go away... (FIXME) */ |
| 57 | |
| 58 | struct field_info |
| 59 | { |
| 60 | struct nextfield |
| 61 | { |
| 62 | struct nextfield *next; |
| 63 | |
| 64 | /* This is the raw visibility from the stab. It is not checked |
| 65 | for being one of the visibilities we recognize, so code which |
| 66 | examines this field better be able to deal. */ |
| 67 | int visibility; |
| 68 | |
| 69 | struct field field; |
| 70 | } *list; |
| 71 | struct next_fnfieldlist |
| 72 | { |
| 73 | struct next_fnfieldlist *next; |
| 74 | struct fn_fieldlist fn_fieldlist; |
| 75 | } *fnlist; |
| 76 | }; |
| 77 | |
| 78 | static void |
| 79 | read_one_struct_field PARAMS ((struct field_info *, char **, char *, |
| 80 | struct type *, struct objfile *)); |
| 81 | |
| 82 | static char * |
| 83 | get_substring PARAMS ((char **, int)); |
| 84 | |
| 85 | static struct type * |
| 86 | dbx_alloc_type PARAMS ((int [2], struct objfile *)); |
| 87 | |
| 88 | static long read_huge_number PARAMS ((char **, int, int *)); |
| 89 | |
| 90 | static struct type *error_type PARAMS ((char **, struct objfile *)); |
| 91 | |
| 92 | static void |
| 93 | patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *, |
| 94 | struct objfile *)); |
| 95 | |
| 96 | static void |
| 97 | fix_common_block PARAMS ((struct symbol *, int)); |
| 98 | |
| 99 | static int |
| 100 | read_type_number PARAMS ((char **, int *)); |
| 101 | |
| 102 | static struct type * |
| 103 | read_range_type PARAMS ((char **, int [2], struct objfile *)); |
| 104 | |
| 105 | static struct type * |
| 106 | read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *)); |
| 107 | |
| 108 | static struct type * |
| 109 | read_sun_floating_type PARAMS ((char **, int [2], struct objfile *)); |
| 110 | |
| 111 | static struct type * |
| 112 | read_enum_type PARAMS ((char **, struct type *, struct objfile *)); |
| 113 | |
| 114 | static struct type * |
| 115 | rs6000_builtin_type PARAMS ((int)); |
| 116 | |
| 117 | static int |
| 118 | read_member_functions PARAMS ((struct field_info *, char **, struct type *, |
| 119 | struct objfile *)); |
| 120 | |
| 121 | static int |
| 122 | read_struct_fields PARAMS ((struct field_info *, char **, struct type *, |
| 123 | struct objfile *)); |
| 124 | |
| 125 | static int |
| 126 | read_baseclasses PARAMS ((struct field_info *, char **, struct type *, |
| 127 | struct objfile *)); |
| 128 | |
| 129 | static int |
| 130 | read_tilde_fields PARAMS ((struct field_info *, char **, struct type *, |
| 131 | struct objfile *)); |
| 132 | |
| 133 | static int |
| 134 | attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *)); |
| 135 | |
| 136 | static int |
| 137 | attach_fields_to_type PARAMS ((struct field_info *, struct type *, |
| 138 | struct objfile *)); |
| 139 | |
| 140 | static struct type * |
| 141 | read_struct_type PARAMS ((char **, struct type *, struct objfile *)); |
| 142 | |
| 143 | static struct type * |
| 144 | read_array_type PARAMS ((char **, struct type *, struct objfile *)); |
| 145 | |
| 146 | static struct type ** |
| 147 | read_args PARAMS ((char **, int, struct objfile *)); |
| 148 | |
| 149 | static int |
| 150 | read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *, |
| 151 | struct objfile *)); |
| 152 | |
| 153 | /* new functions added for cfront support */ |
| 154 | |
| 155 | static int |
| 156 | copy_cfront_struct_fields PARAMS ((struct field_info *, struct type *, |
| 157 | struct objfile *)); |
| 158 | |
| 159 | static char * |
| 160 | get_cfront_method_physname PARAMS ((char *)); |
| 161 | |
| 162 | static int |
| 163 | read_cfront_baseclasses PARAMS ((struct field_info *, char **, |
| 164 | struct type *, struct objfile *)); |
| 165 | |
| 166 | static int |
| 167 | read_cfront_static_fields PARAMS ((struct field_info *, char**, |
| 168 | struct type *, struct objfile *)); |
| 169 | static int |
| 170 | read_cfront_member_functions PARAMS ((struct field_info *, char **, |
| 171 | struct type *, struct objfile *)); |
| 172 | |
| 173 | /* end new functions added for cfront support */ |
| 174 | |
| 175 | static void |
| 176 | add_live_range PARAMS ((struct objfile *, struct symbol *, |
| 177 | CORE_ADDR, CORE_ADDR)); |
| 178 | |
| 179 | static void |
| 180 | resolve_live_range PARAMS ((struct objfile *, struct symbol *, char *)); |
| 181 | |
| 182 | static int |
| 183 | process_reference PARAMS ((char **string)); |
| 184 | |
| 185 | static CORE_ADDR |
| 186 | ref_search_value PARAMS ((int refnum)); |
| 187 | |
| 188 | static void |
| 189 | ref_init PARAMS ((void)); |
| 190 | |
| 191 | static int |
| 192 | resolve_symbol_reference PARAMS ((struct objfile *, struct symbol *, char *)); |
| 193 | |
| 194 | static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' }; |
| 195 | static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' }; |
| 196 | |
| 197 | /* Define this as 1 if a pcc declaration of a char or short argument |
| 198 | gives the correct address. Otherwise assume pcc gives the |
| 199 | address of the corresponding int, which is not the same on a |
| 200 | big-endian machine. */ |
| 201 | |
| 202 | #ifndef BELIEVE_PCC_PROMOTION |
| 203 | #define BELIEVE_PCC_PROMOTION 0 |
| 204 | #endif |
| 205 | |
| 206 | struct complaint invalid_cpp_abbrev_complaint = |
| 207 | {"invalid C++ abbreviation `%s'", 0, 0}; |
| 208 | |
| 209 | struct complaint invalid_cpp_type_complaint = |
| 210 | {"C++ abbreviated type name unknown at symtab pos %d", 0, 0}; |
| 211 | |
| 212 | struct complaint member_fn_complaint = |
| 213 | {"member function type missing, got '%c'", 0, 0}; |
| 214 | |
| 215 | struct complaint const_vol_complaint = |
| 216 | {"const/volatile indicator missing, got '%c'", 0, 0}; |
| 217 | |
| 218 | struct complaint error_type_complaint = |
| 219 | {"debug info mismatch between compiler and debugger", 0, 0}; |
| 220 | |
| 221 | struct complaint invalid_member_complaint = |
| 222 | {"invalid (minimal) member type data format at symtab pos %d.", 0, 0}; |
| 223 | |
| 224 | struct complaint range_type_base_complaint = |
| 225 | {"base type %d of range type is not defined", 0, 0}; |
| 226 | |
| 227 | struct complaint reg_value_complaint = |
| 228 | {"register number %d too large (max %d) in symbol %s", 0, 0}; |
| 229 | |
| 230 | struct complaint vtbl_notfound_complaint = |
| 231 | {"virtual function table pointer not found when defining class `%s'", 0, 0}; |
| 232 | |
| 233 | struct complaint unrecognized_cplus_name_complaint = |
| 234 | {"Unknown C++ symbol name `%s'", 0, 0}; |
| 235 | |
| 236 | struct complaint rs6000_builtin_complaint = |
| 237 | {"Unknown builtin type %d", 0, 0}; |
| 238 | |
| 239 | struct complaint unresolved_sym_chain_complaint = |
| 240 | {"%s: common block `%s' from global_sym_chain unresolved", 0, 0}; |
| 241 | |
| 242 | struct complaint stabs_general_complaint = |
| 243 | {"%s", 0, 0}; |
| 244 | |
| 245 | /* Make a list of forward references which haven't been defined. */ |
| 246 | |
| 247 | static struct type **undef_types; |
| 248 | static int undef_types_allocated; |
| 249 | static int undef_types_length; |
| 250 | static struct symbol *current_symbol = NULL; |
| 251 | |
| 252 | /* Check for and handle cretinous stabs symbol name continuation! */ |
| 253 | #define STABS_CONTINUE(pp,objfile) \ |
| 254 | do { \ |
| 255 | if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \ |
| 256 | *(pp) = next_symbol_text (objfile); \ |
| 257 | } while (0) |
| 258 | \f |
| 259 | /* FIXME: These probably should be our own types (like rs6000_builtin_type |
| 260 | has its own types) rather than builtin_type_*. */ |
| 261 | static struct type **os9k_type_vector[] = { |
| 262 | 0, |
| 263 | &builtin_type_int, |
| 264 | &builtin_type_char, |
| 265 | &builtin_type_long, |
| 266 | &builtin_type_short, |
| 267 | &builtin_type_unsigned_char, |
| 268 | &builtin_type_unsigned_short, |
| 269 | &builtin_type_unsigned_long, |
| 270 | &builtin_type_unsigned_int, |
| 271 | &builtin_type_float, |
| 272 | &builtin_type_double, |
| 273 | &builtin_type_void, |
| 274 | &builtin_type_long_double |
| 275 | }; |
| 276 | |
| 277 | static void os9k_init_type_vector PARAMS ((struct type **)); |
| 278 | |
| 279 | static void |
| 280 | os9k_init_type_vector(tv) |
| 281 | struct type **tv; |
| 282 | { |
| 283 | int i; |
| 284 | for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++) |
| 285 | tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i])); |
| 286 | } |
| 287 | |
| 288 | /* Look up a dbx type-number pair. Return the address of the slot |
| 289 | where the type for that number-pair is stored. |
| 290 | The number-pair is in TYPENUMS. |
| 291 | |
| 292 | This can be used for finding the type associated with that pair |
| 293 | or for associating a new type with the pair. */ |
| 294 | |
| 295 | struct type ** |
| 296 | dbx_lookup_type (typenums) |
| 297 | int typenums[2]; |
| 298 | { |
| 299 | register int filenum = typenums[0]; |
| 300 | register int index = typenums[1]; |
| 301 | unsigned old_len; |
| 302 | register int real_filenum; |
| 303 | register struct header_file *f; |
| 304 | int f_orig_length; |
| 305 | |
| 306 | if (filenum == -1) /* -1,-1 is for temporary types. */ |
| 307 | return 0; |
| 308 | |
| 309 | if (filenum < 0 || filenum >= n_this_object_header_files) |
| 310 | { |
| 311 | static struct complaint msg = {"\ |
| 312 | Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", |
| 313 | 0, 0}; |
| 314 | complain (&msg, filenum, index, symnum); |
| 315 | goto error_return; |
| 316 | } |
| 317 | |
| 318 | if (filenum == 0) |
| 319 | { |
| 320 | if (index < 0) |
| 321 | { |
| 322 | /* Caller wants address of address of type. We think |
| 323 | that negative (rs6k builtin) types will never appear as |
| 324 | "lvalues", (nor should they), so we stuff the real type |
| 325 | pointer into a temp, and return its address. If referenced, |
| 326 | this will do the right thing. */ |
| 327 | static struct type *temp_type; |
| 328 | |
| 329 | temp_type = rs6000_builtin_type(index); |
| 330 | return &temp_type; |
| 331 | } |
| 332 | |
| 333 | /* Type is defined outside of header files. |
| 334 | Find it in this object file's type vector. */ |
| 335 | if (index >= type_vector_length) |
| 336 | { |
| 337 | old_len = type_vector_length; |
| 338 | if (old_len == 0) |
| 339 | { |
| 340 | type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; |
| 341 | type_vector = (struct type **) |
| 342 | xmalloc (type_vector_length * sizeof (struct type *)); |
| 343 | } |
| 344 | while (index >= type_vector_length) |
| 345 | { |
| 346 | type_vector_length *= 2; |
| 347 | } |
| 348 | type_vector = (struct type **) |
| 349 | xrealloc ((char *) type_vector, |
| 350 | (type_vector_length * sizeof (struct type *))); |
| 351 | memset (&type_vector[old_len], 0, |
| 352 | (type_vector_length - old_len) * sizeof (struct type *)); |
| 353 | |
| 354 | if (os9k_stabs) |
| 355 | /* Deal with OS9000 fundamental types. */ |
| 356 | os9k_init_type_vector (type_vector); |
| 357 | } |
| 358 | return (&type_vector[index]); |
| 359 | } |
| 360 | else |
| 361 | { |
| 362 | real_filenum = this_object_header_files[filenum]; |
| 363 | |
| 364 | if (real_filenum >= N_HEADER_FILES (current_objfile)) |
| 365 | { |
| 366 | struct type *temp_type; |
| 367 | struct type **temp_type_p; |
| 368 | |
| 369 | warning ("GDB internal error: bad real_filenum"); |
| 370 | |
| 371 | error_return: |
| 372 | temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL); |
| 373 | temp_type_p = (struct type **) xmalloc (sizeof (struct type *)); |
| 374 | *temp_type_p = temp_type; |
| 375 | return temp_type_p; |
| 376 | } |
| 377 | |
| 378 | f = HEADER_FILES (current_objfile) + real_filenum; |
| 379 | |
| 380 | f_orig_length = f->length; |
| 381 | if (index >= f_orig_length) |
| 382 | { |
| 383 | while (index >= f->length) |
| 384 | { |
| 385 | f->length *= 2; |
| 386 | } |
| 387 | f->vector = (struct type **) |
| 388 | xrealloc ((char *) f->vector, f->length * sizeof (struct type *)); |
| 389 | memset (&f->vector[f_orig_length], 0, |
| 390 | (f->length - f_orig_length) * sizeof (struct type *)); |
| 391 | } |
| 392 | return (&f->vector[index]); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /* Make sure there is a type allocated for type numbers TYPENUMS |
| 397 | and return the type object. |
| 398 | This can create an empty (zeroed) type object. |
| 399 | TYPENUMS may be (-1, -1) to return a new type object that is not |
| 400 | put into the type vector, and so may not be referred to by number. */ |
| 401 | |
| 402 | static struct type * |
| 403 | dbx_alloc_type (typenums, objfile) |
| 404 | int typenums[2]; |
| 405 | struct objfile *objfile; |
| 406 | { |
| 407 | register struct type **type_addr; |
| 408 | |
| 409 | if (typenums[0] == -1) |
| 410 | { |
| 411 | return (alloc_type (objfile)); |
| 412 | } |
| 413 | |
| 414 | type_addr = dbx_lookup_type (typenums); |
| 415 | |
| 416 | /* If we are referring to a type not known at all yet, |
| 417 | allocate an empty type for it. |
| 418 | We will fill it in later if we find out how. */ |
| 419 | if (*type_addr == 0) |
| 420 | { |
| 421 | *type_addr = alloc_type (objfile); |
| 422 | } |
| 423 | |
| 424 | return (*type_addr); |
| 425 | } |
| 426 | |
| 427 | /* for all the stabs in a given stab vector, build appropriate types |
| 428 | and fix their symbols in given symbol vector. */ |
| 429 | |
| 430 | static void |
| 431 | patch_block_stabs (symbols, stabs, objfile) |
| 432 | struct pending *symbols; |
| 433 | struct pending_stabs *stabs; |
| 434 | struct objfile *objfile; |
| 435 | { |
| 436 | int ii; |
| 437 | char *name; |
| 438 | char *pp; |
| 439 | struct symbol *sym; |
| 440 | |
| 441 | if (stabs) |
| 442 | { |
| 443 | |
| 444 | /* for all the stab entries, find their corresponding symbols and |
| 445 | patch their types! */ |
| 446 | |
| 447 | for (ii = 0; ii < stabs->count; ++ii) |
| 448 | { |
| 449 | name = stabs->stab[ii]; |
| 450 | pp = (char*) strchr (name, ':'); |
| 451 | while (pp[1] == ':') |
| 452 | { |
| 453 | pp += 2; |
| 454 | pp = (char *)strchr(pp, ':'); |
| 455 | } |
| 456 | sym = find_symbol_in_list (symbols, name, pp-name); |
| 457 | if (!sym) |
| 458 | { |
| 459 | /* FIXME-maybe: it would be nice if we noticed whether |
| 460 | the variable was defined *anywhere*, not just whether |
| 461 | it is defined in this compilation unit. But neither |
| 462 | xlc or GCC seem to need such a definition, and until |
| 463 | we do psymtabs (so that the minimal symbols from all |
| 464 | compilation units are available now), I'm not sure |
| 465 | how to get the information. */ |
| 466 | |
| 467 | /* On xcoff, if a global is defined and never referenced, |
| 468 | ld will remove it from the executable. There is then |
| 469 | a N_GSYM stab for it, but no regular (C_EXT) symbol. */ |
| 470 | sym = (struct symbol *) |
| 471 | obstack_alloc (&objfile->symbol_obstack, |
| 472 | sizeof (struct symbol)); |
| 473 | |
| 474 | memset (sym, 0, sizeof (struct symbol)); |
| 475 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 476 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 477 | SYMBOL_NAME (sym) = |
| 478 | obsavestring (name, pp - name, &objfile->symbol_obstack); |
| 479 | pp += 2; |
| 480 | if (*(pp-1) == 'F' || *(pp-1) == 'f') |
| 481 | { |
| 482 | /* I don't think the linker does this with functions, |
| 483 | so as far as I know this is never executed. |
| 484 | But it doesn't hurt to check. */ |
| 485 | SYMBOL_TYPE (sym) = |
| 486 | lookup_function_type (read_type (&pp, objfile)); |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
| 491 | } |
| 492 | add_symbol_to_list (sym, &global_symbols); |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | pp += 2; |
| 497 | if (*(pp-1) == 'F' || *(pp-1) == 'f') |
| 498 | { |
| 499 | SYMBOL_TYPE (sym) = |
| 500 | lookup_function_type (read_type (&pp, objfile)); |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | SYMBOL_TYPE (sym) = read_type (&pp, objfile); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | \f |
| 512 | /* Read a number by which a type is referred to in dbx data, |
| 513 | or perhaps read a pair (FILENUM, TYPENUM) in parentheses. |
| 514 | Just a single number N is equivalent to (0,N). |
| 515 | Return the two numbers by storing them in the vector TYPENUMS. |
| 516 | TYPENUMS will then be used as an argument to dbx_lookup_type. |
| 517 | |
| 518 | Returns 0 for success, -1 for error. */ |
| 519 | |
| 520 | static int |
| 521 | read_type_number (pp, typenums) |
| 522 | register char **pp; |
| 523 | register int *typenums; |
| 524 | { |
| 525 | int nbits; |
| 526 | if (**pp == '(') |
| 527 | { |
| 528 | (*pp)++; |
| 529 | typenums[0] = read_huge_number (pp, ',', &nbits); |
| 530 | if (nbits != 0) return -1; |
| 531 | typenums[1] = read_huge_number (pp, ')', &nbits); |
| 532 | if (nbits != 0) return -1; |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | typenums[0] = 0; |
| 537 | typenums[1] = read_huge_number (pp, 0, &nbits); |
| 538 | if (nbits != 0) return -1; |
| 539 | } |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | \f |
| 544 | #if !defined (REG_STRUCT_HAS_ADDR) |
| 545 | #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0 |
| 546 | #endif |
| 547 | |
| 548 | #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */ |
| 549 | #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */ |
| 550 | #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */ |
| 551 | #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */ |
| 552 | |
| 553 | #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */ |
| 554 | #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */ |
| 555 | |
| 556 | /* This code added to support parsing of ARM/Cfront stabs strings */ |
| 557 | |
| 558 | /* Get substring from string up to char c, advance string pointer past |
| 559 | suibstring. */ |
| 560 | |
| 561 | static char * |
| 562 | get_substring (p, c) |
| 563 | char ** p; |
| 564 | int c; |
| 565 | { |
| 566 | char *str; |
| 567 | str = *p; |
| 568 | *p = strchr (*p, c); |
| 569 | if (*p) |
| 570 | { |
| 571 | **p = 0; |
| 572 | (*p)++; |
| 573 | } |
| 574 | else |
| 575 | str = 0; |
| 576 | return str; |
| 577 | } |
| 578 | |
| 579 | /* Physname gets strcat'd onto sname in order to recreate the mangled |
| 580 | name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make |
| 581 | the physname look like that of g++ - take out the initial mangling |
| 582 | eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */ |
| 583 | |
| 584 | static char * |
| 585 | get_cfront_method_physname (fname) |
| 586 | char *fname; |
| 587 | { |
| 588 | int len = 0; |
| 589 | /* FIXME would like to make this generic for g++ too, but |
| 590 | that is already handled in read_member_funcctions */ |
| 591 | char * p = fname; |
| 592 | |
| 593 | /* search ahead to find the start of the mangled suffix */ |
| 594 | if (*p == '_' && *(p+1)=='_') /* compiler generated; probably a ctor/dtor */ |
| 595 | p += 2; |
| 596 | while (p && (unsigned) ((p+1) - fname) < strlen (fname) && *(p+1) != '_') |
| 597 | p = strchr (p, '_'); |
| 598 | if (!(p && *p == '_' && *(p+1) == '_')) |
| 599 | error ("Invalid mangled function name %s",fname); |
| 600 | p += 2; /* advance past '__' */ |
| 601 | |
| 602 | /* struct name length and name of type should come next; advance past it */ |
| 603 | while (isdigit (*p)) |
| 604 | { |
| 605 | len = len * 10 + (*p - '0'); |
| 606 | p++; |
| 607 | } |
| 608 | p += len; |
| 609 | |
| 610 | return p; |
| 611 | } |
| 612 | |
| 613 | /* Read base classes within cfront class definition. |
| 614 | eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;; |
| 615 | ^^^^^^^^^^^^^^^^^^ |
| 616 | |
| 617 | A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;; |
| 618 | ^ |
| 619 | */ |
| 620 | |
| 621 | static int |
| 622 | read_cfront_baseclasses (fip, pp, type, objfile) |
| 623 | struct field_info *fip; |
| 624 | struct objfile *objfile; |
| 625 | char ** pp; |
| 626 | struct type *type; |
| 627 | { |
| 628 | static struct complaint msg_unknown = {"\ |
| 629 | Unsupported token in stabs string %s.\n", |
| 630 | 0, 0}; |
| 631 | static struct complaint msg_notfound = {"\ |
| 632 | Unable to find base type for %s.\n", |
| 633 | 0, 0}; |
| 634 | int bnum = 0; |
| 635 | char * p; |
| 636 | int i; |
| 637 | struct nextfield *new; |
| 638 | |
| 639 | if (**pp == ';') /* no base classes; return */ |
| 640 | { |
| 641 | ++(*pp); |
| 642 | return 1; |
| 643 | } |
| 644 | |
| 645 | /* first count base classes so we can allocate space before parsing */ |
| 646 | for (p = *pp; p && *p && *p != ';'; p++) |
| 647 | { |
| 648 | if (*p == ' ') |
| 649 | bnum++; |
| 650 | } |
| 651 | bnum++; /* add one more for last one */ |
| 652 | |
| 653 | /* now parse the base classes until we get to the start of the methods |
| 654 | (code extracted and munged from read_baseclasses) */ |
| 655 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 656 | TYPE_N_BASECLASSES(type) = bnum; |
| 657 | |
| 658 | /* allocate space */ |
| 659 | { |
| 660 | int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); |
| 661 | char *pointer; |
| 662 | |
| 663 | pointer = (char *) TYPE_ALLOC (type, num_bytes); |
| 664 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; |
| 665 | } |
| 666 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); |
| 667 | |
| 668 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
| 669 | { |
| 670 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 671 | make_cleanup (free, new); |
| 672 | memset (new, 0, sizeof (struct nextfield)); |
| 673 | new -> next = fip -> list; |
| 674 | fip -> list = new; |
| 675 | FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */ |
| 676 | |
| 677 | STABS_CONTINUE (pp, objfile); |
| 678 | |
| 679 | /* virtual? eg: v2@Bvir */ |
| 680 | if (**pp=='v') |
| 681 | { |
| 682 | SET_TYPE_FIELD_VIRTUAL (type, i); |
| 683 | ++(*pp); |
| 684 | } |
| 685 | |
| 686 | /* access? eg: 2@Bvir */ |
| 687 | /* Note: protected inheritance not supported in cfront */ |
| 688 | switch (*(*pp)++) |
| 689 | { |
| 690 | case CFRONT_VISIBILITY_PRIVATE: |
| 691 | new -> visibility = VISIBILITY_PRIVATE; |
| 692 | break; |
| 693 | case CFRONT_VISIBILITY_PUBLIC: |
| 694 | new -> visibility = VISIBILITY_PUBLIC; |
| 695 | break; |
| 696 | default: |
| 697 | /* Bad visibility format. Complain and treat it as |
| 698 | public. */ |
| 699 | { |
| 700 | static struct complaint msg = { |
| 701 | "Unknown visibility `%c' for baseclass", 0, 0}; |
| 702 | complain (&msg, new -> visibility); |
| 703 | new -> visibility = VISIBILITY_PUBLIC; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /* "@" comes next - eg: @Bvir */ |
| 708 | if (**pp!='@') |
| 709 | { |
| 710 | complain (&msg_unknown, *pp); |
| 711 | return 1; |
| 712 | } |
| 713 | ++(*pp); |
| 714 | |
| 715 | |
| 716 | /* Set the bit offset of the portion of the object corresponding |
| 717 | to this baseclass. Always zero in the absence of |
| 718 | multiple inheritance. */ |
| 719 | /* Unable to read bit position from stabs; |
| 720 | Assuming no multiple inheritance for now FIXME! */ |
| 721 | /* We may have read this in the structure definition; |
| 722 | now we should fixup the members to be the actual base classes */ |
| 723 | FIELD_BITPOS (new->field) = 0; |
| 724 | |
| 725 | /* Get the base class name and type */ |
| 726 | { |
| 727 | char * bname; /* base class name */ |
| 728 | struct symbol * bsym; /* base class */ |
| 729 | char * p1, * p2; |
| 730 | p1 = strchr (*pp,' '); |
| 731 | p2 = strchr (*pp,';'); |
| 732 | if (p1<p2) |
| 733 | bname = get_substring (pp,' '); |
| 734 | else |
| 735 | bname = get_substring (pp,';'); |
| 736 | if (!bname || !*bname) |
| 737 | { |
| 738 | complain (&msg_unknown, *pp); |
| 739 | return 1; |
| 740 | } |
| 741 | /* FIXME! attach base info to type */ |
| 742 | bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name*/ |
| 743 | if (bsym) |
| 744 | { |
| 745 | new -> field.type = SYMBOL_TYPE(bsym); |
| 746 | new -> field.name = type_name_no_tag (new -> field.type); |
| 747 | } |
| 748 | else |
| 749 | { |
| 750 | complain (&msg_notfound, *pp); |
| 751 | return 1; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | /* If more base classes to parse, loop again. |
| 756 | We ate the last ' ' or ';' in get_substring, |
| 757 | so on exit we will have skipped the trailing ';' */ |
| 758 | /* if invalid, return 0; add code to detect - FIXME! */ |
| 759 | } |
| 760 | return 1; |
| 761 | } |
| 762 | |
| 763 | /* read cfront member functions. |
| 764 | pp points to string starting with list of functions |
| 765 | eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;; |
| 766 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 767 | A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;; |
| 768 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 769 | */ |
| 770 | |
| 771 | static int |
| 772 | read_cfront_member_functions (fip, pp, type, objfile) |
| 773 | struct field_info *fip; |
| 774 | char **pp; |
| 775 | struct type *type; |
| 776 | struct objfile *objfile; |
| 777 | { |
| 778 | /* This code extracted from read_member_functions |
| 779 | so as to do the similar thing for our funcs */ |
| 780 | |
| 781 | int nfn_fields = 0; |
| 782 | int length = 0; |
| 783 | /* Total number of member functions defined in this class. If the class |
| 784 | defines two `f' functions, and one `g' function, then this will have |
| 785 | the value 3. */ |
| 786 | int total_length = 0; |
| 787 | int i; |
| 788 | struct next_fnfield |
| 789 | { |
| 790 | struct next_fnfield *next; |
| 791 | struct fn_field fn_field; |
| 792 | } *sublist; |
| 793 | struct type *look_ahead_type; |
| 794 | struct next_fnfieldlist *new_fnlist; |
| 795 | struct next_fnfield *new_sublist; |
| 796 | char *main_fn_name; |
| 797 | char * fname; |
| 798 | struct symbol * ref_func = 0; |
| 799 | |
| 800 | /* Process each list until we find the end of the member functions. |
| 801 | eg: p = "__ct__1AFv foo__1AFv ;;;" */ |
| 802 | |
| 803 | STABS_CONTINUE (pp, objfile); /* handle \\ */ |
| 804 | |
| 805 | while (**pp != ';' && (fname = get_substring (pp, ' '), fname)) |
| 806 | { |
| 807 | int is_static = 0; |
| 808 | int sublist_count = 0; |
| 809 | char * pname; |
| 810 | if (fname[0] == '*') /* static member */ |
| 811 | { |
| 812 | is_static=1; |
| 813 | sublist_count++; |
| 814 | fname++; |
| 815 | } |
| 816 | ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */ |
| 817 | if (!ref_func) |
| 818 | { |
| 819 | static struct complaint msg = {"\ |
| 820 | Unable to find function symbol for %s\n", |
| 821 | 0, 0}; |
| 822 | complain (&msg, fname); |
| 823 | continue; |
| 824 | } |
| 825 | sublist = NULL; |
| 826 | look_ahead_type = NULL; |
| 827 | length = 0; |
| 828 | |
| 829 | new_fnlist = (struct next_fnfieldlist *) |
| 830 | xmalloc (sizeof (struct next_fnfieldlist)); |
| 831 | make_cleanup (free, new_fnlist); |
| 832 | memset (new_fnlist, 0, sizeof (struct next_fnfieldlist)); |
| 833 | |
| 834 | /* The following is code to work around cfront generated stabs. |
| 835 | The stabs contains full mangled name for each field. |
| 836 | We try to demangle the name and extract the field name out of it. */ |
| 837 | { |
| 838 | char *dem, *dem_p, *dem_args; |
| 839 | int dem_len; |
| 840 | dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS); |
| 841 | if (dem != NULL) |
| 842 | { |
| 843 | dem_p = strrchr (dem, ':'); |
| 844 | if (dem_p != 0 && *(dem_p-1) == ':') |
| 845 | dem_p++; |
| 846 | /* get rid of args */ |
| 847 | dem_args = strchr (dem_p, '('); |
| 848 | if (dem_args == NULL) |
| 849 | dem_len = strlen (dem_p); |
| 850 | else |
| 851 | dem_len = dem_args - dem_p; |
| 852 | main_fn_name = |
| 853 | obsavestring (dem_p, dem_len, &objfile -> type_obstack); |
| 854 | } |
| 855 | else |
| 856 | { |
| 857 | main_fn_name = |
| 858 | obsavestring (fname, strlen (fname), &objfile -> type_obstack); |
| 859 | } |
| 860 | } /* end of code for cfront work around */ |
| 861 | |
| 862 | new_fnlist -> fn_fieldlist.name = main_fn_name; |
| 863 | |
| 864 | /*-------------------------------------------------*/ |
| 865 | /* Set up the sublists |
| 866 | Sublists are stuff like args, static, visibility, etc. |
| 867 | so in ARM, we have to set that info some other way. |
| 868 | Multiple sublists happen if overloading |
| 869 | eg: foo::26=##1;:;2A.; |
| 870 | In g++, we'd loop here thru all the sublists... */ |
| 871 | |
| 872 | new_sublist = |
| 873 | (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield)); |
| 874 | make_cleanup (free, new_sublist); |
| 875 | memset (new_sublist, 0, sizeof (struct next_fnfield)); |
| 876 | |
| 877 | /* eat 1; from :;2A.; */ |
| 878 | new_sublist -> fn_field.type = SYMBOL_TYPE(ref_func); /* normally takes a read_type */ |
| 879 | /* Make this type look like a method stub for gdb */ |
| 880 | TYPE_FLAGS (new_sublist -> fn_field.type) |= TYPE_FLAG_STUB; |
| 881 | TYPE_CODE (new_sublist -> fn_field.type) = TYPE_CODE_METHOD; |
| 882 | |
| 883 | /* If this is just a stub, then we don't have the real name here. */ |
| 884 | if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB) |
| 885 | { |
| 886 | if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type)) |
| 887 | TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type; |
| 888 | new_sublist -> fn_field.is_stub = 1; |
| 889 | } |
| 890 | |
| 891 | /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i |
| 892 | physname gets strcat'd in order to recreate the onto mangled name */ |
| 893 | pname = get_cfront_method_physname (fname); |
| 894 | new_sublist -> fn_field.physname = savestring (pname, strlen (pname)); |
| 895 | |
| 896 | |
| 897 | /* Set this member function's visibility fields. |
| 898 | Unable to distinguish access from stabs definition! |
| 899 | Assuming public for now. FIXME! |
| 900 | (for private, set new_sublist->fn_field.is_private = 1, |
| 901 | for public, set new_sublist->fn_field.is_protected = 1) */ |
| 902 | |
| 903 | /* Unable to distinguish const/volatile from stabs definition! |
| 904 | Assuming normal for now. FIXME! */ |
| 905 | |
| 906 | new_sublist -> fn_field.is_const = 0; |
| 907 | new_sublist -> fn_field.is_volatile = 0; /* volatile not implemented in cfront */ |
| 908 | |
| 909 | /* Set virtual/static function info |
| 910 | How to get vtable offsets ? |
| 911 | Assuming normal for now FIXME!! |
| 912 | For vtables, figure out from whence this virtual function came. |
| 913 | It may belong to virtual function table of |
| 914 | one of its baseclasses. |
| 915 | set: |
| 916 | new_sublist -> fn_field.voffset = vtable offset, |
| 917 | new_sublist -> fn_field.fcontext = look_ahead_type; |
| 918 | where look_ahead_type is type of baseclass */ |
| 919 | if (is_static) |
| 920 | new_sublist -> fn_field.voffset = VOFFSET_STATIC; |
| 921 | else /* normal member function. */ |
| 922 | new_sublist -> fn_field.voffset = 0; |
| 923 | new_sublist -> fn_field.fcontext = 0; |
| 924 | |
| 925 | |
| 926 | /* Prepare new sublist */ |
| 927 | new_sublist -> next = sublist; |
| 928 | sublist = new_sublist; |
| 929 | length++; |
| 930 | |
| 931 | /* In g++, we loop thu sublists - now we set from functions. */ |
| 932 | new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *) |
| 933 | obstack_alloc (&objfile -> type_obstack, |
| 934 | sizeof (struct fn_field) * length); |
| 935 | memset (new_fnlist -> fn_fieldlist.fn_fields, 0, |
| 936 | sizeof (struct fn_field) * length); |
| 937 | for (i = length; (i--, sublist); sublist = sublist -> next) |
| 938 | { |
| 939 | new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field; |
| 940 | } |
| 941 | |
| 942 | new_fnlist -> fn_fieldlist.length = length; |
| 943 | new_fnlist -> next = fip -> fnlist; |
| 944 | fip -> fnlist = new_fnlist; |
| 945 | nfn_fields++; |
| 946 | total_length += length; |
| 947 | STABS_CONTINUE (pp, objfile); /* handle \\ */ |
| 948 | } /* end of loop */ |
| 949 | |
| 950 | if (nfn_fields) |
| 951 | { |
| 952 | /* type should already have space */ |
| 953 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 954 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); |
| 955 | memset (TYPE_FN_FIELDLISTS (type), 0, |
| 956 | sizeof (struct fn_fieldlist) * nfn_fields); |
| 957 | TYPE_NFN_FIELDS (type) = nfn_fields; |
| 958 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; |
| 959 | } |
| 960 | |
| 961 | /* end of scope for reading member func */ |
| 962 | |
| 963 | /* eg: ";;" */ |
| 964 | |
| 965 | /* Skip trailing ';' and bump count of number of fields seen */ |
| 966 | if (**pp == ';') |
| 967 | (*pp)++; |
| 968 | else |
| 969 | return 0; |
| 970 | return 1; |
| 971 | } |
| 972 | |
| 973 | /* This routine fixes up partial cfront types that were created |
| 974 | while parsing the stabs. The main need for this function is |
| 975 | to add information such as methods to classes. |
| 976 | Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */ |
| 977 | int |
| 978 | resolve_cfront_continuation (objfile, sym, p) |
| 979 | struct objfile * objfile; |
| 980 | struct symbol * sym; |
| 981 | char * p; |
| 982 | { |
| 983 | struct symbol * ref_sym=0; |
| 984 | char * sname; |
| 985 | /* snarfed from read_struct_type */ |
| 986 | struct field_info fi; |
| 987 | struct type *type; |
| 988 | struct cleanup *back_to; |
| 989 | |
| 990 | /* Need to make sure that fi isn't gunna conflict with struct |
| 991 | in case struct already had some fnfs */ |
| 992 | fi.list = NULL; |
| 993 | fi.fnlist = NULL; |
| 994 | back_to = make_cleanup (null_cleanup, 0); |
| 995 | |
| 996 | /* We only accept structs, classes and unions at the moment. |
| 997 | Other continuation types include t (typedef), r (long dbl), ... |
| 998 | We may want to add support for them as well; |
| 999 | right now they are handled by duplicating the symbol information |
| 1000 | into the type information (see define_symbol) */ |
| 1001 | if (*p != 's' /* structs */ |
| 1002 | && *p != 'c' /* class */ |
| 1003 | && *p != 'u') /* union */ |
| 1004 | return 0; /* only handle C++ types */ |
| 1005 | p++; |
| 1006 | |
| 1007 | /* Get symbol typs name and validate |
| 1008 | eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */ |
| 1009 | sname = get_substring (&p, ';'); |
| 1010 | if (!sname || strcmp (sname, SYMBOL_NAME(sym))) |
| 1011 | error ("Internal error: base symbol type name does not match\n"); |
| 1012 | |
| 1013 | /* Find symbol's internal gdb reference using demangled_name. |
| 1014 | This is the real sym that we want; |
| 1015 | sym was a temp hack to make debugger happy */ |
| 1016 | ref_sym = lookup_symbol (SYMBOL_NAME(sym), 0, STRUCT_NAMESPACE, 0, 0); |
| 1017 | type = SYMBOL_TYPE(ref_sym); |
| 1018 | |
| 1019 | |
| 1020 | /* Now read the baseclasses, if any, read the regular C struct or C++ |
| 1021 | class member fields, attach the fields to the type, read the C++ |
| 1022 | member functions, attach them to the type, and then read any tilde |
| 1023 | field (baseclass specifier for the class holding the main vtable). */ |
| 1024 | |
| 1025 | if (!read_cfront_baseclasses (&fi, &p, type, objfile) |
| 1026 | /* g++ does this next, but cfront already did this: |
| 1027 | || !read_struct_fields (&fi, &p, type, objfile) */ |
| 1028 | || !copy_cfront_struct_fields (&fi, type, objfile) |
| 1029 | || !read_cfront_member_functions (&fi, &p, type, objfile) |
| 1030 | || !read_cfront_static_fields (&fi, &p, type, objfile) |
| 1031 | || !attach_fields_to_type (&fi, type, objfile) |
| 1032 | || !attach_fn_fields_to_type (&fi, type) |
| 1033 | /* g++ does this next, but cfront doesn't seem to have this: |
| 1034 | || !read_tilde_fields (&fi, &p, type, objfile) */ |
| 1035 | ) |
| 1036 | { |
| 1037 | type = error_type (&p, objfile); |
| 1038 | } |
| 1039 | |
| 1040 | do_cleanups (back_to); |
| 1041 | return 0; |
| 1042 | } |
| 1043 | /* End of code added to support parsing of ARM/Cfront stabs strings */ |
| 1044 | |
| 1045 | |
| 1046 | /* This routine fixes up symbol references/aliases to point to the original |
| 1047 | symbol definition. */ |
| 1048 | |
| 1049 | static int |
| 1050 | resolve_symbol_reference (objfile, sym, p) |
| 1051 | struct objfile *objfile; |
| 1052 | struct symbol *sym; |
| 1053 | char *p; |
| 1054 | { |
| 1055 | int refnum; |
| 1056 | struct symbol *ref_sym=0; |
| 1057 | struct alias_list *alias; |
| 1058 | |
| 1059 | /* If this is not a symbol reference return now. */ |
| 1060 | if (*p != '#') |
| 1061 | return 0; |
| 1062 | |
| 1063 | /* Use "#<num>" as the name; we'll fix the name later. |
| 1064 | We stored the original symbol name as "#<id>=<name>" |
| 1065 | so we can now search for "#<id>" to resolving the reference. |
| 1066 | We'll fix the names later by removing the "#<id>" or "#<id>=" */ |
| 1067 | |
| 1068 | /*---------------------------------------------------------*/ |
| 1069 | /* Get the reference id number, and |
| 1070 | advance p past the names so we can parse the rest. |
| 1071 | eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */ |
| 1072 | /*---------------------------------------------------------*/ |
| 1073 | |
| 1074 | /* This gets reference name from string. sym may not have a name. */ |
| 1075 | |
| 1076 | /* Get the reference number associated with the reference id in the |
| 1077 | gdb stab string. From that reference number, get the main/primary |
| 1078 | symbol for this alias. */ |
| 1079 | refnum = process_reference (&p); |
| 1080 | ref_sym = ref_search (refnum); |
| 1081 | if (!ref_sym) |
| 1082 | error ("error: symbol for reference not found.\n"); |
| 1083 | |
| 1084 | |
| 1085 | /* Parse the stab of the referencing symbol |
| 1086 | now that we have the referenced symbol. |
| 1087 | Add it as a new symbol and a link back to the referenced symbol. |
| 1088 | eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */ |
| 1089 | |
| 1090 | |
| 1091 | /* If the stab symbol table and string contain: |
| 1092 | RSYM 0 5 00000000 868 #15=z:r(0,1) |
| 1093 | LBRAC 0 0 00000000 899 #5= |
| 1094 | SLINE 0 16 00000003 923 #6= |
| 1095 | Then the same symbols can be later referenced by: |
| 1096 | RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6) |
| 1097 | This is used in live range splitting to: |
| 1098 | 1) specify that a symbol (#15) is actually just a new storage |
| 1099 | class for a symbol (#15=z) which was previously defined. |
| 1100 | 2) specify that the beginning and ending ranges for a symbol |
| 1101 | (#15) are the values of the beginning (#5) and ending (#6) |
| 1102 | symbols. */ |
| 1103 | |
| 1104 | /* Read number as reference id. |
| 1105 | eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */ |
| 1106 | /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 1107 | in case of "l(0,0)"? */ |
| 1108 | |
| 1109 | /*--------------------------------------------------*/ |
| 1110 | /* Add this symbol to the reference list. */ |
| 1111 | /*--------------------------------------------------*/ |
| 1112 | |
| 1113 | alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack, |
| 1114 | sizeof (struct alias_list)); |
| 1115 | if (!alias) |
| 1116 | error ("Unable to allocate alias list memory"); |
| 1117 | |
| 1118 | alias->next = 0; |
| 1119 | alias->sym = sym; |
| 1120 | |
| 1121 | if (!SYMBOL_ALIASES (ref_sym)) |
| 1122 | { |
| 1123 | SYMBOL_ALIASES (ref_sym) = alias; |
| 1124 | } |
| 1125 | else |
| 1126 | { |
| 1127 | struct alias_list *temp; |
| 1128 | |
| 1129 | /* Get to the end of the list. */ |
| 1130 | for (temp = SYMBOL_ALIASES (ref_sym); |
| 1131 | temp->next; |
| 1132 | temp = temp->next); |
| 1133 | ; |
| 1134 | temp->next = alias; |
| 1135 | } |
| 1136 | |
| 1137 | /* Want to fix up name so that other functions (eg. valops) |
| 1138 | will correctly print the name. |
| 1139 | Don't add_symbol_to_list so that lookup_symbol won't find it. |
| 1140 | nope... needed for fixups. */ |
| 1141 | SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym); |
| 1142 | |
| 1143 | /* Done! */ |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | #define MAX_CHUNK_REFS 100 |
| 1148 | #define REF_CHUNK_SIZE \ |
| 1149 | MAX_CHUNK_REFS * sizeof (struct ref_map_s) |
| 1150 | #define REF_MAP_SIZE(ref_chunk) \ |
| 1151 | ref_chunk * REF_CHUNK_SIZE |
| 1152 | |
| 1153 | /* Structure for storing pointers to reference definitions for fast lookup |
| 1154 | during "process_later". */ |
| 1155 | static struct ref_map_s |
| 1156 | { |
| 1157 | char *stabs; |
| 1158 | CORE_ADDR value; |
| 1159 | struct symbol *sym; |
| 1160 | } *ref_map; |
| 1161 | |
| 1162 | /* Ptr to free cell in chunk's linked list. */ |
| 1163 | static int ref_count = 0; |
| 1164 | |
| 1165 | /* Number of chunks malloced. */ |
| 1166 | static int ref_chunk = 0; |
| 1167 | |
| 1168 | /* Initialize our list of references. |
| 1169 | This should be called before any symbol table is read. */ |
| 1170 | |
| 1171 | static void |
| 1172 | ref_init () |
| 1173 | { |
| 1174 | ref_count = 0; |
| 1175 | ref_chunk = 0; |
| 1176 | } |
| 1177 | |
| 1178 | /* Create array of pointers mapping refids to symbols and stab strings. |
| 1179 | Add pointers to reference definition symbols and/or their values as we |
| 1180 | find them, using their reference numbers as our index. |
| 1181 | These will be used later when we resolve references. */ |
| 1182 | void |
| 1183 | ref_add (refnum, sym, stabs, value) |
| 1184 | int refnum; |
| 1185 | struct symbol *sym; |
| 1186 | char *stabs; |
| 1187 | CORE_ADDR value; |
| 1188 | { |
| 1189 | if (ref_count == 0) |
| 1190 | ref_init (); |
| 1191 | if (refnum >= ref_count) |
| 1192 | ref_count = refnum + 1; |
| 1193 | if (ref_count > ref_chunk * MAX_CHUNK_REFS) |
| 1194 | { |
| 1195 | int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS; |
| 1196 | int new_chunks = new_slots / MAX_CHUNK_REFS + 1; |
| 1197 | ref_map = (struct ref_map_s *) |
| 1198 | xrealloc (ref_map, REF_MAP_SIZE(ref_chunk + new_chunks)); |
| 1199 | if (!ref_map) |
| 1200 | error ("no more free slots in chain\n"); |
| 1201 | memset (ref_map + REF_MAP_SIZE(ref_chunk), 0, new_chunks * REF_CHUNK_SIZE); |
| 1202 | ref_chunk += new_chunks; |
| 1203 | } |
| 1204 | ref_map[refnum].stabs = stabs; |
| 1205 | ref_map[refnum].sym = sym; |
| 1206 | ref_map[refnum].value = value; |
| 1207 | } |
| 1208 | |
| 1209 | /* Return defined sym for the reference REFNUM. */ |
| 1210 | struct symbol * |
| 1211 | ref_search (refnum) |
| 1212 | int refnum; |
| 1213 | { |
| 1214 | if (refnum < 0 || refnum > ref_count) |
| 1215 | return 0; |
| 1216 | return ref_map[refnum].sym; |
| 1217 | } |
| 1218 | |
| 1219 | /* Return value for the reference REFNUM. */ |
| 1220 | |
| 1221 | static CORE_ADDR |
| 1222 | ref_search_value (refnum) |
| 1223 | int refnum; |
| 1224 | { |
| 1225 | if (refnum < 0 || refnum > ref_count) |
| 1226 | return 0; |
| 1227 | return ref_map[refnum].value; |
| 1228 | } |
| 1229 | |
| 1230 | /* Parse a reference id in STRING and return the resulting |
| 1231 | reference number. Move STRING beyond the reference id. */ |
| 1232 | |
| 1233 | static int |
| 1234 | process_reference (string) |
| 1235 | char **string; |
| 1236 | { |
| 1237 | char *p; |
| 1238 | int refnum = 0; |
| 1239 | |
| 1240 | if (**string != '#') |
| 1241 | return 0; |
| 1242 | |
| 1243 | /* Advance beyond the initial '#'. */ |
| 1244 | p = *string + 1; |
| 1245 | |
| 1246 | /* Read number as reference id. */ |
| 1247 | while (*p && isdigit (*p)) |
| 1248 | { |
| 1249 | refnum = refnum * 10 + *p - '0'; |
| 1250 | p++; |
| 1251 | } |
| 1252 | *string = p; |
| 1253 | return refnum; |
| 1254 | } |
| 1255 | |
| 1256 | /* If STRING defines a reference, store away a pointer to the reference |
| 1257 | definition for later use. Return the reference number. */ |
| 1258 | |
| 1259 | int |
| 1260 | symbol_reference_defined (string) |
| 1261 | char **string; |
| 1262 | { |
| 1263 | char *p = *string; |
| 1264 | int refnum = 0; |
| 1265 | |
| 1266 | refnum = process_reference (&p); |
| 1267 | |
| 1268 | /* Defining symbols end in '=' */ |
| 1269 | if (*p == '=') |
| 1270 | { |
| 1271 | /* Symbol is being defined here. */ |
| 1272 | *string = p + 1; |
| 1273 | return refnum; |
| 1274 | } |
| 1275 | else |
| 1276 | { |
| 1277 | /* Must be a reference. Either the symbol has already been defined, |
| 1278 | or this is a forward reference to it. */ |
| 1279 | *string = p; |
| 1280 | return -1; |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /* ARGSUSED */ |
| 1285 | struct symbol * |
| 1286 | define_symbol (valu, string, desc, type, objfile) |
| 1287 | CORE_ADDR valu; |
| 1288 | char *string; |
| 1289 | int desc; |
| 1290 | int type; |
| 1291 | struct objfile *objfile; |
| 1292 | { |
| 1293 | register struct symbol *sym; |
| 1294 | char *p = (char *) strchr (string, ':'); |
| 1295 | int deftype; |
| 1296 | int synonym = 0; |
| 1297 | register int i; |
| 1298 | |
| 1299 | /* We would like to eliminate nameless symbols, but keep their types. |
| 1300 | E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer |
| 1301 | to type 2, but, should not create a symbol to address that type. Since |
| 1302 | the symbol will be nameless, there is no way any user can refer to it. */ |
| 1303 | |
| 1304 | int nameless; |
| 1305 | |
| 1306 | /* Ignore syms with empty names. */ |
| 1307 | if (string[0] == 0) |
| 1308 | return 0; |
| 1309 | |
| 1310 | /* Ignore old-style symbols from cc -go */ |
| 1311 | if (p == 0) |
| 1312 | return 0; |
| 1313 | |
| 1314 | while (p[1] == ':') |
| 1315 | { |
| 1316 | p += 2; |
| 1317 | p = strchr (p, ':'); |
| 1318 | } |
| 1319 | |
| 1320 | /* If a nameless stab entry, all we need is the type, not the symbol. |
| 1321 | e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */ |
| 1322 | nameless = (p == string || ((string[0] == ' ') && (string[1] == ':'))); |
| 1323 | |
| 1324 | current_symbol = sym = (struct symbol *) |
| 1325 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 1326 | memset (sym, 0, sizeof (struct symbol)); |
| 1327 | |
| 1328 | switch (type & N_TYPE) |
| 1329 | { |
| 1330 | case N_TEXT: |
| 1331 | SYMBOL_SECTION(sym) = SECT_OFF_TEXT; |
| 1332 | break; |
| 1333 | case N_DATA: |
| 1334 | SYMBOL_SECTION(sym) = SECT_OFF_DATA; |
| 1335 | break; |
| 1336 | case N_BSS: |
| 1337 | SYMBOL_SECTION(sym) = SECT_OFF_BSS; |
| 1338 | break; |
| 1339 | } |
| 1340 | |
| 1341 | if (processing_gcc_compilation) |
| 1342 | { |
| 1343 | /* GCC 2.x puts the line number in desc. SunOS apparently puts in the |
| 1344 | number of bytes occupied by a type or object, which we ignore. */ |
| 1345 | SYMBOL_LINE(sym) = desc; |
| 1346 | } |
| 1347 | else |
| 1348 | { |
| 1349 | SYMBOL_LINE(sym) = 0; /* unknown */ |
| 1350 | } |
| 1351 | |
| 1352 | if (is_cplus_marker (string[0])) |
| 1353 | { |
| 1354 | /* Special GNU C++ names. */ |
| 1355 | switch (string[1]) |
| 1356 | { |
| 1357 | case 't': |
| 1358 | SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"), |
| 1359 | &objfile -> symbol_obstack); |
| 1360 | break; |
| 1361 | |
| 1362 | case 'v': /* $vtbl_ptr_type */ |
| 1363 | /* Was: SYMBOL_NAME (sym) = "vptr"; */ |
| 1364 | goto normal; |
| 1365 | |
| 1366 | case 'e': |
| 1367 | SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"), |
| 1368 | &objfile -> symbol_obstack); |
| 1369 | break; |
| 1370 | |
| 1371 | case '_': |
| 1372 | /* This was an anonymous type that was never fixed up. */ |
| 1373 | goto normal; |
| 1374 | |
| 1375 | #ifdef STATIC_TRANSFORM_NAME |
| 1376 | case 'X': |
| 1377 | /* SunPRO (3.0 at least) static variable encoding. */ |
| 1378 | goto normal; |
| 1379 | #endif |
| 1380 | |
| 1381 | default: |
| 1382 | complain (&unrecognized_cplus_name_complaint, string); |
| 1383 | goto normal; /* Do *something* with it */ |
| 1384 | } |
| 1385 | } |
| 1386 | else if (string[0] == '#') |
| 1387 | { |
| 1388 | /* Special GNU C extension for referencing symbols. */ |
| 1389 | char *s; |
| 1390 | int refnum, nlen; |
| 1391 | |
| 1392 | /* If STRING defines a new reference id, then add it to the |
| 1393 | reference map. Else it must be referring to a previously |
| 1394 | defined symbol, so add it to the alias list of the previously |
| 1395 | defined symbol. */ |
| 1396 | s = string; |
| 1397 | refnum = symbol_reference_defined (&s); |
| 1398 | if (refnum >= 0) |
| 1399 | ref_add (refnum, sym, string, SYMBOL_VALUE (sym)); |
| 1400 | else |
| 1401 | resolve_symbol_reference (objfile, sym, string); |
| 1402 | |
| 1403 | /* S..P contains the name of the symbol. We need to store |
| 1404 | the correct name into SYMBOL_NAME. */ |
| 1405 | nlen = p - s; |
| 1406 | if (refnum >= 0) |
| 1407 | { |
| 1408 | if (nlen > 0) |
| 1409 | { |
| 1410 | SYMBOL_NAME (sym) = (char *) |
| 1411 | obstack_alloc (&objfile -> symbol_obstack, nlen); |
| 1412 | strncpy (SYMBOL_NAME (sym), s, nlen); |
| 1413 | SYMBOL_NAME (sym)[nlen] = '\0'; |
| 1414 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); |
| 1415 | } |
| 1416 | else |
| 1417 | /* FIXME! Want SYMBOL_NAME (sym) = 0; |
| 1418 | Get error if leave name 0. So give it something. */ |
| 1419 | { |
| 1420 | nlen = p - string; |
| 1421 | SYMBOL_NAME (sym) = (char *) |
| 1422 | obstack_alloc (&objfile -> symbol_obstack, nlen); |
| 1423 | strncpy (SYMBOL_NAME (sym), string, nlen); |
| 1424 | SYMBOL_NAME (sym)[nlen] = '\0'; |
| 1425 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); |
| 1426 | } |
| 1427 | } |
| 1428 | /* Advance STRING beyond the reference id. */ |
| 1429 | string = s; |
| 1430 | } |
| 1431 | else |
| 1432 | { |
| 1433 | normal: |
| 1434 | SYMBOL_LANGUAGE (sym) = current_subfile -> language; |
| 1435 | SYMBOL_NAME (sym) = (char *) |
| 1436 | obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1)); |
| 1437 | /* Open-coded memcpy--saves function call time. */ |
| 1438 | /* FIXME: Does it really? Try replacing with simple strcpy and |
| 1439 | try it on an executable with a large symbol table. */ |
| 1440 | /* FIXME: considering that gcc can open code memcpy anyway, I |
| 1441 | doubt it. xoxorich. */ |
| 1442 | { |
| 1443 | register char *p1 = string; |
| 1444 | register char *p2 = SYMBOL_NAME (sym); |
| 1445 | while (p1 != p) |
| 1446 | { |
| 1447 | *p2++ = *p1++; |
| 1448 | } |
| 1449 | *p2++ = '\0'; |
| 1450 | } |
| 1451 | |
| 1452 | /* If this symbol is from a C++ compilation, then attempt to cache the |
| 1453 | demangled form for future reference. This is a typical time versus |
| 1454 | space tradeoff, that was decided in favor of time because it sped up |
| 1455 | C++ symbol lookups by a factor of about 20. */ |
| 1456 | |
| 1457 | SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack); |
| 1458 | } |
| 1459 | p++; |
| 1460 | |
| 1461 | /* Determine the type of name being defined. */ |
| 1462 | #if 0 |
| 1463 | /* Getting GDB to correctly skip the symbol on an undefined symbol |
| 1464 | descriptor and not ever dump core is a very dodgy proposition if |
| 1465 | we do things this way. I say the acorn RISC machine can just |
| 1466 | fix their compiler. */ |
| 1467 | /* The Acorn RISC machine's compiler can put out locals that don't |
| 1468 | start with "234=" or "(3,4)=", so assume anything other than the |
| 1469 | deftypes we know how to handle is a local. */ |
| 1470 | if (!strchr ("cfFGpPrStTvVXCR", *p)) |
| 1471 | #else |
| 1472 | if (isdigit (*p) || *p == '(' || *p == '-') |
| 1473 | #endif |
| 1474 | deftype = 'l'; |
| 1475 | else |
| 1476 | deftype = *p++; |
| 1477 | |
| 1478 | switch (deftype) |
| 1479 | { |
| 1480 | case 'c': |
| 1481 | /* c is a special case, not followed by a type-number. |
| 1482 | SYMBOL:c=iVALUE for an integer constant symbol. |
| 1483 | SYMBOL:c=rVALUE for a floating constant symbol. |
| 1484 | SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. |
| 1485 | e.g. "b:c=e6,0" for "const b = blob1" |
| 1486 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ |
| 1487 | if (*p != '=') |
| 1488 | { |
| 1489 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 1490 | SYMBOL_TYPE (sym) = error_type (&p, objfile); |
| 1491 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1492 | add_symbol_to_list (sym, &file_symbols); |
| 1493 | return sym; |
| 1494 | } |
| 1495 | ++p; |
| 1496 | switch (*p++) |
| 1497 | { |
| 1498 | case 'r': |
| 1499 | { |
| 1500 | double d = atof (p); |
| 1501 | char *dbl_valu; |
| 1502 | |
| 1503 | /* FIXME-if-picky-about-floating-accuracy: Should be using |
| 1504 | target arithmetic to get the value. real.c in GCC |
| 1505 | probably has the necessary code. */ |
| 1506 | |
| 1507 | /* FIXME: lookup_fundamental_type is a hack. We should be |
| 1508 | creating a type especially for the type of float constants. |
| 1509 | Problem is, what type should it be? |
| 1510 | |
| 1511 | Also, what should the name of this type be? Should we |
| 1512 | be using 'S' constants (see stabs.texinfo) instead? */ |
| 1513 | |
| 1514 | SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, |
| 1515 | FT_DBL_PREC_FLOAT); |
| 1516 | dbl_valu = (char *) |
| 1517 | obstack_alloc (&objfile -> symbol_obstack, |
| 1518 | TYPE_LENGTH (SYMBOL_TYPE (sym))); |
| 1519 | store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d); |
| 1520 | SYMBOL_VALUE_BYTES (sym) = dbl_valu; |
| 1521 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 1522 | } |
| 1523 | break; |
| 1524 | case 'i': |
| 1525 | { |
| 1526 | /* Defining integer constants this way is kind of silly, |
| 1527 | since 'e' constants allows the compiler to give not |
| 1528 | only the value, but the type as well. C has at least |
| 1529 | int, long, unsigned int, and long long as constant |
| 1530 | types; other languages probably should have at least |
| 1531 | unsigned as well as signed constants. */ |
| 1532 | |
| 1533 | /* We just need one int constant type for all objfiles. |
| 1534 | It doesn't depend on languages or anything (arguably its |
| 1535 | name should be a language-specific name for a type of |
| 1536 | that size, but I'm inclined to say that if the compiler |
| 1537 | wants a nice name for the type, it can use 'e'). */ |
| 1538 | static struct type *int_const_type; |
| 1539 | |
| 1540 | /* Yes, this is as long as a *host* int. That is because we |
| 1541 | use atoi. */ |
| 1542 | if (int_const_type == NULL) |
| 1543 | int_const_type = |
| 1544 | init_type (TYPE_CODE_INT, |
| 1545 | sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0, |
| 1546 | "integer constant", |
| 1547 | (struct objfile *)NULL); |
| 1548 | SYMBOL_TYPE (sym) = int_const_type; |
| 1549 | SYMBOL_VALUE (sym) = atoi (p); |
| 1550 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 1551 | } |
| 1552 | break; |
| 1553 | case 'e': |
| 1554 | /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value |
| 1555 | can be represented as integral. |
| 1556 | e.g. "b:c=e6,0" for "const b = blob1" |
| 1557 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ |
| 1558 | { |
| 1559 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 1560 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1561 | |
| 1562 | if (*p != ',') |
| 1563 | { |
| 1564 | SYMBOL_TYPE (sym) = error_type (&p, objfile); |
| 1565 | break; |
| 1566 | } |
| 1567 | ++p; |
| 1568 | |
| 1569 | /* If the value is too big to fit in an int (perhaps because |
| 1570 | it is unsigned), or something like that, we silently get |
| 1571 | a bogus value. The type and everything else about it is |
| 1572 | correct. Ideally, we should be using whatever we have |
| 1573 | available for parsing unsigned and long long values, |
| 1574 | however. */ |
| 1575 | SYMBOL_VALUE (sym) = atoi (p); |
| 1576 | } |
| 1577 | break; |
| 1578 | default: |
| 1579 | { |
| 1580 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 1581 | SYMBOL_TYPE (sym) = error_type (&p, objfile); |
| 1582 | } |
| 1583 | } |
| 1584 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1585 | add_symbol_to_list (sym, &file_symbols); |
| 1586 | return sym; |
| 1587 | |
| 1588 | case 'C': |
| 1589 | /* The name of a caught exception. */ |
| 1590 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1591 | SYMBOL_CLASS (sym) = LOC_LABEL; |
| 1592 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1593 | SYMBOL_VALUE_ADDRESS (sym) = valu; |
| 1594 | add_symbol_to_list (sym, &local_symbols); |
| 1595 | break; |
| 1596 | |
| 1597 | case 'f': |
| 1598 | /* A static function definition. */ |
| 1599 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1600 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 1601 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1602 | add_symbol_to_list (sym, &file_symbols); |
| 1603 | /* fall into process_function_types. */ |
| 1604 | |
| 1605 | process_function_types: |
| 1606 | /* Function result types are described as the result type in stabs. |
| 1607 | We need to convert this to the function-returning-type-X type |
| 1608 | in GDB. E.g. "int" is converted to "function returning int". */ |
| 1609 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC) |
| 1610 | SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); |
| 1611 | |
| 1612 | /* All functions in C++ have prototypes. */ |
| 1613 | if (SYMBOL_LANGUAGE (sym) == language_cplus) |
| 1614 | TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED; |
| 1615 | |
| 1616 | /* fall into process_prototype_types */ |
| 1617 | |
| 1618 | process_prototype_types: |
| 1619 | /* Sun acc puts declared types of arguments here. */ |
| 1620 | if (*p == ';') |
| 1621 | { |
| 1622 | struct type *ftype = SYMBOL_TYPE (sym); |
| 1623 | int nsemi = 0; |
| 1624 | int nparams = 0; |
| 1625 | char *p1 = p; |
| 1626 | |
| 1627 | /* Obtain a worst case guess for the number of arguments |
| 1628 | by counting the semicolons. */ |
| 1629 | while (*p1) |
| 1630 | { |
| 1631 | if (*p1++ == ';') |
| 1632 | nsemi++; |
| 1633 | } |
| 1634 | |
| 1635 | /* Allocate parameter information fields and fill them in. */ |
| 1636 | TYPE_FIELDS (ftype) = (struct field *) |
| 1637 | TYPE_ALLOC (ftype, nsemi * sizeof (struct field)); |
| 1638 | while (*p++ == ';') |
| 1639 | { |
| 1640 | struct type *ptype; |
| 1641 | |
| 1642 | /* A type number of zero indicates the start of varargs. |
| 1643 | FIXME: GDB currently ignores vararg functions. */ |
| 1644 | if (p[0] == '0' && p[1] == '\0') |
| 1645 | break; |
| 1646 | ptype = read_type (&p, objfile); |
| 1647 | |
| 1648 | /* The Sun compilers mark integer arguments, which should |
| 1649 | be promoted to the width of the calling conventions, with |
| 1650 | a type which references itself. This type is turned into |
| 1651 | a TYPE_CODE_VOID type by read_type, and we have to turn |
| 1652 | it back into builtin_type_int here. |
| 1653 | FIXME: Do we need a new builtin_type_promoted_int_arg ? */ |
| 1654 | if (TYPE_CODE (ptype) == TYPE_CODE_VOID) |
| 1655 | ptype = builtin_type_int; |
| 1656 | TYPE_FIELD_TYPE (ftype, nparams++) = ptype; |
| 1657 | } |
| 1658 | TYPE_NFIELDS (ftype) = nparams; |
| 1659 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
| 1660 | } |
| 1661 | break; |
| 1662 | |
| 1663 | case 'F': |
| 1664 | /* A global function definition. */ |
| 1665 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1666 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 1667 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1668 | add_symbol_to_list (sym, &global_symbols); |
| 1669 | goto process_function_types; |
| 1670 | |
| 1671 | case 'G': |
| 1672 | /* For a class G (global) symbol, it appears that the |
| 1673 | value is not correct. It is necessary to search for the |
| 1674 | corresponding linker definition to find the value. |
| 1675 | These definitions appear at the end of the namelist. */ |
| 1676 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1677 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 1678 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1679 | /* Don't add symbol references to global_sym_chain. |
| 1680 | Symbol references don't have valid names and wont't match up with |
| 1681 | minimal symbols when the global_sym_chain is relocated. |
| 1682 | We'll fixup symbol references when we fixup the defining symbol. */ |
| 1683 | if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#') |
| 1684 | { |
| 1685 | i = hashname (SYMBOL_NAME (sym)); |
| 1686 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; |
| 1687 | global_sym_chain[i] = sym; |
| 1688 | } |
| 1689 | add_symbol_to_list (sym, &global_symbols); |
| 1690 | break; |
| 1691 | |
| 1692 | /* This case is faked by a conditional above, |
| 1693 | when there is no code letter in the dbx data. |
| 1694 | Dbx data never actually contains 'l'. */ |
| 1695 | case 's': |
| 1696 | case 'l': |
| 1697 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1698 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
| 1699 | SYMBOL_VALUE (sym) = valu; |
| 1700 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1701 | add_symbol_to_list (sym, &local_symbols); |
| 1702 | break; |
| 1703 | |
| 1704 | case 'p': |
| 1705 | if (*p == 'F') |
| 1706 | /* pF is a two-letter code that means a function parameter in Fortran. |
| 1707 | The type-number specifies the type of the return value. |
| 1708 | Translate it into a pointer-to-function type. */ |
| 1709 | { |
| 1710 | p++; |
| 1711 | SYMBOL_TYPE (sym) |
| 1712 | = lookup_pointer_type |
| 1713 | (lookup_function_type (read_type (&p, objfile))); |
| 1714 | } |
| 1715 | else |
| 1716 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1717 | |
| 1718 | /* Normally this is a parameter, a LOC_ARG. On the i960, it |
| 1719 | can also be a LOC_LOCAL_ARG depending on symbol type. */ |
| 1720 | #ifndef DBX_PARM_SYMBOL_CLASS |
| 1721 | #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG |
| 1722 | #endif |
| 1723 | |
| 1724 | SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type); |
| 1725 | SYMBOL_VALUE (sym) = valu; |
| 1726 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1727 | add_symbol_to_list (sym, &local_symbols); |
| 1728 | |
| 1729 | if (TARGET_BYTE_ORDER != BIG_ENDIAN) |
| 1730 | { |
| 1731 | /* On little-endian machines, this crud is never necessary, |
| 1732 | and, if the extra bytes contain garbage, is harmful. */ |
| 1733 | break; |
| 1734 | } |
| 1735 | |
| 1736 | /* If it's gcc-compiled, if it says `short', believe it. */ |
| 1737 | if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION) |
| 1738 | break; |
| 1739 | |
| 1740 | #if !BELIEVE_PCC_PROMOTION |
| 1741 | { |
| 1742 | /* This is the signed type which arguments get promoted to. */ |
| 1743 | static struct type *pcc_promotion_type; |
| 1744 | /* This is the unsigned type which arguments get promoted to. */ |
| 1745 | static struct type *pcc_unsigned_promotion_type; |
| 1746 | |
| 1747 | /* Call it "int" because this is mainly C lossage. */ |
| 1748 | if (pcc_promotion_type == NULL) |
| 1749 | pcc_promotion_type = |
| 1750 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 1751 | 0, "int", NULL); |
| 1752 | |
| 1753 | if (pcc_unsigned_promotion_type == NULL) |
| 1754 | pcc_unsigned_promotion_type = |
| 1755 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 1756 | TYPE_FLAG_UNSIGNED, "unsigned int", NULL); |
| 1757 | |
| 1758 | #if defined(BELIEVE_PCC_PROMOTION_TYPE) |
| 1759 | /* This macro is defined on machines (e.g. sparc) where |
| 1760 | we should believe the type of a PCC 'short' argument, |
| 1761 | but shouldn't believe the address (the address is |
| 1762 | the address of the corresponding int). |
| 1763 | |
| 1764 | My guess is that this correction, as opposed to changing |
| 1765 | the parameter to an 'int' (as done below, for PCC |
| 1766 | on most machines), is the right thing to do |
| 1767 | on all machines, but I don't want to risk breaking |
| 1768 | something that already works. On most PCC machines, |
| 1769 | the sparc problem doesn't come up because the calling |
| 1770 | function has to zero the top bytes (not knowing whether |
| 1771 | the called function wants an int or a short), so there |
| 1772 | is little practical difference between an int and a short |
| 1773 | (except perhaps what happens when the GDB user types |
| 1774 | "print short_arg = 0x10000;"). |
| 1775 | |
| 1776 | Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler |
| 1777 | actually produces the correct address (we don't need to fix it |
| 1778 | up). I made this code adapt so that it will offset the symbol |
| 1779 | if it was pointing at an int-aligned location and not |
| 1780 | otherwise. This way you can use the same gdb for 4.0.x and |
| 1781 | 4.1 systems. |
| 1782 | |
| 1783 | If the parameter is shorter than an int, and is integral |
| 1784 | (e.g. char, short, or unsigned equivalent), and is claimed to |
| 1785 | be passed on an integer boundary, don't believe it! Offset the |
| 1786 | parameter's address to the tail-end of that integer. */ |
| 1787 | |
| 1788 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) |
| 1789 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT |
| 1790 | && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type)) |
| 1791 | { |
| 1792 | SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type) |
| 1793 | - TYPE_LENGTH (SYMBOL_TYPE (sym)); |
| 1794 | } |
| 1795 | break; |
| 1796 | |
| 1797 | #else /* no BELIEVE_PCC_PROMOTION_TYPE. */ |
| 1798 | |
| 1799 | /* If PCC says a parameter is a short or a char, |
| 1800 | it is really an int. */ |
| 1801 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) |
| 1802 | && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT) |
| 1803 | { |
| 1804 | SYMBOL_TYPE (sym) = |
| 1805 | TYPE_UNSIGNED (SYMBOL_TYPE (sym)) |
| 1806 | ? pcc_unsigned_promotion_type |
| 1807 | : pcc_promotion_type; |
| 1808 | } |
| 1809 | break; |
| 1810 | |
| 1811 | #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */ |
| 1812 | } |
| 1813 | #endif /* !BELIEVE_PCC_PROMOTION. */ |
| 1814 | |
| 1815 | case 'P': |
| 1816 | /* acc seems to use P to declare the prototypes of functions that |
| 1817 | are referenced by this file. gdb is not prepared to deal |
| 1818 | with this extra information. FIXME, it ought to. */ |
| 1819 | if (type == N_FUN) |
| 1820 | { |
| 1821 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1822 | goto process_prototype_types; |
| 1823 | } |
| 1824 | /*FALLTHROUGH*/ |
| 1825 | |
| 1826 | case 'R': |
| 1827 | /* Parameter which is in a register. */ |
| 1828 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1829 | SYMBOL_CLASS (sym) = LOC_REGPARM; |
| 1830 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); |
| 1831 | if (SYMBOL_VALUE (sym) >= NUM_REGS) |
| 1832 | { |
| 1833 | complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS, |
| 1834 | SYMBOL_SOURCE_NAME (sym)); |
| 1835 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
| 1836 | } |
| 1837 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1838 | add_symbol_to_list (sym, &local_symbols); |
| 1839 | break; |
| 1840 | |
| 1841 | case 'r': |
| 1842 | /* Register variable (either global or local). */ |
| 1843 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1844 | SYMBOL_CLASS (sym) = LOC_REGISTER; |
| 1845 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); |
| 1846 | if (SYMBOL_VALUE (sym) >= NUM_REGS) |
| 1847 | { |
| 1848 | complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS, |
| 1849 | SYMBOL_SOURCE_NAME (sym)); |
| 1850 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
| 1851 | } |
| 1852 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1853 | if (within_function) |
| 1854 | { |
| 1855 | /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same |
| 1856 | name to represent an argument passed in a register. |
| 1857 | GCC uses 'P' for the same case. So if we find such a symbol pair |
| 1858 | we combine it into one 'P' symbol. For Sun cc we need to do this |
| 1859 | regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out |
| 1860 | the 'p' symbol even if it never saves the argument onto the stack. |
| 1861 | |
| 1862 | On most machines, we want to preserve both symbols, so that |
| 1863 | we can still get information about what is going on with the |
| 1864 | stack (VAX for computing args_printed, using stack slots instead |
| 1865 | of saved registers in backtraces, etc.). |
| 1866 | |
| 1867 | Note that this code illegally combines |
| 1868 | main(argc) struct foo argc; { register struct foo argc; } |
| 1869 | but this case is considered pathological and causes a warning |
| 1870 | from a decent compiler. */ |
| 1871 | |
| 1872 | if (local_symbols |
| 1873 | && local_symbols->nsyms > 0 |
| 1874 | #ifndef USE_REGISTER_NOT_ARG |
| 1875 | && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, |
| 1876 | SYMBOL_TYPE (sym)) |
| 1877 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT |
| 1878 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION |
| 1879 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET |
| 1880 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING) |
| 1881 | #endif |
| 1882 | ) |
| 1883 | { |
| 1884 | struct symbol *prev_sym; |
| 1885 | prev_sym = local_symbols->symbol[local_symbols->nsyms - 1]; |
| 1886 | if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG |
| 1887 | || SYMBOL_CLASS (prev_sym) == LOC_ARG) |
| 1888 | && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym))) |
| 1889 | { |
| 1890 | SYMBOL_CLASS (prev_sym) = LOC_REGPARM; |
| 1891 | /* Use the type from the LOC_REGISTER; that is the type |
| 1892 | that is actually in that register. */ |
| 1893 | SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym); |
| 1894 | SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym); |
| 1895 | sym = prev_sym; |
| 1896 | break; |
| 1897 | } |
| 1898 | } |
| 1899 | add_symbol_to_list (sym, &local_symbols); |
| 1900 | } |
| 1901 | else |
| 1902 | add_symbol_to_list (sym, &file_symbols); |
| 1903 | break; |
| 1904 | |
| 1905 | case 'S': |
| 1906 | /* Static symbol at top level of file */ |
| 1907 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1908 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 1909 | SYMBOL_VALUE_ADDRESS (sym) = valu; |
| 1910 | #ifdef STATIC_TRANSFORM_NAME |
| 1911 | if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym))) |
| 1912 | { |
| 1913 | struct minimal_symbol *msym; |
| 1914 | msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile); |
| 1915 | if (msym != NULL) |
| 1916 | { |
| 1917 | SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)); |
| 1918 | SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym); |
| 1919 | } |
| 1920 | } |
| 1921 | #endif |
| 1922 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1923 | add_symbol_to_list (sym, &file_symbols); |
| 1924 | break; |
| 1925 | |
| 1926 | case 't': |
| 1927 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 1928 | |
| 1929 | /* For a nameless type, we don't want a create a symbol, thus we |
| 1930 | did not use `sym'. Return without further processing. */ |
| 1931 | if (nameless) return NULL; |
| 1932 | |
| 1933 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 1934 | SYMBOL_VALUE (sym) = valu; |
| 1935 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 1936 | /* C++ vagaries: we may have a type which is derived from |
| 1937 | a base type which did not have its name defined when the |
| 1938 | derived class was output. We fill in the derived class's |
| 1939 | base part member's name here in that case. */ |
| 1940 | if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL) |
| 1941 | if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT |
| 1942 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) |
| 1943 | && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) |
| 1944 | { |
| 1945 | int j; |
| 1946 | for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--) |
| 1947 | if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0) |
| 1948 | TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) = |
| 1949 | type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)); |
| 1950 | } |
| 1951 | |
| 1952 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL) |
| 1953 | { |
| 1954 | /* gcc-2.6 or later (when using -fvtable-thunks) |
| 1955 | emits a unique named type for a vtable entry. |
| 1956 | Some gdb code depends on that specific name. */ |
| 1957 | extern const char vtbl_ptr_name[]; |
| 1958 | |
| 1959 | if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR |
| 1960 | && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name)) |
| 1961 | || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC) |
| 1962 | { |
| 1963 | /* If we are giving a name to a type such as "pointer to |
| 1964 | foo" or "function returning foo", we better not set |
| 1965 | the TYPE_NAME. If the program contains "typedef char |
| 1966 | *caddr_t;", we don't want all variables of type char |
| 1967 | * to print as caddr_t. This is not just a |
| 1968 | consequence of GDB's type management; PCC and GCC (at |
| 1969 | least through version 2.4) both output variables of |
| 1970 | either type char * or caddr_t with the type number |
| 1971 | defined in the 't' symbol for caddr_t. If a future |
| 1972 | compiler cleans this up it GDB is not ready for it |
| 1973 | yet, but if it becomes ready we somehow need to |
| 1974 | disable this check (without breaking the PCC/GCC2.4 |
| 1975 | case). |
| 1976 | |
| 1977 | Sigh. |
| 1978 | |
| 1979 | Fortunately, this check seems not to be necessary |
| 1980 | for anything except pointers or functions. */ |
| 1981 | } |
| 1982 | else |
| 1983 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym); |
| 1984 | } |
| 1985 | |
| 1986 | add_symbol_to_list (sym, &file_symbols); |
| 1987 | break; |
| 1988 | |
| 1989 | case 'T': |
| 1990 | /* Struct, union, or enum tag. For GNU C++, this can be be followed |
| 1991 | by 't' which means we are typedef'ing it as well. */ |
| 1992 | synonym = *p == 't'; |
| 1993 | |
| 1994 | if (synonym) |
| 1995 | p++; |
| 1996 | /* The semantics of C++ state that "struct foo { ... }" also defines |
| 1997 | a typedef for "foo". Unfortunately, cfront never makes the typedef |
| 1998 | when translating C++ into C. We make the typedef here so that |
| 1999 | "ptype foo" works as expected for cfront translated code. */ |
| 2000 | else if (current_subfile->language == language_cplus) |
| 2001 | synonym = 1; |
| 2002 | |
| 2003 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 2004 | |
| 2005 | /* For a nameless type, we don't want a create a symbol, thus we |
| 2006 | did not use `sym'. Return without further processing. */ |
| 2007 | if (nameless) return NULL; |
| 2008 | |
| 2009 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 2010 | SYMBOL_VALUE (sym) = valu; |
| 2011 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; |
| 2012 | if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0) |
| 2013 | TYPE_TAG_NAME (SYMBOL_TYPE (sym)) |
| 2014 | = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym)); |
| 2015 | add_symbol_to_list (sym, &file_symbols); |
| 2016 | |
| 2017 | if (synonym) |
| 2018 | { |
| 2019 | /* Clone the sym and then modify it. */ |
| 2020 | register struct symbol *typedef_sym = (struct symbol *) |
| 2021 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 2022 | *typedef_sym = *sym; |
| 2023 | SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; |
| 2024 | SYMBOL_VALUE (typedef_sym) = valu; |
| 2025 | SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE; |
| 2026 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
| 2027 | TYPE_NAME (SYMBOL_TYPE (sym)) |
| 2028 | = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym)); |
| 2029 | add_symbol_to_list (typedef_sym, &file_symbols); |
| 2030 | } |
| 2031 | break; |
| 2032 | |
| 2033 | case 'V': |
| 2034 | /* Static symbol of local scope */ |
| 2035 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 2036 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 2037 | SYMBOL_VALUE_ADDRESS (sym) = valu; |
| 2038 | #ifdef STATIC_TRANSFORM_NAME |
| 2039 | if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym))) |
| 2040 | { |
| 2041 | struct minimal_symbol *msym; |
| 2042 | msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile); |
| 2043 | if (msym != NULL) |
| 2044 | { |
| 2045 | SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)); |
| 2046 | SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym); |
| 2047 | } |
| 2048 | } |
| 2049 | #endif |
| 2050 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 2051 | if (os9k_stabs) |
| 2052 | add_symbol_to_list (sym, &global_symbols); |
| 2053 | else |
| 2054 | add_symbol_to_list (sym, &local_symbols); |
| 2055 | break; |
| 2056 | |
| 2057 | case 'v': |
| 2058 | /* Reference parameter */ |
| 2059 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 2060 | SYMBOL_CLASS (sym) = LOC_REF_ARG; |
| 2061 | SYMBOL_VALUE (sym) = valu; |
| 2062 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 2063 | add_symbol_to_list (sym, &local_symbols); |
| 2064 | break; |
| 2065 | |
| 2066 | case 'a': |
| 2067 | /* Reference parameter which is in a register. */ |
| 2068 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 2069 | SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; |
| 2070 | SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); |
| 2071 | if (SYMBOL_VALUE (sym) >= NUM_REGS) |
| 2072 | { |
| 2073 | complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS, |
| 2074 | SYMBOL_SOURCE_NAME (sym)); |
| 2075 | SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ |
| 2076 | } |
| 2077 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 2078 | add_symbol_to_list (sym, &local_symbols); |
| 2079 | break; |
| 2080 | |
| 2081 | case 'X': |
| 2082 | /* This is used by Sun FORTRAN for "function result value". |
| 2083 | Sun claims ("dbx and dbxtool interfaces", 2nd ed) |
| 2084 | that Pascal uses it too, but when I tried it Pascal used |
| 2085 | "x:3" (local symbol) instead. */ |
| 2086 | SYMBOL_TYPE (sym) = read_type (&p, objfile); |
| 2087 | SYMBOL_CLASS (sym) = LOC_LOCAL; |
| 2088 | SYMBOL_VALUE (sym) = valu; |
| 2089 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 2090 | add_symbol_to_list (sym, &local_symbols); |
| 2091 | break; |
| 2092 | |
| 2093 | /* New code added to support cfront stabs strings. |
| 2094 | Note: case 'P' already handled above */ |
| 2095 | case 'Z': |
| 2096 | /* Cfront type continuation coming up! |
| 2097 | Find the original definition and add to it. |
| 2098 | We'll have to do this for the typedef too, |
| 2099 | since we cloned the symbol to define a type in read_type. |
| 2100 | Stabs info examples: |
| 2101 | __1C :Ztl |
| 2102 | foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24)) |
| 2103 | C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;; |
| 2104 | where C is the name of the class. |
| 2105 | Unfortunately, we can't lookup the original symbol yet 'cuz |
| 2106 | we haven't finished reading all the symbols. |
| 2107 | Instead, we save it for processing later */ |
| 2108 | process_later (sym, p, resolve_cfront_continuation); |
| 2109 | SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */ |
| 2110 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 2111 | SYMBOL_VALUE (sym) = 0; |
| 2112 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 2113 | /* Don't add to list - we'll delete it later when |
| 2114 | we add the continuation to the real sym */ |
| 2115 | return sym; |
| 2116 | /* End of new code added to support cfront stabs strings */ |
| 2117 | |
| 2118 | default: |
| 2119 | SYMBOL_TYPE (sym) = error_type (&p, objfile); |
| 2120 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 2121 | SYMBOL_VALUE (sym) = 0; |
| 2122 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 2123 | add_symbol_to_list (sym, &file_symbols); |
| 2124 | break; |
| 2125 | } |
| 2126 | |
| 2127 | /* When passing structures to a function, some systems sometimes pass |
| 2128 | the address in a register, not the structure itself. */ |
| 2129 | |
| 2130 | if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym)) |
| 2131 | && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG)) |
| 2132 | { |
| 2133 | struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym)); |
| 2134 | |
| 2135 | if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT) |
| 2136 | || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION) |
| 2137 | || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING) |
| 2138 | || (TYPE_CODE (symbol_type) == TYPE_CODE_SET)) |
| 2139 | { |
| 2140 | /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert |
| 2141 | LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */ |
| 2142 | if (SYMBOL_CLASS (sym) == LOC_REGPARM) |
| 2143 | SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; |
| 2144 | /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th |
| 2145 | and subsequent arguments on the sparc, for example). */ |
| 2146 | else if (SYMBOL_CLASS (sym) == LOC_ARG) |
| 2147 | SYMBOL_CLASS (sym) = LOC_REF_ARG; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | /* Is there more to parse? For example LRS/alias information? */ |
| 2152 | while (*p && *p == ';') |
| 2153 | { |
| 2154 | p++; |
| 2155 | if (*p && *p == 'l') |
| 2156 | { |
| 2157 | /* GNU extensions for live range splitting may be appended to |
| 2158 | the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */ |
| 2159 | |
| 2160 | /* Resolve the live range and add it to SYM's live range list. */ |
| 2161 | resolve_live_range (objfile, sym, p); |
| 2162 | |
| 2163 | /* Find end of live range info. */ |
| 2164 | p = strchr (p, ')'); |
| 2165 | if (!*p || *p != ')') |
| 2166 | error ("Internal error: live range format not recognized.\n"); |
| 2167 | p++; |
| 2168 | } |
| 2169 | } |
| 2170 | return sym; |
| 2171 | } |
| 2172 | |
| 2173 | /* Add the live range found in P to the symbol SYM in objfile OBJFILE. */ |
| 2174 | |
| 2175 | static void |
| 2176 | resolve_live_range (objfile, sym, p) |
| 2177 | struct objfile * objfile; |
| 2178 | struct symbol *sym; |
| 2179 | char *p; |
| 2180 | { |
| 2181 | int refnum; |
| 2182 | CORE_ADDR start, end; |
| 2183 | |
| 2184 | /* Sanity check the beginning of the stabs string. */ |
| 2185 | if (!*p || *p != 'l') |
| 2186 | error ("Internal error: live range string.\n"); |
| 2187 | p++; |
| 2188 | |
| 2189 | if (!*p || *p != '(') |
| 2190 | error ("Internal error: live range string.\n"); |
| 2191 | p++; |
| 2192 | |
| 2193 | /* Get starting value of range and advance P past the reference id. |
| 2194 | |
| 2195 | ?!? In theory, the process_reference should never fail, but we should |
| 2196 | catch that case just in case the compiler scrogged the stabs. */ |
| 2197 | refnum = process_reference (&p); |
| 2198 | start = ref_search_value (refnum); |
| 2199 | if (!start) |
| 2200 | error ("Internal error: live range symbol not found.\n"); |
| 2201 | |
| 2202 | if (!*p || *p != ',') |
| 2203 | error ("Internal error: live range string.\n"); |
| 2204 | p++; |
| 2205 | |
| 2206 | /* Get ending value of range and advance P past the reference id. |
| 2207 | |
| 2208 | ?!? In theory, the process_reference should never fail, but we should |
| 2209 | catch that case just in case the compiler scrogged the stabs. */ |
| 2210 | refnum = process_reference (&p); |
| 2211 | end = ref_search_value (refnum); |
| 2212 | if (!end) |
| 2213 | error ("Internal error: live range symbol not found.\n"); |
| 2214 | |
| 2215 | if (!*p || *p != ')') |
| 2216 | error ("Internal error: live range string.\n"); |
| 2217 | |
| 2218 | /* Now that we know the bounds of the range, add it to the |
| 2219 | symbol. */ |
| 2220 | add_live_range (objfile, sym, start, end); |
| 2221 | } |
| 2222 | |
| 2223 | /* Add a new live range defined by START and END to the symbol SYM |
| 2224 | in objfile OBJFILE. */ |
| 2225 | |
| 2226 | static void |
| 2227 | add_live_range (objfile, sym, start, end) |
| 2228 | struct objfile *objfile; |
| 2229 | struct symbol *sym; |
| 2230 | CORE_ADDR start, end; |
| 2231 | { |
| 2232 | struct range_list *r, *rs; |
| 2233 | |
| 2234 | if (start >= end) |
| 2235 | error ("Internal error: end of live range follows start.\n"); |
| 2236 | |
| 2237 | /* Alloc new live range structure. */ |
| 2238 | r = (struct range_list *) |
| 2239 | obstack_alloc (&objfile->type_obstack, |
| 2240 | sizeof (struct range_list)); |
| 2241 | r->start = start; |
| 2242 | r->end = end; |
| 2243 | r->next = 0; |
| 2244 | |
| 2245 | /* Append this range to the symbol's range list. */ |
| 2246 | if (!SYMBOL_RANGES (sym)) |
| 2247 | { |
| 2248 | SYMBOL_RANGES (sym) = r; |
| 2249 | } |
| 2250 | else |
| 2251 | { |
| 2252 | /* Get the last range for the symbol. */ |
| 2253 | for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next) |
| 2254 | ; |
| 2255 | rs->next = r; |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | \f |
| 2260 | /* Skip rest of this symbol and return an error type. |
| 2261 | |
| 2262 | General notes on error recovery: error_type always skips to the |
| 2263 | end of the symbol (modulo cretinous dbx symbol name continuation). |
| 2264 | Thus code like this: |
| 2265 | |
| 2266 | if (*(*pp)++ != ';') |
| 2267 | return error_type (pp, objfile); |
| 2268 | |
| 2269 | is wrong because if *pp starts out pointing at '\0' (typically as the |
| 2270 | result of an earlier error), it will be incremented to point to the |
| 2271 | start of the next symbol, which might produce strange results, at least |
| 2272 | if you run off the end of the string table. Instead use |
| 2273 | |
| 2274 | if (**pp != ';') |
| 2275 | return error_type (pp, objfile); |
| 2276 | ++*pp; |
| 2277 | |
| 2278 | or |
| 2279 | |
| 2280 | if (**pp != ';') |
| 2281 | foo = error_type (pp, objfile); |
| 2282 | else |
| 2283 | ++*pp; |
| 2284 | |
| 2285 | And in case it isn't obvious, the point of all this hair is so the compiler |
| 2286 | can define new types and new syntaxes, and old versions of the |
| 2287 | debugger will be able to read the new symbol tables. */ |
| 2288 | |
| 2289 | static struct type * |
| 2290 | error_type (pp, objfile) |
| 2291 | char **pp; |
| 2292 | struct objfile *objfile; |
| 2293 | { |
| 2294 | complain (&error_type_complaint); |
| 2295 | while (1) |
| 2296 | { |
| 2297 | /* Skip to end of symbol. */ |
| 2298 | while (**pp != '\0') |
| 2299 | { |
| 2300 | (*pp)++; |
| 2301 | } |
| 2302 | |
| 2303 | /* Check for and handle cretinous dbx symbol name continuation! */ |
| 2304 | if ((*pp)[-1] == '\\' || (*pp)[-1] == '?') |
| 2305 | { |
| 2306 | *pp = next_symbol_text (objfile); |
| 2307 | } |
| 2308 | else |
| 2309 | { |
| 2310 | break; |
| 2311 | } |
| 2312 | } |
| 2313 | return (builtin_type_error); |
| 2314 | } |
| 2315 | |
| 2316 | \f |
| 2317 | /* Read type information or a type definition; return the type. Even |
| 2318 | though this routine accepts either type information or a type |
| 2319 | definition, the distinction is relevant--some parts of stabsread.c |
| 2320 | assume that type information starts with a digit, '-', or '(' in |
| 2321 | deciding whether to call read_type. */ |
| 2322 | |
| 2323 | struct type * |
| 2324 | read_type (pp, objfile) |
| 2325 | register char **pp; |
| 2326 | struct objfile *objfile; |
| 2327 | { |
| 2328 | register struct type *type = 0; |
| 2329 | struct type *type1; |
| 2330 | int typenums[2]; |
| 2331 | char type_descriptor; |
| 2332 | |
| 2333 | /* Size in bits of type if specified by a type attribute, or -1 if |
| 2334 | there is no size attribute. */ |
| 2335 | int type_size = -1; |
| 2336 | |
| 2337 | /* Used to distinguish string and bitstring from char-array and set. */ |
| 2338 | int is_string = 0; |
| 2339 | |
| 2340 | /* Read type number if present. The type number may be omitted. |
| 2341 | for instance in a two-dimensional array declared with type |
| 2342 | "ar1;1;10;ar1;1;10;4". */ |
| 2343 | if ((**pp >= '0' && **pp <= '9') |
| 2344 | || **pp == '(' |
| 2345 | || **pp == '-') |
| 2346 | { |
| 2347 | if (read_type_number (pp, typenums) != 0) |
| 2348 | return error_type (pp, objfile); |
| 2349 | |
| 2350 | /* Type is not being defined here. Either it already exists, |
| 2351 | or this is a forward reference to it. dbx_alloc_type handles |
| 2352 | both cases. */ |
| 2353 | if (**pp != '=') |
| 2354 | return dbx_alloc_type (typenums, objfile); |
| 2355 | |
| 2356 | /* Type is being defined here. */ |
| 2357 | /* Skip the '='. |
| 2358 | Also skip the type descriptor - we get it below with (*pp)[-1]. */ |
| 2359 | (*pp)+=2; |
| 2360 | } |
| 2361 | else |
| 2362 | { |
| 2363 | /* 'typenums=' not present, type is anonymous. Read and return |
| 2364 | the definition, but don't put it in the type vector. */ |
| 2365 | typenums[0] = typenums[1] = -1; |
| 2366 | (*pp)++; |
| 2367 | } |
| 2368 | |
| 2369 | again: |
| 2370 | type_descriptor = (*pp)[-1]; |
| 2371 | switch (type_descriptor) |
| 2372 | { |
| 2373 | case 'x': |
| 2374 | { |
| 2375 | enum type_code code; |
| 2376 | |
| 2377 | /* Used to index through file_symbols. */ |
| 2378 | struct pending *ppt; |
| 2379 | int i; |
| 2380 | |
| 2381 | /* Name including "struct", etc. */ |
| 2382 | char *type_name; |
| 2383 | |
| 2384 | { |
| 2385 | char *from, *to, *p, *q1, *q2; |
| 2386 | |
| 2387 | /* Set the type code according to the following letter. */ |
| 2388 | switch ((*pp)[0]) |
| 2389 | { |
| 2390 | case 's': |
| 2391 | code = TYPE_CODE_STRUCT; |
| 2392 | break; |
| 2393 | case 'u': |
| 2394 | code = TYPE_CODE_UNION; |
| 2395 | break; |
| 2396 | case 'e': |
| 2397 | code = TYPE_CODE_ENUM; |
| 2398 | break; |
| 2399 | default: |
| 2400 | { |
| 2401 | /* Complain and keep going, so compilers can invent new |
| 2402 | cross-reference types. */ |
| 2403 | static struct complaint msg = |
| 2404 | {"Unrecognized cross-reference type `%c'", 0, 0}; |
| 2405 | complain (&msg, (*pp)[0]); |
| 2406 | code = TYPE_CODE_STRUCT; |
| 2407 | break; |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | q1 = strchr (*pp, '<'); |
| 2412 | p = strchr (*pp, ':'); |
| 2413 | if (p == NULL) |
| 2414 | return error_type (pp, objfile); |
| 2415 | if (q1 && p > q1 && p[1] == ':') |
| 2416 | { |
| 2417 | int nesting_level = 0; |
| 2418 | for (q2 = q1; *q2; q2++) |
| 2419 | { |
| 2420 | if (*q2 == '<') |
| 2421 | nesting_level++; |
| 2422 | else if (*q2 == '>') |
| 2423 | nesting_level--; |
| 2424 | else if (*q2 == ':' && nesting_level == 0) |
| 2425 | break; |
| 2426 | } |
| 2427 | p = q2; |
| 2428 | if (*p != ':') |
| 2429 | return error_type (pp, objfile); |
| 2430 | } |
| 2431 | to = type_name = |
| 2432 | (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1); |
| 2433 | |
| 2434 | /* Copy the name. */ |
| 2435 | from = *pp + 1; |
| 2436 | while (from < p) |
| 2437 | *to++ = *from++; |
| 2438 | *to = '\0'; |
| 2439 | |
| 2440 | /* Set the pointer ahead of the name which we just read, and |
| 2441 | the colon. */ |
| 2442 | *pp = from + 1; |
| 2443 | } |
| 2444 | |
| 2445 | /* Now check to see whether the type has already been |
| 2446 | declared. This was written for arrays of cross-referenced |
| 2447 | types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty |
| 2448 | sure it is not necessary anymore. But it might be a good |
| 2449 | idea, to save a little memory. */ |
| 2450 | |
| 2451 | for (ppt = file_symbols; ppt; ppt = ppt->next) |
| 2452 | for (i = 0; i < ppt->nsyms; i++) |
| 2453 | { |
| 2454 | struct symbol *sym = ppt->symbol[i]; |
| 2455 | |
| 2456 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF |
| 2457 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE |
| 2458 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == code) |
| 2459 | && STREQ (SYMBOL_NAME (sym), type_name)) |
| 2460 | { |
| 2461 | obstack_free (&objfile -> type_obstack, type_name); |
| 2462 | type = SYMBOL_TYPE (sym); |
| 2463 | return type; |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | /* Didn't find the type to which this refers, so we must |
| 2468 | be dealing with a forward reference. Allocate a type |
| 2469 | structure for it, and keep track of it so we can |
| 2470 | fill in the rest of the fields when we get the full |
| 2471 | type. */ |
| 2472 | type = dbx_alloc_type (typenums, objfile); |
| 2473 | TYPE_CODE (type) = code; |
| 2474 | TYPE_TAG_NAME (type) = type_name; |
| 2475 | INIT_CPLUS_SPECIFIC(type); |
| 2476 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; |
| 2477 | |
| 2478 | add_undefined_type (type); |
| 2479 | return type; |
| 2480 | } |
| 2481 | |
| 2482 | case '-': /* RS/6000 built-in type */ |
| 2483 | case '0': |
| 2484 | case '1': |
| 2485 | case '2': |
| 2486 | case '3': |
| 2487 | case '4': |
| 2488 | case '5': |
| 2489 | case '6': |
| 2490 | case '7': |
| 2491 | case '8': |
| 2492 | case '9': |
| 2493 | case '(': |
| 2494 | (*pp)--; |
| 2495 | |
| 2496 | /* We deal with something like t(1,2)=(3,4)=... which |
| 2497 | the Lucid compiler and recent gcc versions (post 2.7.3) use. */ |
| 2498 | |
| 2499 | /* Allocate and enter the typedef type first. |
| 2500 | This handles recursive types. */ |
| 2501 | type = dbx_alloc_type (typenums, objfile); |
| 2502 | TYPE_CODE (type) = TYPE_CODE_TYPEDEF; |
| 2503 | { struct type *xtype = read_type (pp, objfile); |
| 2504 | if (type == xtype) |
| 2505 | { |
| 2506 | /* It's being defined as itself. That means it is "void". */ |
| 2507 | TYPE_CODE (type) = TYPE_CODE_VOID; |
| 2508 | TYPE_LENGTH (type) = 1; |
| 2509 | } |
| 2510 | else if (type_size >= 0 || is_string) |
| 2511 | { |
| 2512 | *type = *xtype; |
| 2513 | TYPE_NAME (type) = NULL; |
| 2514 | TYPE_TAG_NAME (type) = NULL; |
| 2515 | } |
| 2516 | else |
| 2517 | { |
| 2518 | TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB; |
| 2519 | TYPE_TARGET_TYPE (type) = xtype; |
| 2520 | } |
| 2521 | } |
| 2522 | break; |
| 2523 | |
| 2524 | /* In the following types, we must be sure to overwrite any existing |
| 2525 | type that the typenums refer to, rather than allocating a new one |
| 2526 | and making the typenums point to the new one. This is because there |
| 2527 | may already be pointers to the existing type (if it had been |
| 2528 | forward-referenced), and we must change it to a pointer, function, |
| 2529 | reference, or whatever, *in-place*. */ |
| 2530 | |
| 2531 | case '*': |
| 2532 | type1 = read_type (pp, objfile); |
| 2533 | type = make_pointer_type (type1, dbx_lookup_type (typenums)); |
| 2534 | break; |
| 2535 | |
| 2536 | case '&': /* Reference to another type */ |
| 2537 | type1 = read_type (pp, objfile); |
| 2538 | type = make_reference_type (type1, dbx_lookup_type (typenums)); |
| 2539 | break; |
| 2540 | |
| 2541 | case 'f': /* Function returning another type */ |
| 2542 | if (os9k_stabs && **pp == '(') |
| 2543 | { |
| 2544 | /* Function prototype; parse it. |
| 2545 | We must conditionalize this on os9k_stabs because otherwise |
| 2546 | it could be confused with a Sun-style (1,3) typenumber |
| 2547 | (I think). */ |
| 2548 | struct type *t; |
| 2549 | ++*pp; |
| 2550 | while (**pp != ')') |
| 2551 | { |
| 2552 | t = read_type (pp, objfile); |
| 2553 | if (**pp == ',') ++*pp; |
| 2554 | } |
| 2555 | } |
| 2556 | type1 = read_type (pp, objfile); |
| 2557 | type = make_function_type (type1, dbx_lookup_type (typenums)); |
| 2558 | break; |
| 2559 | |
| 2560 | case 'k': /* Const qualifier on some type (Sun) */ |
| 2561 | case 'c': /* Const qualifier on some type (OS9000) */ |
| 2562 | /* Because 'c' means other things to AIX and 'k' is perfectly good, |
| 2563 | only accept 'c' in the os9k_stabs case. */ |
| 2564 | if (type_descriptor == 'c' && !os9k_stabs) |
| 2565 | return error_type (pp, objfile); |
| 2566 | type = read_type (pp, objfile); |
| 2567 | /* FIXME! For now, we ignore const and volatile qualifiers. */ |
| 2568 | break; |
| 2569 | |
| 2570 | case 'B': /* Volatile qual on some type (Sun) */ |
| 2571 | case 'i': /* Volatile qual on some type (OS9000) */ |
| 2572 | /* Because 'i' means other things to AIX and 'B' is perfectly good, |
| 2573 | only accept 'i' in the os9k_stabs case. */ |
| 2574 | if (type_descriptor == 'i' && !os9k_stabs) |
| 2575 | return error_type (pp, objfile); |
| 2576 | type = read_type (pp, objfile); |
| 2577 | /* FIXME! For now, we ignore const and volatile qualifiers. */ |
| 2578 | break; |
| 2579 | |
| 2580 | case '@': |
| 2581 | if (isdigit (**pp) || **pp == '(' || **pp == '-') |
| 2582 | { /* Member (class & variable) type */ |
| 2583 | /* FIXME -- we should be doing smash_to_XXX types here. */ |
| 2584 | |
| 2585 | struct type *domain = read_type (pp, objfile); |
| 2586 | struct type *memtype; |
| 2587 | |
| 2588 | if (**pp != ',') |
| 2589 | /* Invalid member type data format. */ |
| 2590 | return error_type (pp, objfile); |
| 2591 | ++*pp; |
| 2592 | |
| 2593 | memtype = read_type (pp, objfile); |
| 2594 | type = dbx_alloc_type (typenums, objfile); |
| 2595 | smash_to_member_type (type, domain, memtype); |
| 2596 | } |
| 2597 | else /* type attribute */ |
| 2598 | { |
| 2599 | char *attr = *pp; |
| 2600 | /* Skip to the semicolon. */ |
| 2601 | while (**pp != ';' && **pp != '\0') |
| 2602 | ++(*pp); |
| 2603 | if (**pp == '\0') |
| 2604 | return error_type (pp, objfile); |
| 2605 | else |
| 2606 | ++*pp; /* Skip the semicolon. */ |
| 2607 | |
| 2608 | switch (*attr) |
| 2609 | { |
| 2610 | case 's': |
| 2611 | type_size = atoi (attr + 1); |
| 2612 | if (type_size <= 0) |
| 2613 | type_size = -1; |
| 2614 | break; |
| 2615 | |
| 2616 | case 'S': |
| 2617 | is_string = 1; |
| 2618 | break; |
| 2619 | |
| 2620 | default: |
| 2621 | /* Ignore unrecognized type attributes, so future compilers |
| 2622 | can invent new ones. */ |
| 2623 | break; |
| 2624 | } |
| 2625 | ++*pp; |
| 2626 | goto again; |
| 2627 | } |
| 2628 | break; |
| 2629 | |
| 2630 | case '#': /* Method (class & fn) type */ |
| 2631 | if ((*pp)[0] == '#') |
| 2632 | { |
| 2633 | /* We'll get the parameter types from the name. */ |
| 2634 | struct type *return_type; |
| 2635 | |
| 2636 | (*pp)++; |
| 2637 | return_type = read_type (pp, objfile); |
| 2638 | if (*(*pp)++ != ';') |
| 2639 | complain (&invalid_member_complaint, symnum); |
| 2640 | type = allocate_stub_method (return_type); |
| 2641 | if (typenums[0] != -1) |
| 2642 | *dbx_lookup_type (typenums) = type; |
| 2643 | } |
| 2644 | else |
| 2645 | { |
| 2646 | struct type *domain = read_type (pp, objfile); |
| 2647 | struct type *return_type; |
| 2648 | struct type **args; |
| 2649 | |
| 2650 | if (**pp != ',') |
| 2651 | /* Invalid member type data format. */ |
| 2652 | return error_type (pp, objfile); |
| 2653 | else |
| 2654 | ++(*pp); |
| 2655 | |
| 2656 | return_type = read_type (pp, objfile); |
| 2657 | args = read_args (pp, ';', objfile); |
| 2658 | type = dbx_alloc_type (typenums, objfile); |
| 2659 | smash_to_method_type (type, domain, return_type, args); |
| 2660 | } |
| 2661 | break; |
| 2662 | |
| 2663 | case 'r': /* Range type */ |
| 2664 | type = read_range_type (pp, typenums, objfile); |
| 2665 | if (typenums[0] != -1) |
| 2666 | *dbx_lookup_type (typenums) = type; |
| 2667 | break; |
| 2668 | |
| 2669 | case 'b': |
| 2670 | if (os9k_stabs) |
| 2671 | /* Const and volatile qualified type. */ |
| 2672 | type = read_type (pp, objfile); |
| 2673 | else |
| 2674 | { |
| 2675 | /* Sun ACC builtin int type */ |
| 2676 | type = read_sun_builtin_type (pp, typenums, objfile); |
| 2677 | if (typenums[0] != -1) |
| 2678 | *dbx_lookup_type (typenums) = type; |
| 2679 | } |
| 2680 | break; |
| 2681 | |
| 2682 | case 'R': /* Sun ACC builtin float type */ |
| 2683 | type = read_sun_floating_type (pp, typenums, objfile); |
| 2684 | if (typenums[0] != -1) |
| 2685 | *dbx_lookup_type (typenums) = type; |
| 2686 | break; |
| 2687 | |
| 2688 | case 'e': /* Enumeration type */ |
| 2689 | type = dbx_alloc_type (typenums, objfile); |
| 2690 | type = read_enum_type (pp, type, objfile); |
| 2691 | if (typenums[0] != -1) |
| 2692 | *dbx_lookup_type (typenums) = type; |
| 2693 | break; |
| 2694 | |
| 2695 | case 's': /* Struct type */ |
| 2696 | case 'u': /* Union type */ |
| 2697 | type = dbx_alloc_type (typenums, objfile); |
| 2698 | switch (type_descriptor) |
| 2699 | { |
| 2700 | case 's': |
| 2701 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
| 2702 | break; |
| 2703 | case 'u': |
| 2704 | TYPE_CODE (type) = TYPE_CODE_UNION; |
| 2705 | break; |
| 2706 | } |
| 2707 | type = read_struct_type (pp, type, objfile); |
| 2708 | break; |
| 2709 | |
| 2710 | case 'a': /* Array type */ |
| 2711 | if (**pp != 'r') |
| 2712 | return error_type (pp, objfile); |
| 2713 | ++*pp; |
| 2714 | |
| 2715 | type = dbx_alloc_type (typenums, objfile); |
| 2716 | type = read_array_type (pp, type, objfile); |
| 2717 | if (is_string) |
| 2718 | TYPE_CODE (type) = TYPE_CODE_STRING; |
| 2719 | break; |
| 2720 | |
| 2721 | case 'S': |
| 2722 | type1 = read_type (pp, objfile); |
| 2723 | type = create_set_type ((struct type*) NULL, type1); |
| 2724 | if (is_string) |
| 2725 | TYPE_CODE (type) = TYPE_CODE_BITSTRING; |
| 2726 | if (typenums[0] != -1) |
| 2727 | *dbx_lookup_type (typenums) = type; |
| 2728 | break; |
| 2729 | |
| 2730 | default: |
| 2731 | --*pp; /* Go back to the symbol in error */ |
| 2732 | /* Particularly important if it was \0! */ |
| 2733 | return error_type (pp, objfile); |
| 2734 | } |
| 2735 | |
| 2736 | if (type == 0) |
| 2737 | { |
| 2738 | warning ("GDB internal error, type is NULL in stabsread.c\n"); |
| 2739 | return error_type (pp, objfile); |
| 2740 | } |
| 2741 | |
| 2742 | /* Size specified in a type attribute overrides any other size. */ |
| 2743 | if (type_size != -1) |
| 2744 | TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; |
| 2745 | |
| 2746 | return type; |
| 2747 | } |
| 2748 | \f |
| 2749 | /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1. |
| 2750 | Return the proper type node for a given builtin type number. */ |
| 2751 | |
| 2752 | static struct type * |
| 2753 | rs6000_builtin_type (typenum) |
| 2754 | int typenum; |
| 2755 | { |
| 2756 | /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */ |
| 2757 | #define NUMBER_RECOGNIZED 34 |
| 2758 | /* This includes an empty slot for type number -0. */ |
| 2759 | static struct type *negative_types[NUMBER_RECOGNIZED + 1]; |
| 2760 | struct type *rettype = NULL; |
| 2761 | |
| 2762 | if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED) |
| 2763 | { |
| 2764 | complain (&rs6000_builtin_complaint, typenum); |
| 2765 | return builtin_type_error; |
| 2766 | } |
| 2767 | if (negative_types[-typenum] != NULL) |
| 2768 | return negative_types[-typenum]; |
| 2769 | |
| 2770 | #if TARGET_CHAR_BIT != 8 |
| 2771 | #error This code wrong for TARGET_CHAR_BIT not 8 |
| 2772 | /* These definitions all assume that TARGET_CHAR_BIT is 8. I think |
| 2773 | that if that ever becomes not true, the correct fix will be to |
| 2774 | make the size in the struct type to be in bits, not in units of |
| 2775 | TARGET_CHAR_BIT. */ |
| 2776 | #endif |
| 2777 | |
| 2778 | switch (-typenum) |
| 2779 | { |
| 2780 | case 1: |
| 2781 | /* The size of this and all the other types are fixed, defined |
| 2782 | by the debugging format. If there is a type called "int" which |
| 2783 | is other than 32 bits, then it should use a new negative type |
| 2784 | number (or avoid negative type numbers for that case). |
| 2785 | See stabs.texinfo. */ |
| 2786 | rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL); |
| 2787 | break; |
| 2788 | case 2: |
| 2789 | rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL); |
| 2790 | break; |
| 2791 | case 3: |
| 2792 | rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL); |
| 2793 | break; |
| 2794 | case 4: |
| 2795 | rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL); |
| 2796 | break; |
| 2797 | case 5: |
| 2798 | rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, |
| 2799 | "unsigned char", NULL); |
| 2800 | break; |
| 2801 | case 6: |
| 2802 | rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL); |
| 2803 | break; |
| 2804 | case 7: |
| 2805 | rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, |
| 2806 | "unsigned short", NULL); |
| 2807 | break; |
| 2808 | case 8: |
| 2809 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, |
| 2810 | "unsigned int", NULL); |
| 2811 | break; |
| 2812 | case 9: |
| 2813 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, |
| 2814 | "unsigned", NULL); |
| 2815 | case 10: |
| 2816 | rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, |
| 2817 | "unsigned long", NULL); |
| 2818 | break; |
| 2819 | case 11: |
| 2820 | rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL); |
| 2821 | break; |
| 2822 | case 12: |
| 2823 | /* IEEE single precision (32 bit). */ |
| 2824 | rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL); |
| 2825 | break; |
| 2826 | case 13: |
| 2827 | /* IEEE double precision (64 bit). */ |
| 2828 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL); |
| 2829 | break; |
| 2830 | case 14: |
| 2831 | /* This is an IEEE double on the RS/6000, and different machines with |
| 2832 | different sizes for "long double" should use different negative |
| 2833 | type numbers. See stabs.texinfo. */ |
| 2834 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL); |
| 2835 | break; |
| 2836 | case 15: |
| 2837 | rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL); |
| 2838 | break; |
| 2839 | case 16: |
| 2840 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
| 2841 | "boolean", NULL); |
| 2842 | break; |
| 2843 | case 17: |
| 2844 | rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL); |
| 2845 | break; |
| 2846 | case 18: |
| 2847 | rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL); |
| 2848 | break; |
| 2849 | case 19: |
| 2850 | rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL); |
| 2851 | break; |
| 2852 | case 20: |
| 2853 | rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, |
| 2854 | "character", NULL); |
| 2855 | break; |
| 2856 | case 21: |
| 2857 | rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, |
| 2858 | "logical*1", NULL); |
| 2859 | break; |
| 2860 | case 22: |
| 2861 | rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED, |
| 2862 | "logical*2", NULL); |
| 2863 | break; |
| 2864 | case 23: |
| 2865 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
| 2866 | "logical*4", NULL); |
| 2867 | break; |
| 2868 | case 24: |
| 2869 | rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, |
| 2870 | "logical", NULL); |
| 2871 | break; |
| 2872 | case 25: |
| 2873 | /* Complex type consisting of two IEEE single precision values. */ |
| 2874 | rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL); |
| 2875 | break; |
| 2876 | case 26: |
| 2877 | /* Complex type consisting of two IEEE double precision values. */ |
| 2878 | rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL); |
| 2879 | break; |
| 2880 | case 27: |
| 2881 | rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL); |
| 2882 | break; |
| 2883 | case 28: |
| 2884 | rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL); |
| 2885 | break; |
| 2886 | case 29: |
| 2887 | rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL); |
| 2888 | break; |
| 2889 | case 30: |
| 2890 | rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL); |
| 2891 | break; |
| 2892 | case 31: |
| 2893 | rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL); |
| 2894 | break; |
| 2895 | case 32: |
| 2896 | rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED, |
| 2897 | "unsigned long long", NULL); |
| 2898 | break; |
| 2899 | case 33: |
| 2900 | rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED, |
| 2901 | "logical*8", NULL); |
| 2902 | break; |
| 2903 | case 34: |
| 2904 | rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL); |
| 2905 | break; |
| 2906 | } |
| 2907 | negative_types[-typenum] = rettype; |
| 2908 | return rettype; |
| 2909 | } |
| 2910 | \f |
| 2911 | /* This page contains subroutines of read_type. */ |
| 2912 | |
| 2913 | /* Read member function stabs info for C++ classes. The form of each member |
| 2914 | function data is: |
| 2915 | |
| 2916 | NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; |
| 2917 | |
| 2918 | An example with two member functions is: |
| 2919 | |
| 2920 | afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; |
| 2921 | |
| 2922 | For the case of overloaded operators, the format is op$::*.funcs, where |
| 2923 | $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator |
| 2924 | name (such as `+=') and `.' marks the end of the operator name. |
| 2925 | |
| 2926 | Returns 1 for success, 0 for failure. */ |
| 2927 | |
| 2928 | static int |
| 2929 | read_member_functions (fip, pp, type, objfile) |
| 2930 | struct field_info *fip; |
| 2931 | char **pp; |
| 2932 | struct type *type; |
| 2933 | struct objfile *objfile; |
| 2934 | { |
| 2935 | int nfn_fields = 0; |
| 2936 | int length = 0; |
| 2937 | /* Total number of member functions defined in this class. If the class |
| 2938 | defines two `f' functions, and one `g' function, then this will have |
| 2939 | the value 3. */ |
| 2940 | int total_length = 0; |
| 2941 | int i; |
| 2942 | struct next_fnfield |
| 2943 | { |
| 2944 | struct next_fnfield *next; |
| 2945 | struct fn_field fn_field; |
| 2946 | } *sublist; |
| 2947 | struct type *look_ahead_type; |
| 2948 | struct next_fnfieldlist *new_fnlist; |
| 2949 | struct next_fnfield *new_sublist; |
| 2950 | char *main_fn_name; |
| 2951 | register char *p; |
| 2952 | |
| 2953 | /* Process each list until we find something that is not a member function |
| 2954 | or find the end of the functions. */ |
| 2955 | |
| 2956 | while (**pp != ';') |
| 2957 | { |
| 2958 | /* We should be positioned at the start of the function name. |
| 2959 | Scan forward to find the first ':' and if it is not the |
| 2960 | first of a "::" delimiter, then this is not a member function. */ |
| 2961 | p = *pp; |
| 2962 | while (*p != ':') |
| 2963 | { |
| 2964 | p++; |
| 2965 | } |
| 2966 | if (p[1] != ':') |
| 2967 | { |
| 2968 | break; |
| 2969 | } |
| 2970 | |
| 2971 | sublist = NULL; |
| 2972 | look_ahead_type = NULL; |
| 2973 | length = 0; |
| 2974 | |
| 2975 | new_fnlist = (struct next_fnfieldlist *) |
| 2976 | xmalloc (sizeof (struct next_fnfieldlist)); |
| 2977 | make_cleanup (free, new_fnlist); |
| 2978 | memset (new_fnlist, 0, sizeof (struct next_fnfieldlist)); |
| 2979 | |
| 2980 | if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2])) |
| 2981 | { |
| 2982 | /* This is a completely wierd case. In order to stuff in the |
| 2983 | names that might contain colons (the usual name delimiter), |
| 2984 | Mike Tiemann defined a different name format which is |
| 2985 | signalled if the identifier is "op$". In that case, the |
| 2986 | format is "op$::XXXX." where XXXX is the name. This is |
| 2987 | used for names like "+" or "=". YUUUUUUUK! FIXME! */ |
| 2988 | /* This lets the user type "break operator+". |
| 2989 | We could just put in "+" as the name, but that wouldn't |
| 2990 | work for "*". */ |
| 2991 | static char opname[32] = {'o', 'p', CPLUS_MARKER}; |
| 2992 | char *o = opname + 3; |
| 2993 | |
| 2994 | /* Skip past '::'. */ |
| 2995 | *pp = p + 2; |
| 2996 | |
| 2997 | STABS_CONTINUE (pp, objfile); |
| 2998 | p = *pp; |
| 2999 | while (*p != '.') |
| 3000 | { |
| 3001 | *o++ = *p++; |
| 3002 | } |
| 3003 | main_fn_name = savestring (opname, o - opname); |
| 3004 | /* Skip past '.' */ |
| 3005 | *pp = p + 1; |
| 3006 | } |
| 3007 | else |
| 3008 | { |
| 3009 | main_fn_name = savestring (*pp, p - *pp); |
| 3010 | /* Skip past '::'. */ |
| 3011 | *pp = p + 2; |
| 3012 | } |
| 3013 | new_fnlist -> fn_fieldlist.name = main_fn_name; |
| 3014 | |
| 3015 | do |
| 3016 | { |
| 3017 | new_sublist = |
| 3018 | (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield)); |
| 3019 | make_cleanup (free, new_sublist); |
| 3020 | memset (new_sublist, 0, sizeof (struct next_fnfield)); |
| 3021 | |
| 3022 | /* Check for and handle cretinous dbx symbol name continuation! */ |
| 3023 | if (look_ahead_type == NULL) |
| 3024 | { |
| 3025 | /* Normal case. */ |
| 3026 | STABS_CONTINUE (pp, objfile); |
| 3027 | |
| 3028 | new_sublist -> fn_field.type = read_type (pp, objfile); |
| 3029 | if (**pp != ':') |
| 3030 | { |
| 3031 | /* Invalid symtab info for member function. */ |
| 3032 | return 0; |
| 3033 | } |
| 3034 | } |
| 3035 | else |
| 3036 | { |
| 3037 | /* g++ version 1 kludge */ |
| 3038 | new_sublist -> fn_field.type = look_ahead_type; |
| 3039 | look_ahead_type = NULL; |
| 3040 | } |
| 3041 | |
| 3042 | (*pp)++; |
| 3043 | p = *pp; |
| 3044 | while (*p != ';') |
| 3045 | { |
| 3046 | p++; |
| 3047 | } |
| 3048 | |
| 3049 | /* If this is just a stub, then we don't have the real name here. */ |
| 3050 | |
| 3051 | if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB) |
| 3052 | { |
| 3053 | if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type)) |
| 3054 | TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type; |
| 3055 | new_sublist -> fn_field.is_stub = 1; |
| 3056 | } |
| 3057 | new_sublist -> fn_field.physname = savestring (*pp, p - *pp); |
| 3058 | *pp = p + 1; |
| 3059 | |
| 3060 | /* Set this member function's visibility fields. */ |
| 3061 | switch (*(*pp)++) |
| 3062 | { |
| 3063 | case VISIBILITY_PRIVATE: |
| 3064 | new_sublist -> fn_field.is_private = 1; |
| 3065 | break; |
| 3066 | case VISIBILITY_PROTECTED: |
| 3067 | new_sublist -> fn_field.is_protected = 1; |
| 3068 | break; |
| 3069 | } |
| 3070 | |
| 3071 | STABS_CONTINUE (pp, objfile); |
| 3072 | switch (**pp) |
| 3073 | { |
| 3074 | case 'A': /* Normal functions. */ |
| 3075 | new_sublist -> fn_field.is_const = 0; |
| 3076 | new_sublist -> fn_field.is_volatile = 0; |
| 3077 | (*pp)++; |
| 3078 | break; |
| 3079 | case 'B': /* `const' member functions. */ |
| 3080 | new_sublist -> fn_field.is_const = 1; |
| 3081 | new_sublist -> fn_field.is_volatile = 0; |
| 3082 | (*pp)++; |
| 3083 | break; |
| 3084 | case 'C': /* `volatile' member function. */ |
| 3085 | new_sublist -> fn_field.is_const = 0; |
| 3086 | new_sublist -> fn_field.is_volatile = 1; |
| 3087 | (*pp)++; |
| 3088 | break; |
| 3089 | case 'D': /* `const volatile' member function. */ |
| 3090 | new_sublist -> fn_field.is_const = 1; |
| 3091 | new_sublist -> fn_field.is_volatile = 1; |
| 3092 | (*pp)++; |
| 3093 | break; |
| 3094 | case '*': /* File compiled with g++ version 1 -- no info */ |
| 3095 | case '?': |
| 3096 | case '.': |
| 3097 | break; |
| 3098 | default: |
| 3099 | complain (&const_vol_complaint, **pp); |
| 3100 | break; |
| 3101 | } |
| 3102 | |
| 3103 | switch (*(*pp)++) |
| 3104 | { |
| 3105 | case '*': |
| 3106 | { |
| 3107 | int nbits; |
| 3108 | /* virtual member function, followed by index. |
| 3109 | The sign bit is set to distinguish pointers-to-methods |
| 3110 | from virtual function indicies. Since the array is |
| 3111 | in words, the quantity must be shifted left by 1 |
| 3112 | on 16 bit machine, and by 2 on 32 bit machine, forcing |
| 3113 | the sign bit out, and usable as a valid index into |
| 3114 | the array. Remove the sign bit here. */ |
| 3115 | new_sublist -> fn_field.voffset = |
| 3116 | (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2; |
| 3117 | if (nbits != 0) |
| 3118 | return 0; |
| 3119 | |
| 3120 | STABS_CONTINUE (pp, objfile); |
| 3121 | if (**pp == ';' || **pp == '\0') |
| 3122 | { |
| 3123 | /* Must be g++ version 1. */ |
| 3124 | new_sublist -> fn_field.fcontext = 0; |
| 3125 | } |
| 3126 | else |
| 3127 | { |
| 3128 | /* Figure out from whence this virtual function came. |
| 3129 | It may belong to virtual function table of |
| 3130 | one of its baseclasses. */ |
| 3131 | look_ahead_type = read_type (pp, objfile); |
| 3132 | if (**pp == ':') |
| 3133 | { |
| 3134 | /* g++ version 1 overloaded methods. */ |
| 3135 | } |
| 3136 | else |
| 3137 | { |
| 3138 | new_sublist -> fn_field.fcontext = look_ahead_type; |
| 3139 | if (**pp != ';') |
| 3140 | { |
| 3141 | return 0; |
| 3142 | } |
| 3143 | else |
| 3144 | { |
| 3145 | ++*pp; |
| 3146 | } |
| 3147 | look_ahead_type = NULL; |
| 3148 | } |
| 3149 | } |
| 3150 | break; |
| 3151 | } |
| 3152 | case '?': |
| 3153 | /* static member function. */ |
| 3154 | new_sublist -> fn_field.voffset = VOFFSET_STATIC; |
| 3155 | if (strncmp (new_sublist -> fn_field.physname, |
| 3156 | main_fn_name, strlen (main_fn_name))) |
| 3157 | { |
| 3158 | new_sublist -> fn_field.is_stub = 1; |
| 3159 | } |
| 3160 | break; |
| 3161 | |
| 3162 | default: |
| 3163 | /* error */ |
| 3164 | complain (&member_fn_complaint, (*pp)[-1]); |
| 3165 | /* Fall through into normal member function. */ |
| 3166 | |
| 3167 | case '.': |
| 3168 | /* normal member function. */ |
| 3169 | new_sublist -> fn_field.voffset = 0; |
| 3170 | new_sublist -> fn_field.fcontext = 0; |
| 3171 | break; |
| 3172 | } |
| 3173 | |
| 3174 | new_sublist -> next = sublist; |
| 3175 | sublist = new_sublist; |
| 3176 | length++; |
| 3177 | STABS_CONTINUE (pp, objfile); |
| 3178 | } |
| 3179 | while (**pp != ';' && **pp != '\0'); |
| 3180 | |
| 3181 | (*pp)++; |
| 3182 | |
| 3183 | new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *) |
| 3184 | obstack_alloc (&objfile -> type_obstack, |
| 3185 | sizeof (struct fn_field) * length); |
| 3186 | memset (new_fnlist -> fn_fieldlist.fn_fields, 0, |
| 3187 | sizeof (struct fn_field) * length); |
| 3188 | for (i = length; (i--, sublist); sublist = sublist -> next) |
| 3189 | { |
| 3190 | new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field; |
| 3191 | } |
| 3192 | |
| 3193 | new_fnlist -> fn_fieldlist.length = length; |
| 3194 | new_fnlist -> next = fip -> fnlist; |
| 3195 | fip -> fnlist = new_fnlist; |
| 3196 | nfn_fields++; |
| 3197 | total_length += length; |
| 3198 | STABS_CONTINUE (pp, objfile); |
| 3199 | } |
| 3200 | |
| 3201 | if (nfn_fields) |
| 3202 | { |
| 3203 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 3204 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 3205 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); |
| 3206 | memset (TYPE_FN_FIELDLISTS (type), 0, |
| 3207 | sizeof (struct fn_fieldlist) * nfn_fields); |
| 3208 | TYPE_NFN_FIELDS (type) = nfn_fields; |
| 3209 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; |
| 3210 | } |
| 3211 | |
| 3212 | return 1; |
| 3213 | } |
| 3214 | |
| 3215 | /* Special GNU C++ name. |
| 3216 | |
| 3217 | Returns 1 for success, 0 for failure. "failure" means that we can't |
| 3218 | keep parsing and it's time for error_type(). */ |
| 3219 | |
| 3220 | static int |
| 3221 | read_cpp_abbrev (fip, pp, type, objfile) |
| 3222 | struct field_info *fip; |
| 3223 | char **pp; |
| 3224 | struct type *type; |
| 3225 | struct objfile *objfile; |
| 3226 | { |
| 3227 | register char *p; |
| 3228 | char *name; |
| 3229 | char cpp_abbrev; |
| 3230 | struct type *context; |
| 3231 | |
| 3232 | p = *pp; |
| 3233 | if (*++p == 'v') |
| 3234 | { |
| 3235 | name = NULL; |
| 3236 | cpp_abbrev = *++p; |
| 3237 | |
| 3238 | *pp = p + 1; |
| 3239 | |
| 3240 | /* At this point, *pp points to something like "22:23=*22...", |
| 3241 | where the type number before the ':' is the "context" and |
| 3242 | everything after is a regular type definition. Lookup the |
| 3243 | type, find it's name, and construct the field name. */ |
| 3244 | |
| 3245 | context = read_type (pp, objfile); |
| 3246 | |
| 3247 | switch (cpp_abbrev) |
| 3248 | { |
| 3249 | case 'f': /* $vf -- a virtual function table pointer */ |
| 3250 | fip->list->field.name = |
| 3251 | obconcat (&objfile->type_obstack, vptr_name, "", ""); |
| 3252 | break; |
| 3253 | |
| 3254 | case 'b': /* $vb -- a virtual bsomethingorother */ |
| 3255 | name = type_name_no_tag (context); |
| 3256 | if (name == NULL) |
| 3257 | { |
| 3258 | complain (&invalid_cpp_type_complaint, symnum); |
| 3259 | name = "FOO"; |
| 3260 | } |
| 3261 | fip->list->field.name = |
| 3262 | obconcat (&objfile->type_obstack, vb_name, name, ""); |
| 3263 | break; |
| 3264 | |
| 3265 | default: |
| 3266 | complain (&invalid_cpp_abbrev_complaint, *pp); |
| 3267 | fip->list->field.name = |
| 3268 | obconcat (&objfile->type_obstack, |
| 3269 | "INVALID_CPLUSPLUS_ABBREV", "", ""); |
| 3270 | break; |
| 3271 | } |
| 3272 | |
| 3273 | /* At this point, *pp points to the ':'. Skip it and read the |
| 3274 | field type. */ |
| 3275 | |
| 3276 | p = ++(*pp); |
| 3277 | if (p[-1] != ':') |
| 3278 | { |
| 3279 | complain (&invalid_cpp_abbrev_complaint, *pp); |
| 3280 | return 0; |
| 3281 | } |
| 3282 | fip->list->field.type = read_type (pp, objfile); |
| 3283 | if (**pp == ',') |
| 3284 | (*pp)++; /* Skip the comma. */ |
| 3285 | else |
| 3286 | return 0; |
| 3287 | |
| 3288 | { |
| 3289 | int nbits; |
| 3290 | FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits); |
| 3291 | if (nbits != 0) |
| 3292 | return 0; |
| 3293 | } |
| 3294 | /* This field is unpacked. */ |
| 3295 | FIELD_BITSIZE (fip->list->field) = 0; |
| 3296 | fip->list->visibility = VISIBILITY_PRIVATE; |
| 3297 | } |
| 3298 | else |
| 3299 | { |
| 3300 | complain (&invalid_cpp_abbrev_complaint, *pp); |
| 3301 | /* We have no idea what syntax an unrecognized abbrev would have, so |
| 3302 | better return 0. If we returned 1, we would need to at least advance |
| 3303 | *pp to avoid an infinite loop. */ |
| 3304 | return 0; |
| 3305 | } |
| 3306 | return 1; |
| 3307 | } |
| 3308 | |
| 3309 | static void |
| 3310 | read_one_struct_field (fip, pp, p, type, objfile) |
| 3311 | struct field_info *fip; |
| 3312 | char **pp; |
| 3313 | char *p; |
| 3314 | struct type *type; |
| 3315 | struct objfile *objfile; |
| 3316 | { |
| 3317 | /* The following is code to work around cfront generated stabs. |
| 3318 | The stabs contains full mangled name for each field. |
| 3319 | We try to demangle the name and extract the field name out of it. |
| 3320 | */ |
| 3321 | if (ARM_DEMANGLING && current_subfile->language == language_cplus) |
| 3322 | { |
| 3323 | char save_p; |
| 3324 | char *dem, *dem_p; |
| 3325 | save_p = *p; |
| 3326 | *p = '\0'; |
| 3327 | dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS); |
| 3328 | if (dem != NULL) |
| 3329 | { |
| 3330 | dem_p = strrchr (dem, ':'); |
| 3331 | if (dem_p != 0 && *(dem_p-1)==':') |
| 3332 | dem_p++; |
| 3333 | FIELD_NAME (fip->list->field) = |
| 3334 | obsavestring (dem_p, strlen (dem_p), &objfile -> type_obstack); |
| 3335 | } |
| 3336 | else |
| 3337 | { |
| 3338 | FIELD_NAME (fip->list->field) = |
| 3339 | obsavestring (*pp, p - *pp, &objfile -> type_obstack); |
| 3340 | } |
| 3341 | *p = save_p; |
| 3342 | } |
| 3343 | /* end of code for cfront work around */ |
| 3344 | |
| 3345 | else |
| 3346 | fip -> list -> field.name = |
| 3347 | obsavestring (*pp, p - *pp, &objfile -> type_obstack); |
| 3348 | *pp = p + 1; |
| 3349 | |
| 3350 | /* This means we have a visibility for a field coming. */ |
| 3351 | if (**pp == '/') |
| 3352 | { |
| 3353 | (*pp)++; |
| 3354 | fip -> list -> visibility = *(*pp)++; |
| 3355 | } |
| 3356 | else |
| 3357 | { |
| 3358 | /* normal dbx-style format, no explicit visibility */ |
| 3359 | fip -> list -> visibility = VISIBILITY_PUBLIC; |
| 3360 | } |
| 3361 | |
| 3362 | fip -> list -> field.type = read_type (pp, objfile); |
| 3363 | if (**pp == ':') |
| 3364 | { |
| 3365 | p = ++(*pp); |
| 3366 | #if 0 |
| 3367 | /* Possible future hook for nested types. */ |
| 3368 | if (**pp == '!') |
| 3369 | { |
| 3370 | fip -> list -> field.bitpos = (long)-2; /* nested type */ |
| 3371 | p = ++(*pp); |
| 3372 | } |
| 3373 | else ...; |
| 3374 | #endif |
| 3375 | while (*p != ';') |
| 3376 | { |
| 3377 | p++; |
| 3378 | } |
| 3379 | /* Static class member. */ |
| 3380 | SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp)); |
| 3381 | *pp = p + 1; |
| 3382 | return; |
| 3383 | } |
| 3384 | else if (**pp != ',') |
| 3385 | { |
| 3386 | /* Bad structure-type format. */ |
| 3387 | complain (&stabs_general_complaint, "bad structure-type format"); |
| 3388 | return; |
| 3389 | } |
| 3390 | |
| 3391 | (*pp)++; /* Skip the comma. */ |
| 3392 | |
| 3393 | { |
| 3394 | int nbits; |
| 3395 | FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits); |
| 3396 | if (nbits != 0) |
| 3397 | { |
| 3398 | complain (&stabs_general_complaint, "bad structure-type format"); |
| 3399 | return; |
| 3400 | } |
| 3401 | FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits); |
| 3402 | if (nbits != 0) |
| 3403 | { |
| 3404 | complain (&stabs_general_complaint, "bad structure-type format"); |
| 3405 | return; |
| 3406 | } |
| 3407 | } |
| 3408 | |
| 3409 | if (FIELD_BITPOS (fip->list->field) == 0 |
| 3410 | && FIELD_BITSIZE (fip->list->field) == 0) |
| 3411 | { |
| 3412 | /* This can happen in two cases: (1) at least for gcc 2.4.5 or so, |
| 3413 | it is a field which has been optimized out. The correct stab for |
| 3414 | this case is to use VISIBILITY_IGNORE, but that is a recent |
| 3415 | invention. (2) It is a 0-size array. For example |
| 3416 | union { int num; char str[0]; } foo. Printing "<no value>" for |
| 3417 | str in "p foo" is OK, since foo.str (and thus foo.str[3]) |
| 3418 | will continue to work, and a 0-size array as a whole doesn't |
| 3419 | have any contents to print. |
| 3420 | |
| 3421 | I suspect this probably could also happen with gcc -gstabs (not |
| 3422 | -gstabs+) for static fields, and perhaps other C++ extensions. |
| 3423 | Hopefully few people use -gstabs with gdb, since it is intended |
| 3424 | for dbx compatibility. */ |
| 3425 | |
| 3426 | /* Ignore this field. */ |
| 3427 | fip -> list-> visibility = VISIBILITY_IGNORE; |
| 3428 | } |
| 3429 | else |
| 3430 | { |
| 3431 | /* Detect an unpacked field and mark it as such. |
| 3432 | dbx gives a bit size for all fields. |
| 3433 | Note that forward refs cannot be packed, |
| 3434 | and treat enums as if they had the width of ints. */ |
| 3435 | |
| 3436 | struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field)); |
| 3437 | |
| 3438 | if (TYPE_CODE (field_type) != TYPE_CODE_INT |
| 3439 | && TYPE_CODE (field_type) != TYPE_CODE_RANGE |
| 3440 | && TYPE_CODE (field_type) != TYPE_CODE_BOOL |
| 3441 | && TYPE_CODE (field_type) != TYPE_CODE_ENUM) |
| 3442 | { |
| 3443 | FIELD_BITSIZE (fip->list->field) = 0; |
| 3444 | } |
| 3445 | if ((FIELD_BITSIZE (fip->list->field) |
| 3446 | == TARGET_CHAR_BIT * TYPE_LENGTH (field_type) |
| 3447 | || (TYPE_CODE (field_type) == TYPE_CODE_ENUM |
| 3448 | && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT ) |
| 3449 | ) |
| 3450 | && |
| 3451 | FIELD_BITPOS (fip->list->field) % 8 == 0) |
| 3452 | { |
| 3453 | FIELD_BITSIZE (fip->list->field) = 0; |
| 3454 | } |
| 3455 | } |
| 3456 | } |
| 3457 | |
| 3458 | |
| 3459 | /* Read struct or class data fields. They have the form: |
| 3460 | |
| 3461 | NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; |
| 3462 | |
| 3463 | At the end, we see a semicolon instead of a field. |
| 3464 | |
| 3465 | In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for |
| 3466 | a static field. |
| 3467 | |
| 3468 | The optional VISIBILITY is one of: |
| 3469 | |
| 3470 | '/0' (VISIBILITY_PRIVATE) |
| 3471 | '/1' (VISIBILITY_PROTECTED) |
| 3472 | '/2' (VISIBILITY_PUBLIC) |
| 3473 | '/9' (VISIBILITY_IGNORE) |
| 3474 | |
| 3475 | or nothing, for C style fields with public visibility. |
| 3476 | |
| 3477 | Returns 1 for success, 0 for failure. */ |
| 3478 | |
| 3479 | static int |
| 3480 | read_struct_fields (fip, pp, type, objfile) |
| 3481 | struct field_info *fip; |
| 3482 | char **pp; |
| 3483 | struct type *type; |
| 3484 | struct objfile *objfile; |
| 3485 | { |
| 3486 | register char *p; |
| 3487 | struct nextfield *new; |
| 3488 | |
| 3489 | /* We better set p right now, in case there are no fields at all... */ |
| 3490 | |
| 3491 | p = *pp; |
| 3492 | |
| 3493 | /* Read each data member type until we find the terminating ';' at the end of |
| 3494 | the data member list, or break for some other reason such as finding the |
| 3495 | start of the member function list. */ |
| 3496 | |
| 3497 | while (**pp != ';') |
| 3498 | { |
| 3499 | if (os9k_stabs && **pp == ',') break; |
| 3500 | STABS_CONTINUE (pp, objfile); |
| 3501 | /* Get space to record the next field's data. */ |
| 3502 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 3503 | make_cleanup (free, new); |
| 3504 | memset (new, 0, sizeof (struct nextfield)); |
| 3505 | new -> next = fip -> list; |
| 3506 | fip -> list = new; |
| 3507 | |
| 3508 | /* Get the field name. */ |
| 3509 | p = *pp; |
| 3510 | |
| 3511 | /* If is starts with CPLUS_MARKER it is a special abbreviation, |
| 3512 | unless the CPLUS_MARKER is followed by an underscore, in |
| 3513 | which case it is just the name of an anonymous type, which we |
| 3514 | should handle like any other type name. */ |
| 3515 | |
| 3516 | if (is_cplus_marker (p[0]) && p[1] != '_') |
| 3517 | { |
| 3518 | if (!read_cpp_abbrev (fip, pp, type, objfile)) |
| 3519 | return 0; |
| 3520 | continue; |
| 3521 | } |
| 3522 | |
| 3523 | /* Look for the ':' that separates the field name from the field |
| 3524 | values. Data members are delimited by a single ':', while member |
| 3525 | functions are delimited by a pair of ':'s. When we hit the member |
| 3526 | functions (if any), terminate scan loop and return. */ |
| 3527 | |
| 3528 | while (*p != ':' && *p != '\0') |
| 3529 | { |
| 3530 | p++; |
| 3531 | } |
| 3532 | if (*p == '\0') |
| 3533 | return 0; |
| 3534 | |
| 3535 | /* Check to see if we have hit the member functions yet. */ |
| 3536 | if (p[1] == ':') |
| 3537 | { |
| 3538 | break; |
| 3539 | } |
| 3540 | read_one_struct_field (fip, pp, p, type, objfile); |
| 3541 | } |
| 3542 | if (p[0] == ':' && p[1] == ':') |
| 3543 | { |
| 3544 | /* chill the list of fields: the last entry (at the head) is a |
| 3545 | partially constructed entry which we now scrub. */ |
| 3546 | fip -> list = fip -> list -> next; |
| 3547 | } |
| 3548 | return 1; |
| 3549 | } |
| 3550 | |
| 3551 | /* The stabs for C++ derived classes contain baseclass information which |
| 3552 | is marked by a '!' character after the total size. This function is |
| 3553 | called when we encounter the baseclass marker, and slurps up all the |
| 3554 | baseclass information. |
| 3555 | |
| 3556 | Immediately following the '!' marker is the number of base classes that |
| 3557 | the class is derived from, followed by information for each base class. |
| 3558 | For each base class, there are two visibility specifiers, a bit offset |
| 3559 | to the base class information within the derived class, a reference to |
| 3560 | the type for the base class, and a terminating semicolon. |
| 3561 | |
| 3562 | A typical example, with two base classes, would be "!2,020,19;0264,21;". |
| 3563 | ^^ ^ ^ ^ ^ ^ ^ |
| 3564 | Baseclass information marker __________________|| | | | | | | |
| 3565 | Number of baseclasses __________________________| | | | | | | |
| 3566 | Visibility specifiers (2) ________________________| | | | | | |
| 3567 | Offset in bits from start of class _________________| | | | | |
| 3568 | Type number for base class ___________________________| | | | |
| 3569 | Visibility specifiers (2) _______________________________| | | |
| 3570 | Offset in bits from start of class ________________________| | |
| 3571 | Type number of base class ____________________________________| |
| 3572 | |
| 3573 | Return 1 for success, 0 for (error-type-inducing) failure. */ |
| 3574 | |
| 3575 | static int |
| 3576 | read_baseclasses (fip, pp, type, objfile) |
| 3577 | struct field_info *fip; |
| 3578 | char **pp; |
| 3579 | struct type *type; |
| 3580 | struct objfile *objfile; |
| 3581 | { |
| 3582 | int i; |
| 3583 | struct nextfield *new; |
| 3584 | |
| 3585 | if (**pp != '!') |
| 3586 | { |
| 3587 | return 1; |
| 3588 | } |
| 3589 | else |
| 3590 | { |
| 3591 | /* Skip the '!' baseclass information marker. */ |
| 3592 | (*pp)++; |
| 3593 | } |
| 3594 | |
| 3595 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 3596 | { |
| 3597 | int nbits; |
| 3598 | TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits); |
| 3599 | if (nbits != 0) |
| 3600 | return 0; |
| 3601 | } |
| 3602 | |
| 3603 | #if 0 |
| 3604 | /* Some stupid compilers have trouble with the following, so break |
| 3605 | it up into simpler expressions. */ |
| 3606 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) |
| 3607 | TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); |
| 3608 | #else |
| 3609 | { |
| 3610 | int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); |
| 3611 | char *pointer; |
| 3612 | |
| 3613 | pointer = (char *) TYPE_ALLOC (type, num_bytes); |
| 3614 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; |
| 3615 | } |
| 3616 | #endif /* 0 */ |
| 3617 | |
| 3618 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); |
| 3619 | |
| 3620 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
| 3621 | { |
| 3622 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 3623 | make_cleanup (free, new); |
| 3624 | memset (new, 0, sizeof (struct nextfield)); |
| 3625 | new -> next = fip -> list; |
| 3626 | fip -> list = new; |
| 3627 | FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */ |
| 3628 | |
| 3629 | STABS_CONTINUE (pp, objfile); |
| 3630 | switch (**pp) |
| 3631 | { |
| 3632 | case '0': |
| 3633 | /* Nothing to do. */ |
| 3634 | break; |
| 3635 | case '1': |
| 3636 | SET_TYPE_FIELD_VIRTUAL (type, i); |
| 3637 | break; |
| 3638 | default: |
| 3639 | /* Unknown character. Complain and treat it as non-virtual. */ |
| 3640 | { |
| 3641 | static struct complaint msg = { |
| 3642 | "Unknown virtual character `%c' for baseclass", 0, 0}; |
| 3643 | complain (&msg, **pp); |
| 3644 | } |
| 3645 | } |
| 3646 | ++(*pp); |
| 3647 | |
| 3648 | new -> visibility = *(*pp)++; |
| 3649 | switch (new -> visibility) |
| 3650 | { |
| 3651 | case VISIBILITY_PRIVATE: |
| 3652 | case VISIBILITY_PROTECTED: |
| 3653 | case VISIBILITY_PUBLIC: |
| 3654 | break; |
| 3655 | default: |
| 3656 | /* Bad visibility format. Complain and treat it as |
| 3657 | public. */ |
| 3658 | { |
| 3659 | static struct complaint msg = { |
| 3660 | "Unknown visibility `%c' for baseclass", 0, 0}; |
| 3661 | complain (&msg, new -> visibility); |
| 3662 | new -> visibility = VISIBILITY_PUBLIC; |
| 3663 | } |
| 3664 | } |
| 3665 | |
| 3666 | { |
| 3667 | int nbits; |
| 3668 | |
| 3669 | /* The remaining value is the bit offset of the portion of the object |
| 3670 | corresponding to this baseclass. Always zero in the absence of |
| 3671 | multiple inheritance. */ |
| 3672 | |
| 3673 | FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits); |
| 3674 | if (nbits != 0) |
| 3675 | return 0; |
| 3676 | } |
| 3677 | |
| 3678 | /* The last piece of baseclass information is the type of the |
| 3679 | base class. Read it, and remember it's type name as this |
| 3680 | field's name. */ |
| 3681 | |
| 3682 | new -> field.type = read_type (pp, objfile); |
| 3683 | new -> field.name = type_name_no_tag (new -> field.type); |
| 3684 | |
| 3685 | /* skip trailing ';' and bump count of number of fields seen */ |
| 3686 | if (**pp == ';') |
| 3687 | (*pp)++; |
| 3688 | else |
| 3689 | return 0; |
| 3690 | } |
| 3691 | return 1; |
| 3692 | } |
| 3693 | |
| 3694 | /* The tail end of stabs for C++ classes that contain a virtual function |
| 3695 | pointer contains a tilde, a %, and a type number. |
| 3696 | The type number refers to the base class (possibly this class itself) which |
| 3697 | contains the vtable pointer for the current class. |
| 3698 | |
| 3699 | This function is called when we have parsed all the method declarations, |
| 3700 | so we can look for the vptr base class info. */ |
| 3701 | |
| 3702 | static int |
| 3703 | read_tilde_fields (fip, pp, type, objfile) |
| 3704 | struct field_info *fip; |
| 3705 | char **pp; |
| 3706 | struct type *type; |
| 3707 | struct objfile *objfile; |
| 3708 | { |
| 3709 | register char *p; |
| 3710 | |
| 3711 | STABS_CONTINUE (pp, objfile); |
| 3712 | |
| 3713 | /* If we are positioned at a ';', then skip it. */ |
| 3714 | if (**pp == ';') |
| 3715 | { |
| 3716 | (*pp)++; |
| 3717 | } |
| 3718 | |
| 3719 | if (**pp == '~') |
| 3720 | { |
| 3721 | (*pp)++; |
| 3722 | |
| 3723 | if (**pp == '=' || **pp == '+' || **pp == '-') |
| 3724 | { |
| 3725 | /* Obsolete flags that used to indicate the presence |
| 3726 | of constructors and/or destructors. */ |
| 3727 | (*pp)++; |
| 3728 | } |
| 3729 | |
| 3730 | /* Read either a '%' or the final ';'. */ |
| 3731 | if (*(*pp)++ == '%') |
| 3732 | { |
| 3733 | /* The next number is the type number of the base class |
| 3734 | (possibly our own class) which supplies the vtable for |
| 3735 | this class. Parse it out, and search that class to find |
| 3736 | its vtable pointer, and install those into TYPE_VPTR_BASETYPE |
| 3737 | and TYPE_VPTR_FIELDNO. */ |
| 3738 | |
| 3739 | struct type *t; |
| 3740 | int i; |
| 3741 | |
| 3742 | t = read_type (pp, objfile); |
| 3743 | p = (*pp)++; |
| 3744 | while (*p != '\0' && *p != ';') |
| 3745 | { |
| 3746 | p++; |
| 3747 | } |
| 3748 | if (*p == '\0') |
| 3749 | { |
| 3750 | /* Premature end of symbol. */ |
| 3751 | return 0; |
| 3752 | } |
| 3753 | |
| 3754 | TYPE_VPTR_BASETYPE (type) = t; |
| 3755 | if (type == t) /* Our own class provides vtbl ptr */ |
| 3756 | { |
| 3757 | for (i = TYPE_NFIELDS (t) - 1; |
| 3758 | i >= TYPE_N_BASECLASSES (t); |
| 3759 | --i) |
| 3760 | { |
| 3761 | if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name, |
| 3762 | sizeof (vptr_name) - 1)) |
| 3763 | { |
| 3764 | TYPE_VPTR_FIELDNO (type) = i; |
| 3765 | goto gotit; |
| 3766 | } |
| 3767 | } |
| 3768 | /* Virtual function table field not found. */ |
| 3769 | complain (&vtbl_notfound_complaint, TYPE_NAME (type)); |
| 3770 | return 0; |
| 3771 | } |
| 3772 | else |
| 3773 | { |
| 3774 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); |
| 3775 | } |
| 3776 | |
| 3777 | gotit: |
| 3778 | *pp = p + 1; |
| 3779 | } |
| 3780 | } |
| 3781 | return 1; |
| 3782 | } |
| 3783 | |
| 3784 | static int |
| 3785 | attach_fn_fields_to_type (fip, type) |
| 3786 | struct field_info *fip; |
| 3787 | register struct type *type; |
| 3788 | { |
| 3789 | register int n; |
| 3790 | |
| 3791 | for (n = TYPE_NFN_FIELDS (type); |
| 3792 | fip -> fnlist != NULL; |
| 3793 | fip -> fnlist = fip -> fnlist -> next) |
| 3794 | { |
| 3795 | --n; /* Circumvent Sun3 compiler bug */ |
| 3796 | TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist; |
| 3797 | } |
| 3798 | return 1; |
| 3799 | } |
| 3800 | |
| 3801 | /* read cfront class static data. |
| 3802 | pp points to string starting with the list of static data |
| 3803 | eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;; |
| 3804 | ^^^^^^^^ |
| 3805 | |
| 3806 | A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;; |
| 3807 | ^ |
| 3808 | */ |
| 3809 | |
| 3810 | static int |
| 3811 | read_cfront_static_fields (fip, pp, type, objfile) |
| 3812 | struct field_info *fip; |
| 3813 | char **pp; |
| 3814 | struct type *type; |
| 3815 | struct objfile *objfile; |
| 3816 | { |
| 3817 | struct nextfield * new; |
| 3818 | struct type *stype; |
| 3819 | char * sname; |
| 3820 | struct symbol * ref_static=0; |
| 3821 | |
| 3822 | if (**pp==';') /* no static data; return */ |
| 3823 | { |
| 3824 | ++(*pp); |
| 3825 | return 1; |
| 3826 | } |
| 3827 | |
| 3828 | /* Process each field in the list until we find the terminating ";" */ |
| 3829 | |
| 3830 | /* eg: p = "as__1A ;;;" */ |
| 3831 | STABS_CONTINUE (pp, objfile); /* handle \\ */ |
| 3832 | while (**pp!=';' && (sname = get_substring (pp, ' '), sname)) |
| 3833 | { |
| 3834 | ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name*/ |
| 3835 | if (!ref_static) |
| 3836 | { |
| 3837 | static struct complaint msg = {"\ |
| 3838 | Unable to find symbol for static data field %s\n", |
| 3839 | 0, 0}; |
| 3840 | complain (&msg, sname); |
| 3841 | continue; |
| 3842 | } |
| 3843 | stype = SYMBOL_TYPE(ref_static); |
| 3844 | |
| 3845 | /* allocate a new fip */ |
| 3846 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 3847 | make_cleanup (free, new); |
| 3848 | memset (new, 0, sizeof (struct nextfield)); |
| 3849 | new -> next = fip -> list; |
| 3850 | fip -> list = new; |
| 3851 | |
| 3852 | /* set visibility */ |
| 3853 | /* FIXME! no way to tell visibility from stabs??? */ |
| 3854 | new -> visibility = VISIBILITY_PUBLIC; |
| 3855 | |
| 3856 | /* set field info into fip */ |
| 3857 | fip -> list -> field.type = stype; |
| 3858 | |
| 3859 | /* set bitpos & bitsize */ |
| 3860 | SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname))); |
| 3861 | |
| 3862 | /* set name field */ |
| 3863 | /* The following is code to work around cfront generated stabs. |
| 3864 | The stabs contains full mangled name for each field. |
| 3865 | We try to demangle the name and extract the field name out of it. |
| 3866 | */ |
| 3867 | if (ARM_DEMANGLING) |
| 3868 | { |
| 3869 | char *dem, *dem_p; |
| 3870 | dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS); |
| 3871 | if (dem != NULL) |
| 3872 | { |
| 3873 | dem_p = strrchr (dem, ':'); |
| 3874 | if (dem_p != 0 && *(dem_p-1)==':') |
| 3875 | dem_p++; |
| 3876 | fip->list->field.name = |
| 3877 | obsavestring (dem_p, strlen (dem_p), &objfile -> type_obstack); |
| 3878 | } |
| 3879 | else |
| 3880 | { |
| 3881 | fip->list->field.name = |
| 3882 | obsavestring (sname, strlen (sname), &objfile -> type_obstack); |
| 3883 | } |
| 3884 | } /* end of code for cfront work around */ |
| 3885 | } /* loop again for next static field */ |
| 3886 | return 1; |
| 3887 | } |
| 3888 | |
| 3889 | /* Copy structure fields to fip so attach_fields_to_type will work. |
| 3890 | type has already been created with the initial instance data fields. |
| 3891 | Now we want to be able to add the other members to the class, |
| 3892 | so we want to add them back to the fip and reattach them again |
| 3893 | once we have collected all the class members. */ |
| 3894 | |
| 3895 | static int |
| 3896 | copy_cfront_struct_fields (fip, type, objfile) |
| 3897 | struct field_info *fip; |
| 3898 | struct type *type; |
| 3899 | struct objfile *objfile; |
| 3900 | { |
| 3901 | int nfields = TYPE_NFIELDS(type); |
| 3902 | int i; |
| 3903 | struct nextfield * new; |
| 3904 | |
| 3905 | /* Copy the fields into the list of fips and reset the types |
| 3906 | to remove the old fields */ |
| 3907 | |
| 3908 | for (i=0; i<nfields; i++) |
| 3909 | { |
| 3910 | /* allocate a new fip */ |
| 3911 | new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 3912 | make_cleanup (free, new); |
| 3913 | memset (new, 0, sizeof (struct nextfield)); |
| 3914 | new -> next = fip -> list; |
| 3915 | fip -> list = new; |
| 3916 | |
| 3917 | /* copy field info into fip */ |
| 3918 | new -> field = TYPE_FIELD (type, i); |
| 3919 | /* set visibility */ |
| 3920 | if (TYPE_FIELD_PROTECTED (type, i)) |
| 3921 | new -> visibility = VISIBILITY_PROTECTED; |
| 3922 | else if (TYPE_FIELD_PRIVATE (type, i)) |
| 3923 | new -> visibility = VISIBILITY_PRIVATE; |
| 3924 | else |
| 3925 | new -> visibility = VISIBILITY_PUBLIC; |
| 3926 | } |
| 3927 | /* Now delete the fields from the type since we will be |
| 3928 | allocing new space once we get the rest of the fields |
| 3929 | in attach_fields_to_type. |
| 3930 | The pointer TYPE_FIELDS(type) is left dangling but should |
| 3931 | be freed later by objstack_free */ |
| 3932 | TYPE_FIELDS (type)=0; |
| 3933 | TYPE_NFIELDS (type) = 0; |
| 3934 | |
| 3935 | return 1; |
| 3936 | } |
| 3937 | |
| 3938 | /* Create the vector of fields, and record how big it is. |
| 3939 | We need this info to record proper virtual function table information |
| 3940 | for this class's virtual functions. */ |
| 3941 | |
| 3942 | static int |
| 3943 | attach_fields_to_type (fip, type, objfile) |
| 3944 | struct field_info *fip; |
| 3945 | register struct type *type; |
| 3946 | struct objfile *objfile; |
| 3947 | { |
| 3948 | register int nfields = 0; |
| 3949 | register int non_public_fields = 0; |
| 3950 | register struct nextfield *scan; |
| 3951 | |
| 3952 | /* Count up the number of fields that we have, as well as taking note of |
| 3953 | whether or not there are any non-public fields, which requires us to |
| 3954 | allocate and build the private_field_bits and protected_field_bits |
| 3955 | bitfields. */ |
| 3956 | |
| 3957 | for (scan = fip -> list; scan != NULL; scan = scan -> next) |
| 3958 | { |
| 3959 | nfields++; |
| 3960 | if (scan -> visibility != VISIBILITY_PUBLIC) |
| 3961 | { |
| 3962 | non_public_fields++; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | /* Now we know how many fields there are, and whether or not there are any |
| 3967 | non-public fields. Record the field count, allocate space for the |
| 3968 | array of fields, and create blank visibility bitfields if necessary. */ |
| 3969 | |
| 3970 | TYPE_NFIELDS (type) = nfields; |
| 3971 | TYPE_FIELDS (type) = (struct field *) |
| 3972 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
| 3973 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); |
| 3974 | |
| 3975 | if (non_public_fields) |
| 3976 | { |
| 3977 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 3978 | |
| 3979 | TYPE_FIELD_PRIVATE_BITS (type) = |
| 3980 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 3981 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); |
| 3982 | |
| 3983 | TYPE_FIELD_PROTECTED_BITS (type) = |
| 3984 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 3985 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); |
| 3986 | |
| 3987 | TYPE_FIELD_IGNORE_BITS (type) = |
| 3988 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 3989 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); |
| 3990 | } |
| 3991 | |
| 3992 | /* Copy the saved-up fields into the field vector. Start from the head |
| 3993 | of the list, adding to the tail of the field array, so that they end |
| 3994 | up in the same order in the array in which they were added to the list. */ |
| 3995 | |
| 3996 | while (nfields-- > 0) |
| 3997 | { |
| 3998 | TYPE_FIELD (type, nfields) = fip -> list -> field; |
| 3999 | switch (fip -> list -> visibility) |
| 4000 | { |
| 4001 | case VISIBILITY_PRIVATE: |
| 4002 | SET_TYPE_FIELD_PRIVATE (type, nfields); |
| 4003 | break; |
| 4004 | |
| 4005 | case VISIBILITY_PROTECTED: |
| 4006 | SET_TYPE_FIELD_PROTECTED (type, nfields); |
| 4007 | break; |
| 4008 | |
| 4009 | case VISIBILITY_IGNORE: |
| 4010 | SET_TYPE_FIELD_IGNORE (type, nfields); |
| 4011 | break; |
| 4012 | |
| 4013 | case VISIBILITY_PUBLIC: |
| 4014 | break; |
| 4015 | |
| 4016 | default: |
| 4017 | /* Unknown visibility. Complain and treat it as public. */ |
| 4018 | { |
| 4019 | static struct complaint msg = { |
| 4020 | "Unknown visibility `%c' for field", 0, 0}; |
| 4021 | complain (&msg, fip -> list -> visibility); |
| 4022 | } |
| 4023 | break; |
| 4024 | } |
| 4025 | fip -> list = fip -> list -> next; |
| 4026 | } |
| 4027 | return 1; |
| 4028 | } |
| 4029 | |
| 4030 | /* Read the description of a structure (or union type) and return an object |
| 4031 | describing the type. |
| 4032 | |
| 4033 | PP points to a character pointer that points to the next unconsumed token |
| 4034 | in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", |
| 4035 | *PP will point to "4a:1,0,32;;". |
| 4036 | |
| 4037 | TYPE points to an incomplete type that needs to be filled in. |
| 4038 | |
| 4039 | OBJFILE points to the current objfile from which the stabs information is |
| 4040 | being read. (Note that it is redundant in that TYPE also contains a pointer |
| 4041 | to this same objfile, so it might be a good idea to eliminate it. FIXME). |
| 4042 | */ |
| 4043 | |
| 4044 | static struct type * |
| 4045 | read_struct_type (pp, type, objfile) |
| 4046 | char **pp; |
| 4047 | struct type *type; |
| 4048 | struct objfile *objfile; |
| 4049 | { |
| 4050 | struct cleanup *back_to; |
| 4051 | struct field_info fi; |
| 4052 | |
| 4053 | fi.list = NULL; |
| 4054 | fi.fnlist = NULL; |
| 4055 | |
| 4056 | back_to = make_cleanup (null_cleanup, 0); |
| 4057 | |
| 4058 | INIT_CPLUS_SPECIFIC (type); |
| 4059 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; |
| 4060 | |
| 4061 | /* First comes the total size in bytes. */ |
| 4062 | |
| 4063 | { |
| 4064 | int nbits; |
| 4065 | TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits); |
| 4066 | if (nbits != 0) |
| 4067 | return error_type (pp, objfile); |
| 4068 | } |
| 4069 | |
| 4070 | /* Now read the baseclasses, if any, read the regular C struct or C++ |
| 4071 | class member fields, attach the fields to the type, read the C++ |
| 4072 | member functions, attach them to the type, and then read any tilde |
| 4073 | field (baseclass specifier for the class holding the main vtable). */ |
| 4074 | |
| 4075 | if (!read_baseclasses (&fi, pp, type, objfile) |
| 4076 | || !read_struct_fields (&fi, pp, type, objfile) |
| 4077 | || !attach_fields_to_type (&fi, type, objfile) |
| 4078 | || !read_member_functions (&fi, pp, type, objfile) |
| 4079 | || !attach_fn_fields_to_type (&fi, type) |
| 4080 | || !read_tilde_fields (&fi, pp, type, objfile)) |
| 4081 | { |
| 4082 | type = error_type (pp, objfile); |
| 4083 | } |
| 4084 | |
| 4085 | do_cleanups (back_to); |
| 4086 | return (type); |
| 4087 | } |
| 4088 | |
| 4089 | /* Read a definition of an array type, |
| 4090 | and create and return a suitable type object. |
| 4091 | Also creates a range type which represents the bounds of that |
| 4092 | array. */ |
| 4093 | |
| 4094 | static struct type * |
| 4095 | read_array_type (pp, type, objfile) |
| 4096 | register char **pp; |
| 4097 | register struct type *type; |
| 4098 | struct objfile *objfile; |
| 4099 | { |
| 4100 | struct type *index_type, *element_type, *range_type; |
| 4101 | int lower, upper; |
| 4102 | int adjustable = 0; |
| 4103 | int nbits; |
| 4104 | |
| 4105 | /* Format of an array type: |
| 4106 | "ar<index type>;lower;upper;<array_contents_type>". |
| 4107 | OS9000: "arlower,upper;<array_contents_type>". |
| 4108 | |
| 4109 | Fortran adjustable arrays use Adigits or Tdigits for lower or upper; |
| 4110 | for these, produce a type like float[][]. */ |
| 4111 | |
| 4112 | if (os9k_stabs) |
| 4113 | index_type = builtin_type_int; |
| 4114 | else |
| 4115 | { |
| 4116 | index_type = read_type (pp, objfile); |
| 4117 | if (**pp != ';') |
| 4118 | /* Improper format of array type decl. */ |
| 4119 | return error_type (pp, objfile); |
| 4120 | ++*pp; |
| 4121 | } |
| 4122 | |
| 4123 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') |
| 4124 | { |
| 4125 | (*pp)++; |
| 4126 | adjustable = 1; |
| 4127 | } |
| 4128 | lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits); |
| 4129 | if (nbits != 0) |
| 4130 | return error_type (pp, objfile); |
| 4131 | |
| 4132 | if (!(**pp >= '0' && **pp <= '9') && **pp != '-') |
| 4133 | { |
| 4134 | (*pp)++; |
| 4135 | adjustable = 1; |
| 4136 | } |
| 4137 | upper = read_huge_number (pp, ';', &nbits); |
| 4138 | if (nbits != 0) |
| 4139 | return error_type (pp, objfile); |
| 4140 | |
| 4141 | element_type = read_type (pp, objfile); |
| 4142 | |
| 4143 | if (adjustable) |
| 4144 | { |
| 4145 | lower = 0; |
| 4146 | upper = -1; |
| 4147 | } |
| 4148 | |
| 4149 | range_type = |
| 4150 | create_range_type ((struct type *) NULL, index_type, lower, upper); |
| 4151 | type = create_array_type (type, element_type, range_type); |
| 4152 | |
| 4153 | return type; |
| 4154 | } |
| 4155 | |
| 4156 | |
| 4157 | /* Read a definition of an enumeration type, |
| 4158 | and create and return a suitable type object. |
| 4159 | Also defines the symbols that represent the values of the type. */ |
| 4160 | |
| 4161 | static struct type * |
| 4162 | read_enum_type (pp, type, objfile) |
| 4163 | register char **pp; |
| 4164 | register struct type *type; |
| 4165 | struct objfile *objfile; |
| 4166 | { |
| 4167 | register char *p; |
| 4168 | char *name; |
| 4169 | register long n; |
| 4170 | register struct symbol *sym; |
| 4171 | int nsyms = 0; |
| 4172 | struct pending **symlist; |
| 4173 | struct pending *osyms, *syms; |
| 4174 | int o_nsyms; |
| 4175 | int nbits; |
| 4176 | int unsigned_enum = 1; |
| 4177 | |
| 4178 | #if 0 |
| 4179 | /* FIXME! The stabs produced by Sun CC merrily define things that ought |
| 4180 | to be file-scope, between N_FN entries, using N_LSYM. What's a mother |
| 4181 | to do? For now, force all enum values to file scope. */ |
| 4182 | if (within_function) |
| 4183 | symlist = &local_symbols; |
| 4184 | else |
| 4185 | #endif |
| 4186 | symlist = &file_symbols; |
| 4187 | osyms = *symlist; |
| 4188 | o_nsyms = osyms ? osyms->nsyms : 0; |
| 4189 | |
| 4190 | if (os9k_stabs) |
| 4191 | { |
| 4192 | /* Size. Perhaps this does not have to be conditionalized on |
| 4193 | os9k_stabs (assuming the name of an enum constant can't start |
| 4194 | with a digit). */ |
| 4195 | read_huge_number (pp, 0, &nbits); |
| 4196 | if (nbits != 0) |
| 4197 | return error_type (pp, objfile); |
| 4198 | } |
| 4199 | |
| 4200 | /* The aix4 compiler emits an extra field before the enum members; |
| 4201 | my guess is it's a type of some sort. Just ignore it. */ |
| 4202 | if (**pp == '-') |
| 4203 | { |
| 4204 | /* Skip over the type. */ |
| 4205 | while (**pp != ':') |
| 4206 | (*pp)++; |
| 4207 | |
| 4208 | /* Skip over the colon. */ |
| 4209 | (*pp)++; |
| 4210 | } |
| 4211 | |
| 4212 | /* Read the value-names and their values. |
| 4213 | The input syntax is NAME:VALUE,NAME:VALUE, and so on. |
| 4214 | A semicolon or comma instead of a NAME means the end. */ |
| 4215 | while (**pp && **pp != ';' && **pp != ',') |
| 4216 | { |
| 4217 | STABS_CONTINUE (pp, objfile); |
| 4218 | p = *pp; |
| 4219 | while (*p != ':') p++; |
| 4220 | name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack); |
| 4221 | *pp = p + 1; |
| 4222 | n = read_huge_number (pp, ',', &nbits); |
| 4223 | if (nbits != 0) |
| 4224 | return error_type (pp, objfile); |
| 4225 | |
| 4226 | sym = (struct symbol *) |
| 4227 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 4228 | memset (sym, 0, sizeof (struct symbol)); |
| 4229 | SYMBOL_NAME (sym) = name; |
| 4230 | SYMBOL_LANGUAGE (sym) = current_subfile -> language; |
| 4231 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 4232 | SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; |
| 4233 | SYMBOL_VALUE (sym) = n; |
| 4234 | if (n < 0) |
| 4235 | unsigned_enum = 0; |
| 4236 | add_symbol_to_list (sym, symlist); |
| 4237 | nsyms++; |
| 4238 | } |
| 4239 | |
| 4240 | if (**pp == ';') |
| 4241 | (*pp)++; /* Skip the semicolon. */ |
| 4242 | |
| 4243 | /* Now fill in the fields of the type-structure. */ |
| 4244 | |
| 4245 | TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT; |
| 4246 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
| 4247 | TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; |
| 4248 | if (unsigned_enum) |
| 4249 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; |
| 4250 | TYPE_NFIELDS (type) = nsyms; |
| 4251 | TYPE_FIELDS (type) = (struct field *) |
| 4252 | TYPE_ALLOC (type, sizeof (struct field) * nsyms); |
| 4253 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms); |
| 4254 | |
| 4255 | /* Find the symbols for the values and put them into the type. |
| 4256 | The symbols can be found in the symlist that we put them on |
| 4257 | to cause them to be defined. osyms contains the old value |
| 4258 | of that symlist; everything up to there was defined by us. */ |
| 4259 | /* Note that we preserve the order of the enum constants, so |
| 4260 | that in something like "enum {FOO, LAST_THING=FOO}" we print |
| 4261 | FOO, not LAST_THING. */ |
| 4262 | |
| 4263 | for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next) |
| 4264 | { |
| 4265 | int last = syms == osyms ? o_nsyms : 0; |
| 4266 | int j = syms->nsyms; |
| 4267 | for (; --j >= last; --n) |
| 4268 | { |
| 4269 | struct symbol *xsym = syms->symbol[j]; |
| 4270 | SYMBOL_TYPE (xsym) = type; |
| 4271 | TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); |
| 4272 | TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); |
| 4273 | TYPE_FIELD_BITSIZE (type, n) = 0; |
| 4274 | } |
| 4275 | if (syms == osyms) |
| 4276 | break; |
| 4277 | } |
| 4278 | |
| 4279 | return type; |
| 4280 | } |
| 4281 | |
| 4282 | /* Sun's ACC uses a somewhat saner method for specifying the builtin |
| 4283 | typedefs in every file (for int, long, etc): |
| 4284 | |
| 4285 | type = b <signed> <width>; <offset>; <nbits> |
| 4286 | signed = u or s. Possible c in addition to u or s (for char?). |
| 4287 | offset = offset from high order bit to start bit of type. |
| 4288 | width is # bytes in object of this type, nbits is # bits in type. |
| 4289 | |
| 4290 | The width/offset stuff appears to be for small objects stored in |
| 4291 | larger ones (e.g. `shorts' in `int' registers). We ignore it for now, |
| 4292 | FIXME. */ |
| 4293 | |
| 4294 | static struct type * |
| 4295 | read_sun_builtin_type (pp, typenums, objfile) |
| 4296 | char **pp; |
| 4297 | int typenums[2]; |
| 4298 | struct objfile *objfile; |
| 4299 | { |
| 4300 | int type_bits; |
| 4301 | int nbits; |
| 4302 | int signed_type; |
| 4303 | |
| 4304 | switch (**pp) |
| 4305 | { |
| 4306 | case 's': |
| 4307 | signed_type = 1; |
| 4308 | break; |
| 4309 | case 'u': |
| 4310 | signed_type = 0; |
| 4311 | break; |
| 4312 | default: |
| 4313 | return error_type (pp, objfile); |
| 4314 | } |
| 4315 | (*pp)++; |
| 4316 | |
| 4317 | /* For some odd reason, all forms of char put a c here. This is strange |
| 4318 | because no other type has this honor. We can safely ignore this because |
| 4319 | we actually determine 'char'acterness by the number of bits specified in |
| 4320 | the descriptor. */ |
| 4321 | |
| 4322 | if (**pp == 'c') |
| 4323 | (*pp)++; |
| 4324 | |
| 4325 | /* The first number appears to be the number of bytes occupied |
| 4326 | by this type, except that unsigned short is 4 instead of 2. |
| 4327 | Since this information is redundant with the third number, |
| 4328 | we will ignore it. */ |
| 4329 | read_huge_number (pp, ';', &nbits); |
| 4330 | if (nbits != 0) |
| 4331 | return error_type (pp, objfile); |
| 4332 | |
| 4333 | /* The second number is always 0, so ignore it too. */ |
| 4334 | read_huge_number (pp, ';', &nbits); |
| 4335 | if (nbits != 0) |
| 4336 | return error_type (pp, objfile); |
| 4337 | |
| 4338 | /* The third number is the number of bits for this type. */ |
| 4339 | type_bits = read_huge_number (pp, 0, &nbits); |
| 4340 | if (nbits != 0) |
| 4341 | return error_type (pp, objfile); |
| 4342 | /* The type *should* end with a semicolon. If it are embedded |
| 4343 | in a larger type the semicolon may be the only way to know where |
| 4344 | the type ends. If this type is at the end of the stabstring we |
| 4345 | can deal with the omitted semicolon (but we don't have to like |
| 4346 | it). Don't bother to complain(), Sun's compiler omits the semicolon |
| 4347 | for "void". */ |
| 4348 | if (**pp == ';') |
| 4349 | ++(*pp); |
| 4350 | |
| 4351 | if (type_bits == 0) |
| 4352 | return init_type (TYPE_CODE_VOID, 1, |
| 4353 | signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL, |
| 4354 | objfile); |
| 4355 | else |
| 4356 | return init_type (TYPE_CODE_INT, |
| 4357 | type_bits / TARGET_CHAR_BIT, |
| 4358 | signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL, |
| 4359 | objfile); |
| 4360 | } |
| 4361 | |
| 4362 | static struct type * |
| 4363 | read_sun_floating_type (pp, typenums, objfile) |
| 4364 | char **pp; |
| 4365 | int typenums[2]; |
| 4366 | struct objfile *objfile; |
| 4367 | { |
| 4368 | int nbits; |
| 4369 | int details; |
| 4370 | int nbytes; |
| 4371 | |
| 4372 | /* The first number has more details about the type, for example |
| 4373 | FN_COMPLEX. */ |
| 4374 | details = read_huge_number (pp, ';', &nbits); |
| 4375 | if (nbits != 0) |
| 4376 | return error_type (pp, objfile); |
| 4377 | |
| 4378 | /* The second number is the number of bytes occupied by this type */ |
| 4379 | nbytes = read_huge_number (pp, ';', &nbits); |
| 4380 | if (nbits != 0) |
| 4381 | return error_type (pp, objfile); |
| 4382 | |
| 4383 | if (details == NF_COMPLEX || details == NF_COMPLEX16 |
| 4384 | || details == NF_COMPLEX32) |
| 4385 | /* This is a type we can't handle, but we do know the size. |
| 4386 | We also will be able to give it a name. */ |
| 4387 | return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile); |
| 4388 | |
| 4389 | return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile); |
| 4390 | } |
| 4391 | |
| 4392 | /* Read a number from the string pointed to by *PP. |
| 4393 | The value of *PP is advanced over the number. |
| 4394 | If END is nonzero, the character that ends the |
| 4395 | number must match END, or an error happens; |
| 4396 | and that character is skipped if it does match. |
| 4397 | If END is zero, *PP is left pointing to that character. |
| 4398 | |
| 4399 | If the number fits in a long, set *BITS to 0 and return the value. |
| 4400 | If not, set *BITS to be the number of bits in the number and return 0. |
| 4401 | |
| 4402 | If encounter garbage, set *BITS to -1 and return 0. */ |
| 4403 | |
| 4404 | static long |
| 4405 | read_huge_number (pp, end, bits) |
| 4406 | char **pp; |
| 4407 | int end; |
| 4408 | int *bits; |
| 4409 | { |
| 4410 | char *p = *pp; |
| 4411 | int sign = 1; |
| 4412 | long n = 0; |
| 4413 | int radix = 10; |
| 4414 | char overflow = 0; |
| 4415 | int nbits = 0; |
| 4416 | int c; |
| 4417 | long upper_limit; |
| 4418 | |
| 4419 | if (*p == '-') |
| 4420 | { |
| 4421 | sign = -1; |
| 4422 | p++; |
| 4423 | } |
| 4424 | |
| 4425 | /* Leading zero means octal. GCC uses this to output values larger |
| 4426 | than an int (because that would be hard in decimal). */ |
| 4427 | if (*p == '0') |
| 4428 | { |
| 4429 | radix = 8; |
| 4430 | p++; |
| 4431 | } |
| 4432 | |
| 4433 | if (os9k_stabs) |
| 4434 | upper_limit = ULONG_MAX / radix; |
| 4435 | else |
| 4436 | upper_limit = LONG_MAX / radix; |
| 4437 | |
| 4438 | while ((c = *p++) >= '0' && c < ('0' + radix)) |
| 4439 | { |
| 4440 | if (n <= upper_limit) |
| 4441 | { |
| 4442 | n *= radix; |
| 4443 | n += c - '0'; /* FIXME this overflows anyway */ |
| 4444 | } |
| 4445 | else |
| 4446 | overflow = 1; |
| 4447 | |
| 4448 | /* This depends on large values being output in octal, which is |
| 4449 | what GCC does. */ |
| 4450 | if (radix == 8) |
| 4451 | { |
| 4452 | if (nbits == 0) |
| 4453 | { |
| 4454 | if (c == '0') |
| 4455 | /* Ignore leading zeroes. */ |
| 4456 | ; |
| 4457 | else if (c == '1') |
| 4458 | nbits = 1; |
| 4459 | else if (c == '2' || c == '3') |
| 4460 | nbits = 2; |
| 4461 | else |
| 4462 | nbits = 3; |
| 4463 | } |
| 4464 | else |
| 4465 | nbits += 3; |
| 4466 | } |
| 4467 | } |
| 4468 | if (end) |
| 4469 | { |
| 4470 | if (c && c != end) |
| 4471 | { |
| 4472 | if (bits != NULL) |
| 4473 | *bits = -1; |
| 4474 | return 0; |
| 4475 | } |
| 4476 | } |
| 4477 | else |
| 4478 | --p; |
| 4479 | |
| 4480 | *pp = p; |
| 4481 | if (overflow) |
| 4482 | { |
| 4483 | if (nbits == 0) |
| 4484 | { |
| 4485 | /* Large decimal constants are an error (because it is hard to |
| 4486 | count how many bits are in them). */ |
| 4487 | if (bits != NULL) |
| 4488 | *bits = -1; |
| 4489 | return 0; |
| 4490 | } |
| 4491 | |
| 4492 | /* -0x7f is the same as 0x80. So deal with it by adding one to |
| 4493 | the number of bits. */ |
| 4494 | if (sign == -1) |
| 4495 | ++nbits; |
| 4496 | if (bits) |
| 4497 | *bits = nbits; |
| 4498 | } |
| 4499 | else |
| 4500 | { |
| 4501 | if (bits) |
| 4502 | *bits = 0; |
| 4503 | return n * sign; |
| 4504 | } |
| 4505 | /* It's *BITS which has the interesting information. */ |
| 4506 | return 0; |
| 4507 | } |
| 4508 | |
| 4509 | static struct type * |
| 4510 | read_range_type (pp, typenums, objfile) |
| 4511 | char **pp; |
| 4512 | int typenums[2]; |
| 4513 | struct objfile *objfile; |
| 4514 | { |
| 4515 | char *orig_pp = *pp; |
| 4516 | int rangenums[2]; |
| 4517 | long n2, n3; |
| 4518 | int n2bits, n3bits; |
| 4519 | int self_subrange; |
| 4520 | struct type *result_type; |
| 4521 | struct type *index_type = NULL; |
| 4522 | |
| 4523 | /* First comes a type we are a subrange of. |
| 4524 | In C it is usually 0, 1 or the type being defined. */ |
| 4525 | if (read_type_number (pp, rangenums) != 0) |
| 4526 | return error_type (pp, objfile); |
| 4527 | self_subrange = (rangenums[0] == typenums[0] && |
| 4528 | rangenums[1] == typenums[1]); |
| 4529 | |
| 4530 | if (**pp == '=') |
| 4531 | { |
| 4532 | *pp = orig_pp; |
| 4533 | index_type = read_type (pp, objfile); |
| 4534 | } |
| 4535 | |
| 4536 | /* A semicolon should now follow; skip it. */ |
| 4537 | if (**pp == ';') |
| 4538 | (*pp)++; |
| 4539 | |
| 4540 | /* The remaining two operands are usually lower and upper bounds |
| 4541 | of the range. But in some special cases they mean something else. */ |
| 4542 | n2 = read_huge_number (pp, ';', &n2bits); |
| 4543 | n3 = read_huge_number (pp, ';', &n3bits); |
| 4544 | |
| 4545 | if (n2bits == -1 || n3bits == -1) |
| 4546 | return error_type (pp, objfile); |
| 4547 | |
| 4548 | if (index_type) |
| 4549 | goto handle_true_range; |
| 4550 | |
| 4551 | /* If limits are huge, must be large integral type. */ |
| 4552 | if (n2bits != 0 || n3bits != 0) |
| 4553 | { |
| 4554 | char got_signed = 0; |
| 4555 | char got_unsigned = 0; |
| 4556 | /* Number of bits in the type. */ |
| 4557 | int nbits = 0; |
| 4558 | |
| 4559 | /* Range from 0 to <large number> is an unsigned large integral type. */ |
| 4560 | if ((n2bits == 0 && n2 == 0) && n3bits != 0) |
| 4561 | { |
| 4562 | got_unsigned = 1; |
| 4563 | nbits = n3bits; |
| 4564 | } |
| 4565 | /* Range from <large number> to <large number>-1 is a large signed |
| 4566 | integral type. Take care of the case where <large number> doesn't |
| 4567 | fit in a long but <large number>-1 does. */ |
| 4568 | else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) |
| 4569 | || (n2bits != 0 && n3bits == 0 |
| 4570 | && (n2bits == sizeof (long) * HOST_CHAR_BIT) |
| 4571 | && n3 == LONG_MAX)) |
| 4572 | { |
| 4573 | got_signed = 1; |
| 4574 | nbits = n2bits; |
| 4575 | } |
| 4576 | |
| 4577 | if (got_signed || got_unsigned) |
| 4578 | { |
| 4579 | return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT, |
| 4580 | got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL, |
| 4581 | objfile); |
| 4582 | } |
| 4583 | else |
| 4584 | return error_type (pp, objfile); |
| 4585 | } |
| 4586 | |
| 4587 | /* A type defined as a subrange of itself, with bounds both 0, is void. */ |
| 4588 | if (self_subrange && n2 == 0 && n3 == 0) |
| 4589 | return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
| 4590 | |
| 4591 | /* If n3 is zero and n2 is positive, we want a floating type, |
| 4592 | and n2 is the width in bytes. |
| 4593 | |
| 4594 | Fortran programs appear to use this for complex types also, |
| 4595 | and they give no way to distinguish between double and single-complex! |
| 4596 | |
| 4597 | GDB does not have complex types. |
| 4598 | |
| 4599 | Just return the complex as a float of that size. It won't work right |
| 4600 | for the complex values, but at least it makes the file loadable. */ |
| 4601 | |
| 4602 | if (n3 == 0 && n2 > 0) |
| 4603 | { |
| 4604 | return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile); |
| 4605 | } |
| 4606 | |
| 4607 | /* If the upper bound is -1, it must really be an unsigned int. */ |
| 4608 | |
| 4609 | else if (n2 == 0 && n3 == -1) |
| 4610 | { |
| 4611 | /* It is unsigned int or unsigned long. */ |
| 4612 | /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5 |
| 4613 | compatibility hack. */ |
| 4614 | return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 4615 | TYPE_FLAG_UNSIGNED, NULL, objfile); |
| 4616 | } |
| 4617 | |
| 4618 | /* Special case: char is defined (Who knows why) as a subrange of |
| 4619 | itself with range 0-127. */ |
| 4620 | else if (self_subrange && n2 == 0 && n3 == 127) |
| 4621 | return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); |
| 4622 | |
| 4623 | else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill |
| 4624 | && !self_subrange) |
| 4625 | goto handle_true_range; |
| 4626 | |
| 4627 | /* We used to do this only for subrange of self or subrange of int. */ |
| 4628 | else if (n2 == 0) |
| 4629 | { |
| 4630 | if (n3 < 0) |
| 4631 | /* n3 actually gives the size. */ |
| 4632 | return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED, |
| 4633 | NULL, objfile); |
| 4634 | if (n3 == 0xff) |
| 4635 | return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile); |
| 4636 | if (n3 == 0xffff) |
| 4637 | return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile); |
| 4638 | |
| 4639 | /* -1 is used for the upper bound of (4 byte) "unsigned int" and |
| 4640 | "unsigned long", and we already checked for that, |
| 4641 | so don't need to test for it here. */ |
| 4642 | } |
| 4643 | /* I think this is for Convex "long long". Since I don't know whether |
| 4644 | Convex sets self_subrange, I also accept that particular size regardless |
| 4645 | of self_subrange. */ |
| 4646 | else if (n3 == 0 && n2 < 0 |
| 4647 | && (self_subrange |
| 4648 | || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT)) |
| 4649 | return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile); |
| 4650 | else if (n2 == -n3 -1) |
| 4651 | { |
| 4652 | if (n3 == 0x7f) |
| 4653 | return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); |
| 4654 | if (n3 == 0x7fff) |
| 4655 | return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile); |
| 4656 | if (n3 == 0x7fffffff) |
| 4657 | return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile); |
| 4658 | } |
| 4659 | |
| 4660 | /* We have a real range type on our hands. Allocate space and |
| 4661 | return a real pointer. */ |
| 4662 | handle_true_range: |
| 4663 | |
| 4664 | if (self_subrange) |
| 4665 | index_type = builtin_type_int; |
| 4666 | else |
| 4667 | index_type = *dbx_lookup_type (rangenums); |
| 4668 | if (index_type == NULL) |
| 4669 | { |
| 4670 | /* Does this actually ever happen? Is that why we are worrying |
| 4671 | about dealing with it rather than just calling error_type? */ |
| 4672 | |
| 4673 | static struct type *range_type_index; |
| 4674 | |
| 4675 | complain (&range_type_base_complaint, rangenums[1]); |
| 4676 | if (range_type_index == NULL) |
| 4677 | range_type_index = |
| 4678 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 4679 | 0, "range type index type", NULL); |
| 4680 | index_type = range_type_index; |
| 4681 | } |
| 4682 | |
| 4683 | result_type = create_range_type ((struct type *) NULL, index_type, n2, n3); |
| 4684 | return (result_type); |
| 4685 | } |
| 4686 | |
| 4687 | /* Read in an argument list. This is a list of types, separated by commas |
| 4688 | and terminated with END. Return the list of types read in, or (struct type |
| 4689 | **)-1 if there is an error. */ |
| 4690 | |
| 4691 | static struct type ** |
| 4692 | read_args (pp, end, objfile) |
| 4693 | char **pp; |
| 4694 | int end; |
| 4695 | struct objfile *objfile; |
| 4696 | { |
| 4697 | /* FIXME! Remove this arbitrary limit! */ |
| 4698 | struct type *types[1024], **rval; /* allow for fns of 1023 parameters */ |
| 4699 | int n = 0; |
| 4700 | |
| 4701 | while (**pp != end) |
| 4702 | { |
| 4703 | if (**pp != ',') |
| 4704 | /* Invalid argument list: no ','. */ |
| 4705 | return (struct type **)-1; |
| 4706 | (*pp)++; |
| 4707 | STABS_CONTINUE (pp, objfile); |
| 4708 | types[n++] = read_type (pp, objfile); |
| 4709 | } |
| 4710 | (*pp)++; /* get past `end' (the ':' character) */ |
| 4711 | |
| 4712 | if (n == 1) |
| 4713 | { |
| 4714 | rval = (struct type **) xmalloc (2 * sizeof (struct type *)); |
| 4715 | } |
| 4716 | else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID) |
| 4717 | { |
| 4718 | rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *)); |
| 4719 | memset (rval + n, 0, sizeof (struct type *)); |
| 4720 | } |
| 4721 | else |
| 4722 | { |
| 4723 | rval = (struct type **) xmalloc (n * sizeof (struct type *)); |
| 4724 | } |
| 4725 | memcpy (rval, types, n * sizeof (struct type *)); |
| 4726 | return rval; |
| 4727 | } |
| 4728 | \f |
| 4729 | /* Common block handling. */ |
| 4730 | |
| 4731 | /* List of symbols declared since the last BCOMM. This list is a tail |
| 4732 | of local_symbols. When ECOMM is seen, the symbols on the list |
| 4733 | are noted so their proper addresses can be filled in later, |
| 4734 | using the common block base address gotten from the assembler |
| 4735 | stabs. */ |
| 4736 | |
| 4737 | static struct pending *common_block; |
| 4738 | static int common_block_i; |
| 4739 | |
| 4740 | /* Name of the current common block. We get it from the BCOMM instead of the |
| 4741 | ECOMM to match IBM documentation (even though IBM puts the name both places |
| 4742 | like everyone else). */ |
| 4743 | static char *common_block_name; |
| 4744 | |
| 4745 | /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed |
| 4746 | to remain after this function returns. */ |
| 4747 | |
| 4748 | void |
| 4749 | common_block_start (name, objfile) |
| 4750 | char *name; |
| 4751 | struct objfile *objfile; |
| 4752 | { |
| 4753 | if (common_block_name != NULL) |
| 4754 | { |
| 4755 | static struct complaint msg = { |
| 4756 | "Invalid symbol data: common block within common block", |
| 4757 | 0, 0}; |
| 4758 | complain (&msg); |
| 4759 | } |
| 4760 | common_block = local_symbols; |
| 4761 | common_block_i = local_symbols ? local_symbols->nsyms : 0; |
| 4762 | common_block_name = obsavestring (name, strlen (name), |
| 4763 | &objfile -> symbol_obstack); |
| 4764 | } |
| 4765 | |
| 4766 | /* Process a N_ECOMM symbol. */ |
| 4767 | |
| 4768 | void |
| 4769 | common_block_end (objfile) |
| 4770 | struct objfile *objfile; |
| 4771 | { |
| 4772 | /* Symbols declared since the BCOMM are to have the common block |
| 4773 | start address added in when we know it. common_block and |
| 4774 | common_block_i point to the first symbol after the BCOMM in |
| 4775 | the local_symbols list; copy the list and hang it off the |
| 4776 | symbol for the common block name for later fixup. */ |
| 4777 | int i; |
| 4778 | struct symbol *sym; |
| 4779 | struct pending *new = 0; |
| 4780 | struct pending *next; |
| 4781 | int j; |
| 4782 | |
| 4783 | if (common_block_name == NULL) |
| 4784 | { |
| 4785 | static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0}; |
| 4786 | complain (&msg); |
| 4787 | return; |
| 4788 | } |
| 4789 | |
| 4790 | sym = (struct symbol *) |
| 4791 | obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); |
| 4792 | memset (sym, 0, sizeof (struct symbol)); |
| 4793 | /* Note: common_block_name already saved on symbol_obstack */ |
| 4794 | SYMBOL_NAME (sym) = common_block_name; |
| 4795 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 4796 | |
| 4797 | /* Now we copy all the symbols which have been defined since the BCOMM. */ |
| 4798 | |
| 4799 | /* Copy all the struct pendings before common_block. */ |
| 4800 | for (next = local_symbols; |
| 4801 | next != NULL && next != common_block; |
| 4802 | next = next->next) |
| 4803 | { |
| 4804 | for (j = 0; j < next->nsyms; j++) |
| 4805 | add_symbol_to_list (next->symbol[j], &new); |
| 4806 | } |
| 4807 | |
| 4808 | /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is |
| 4809 | NULL, it means copy all the local symbols (which we already did |
| 4810 | above). */ |
| 4811 | |
| 4812 | if (common_block != NULL) |
| 4813 | for (j = common_block_i; j < common_block->nsyms; j++) |
| 4814 | add_symbol_to_list (common_block->symbol[j], &new); |
| 4815 | |
| 4816 | SYMBOL_TYPE (sym) = (struct type *) new; |
| 4817 | |
| 4818 | /* Should we be putting local_symbols back to what it was? |
| 4819 | Does it matter? */ |
| 4820 | |
| 4821 | i = hashname (SYMBOL_NAME (sym)); |
| 4822 | SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; |
| 4823 | global_sym_chain[i] = sym; |
| 4824 | common_block_name = NULL; |
| 4825 | } |
| 4826 | |
| 4827 | /* Add a common block's start address to the offset of each symbol |
| 4828 | declared to be in it (by being between a BCOMM/ECOMM pair that uses |
| 4829 | the common block name). */ |
| 4830 | |
| 4831 | static void |
| 4832 | fix_common_block (sym, valu) |
| 4833 | struct symbol *sym; |
| 4834 | int valu; |
| 4835 | { |
| 4836 | struct pending *next = (struct pending *) SYMBOL_TYPE (sym); |
| 4837 | for ( ; next; next = next->next) |
| 4838 | { |
| 4839 | register int j; |
| 4840 | for (j = next->nsyms - 1; j >= 0; j--) |
| 4841 | SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | |
| 4846 | \f |
| 4847 | /* What about types defined as forward references inside of a small lexical |
| 4848 | scope? */ |
| 4849 | /* Add a type to the list of undefined types to be checked through |
| 4850 | once this file has been read in. */ |
| 4851 | |
| 4852 | void |
| 4853 | add_undefined_type (type) |
| 4854 | struct type *type; |
| 4855 | { |
| 4856 | if (undef_types_length == undef_types_allocated) |
| 4857 | { |
| 4858 | undef_types_allocated *= 2; |
| 4859 | undef_types = (struct type **) |
| 4860 | xrealloc ((char *) undef_types, |
| 4861 | undef_types_allocated * sizeof (struct type *)); |
| 4862 | } |
| 4863 | undef_types[undef_types_length++] = type; |
| 4864 | } |
| 4865 | |
| 4866 | /* Go through each undefined type, see if it's still undefined, and fix it |
| 4867 | up if possible. We have two kinds of undefined types: |
| 4868 | |
| 4869 | TYPE_CODE_ARRAY: Array whose target type wasn't defined yet. |
| 4870 | Fix: update array length using the element bounds |
| 4871 | and the target type's length. |
| 4872 | TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not |
| 4873 | yet defined at the time a pointer to it was made. |
| 4874 | Fix: Do a full lookup on the struct/union tag. */ |
| 4875 | void |
| 4876 | cleanup_undefined_types () |
| 4877 | { |
| 4878 | struct type **type; |
| 4879 | |
| 4880 | for (type = undef_types; type < undef_types + undef_types_length; type++) |
| 4881 | { |
| 4882 | switch (TYPE_CODE (*type)) |
| 4883 | { |
| 4884 | |
| 4885 | case TYPE_CODE_STRUCT: |
| 4886 | case TYPE_CODE_UNION: |
| 4887 | case TYPE_CODE_ENUM: |
| 4888 | { |
| 4889 | /* Check if it has been defined since. Need to do this here |
| 4890 | as well as in check_typedef to deal with the (legitimate in |
| 4891 | C though not C++) case of several types with the same name |
| 4892 | in different source files. */ |
| 4893 | if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB) |
| 4894 | { |
| 4895 | struct pending *ppt; |
| 4896 | int i; |
| 4897 | /* Name of the type, without "struct" or "union" */ |
| 4898 | char *typename = TYPE_TAG_NAME (*type); |
| 4899 | |
| 4900 | if (typename == NULL) |
| 4901 | { |
| 4902 | static struct complaint msg = {"need a type name", 0, 0}; |
| 4903 | complain (&msg); |
| 4904 | break; |
| 4905 | } |
| 4906 | for (ppt = file_symbols; ppt; ppt = ppt->next) |
| 4907 | { |
| 4908 | for (i = 0; i < ppt->nsyms; i++) |
| 4909 | { |
| 4910 | struct symbol *sym = ppt->symbol[i]; |
| 4911 | |
| 4912 | if (SYMBOL_CLASS (sym) == LOC_TYPEDEF |
| 4913 | && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE |
| 4914 | && (TYPE_CODE (SYMBOL_TYPE (sym)) == |
| 4915 | TYPE_CODE (*type)) |
| 4916 | && STREQ (SYMBOL_NAME (sym), typename)) |
| 4917 | { |
| 4918 | memcpy (*type, SYMBOL_TYPE (sym), |
| 4919 | sizeof (struct type)); |
| 4920 | } |
| 4921 | } |
| 4922 | } |
| 4923 | } |
| 4924 | } |
| 4925 | break; |
| 4926 | |
| 4927 | default: |
| 4928 | { |
| 4929 | static struct complaint msg = {"\ |
| 4930 | GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0}; |
| 4931 | complain (&msg, TYPE_CODE (*type)); |
| 4932 | } |
| 4933 | break; |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | undef_types_length = 0; |
| 4938 | } |
| 4939 | |
| 4940 | /* Scan through all of the global symbols defined in the object file, |
| 4941 | assigning values to the debugging symbols that need to be assigned |
| 4942 | to. Get these symbols from the minimal symbol table. */ |
| 4943 | |
| 4944 | void |
| 4945 | scan_file_globals (objfile) |
| 4946 | struct objfile *objfile; |
| 4947 | { |
| 4948 | int hash; |
| 4949 | struct minimal_symbol *msymbol; |
| 4950 | struct symbol *sym, *prev, *rsym; |
| 4951 | struct objfile *resolve_objfile; |
| 4952 | |
| 4953 | /* SVR4 based linkers copy referenced global symbols from shared |
| 4954 | libraries to the main executable. |
| 4955 | If we are scanning the symbols for a shared library, try to resolve |
| 4956 | them from the minimal symbols of the main executable first. */ |
| 4957 | |
| 4958 | if (symfile_objfile && objfile != symfile_objfile) |
| 4959 | resolve_objfile = symfile_objfile; |
| 4960 | else |
| 4961 | resolve_objfile = objfile; |
| 4962 | |
| 4963 | while (1) |
| 4964 | { |
| 4965 | /* Avoid expensive loop through all minimal symbols if there are |
| 4966 | no unresolved symbols. */ |
| 4967 | for (hash = 0; hash < HASHSIZE; hash++) |
| 4968 | { |
| 4969 | if (global_sym_chain[hash]) |
| 4970 | break; |
| 4971 | } |
| 4972 | if (hash >= HASHSIZE) |
| 4973 | return; |
| 4974 | |
| 4975 | for (msymbol = resolve_objfile -> msymbols; |
| 4976 | msymbol && SYMBOL_NAME (msymbol) != NULL; |
| 4977 | msymbol++) |
| 4978 | { |
| 4979 | QUIT; |
| 4980 | |
| 4981 | /* Skip static symbols. */ |
| 4982 | switch (MSYMBOL_TYPE (msymbol)) |
| 4983 | { |
| 4984 | case mst_file_text: |
| 4985 | case mst_file_data: |
| 4986 | case mst_file_bss: |
| 4987 | continue; |
| 4988 | default: |
| 4989 | break; |
| 4990 | } |
| 4991 | |
| 4992 | prev = NULL; |
| 4993 | |
| 4994 | /* Get the hash index and check all the symbols |
| 4995 | under that hash index. */ |
| 4996 | |
| 4997 | hash = hashname (SYMBOL_NAME (msymbol)); |
| 4998 | |
| 4999 | for (sym = global_sym_chain[hash]; sym;) |
| 5000 | { |
| 5001 | if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] && |
| 5002 | STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1)) |
| 5003 | { |
| 5004 | |
| 5005 | struct alias_list *aliases; |
| 5006 | |
| 5007 | /* Splice this symbol out of the hash chain and |
| 5008 | assign the value we have to it. */ |
| 5009 | if (prev) |
| 5010 | { |
| 5011 | SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); |
| 5012 | } |
| 5013 | else |
| 5014 | { |
| 5015 | global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); |
| 5016 | } |
| 5017 | |
| 5018 | /* Check to see whether we need to fix up a common block. */ |
| 5019 | /* Note: this code might be executed several times for |
| 5020 | the same symbol if there are multiple references. */ |
| 5021 | |
| 5022 | /* If symbol has aliases, do minimal symbol fixups for each. |
| 5023 | These live aliases/references weren't added to |
| 5024 | global_sym_chain hash but may also need to be fixed up. */ |
| 5025 | /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal |
| 5026 | symbols? Still, we wouldn't want to add_to_list. */ |
| 5027 | /* Now do the same for each alias of this symbol */ |
| 5028 | rsym = sym; |
| 5029 | aliases = SYMBOL_ALIASES (sym); |
| 5030 | while (rsym) |
| 5031 | { |
| 5032 | if (SYMBOL_CLASS (rsym) == LOC_BLOCK) |
| 5033 | { |
| 5034 | fix_common_block (rsym, |
| 5035 | SYMBOL_VALUE_ADDRESS (msymbol)); |
| 5036 | } |
| 5037 | else |
| 5038 | { |
| 5039 | SYMBOL_VALUE_ADDRESS (rsym) |
| 5040 | = SYMBOL_VALUE_ADDRESS (msymbol); |
| 5041 | } |
| 5042 | SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol); |
| 5043 | if (aliases) |
| 5044 | { |
| 5045 | rsym = aliases->sym; |
| 5046 | aliases = aliases->next; |
| 5047 | } |
| 5048 | else |
| 5049 | rsym = NULL; |
| 5050 | } |
| 5051 | |
| 5052 | |
| 5053 | if (prev) |
| 5054 | { |
| 5055 | sym = SYMBOL_VALUE_CHAIN (prev); |
| 5056 | } |
| 5057 | else |
| 5058 | { |
| 5059 | sym = global_sym_chain[hash]; |
| 5060 | } |
| 5061 | } |
| 5062 | else |
| 5063 | { |
| 5064 | prev = sym; |
| 5065 | sym = SYMBOL_VALUE_CHAIN (sym); |
| 5066 | } |
| 5067 | } |
| 5068 | } |
| 5069 | if (resolve_objfile == objfile) |
| 5070 | break; |
| 5071 | resolve_objfile = objfile; |
| 5072 | } |
| 5073 | |
| 5074 | /* Change the storage class of any remaining unresolved globals to |
| 5075 | LOC_UNRESOLVED and remove them from the chain. */ |
| 5076 | for (hash = 0; hash < HASHSIZE; hash++) |
| 5077 | { |
| 5078 | sym = global_sym_chain[hash]; |
| 5079 | while (sym) |
| 5080 | { |
| 5081 | prev = sym; |
| 5082 | sym = SYMBOL_VALUE_CHAIN (sym); |
| 5083 | |
| 5084 | /* Change the symbol address from the misleading chain value |
| 5085 | to address zero. */ |
| 5086 | SYMBOL_VALUE_ADDRESS (prev) = 0; |
| 5087 | |
| 5088 | /* Complain about unresolved common block symbols. */ |
| 5089 | if (SYMBOL_CLASS (prev) == LOC_STATIC) |
| 5090 | SYMBOL_CLASS (prev) = LOC_UNRESOLVED; |
| 5091 | else |
| 5092 | complain (&unresolved_sym_chain_complaint, |
| 5093 | objfile -> name, SYMBOL_NAME (prev)); |
| 5094 | } |
| 5095 | } |
| 5096 | memset (global_sym_chain, 0, sizeof (global_sym_chain)); |
| 5097 | } |
| 5098 | |
| 5099 | /* Initialize anything that needs initializing when starting to read |
| 5100 | a fresh piece of a symbol file, e.g. reading in the stuff corresponding |
| 5101 | to a psymtab. */ |
| 5102 | |
| 5103 | void |
| 5104 | stabsread_init () |
| 5105 | { |
| 5106 | } |
| 5107 | |
| 5108 | /* Initialize anything that needs initializing when a completely new |
| 5109 | symbol file is specified (not just adding some symbols from another |
| 5110 | file, e.g. a shared library). */ |
| 5111 | |
| 5112 | void |
| 5113 | stabsread_new_init () |
| 5114 | { |
| 5115 | /* Empty the hash table of global syms looking for values. */ |
| 5116 | memset (global_sym_chain, 0, sizeof (global_sym_chain)); |
| 5117 | } |
| 5118 | |
| 5119 | /* Initialize anything that needs initializing at the same time as |
| 5120 | start_symtab() is called. */ |
| 5121 | |
| 5122 | void start_stabs () |
| 5123 | { |
| 5124 | global_stabs = NULL; /* AIX COFF */ |
| 5125 | /* Leave FILENUM of 0 free for builtin types and this file's types. */ |
| 5126 | n_this_object_header_files = 1; |
| 5127 | type_vector_length = 0; |
| 5128 | type_vector = (struct type **) 0; |
| 5129 | |
| 5130 | /* FIXME: If common_block_name is not already NULL, we should complain(). */ |
| 5131 | common_block_name = NULL; |
| 5132 | |
| 5133 | os9k_stabs = 0; |
| 5134 | } |
| 5135 | |
| 5136 | /* Call after end_symtab() */ |
| 5137 | |
| 5138 | void end_stabs () |
| 5139 | { |
| 5140 | if (type_vector) |
| 5141 | { |
| 5142 | free ((char *) type_vector); |
| 5143 | } |
| 5144 | type_vector = 0; |
| 5145 | type_vector_length = 0; |
| 5146 | previous_stab_code = 0; |
| 5147 | } |
| 5148 | |
| 5149 | void |
| 5150 | finish_global_stabs (objfile) |
| 5151 | struct objfile *objfile; |
| 5152 | { |
| 5153 | if (global_stabs) |
| 5154 | { |
| 5155 | patch_block_stabs (global_symbols, global_stabs, objfile); |
| 5156 | free ((PTR) global_stabs); |
| 5157 | global_stabs = NULL; |
| 5158 | } |
| 5159 | } |
| 5160 | |
| 5161 | /* Initializer for this module */ |
| 5162 | |
| 5163 | void |
| 5164 | _initialize_stabsread () |
| 5165 | { |
| 5166 | undef_types_allocated = 20; |
| 5167 | undef_types_length = 0; |
| 5168 | undef_types = (struct type **) |
| 5169 | xmalloc (undef_types_allocated * sizeof (struct type *)); |
| 5170 | } |