| 1 | /* Support routines for manipulating internal types for GDB. |
| 2 | Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, |
| 3 | 2004 Free Software Foundation, Inc. |
| 4 | Contributed by Cygnus Support, using pieces from other GDB modules. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 21 | Boston, MA 02111-1307, USA. */ |
| 22 | |
| 23 | #include "defs.h" |
| 24 | #include "gdb_string.h" |
| 25 | #include "bfd.h" |
| 26 | #include "symtab.h" |
| 27 | #include "symfile.h" |
| 28 | #include "objfiles.h" |
| 29 | #include "gdbtypes.h" |
| 30 | #include "expression.h" |
| 31 | #include "language.h" |
| 32 | #include "target.h" |
| 33 | #include "value.h" |
| 34 | #include "demangle.h" |
| 35 | #include "complaints.h" |
| 36 | #include "gdbcmd.h" |
| 37 | #include "wrapper.h" |
| 38 | #include "cp-abi.h" |
| 39 | #include "gdb_assert.h" |
| 40 | |
| 41 | /* These variables point to the objects |
| 42 | representing the predefined C data types. */ |
| 43 | |
| 44 | struct type *builtin_type_void; |
| 45 | struct type *builtin_type_char; |
| 46 | struct type *builtin_type_true_char; |
| 47 | struct type *builtin_type_short; |
| 48 | struct type *builtin_type_int; |
| 49 | struct type *builtin_type_long; |
| 50 | struct type *builtin_type_long_long; |
| 51 | struct type *builtin_type_signed_char; |
| 52 | struct type *builtin_type_unsigned_char; |
| 53 | struct type *builtin_type_unsigned_short; |
| 54 | struct type *builtin_type_unsigned_int; |
| 55 | struct type *builtin_type_unsigned_long; |
| 56 | struct type *builtin_type_unsigned_long_long; |
| 57 | struct type *builtin_type_float; |
| 58 | struct type *builtin_type_double; |
| 59 | struct type *builtin_type_long_double; |
| 60 | struct type *builtin_type_complex; |
| 61 | struct type *builtin_type_double_complex; |
| 62 | struct type *builtin_type_string; |
| 63 | struct type *builtin_type_int0; |
| 64 | struct type *builtin_type_int8; |
| 65 | struct type *builtin_type_uint8; |
| 66 | struct type *builtin_type_int16; |
| 67 | struct type *builtin_type_uint16; |
| 68 | struct type *builtin_type_int32; |
| 69 | struct type *builtin_type_uint32; |
| 70 | struct type *builtin_type_int64; |
| 71 | struct type *builtin_type_uint64; |
| 72 | struct type *builtin_type_int128; |
| 73 | struct type *builtin_type_uint128; |
| 74 | struct type *builtin_type_bool; |
| 75 | |
| 76 | /* 128 bit long vector types */ |
| 77 | struct type *builtin_type_v2_double; |
| 78 | struct type *builtin_type_v4_float; |
| 79 | struct type *builtin_type_v2_int64; |
| 80 | struct type *builtin_type_v4_int32; |
| 81 | struct type *builtin_type_v8_int16; |
| 82 | struct type *builtin_type_v16_int8; |
| 83 | /* 64 bit long vector types */ |
| 84 | struct type *builtin_type_v2_float; |
| 85 | struct type *builtin_type_v2_int32; |
| 86 | struct type *builtin_type_v4_int16; |
| 87 | struct type *builtin_type_v8_int8; |
| 88 | |
| 89 | struct type *builtin_type_v4sf; |
| 90 | struct type *builtin_type_v4si; |
| 91 | struct type *builtin_type_v16qi; |
| 92 | struct type *builtin_type_v8qi; |
| 93 | struct type *builtin_type_v8hi; |
| 94 | struct type *builtin_type_v4hi; |
| 95 | struct type *builtin_type_v2si; |
| 96 | struct type *builtin_type_vec64; |
| 97 | struct type *builtin_type_vec64i; |
| 98 | struct type *builtin_type_vec128; |
| 99 | struct type *builtin_type_vec128i; |
| 100 | struct type *builtin_type_ieee_single_big; |
| 101 | struct type *builtin_type_ieee_single_little; |
| 102 | struct type *builtin_type_ieee_double_big; |
| 103 | struct type *builtin_type_ieee_double_little; |
| 104 | struct type *builtin_type_ieee_double_littlebyte_bigword; |
| 105 | struct type *builtin_type_i387_ext; |
| 106 | struct type *builtin_type_m68881_ext; |
| 107 | struct type *builtin_type_i960_ext; |
| 108 | struct type *builtin_type_m88110_ext; |
| 109 | struct type *builtin_type_m88110_harris_ext; |
| 110 | struct type *builtin_type_arm_ext_big; |
| 111 | struct type *builtin_type_arm_ext_littlebyte_bigword; |
| 112 | struct type *builtin_type_ia64_spill_big; |
| 113 | struct type *builtin_type_ia64_spill_little; |
| 114 | struct type *builtin_type_ia64_quad_big; |
| 115 | struct type *builtin_type_ia64_quad_little; |
| 116 | struct type *builtin_type_void_data_ptr; |
| 117 | struct type *builtin_type_void_func_ptr; |
| 118 | struct type *builtin_type_CORE_ADDR; |
| 119 | struct type *builtin_type_bfd_vma; |
| 120 | |
| 121 | int opaque_type_resolution = 1; |
| 122 | int overload_debug = 0; |
| 123 | |
| 124 | struct extra |
| 125 | { |
| 126 | char str[128]; |
| 127 | int len; |
| 128 | }; /* maximum extension is 128! FIXME */ |
| 129 | |
| 130 | static void print_bit_vector (B_TYPE *, int); |
| 131 | static void print_arg_types (struct field *, int, int); |
| 132 | static void dump_fn_fieldlists (struct type *, int); |
| 133 | static void print_cplus_stuff (struct type *, int); |
| 134 | static void virtual_base_list_aux (struct type *dclass); |
| 135 | |
| 136 | |
| 137 | /* Alloc a new type structure and fill it with some defaults. If |
| 138 | OBJFILE is non-NULL, then allocate the space for the type structure |
| 139 | in that objfile's objfile_obstack. Otherwise allocate the new type structure |
| 140 | by xmalloc () (for permanent types). */ |
| 141 | |
| 142 | struct type * |
| 143 | alloc_type (struct objfile *objfile) |
| 144 | { |
| 145 | struct type *type; |
| 146 | |
| 147 | /* Alloc the structure and start off with all fields zeroed. */ |
| 148 | |
| 149 | if (objfile == NULL) |
| 150 | { |
| 151 | type = xmalloc (sizeof (struct type)); |
| 152 | memset (type, 0, sizeof (struct type)); |
| 153 | TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type)); |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | type = obstack_alloc (&objfile->objfile_obstack, |
| 158 | sizeof (struct type)); |
| 159 | memset (type, 0, sizeof (struct type)); |
| 160 | TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack, |
| 161 | sizeof (struct main_type)); |
| 162 | OBJSTAT (objfile, n_types++); |
| 163 | } |
| 164 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); |
| 165 | |
| 166 | /* Initialize the fields that might not be zero. */ |
| 167 | |
| 168 | TYPE_CODE (type) = TYPE_CODE_UNDEF; |
| 169 | TYPE_OBJFILE (type) = objfile; |
| 170 | TYPE_VPTR_FIELDNO (type) = -1; |
| 171 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ |
| 172 | |
| 173 | return (type); |
| 174 | } |
| 175 | |
| 176 | /* Alloc a new type instance structure, fill it with some defaults, |
| 177 | and point it at OLDTYPE. Allocate the new type instance from the |
| 178 | same place as OLDTYPE. */ |
| 179 | |
| 180 | static struct type * |
| 181 | alloc_type_instance (struct type *oldtype) |
| 182 | { |
| 183 | struct type *type; |
| 184 | |
| 185 | /* Allocate the structure. */ |
| 186 | |
| 187 | if (TYPE_OBJFILE (oldtype) == NULL) |
| 188 | { |
| 189 | type = xmalloc (sizeof (struct type)); |
| 190 | memset (type, 0, sizeof (struct type)); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack, |
| 195 | sizeof (struct type)); |
| 196 | memset (type, 0, sizeof (struct type)); |
| 197 | } |
| 198 | TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype); |
| 199 | |
| 200 | TYPE_CHAIN (type) = type; /* Chain back to itself for now. */ |
| 201 | |
| 202 | return (type); |
| 203 | } |
| 204 | |
| 205 | /* Clear all remnants of the previous type at TYPE, in preparation for |
| 206 | replacing it with something else. */ |
| 207 | static void |
| 208 | smash_type (struct type *type) |
| 209 | { |
| 210 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); |
| 211 | |
| 212 | /* For now, delete the rings. */ |
| 213 | TYPE_CHAIN (type) = type; |
| 214 | |
| 215 | /* For now, leave the pointer/reference types alone. */ |
| 216 | } |
| 217 | |
| 218 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
| 219 | to a pointer to memory where the pointer type should be stored. |
| 220 | If *TYPEPTR is zero, update it to point to the pointer type we return. |
| 221 | We allocate new memory if needed. */ |
| 222 | |
| 223 | struct type * |
| 224 | make_pointer_type (struct type *type, struct type **typeptr) |
| 225 | { |
| 226 | struct type *ntype; /* New type */ |
| 227 | struct objfile *objfile; |
| 228 | |
| 229 | ntype = TYPE_POINTER_TYPE (type); |
| 230 | |
| 231 | if (ntype) |
| 232 | { |
| 233 | if (typeptr == 0) |
| 234 | return ntype; /* Don't care about alloc, and have new type. */ |
| 235 | else if (*typeptr == 0) |
| 236 | { |
| 237 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
| 238 | return ntype; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 243 | { |
| 244 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 245 | if (typeptr) |
| 246 | *typeptr = ntype; |
| 247 | } |
| 248 | else |
| 249 | /* We have storage, but need to reset it. */ |
| 250 | { |
| 251 | ntype = *typeptr; |
| 252 | objfile = TYPE_OBJFILE (ntype); |
| 253 | smash_type (ntype); |
| 254 | TYPE_OBJFILE (ntype) = objfile; |
| 255 | } |
| 256 | |
| 257 | TYPE_TARGET_TYPE (ntype) = type; |
| 258 | TYPE_POINTER_TYPE (type) = ntype; |
| 259 | |
| 260 | /* FIXME! Assume the machine has only one representation for pointers! */ |
| 261 | |
| 262 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; |
| 263 | TYPE_CODE (ntype) = TYPE_CODE_PTR; |
| 264 | |
| 265 | /* Mark pointers as unsigned. The target converts between pointers |
| 266 | and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and |
| 267 | ADDRESS_TO_POINTER(). */ |
| 268 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; |
| 269 | |
| 270 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ |
| 271 | TYPE_POINTER_TYPE (type) = ntype; |
| 272 | |
| 273 | return ntype; |
| 274 | } |
| 275 | |
| 276 | /* Given a type TYPE, return a type of pointers to that type. |
| 277 | May need to construct such a type if this is the first use. */ |
| 278 | |
| 279 | struct type * |
| 280 | lookup_pointer_type (struct type *type) |
| 281 | { |
| 282 | return make_pointer_type (type, (struct type **) 0); |
| 283 | } |
| 284 | |
| 285 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points |
| 286 | to a pointer to memory where the reference type should be stored. |
| 287 | If *TYPEPTR is zero, update it to point to the reference type we return. |
| 288 | We allocate new memory if needed. */ |
| 289 | |
| 290 | struct type * |
| 291 | make_reference_type (struct type *type, struct type **typeptr) |
| 292 | { |
| 293 | struct type *ntype; /* New type */ |
| 294 | struct objfile *objfile; |
| 295 | |
| 296 | ntype = TYPE_REFERENCE_TYPE (type); |
| 297 | |
| 298 | if (ntype) |
| 299 | { |
| 300 | if (typeptr == 0) |
| 301 | return ntype; /* Don't care about alloc, and have new type. */ |
| 302 | else if (*typeptr == 0) |
| 303 | { |
| 304 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
| 305 | return ntype; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 310 | { |
| 311 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 312 | if (typeptr) |
| 313 | *typeptr = ntype; |
| 314 | } |
| 315 | else |
| 316 | /* We have storage, but need to reset it. */ |
| 317 | { |
| 318 | ntype = *typeptr; |
| 319 | objfile = TYPE_OBJFILE (ntype); |
| 320 | smash_type (ntype); |
| 321 | TYPE_OBJFILE (ntype) = objfile; |
| 322 | } |
| 323 | |
| 324 | TYPE_TARGET_TYPE (ntype) = type; |
| 325 | TYPE_REFERENCE_TYPE (type) = ntype; |
| 326 | |
| 327 | /* FIXME! Assume the machine has only one representation for references, |
| 328 | and that it matches the (only) representation for pointers! */ |
| 329 | |
| 330 | TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; |
| 331 | TYPE_CODE (ntype) = TYPE_CODE_REF; |
| 332 | |
| 333 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
| 334 | TYPE_REFERENCE_TYPE (type) = ntype; |
| 335 | |
| 336 | return ntype; |
| 337 | } |
| 338 | |
| 339 | /* Same as above, but caller doesn't care about memory allocation details. */ |
| 340 | |
| 341 | struct type * |
| 342 | lookup_reference_type (struct type *type) |
| 343 | { |
| 344 | return make_reference_type (type, (struct type **) 0); |
| 345 | } |
| 346 | |
| 347 | /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points |
| 348 | to a pointer to memory where the function type should be stored. |
| 349 | If *TYPEPTR is zero, update it to point to the function type we return. |
| 350 | We allocate new memory if needed. */ |
| 351 | |
| 352 | struct type * |
| 353 | make_function_type (struct type *type, struct type **typeptr) |
| 354 | { |
| 355 | struct type *ntype; /* New type */ |
| 356 | struct objfile *objfile; |
| 357 | |
| 358 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ |
| 359 | { |
| 360 | ntype = alloc_type (TYPE_OBJFILE (type)); |
| 361 | if (typeptr) |
| 362 | *typeptr = ntype; |
| 363 | } |
| 364 | else |
| 365 | /* We have storage, but need to reset it. */ |
| 366 | { |
| 367 | ntype = *typeptr; |
| 368 | objfile = TYPE_OBJFILE (ntype); |
| 369 | smash_type (ntype); |
| 370 | TYPE_OBJFILE (ntype) = objfile; |
| 371 | } |
| 372 | |
| 373 | TYPE_TARGET_TYPE (ntype) = type; |
| 374 | |
| 375 | TYPE_LENGTH (ntype) = 1; |
| 376 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; |
| 377 | |
| 378 | return ntype; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | /* Given a type TYPE, return a type of functions that return that type. |
| 383 | May need to construct such a type if this is the first use. */ |
| 384 | |
| 385 | struct type * |
| 386 | lookup_function_type (struct type *type) |
| 387 | { |
| 388 | return make_function_type (type, (struct type **) 0); |
| 389 | } |
| 390 | |
| 391 | /* Identify address space identifier by name -- |
| 392 | return the integer flag defined in gdbtypes.h. */ |
| 393 | extern int |
| 394 | address_space_name_to_int (char *space_identifier) |
| 395 | { |
| 396 | struct gdbarch *gdbarch = current_gdbarch; |
| 397 | int type_flags; |
| 398 | /* Check for known address space delimiters. */ |
| 399 | if (!strcmp (space_identifier, "code")) |
| 400 | return TYPE_FLAG_CODE_SPACE; |
| 401 | else if (!strcmp (space_identifier, "data")) |
| 402 | return TYPE_FLAG_DATA_SPACE; |
| 403 | else if (gdbarch_address_class_name_to_type_flags_p (gdbarch) |
| 404 | && gdbarch_address_class_name_to_type_flags (gdbarch, |
| 405 | space_identifier, |
| 406 | &type_flags)) |
| 407 | return type_flags; |
| 408 | else |
| 409 | error ("Unknown address space specifier: \"%s\"", space_identifier); |
| 410 | } |
| 411 | |
| 412 | /* Identify address space identifier by integer flag as defined in |
| 413 | gdbtypes.h -- return the string version of the adress space name. */ |
| 414 | |
| 415 | const char * |
| 416 | address_space_int_to_name (int space_flag) |
| 417 | { |
| 418 | struct gdbarch *gdbarch = current_gdbarch; |
| 419 | if (space_flag & TYPE_FLAG_CODE_SPACE) |
| 420 | return "code"; |
| 421 | else if (space_flag & TYPE_FLAG_DATA_SPACE) |
| 422 | return "data"; |
| 423 | else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL) |
| 424 | && gdbarch_address_class_type_flags_to_name_p (gdbarch)) |
| 425 | return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag); |
| 426 | else |
| 427 | return NULL; |
| 428 | } |
| 429 | |
| 430 | /* Create a new type with instance flags NEW_FLAGS, based on TYPE. |
| 431 | If STORAGE is non-NULL, create the new type instance there. */ |
| 432 | |
| 433 | static struct type * |
| 434 | make_qualified_type (struct type *type, int new_flags, |
| 435 | struct type *storage) |
| 436 | { |
| 437 | struct type *ntype; |
| 438 | |
| 439 | ntype = type; |
| 440 | do { |
| 441 | if (TYPE_INSTANCE_FLAGS (ntype) == new_flags) |
| 442 | return ntype; |
| 443 | ntype = TYPE_CHAIN (ntype); |
| 444 | } while (ntype != type); |
| 445 | |
| 446 | /* Create a new type instance. */ |
| 447 | if (storage == NULL) |
| 448 | ntype = alloc_type_instance (type); |
| 449 | else |
| 450 | { |
| 451 | ntype = storage; |
| 452 | TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type); |
| 453 | TYPE_CHAIN (ntype) = ntype; |
| 454 | } |
| 455 | |
| 456 | /* Pointers or references to the original type are not relevant to |
| 457 | the new type. */ |
| 458 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; |
| 459 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; |
| 460 | |
| 461 | /* Chain the new qualified type to the old type. */ |
| 462 | TYPE_CHAIN (ntype) = TYPE_CHAIN (type); |
| 463 | TYPE_CHAIN (type) = ntype; |
| 464 | |
| 465 | /* Now set the instance flags and return the new type. */ |
| 466 | TYPE_INSTANCE_FLAGS (ntype) = new_flags; |
| 467 | |
| 468 | /* Set length of new type to that of the original type. */ |
| 469 | TYPE_LENGTH (ntype) = TYPE_LENGTH (type); |
| 470 | |
| 471 | return ntype; |
| 472 | } |
| 473 | |
| 474 | /* Make an address-space-delimited variant of a type -- a type that |
| 475 | is identical to the one supplied except that it has an address |
| 476 | space attribute attached to it (such as "code" or "data"). |
| 477 | |
| 478 | The space attributes "code" and "data" are for Harvard architectures. |
| 479 | The address space attributes are for architectures which have |
| 480 | alternately sized pointers or pointers with alternate representations. */ |
| 481 | |
| 482 | struct type * |
| 483 | make_type_with_address_space (struct type *type, int space_flag) |
| 484 | { |
| 485 | struct type *ntype; |
| 486 | int new_flags = ((TYPE_INSTANCE_FLAGS (type) |
| 487 | & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE |
| 488 | | TYPE_FLAG_ADDRESS_CLASS_ALL)) |
| 489 | | space_flag); |
| 490 | |
| 491 | return make_qualified_type (type, new_flags, NULL); |
| 492 | } |
| 493 | |
| 494 | /* Make a "c-v" variant of a type -- a type that is identical to the |
| 495 | one supplied except that it may have const or volatile attributes |
| 496 | CNST is a flag for setting the const attribute |
| 497 | VOLTL is a flag for setting the volatile attribute |
| 498 | TYPE is the base type whose variant we are creating. |
| 499 | TYPEPTR, if nonzero, points |
| 500 | to a pointer to memory where the reference type should be stored. |
| 501 | If *TYPEPTR is zero, update it to point to the reference type we return. |
| 502 | We allocate new memory if needed. */ |
| 503 | |
| 504 | struct type * |
| 505 | make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr) |
| 506 | { |
| 507 | struct type *ntype; /* New type */ |
| 508 | struct type *tmp_type = type; /* tmp type */ |
| 509 | struct objfile *objfile; |
| 510 | |
| 511 | int new_flags = (TYPE_INSTANCE_FLAGS (type) |
| 512 | & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE)); |
| 513 | |
| 514 | if (cnst) |
| 515 | new_flags |= TYPE_FLAG_CONST; |
| 516 | |
| 517 | if (voltl) |
| 518 | new_flags |= TYPE_FLAG_VOLATILE; |
| 519 | |
| 520 | if (typeptr && *typeptr != NULL) |
| 521 | { |
| 522 | /* Objfile is per-core-type. This const-qualified type had best |
| 523 | belong to the same objfile as the type it is qualifying, unless |
| 524 | we are overwriting a stub type, in which case the safest thing |
| 525 | to do is to copy the core type into the new objfile. */ |
| 526 | |
| 527 | gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type) |
| 528 | || TYPE_STUB (*typeptr)); |
| 529 | if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type)) |
| 530 | { |
| 531 | TYPE_MAIN_TYPE (*typeptr) |
| 532 | = TYPE_ALLOC (*typeptr, sizeof (struct main_type)); |
| 533 | *TYPE_MAIN_TYPE (*typeptr) |
| 534 | = *TYPE_MAIN_TYPE (type); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL); |
| 539 | |
| 540 | if (typeptr != NULL) |
| 541 | *typeptr = ntype; |
| 542 | |
| 543 | return ntype; |
| 544 | } |
| 545 | |
| 546 | /* Replace the contents of ntype with the type *type. This changes the |
| 547 | contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus |
| 548 | the changes are propogated to all types in the TYPE_CHAIN. |
| 549 | |
| 550 | In order to build recursive types, it's inevitable that we'll need |
| 551 | to update types in place --- but this sort of indiscriminate |
| 552 | smashing is ugly, and needs to be replaced with something more |
| 553 | controlled. TYPE_MAIN_TYPE is a step in this direction; it's not |
| 554 | clear if more steps are needed. */ |
| 555 | void |
| 556 | replace_type (struct type *ntype, struct type *type) |
| 557 | { |
| 558 | struct type *chain; |
| 559 | |
| 560 | *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type); |
| 561 | |
| 562 | /* The type length is not a part of the main type. Update it for each |
| 563 | type on the variant chain. */ |
| 564 | chain = ntype; |
| 565 | do { |
| 566 | /* Assert that this element of the chain has no address-class bits |
| 567 | set in its flags. Such type variants might have type lengths |
| 568 | which are supposed to be different from the non-address-class |
| 569 | variants. This assertion shouldn't ever be triggered because |
| 570 | symbol readers which do construct address-class variants don't |
| 571 | call replace_type(). */ |
| 572 | gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0); |
| 573 | |
| 574 | TYPE_LENGTH (ntype) = TYPE_LENGTH (type); |
| 575 | chain = TYPE_CHAIN (chain); |
| 576 | } while (ntype != chain); |
| 577 | |
| 578 | /* Assert that the two types have equivalent instance qualifiers. |
| 579 | This should be true for at least all of our debug readers. */ |
| 580 | gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type)); |
| 581 | } |
| 582 | |
| 583 | /* Implement direct support for MEMBER_TYPE in GNU C++. |
| 584 | May need to construct such a type if this is the first use. |
| 585 | The TYPE is the type of the member. The DOMAIN is the type |
| 586 | of the aggregate that the member belongs to. */ |
| 587 | |
| 588 | struct type * |
| 589 | lookup_member_type (struct type *type, struct type *domain) |
| 590 | { |
| 591 | struct type *mtype; |
| 592 | |
| 593 | mtype = alloc_type (TYPE_OBJFILE (type)); |
| 594 | smash_to_member_type (mtype, domain, type); |
| 595 | return (mtype); |
| 596 | } |
| 597 | |
| 598 | /* Allocate a stub method whose return type is TYPE. |
| 599 | This apparently happens for speed of symbol reading, since parsing |
| 600 | out the arguments to the method is cpu-intensive, the way we are doing |
| 601 | it. So, we will fill in arguments later. |
| 602 | This always returns a fresh type. */ |
| 603 | |
| 604 | struct type * |
| 605 | allocate_stub_method (struct type *type) |
| 606 | { |
| 607 | struct type *mtype; |
| 608 | |
| 609 | mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL, |
| 610 | TYPE_OBJFILE (type)); |
| 611 | TYPE_TARGET_TYPE (mtype) = type; |
| 612 | /* _DOMAIN_TYPE (mtype) = unknown yet */ |
| 613 | return (mtype); |
| 614 | } |
| 615 | |
| 616 | /* Create a range type using either a blank type supplied in RESULT_TYPE, |
| 617 | or creating a new type, inheriting the objfile from INDEX_TYPE. |
| 618 | |
| 619 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to |
| 620 | HIGH_BOUND, inclusive. |
| 621 | |
| 622 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
| 623 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ |
| 624 | |
| 625 | struct type * |
| 626 | create_range_type (struct type *result_type, struct type *index_type, |
| 627 | int low_bound, int high_bound) |
| 628 | { |
| 629 | if (result_type == NULL) |
| 630 | { |
| 631 | result_type = alloc_type (TYPE_OBJFILE (index_type)); |
| 632 | } |
| 633 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; |
| 634 | TYPE_TARGET_TYPE (result_type) = index_type; |
| 635 | if (TYPE_STUB (index_type)) |
| 636 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; |
| 637 | else |
| 638 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); |
| 639 | TYPE_NFIELDS (result_type) = 2; |
| 640 | TYPE_FIELDS (result_type) = (struct field *) |
| 641 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); |
| 642 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); |
| 643 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; |
| 644 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; |
| 645 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ |
| 646 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ |
| 647 | |
| 648 | if (low_bound >= 0) |
| 649 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
| 650 | |
| 651 | return (result_type); |
| 652 | } |
| 653 | |
| 654 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. |
| 655 | Return 1 of type is a range type, 0 if it is discrete (and bounds |
| 656 | will fit in LONGEST), or -1 otherwise. */ |
| 657 | |
| 658 | int |
| 659 | get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) |
| 660 | { |
| 661 | CHECK_TYPEDEF (type); |
| 662 | switch (TYPE_CODE (type)) |
| 663 | { |
| 664 | case TYPE_CODE_RANGE: |
| 665 | *lowp = TYPE_LOW_BOUND (type); |
| 666 | *highp = TYPE_HIGH_BOUND (type); |
| 667 | return 1; |
| 668 | case TYPE_CODE_ENUM: |
| 669 | if (TYPE_NFIELDS (type) > 0) |
| 670 | { |
| 671 | /* The enums may not be sorted by value, so search all |
| 672 | entries */ |
| 673 | int i; |
| 674 | |
| 675 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); |
| 676 | for (i = 0; i < TYPE_NFIELDS (type); i++) |
| 677 | { |
| 678 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) |
| 679 | *lowp = TYPE_FIELD_BITPOS (type, i); |
| 680 | if (TYPE_FIELD_BITPOS (type, i) > *highp) |
| 681 | *highp = TYPE_FIELD_BITPOS (type, i); |
| 682 | } |
| 683 | |
| 684 | /* Set unsigned indicator if warranted. */ |
| 685 | if (*lowp >= 0) |
| 686 | { |
| 687 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; |
| 688 | } |
| 689 | } |
| 690 | else |
| 691 | { |
| 692 | *lowp = 0; |
| 693 | *highp = -1; |
| 694 | } |
| 695 | return 0; |
| 696 | case TYPE_CODE_BOOL: |
| 697 | *lowp = 0; |
| 698 | *highp = 1; |
| 699 | return 0; |
| 700 | case TYPE_CODE_INT: |
| 701 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
| 702 | return -1; |
| 703 | if (!TYPE_UNSIGNED (type)) |
| 704 | { |
| 705 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
| 706 | *highp = -*lowp - 1; |
| 707 | return 0; |
| 708 | } |
| 709 | /* ... fall through for unsigned ints ... */ |
| 710 | case TYPE_CODE_CHAR: |
| 711 | *lowp = 0; |
| 712 | /* This round-about calculation is to avoid shifting by |
| 713 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
| 714 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ |
| 715 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
| 716 | *highp = (*highp - 1) | *highp; |
| 717 | return 0; |
| 718 | default: |
| 719 | return -1; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /* Create an array type using either a blank type supplied in RESULT_TYPE, |
| 724 | or creating a new type, inheriting the objfile from RANGE_TYPE. |
| 725 | |
| 726 | Elements will be of type ELEMENT_TYPE, the indices will be of type |
| 727 | RANGE_TYPE. |
| 728 | |
| 729 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
| 730 | sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ |
| 731 | |
| 732 | struct type * |
| 733 | create_array_type (struct type *result_type, struct type *element_type, |
| 734 | struct type *range_type) |
| 735 | { |
| 736 | LONGEST low_bound, high_bound; |
| 737 | |
| 738 | if (result_type == NULL) |
| 739 | { |
| 740 | result_type = alloc_type (TYPE_OBJFILE (range_type)); |
| 741 | } |
| 742 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; |
| 743 | TYPE_TARGET_TYPE (result_type) = element_type; |
| 744 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) |
| 745 | low_bound = high_bound = 0; |
| 746 | CHECK_TYPEDEF (element_type); |
| 747 | TYPE_LENGTH (result_type) = |
| 748 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); |
| 749 | TYPE_NFIELDS (result_type) = 1; |
| 750 | TYPE_FIELDS (result_type) = |
| 751 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); |
| 752 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); |
| 753 | TYPE_FIELD_TYPE (result_type, 0) = range_type; |
| 754 | TYPE_VPTR_FIELDNO (result_type) = -1; |
| 755 | |
| 756 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ |
| 757 | if (TYPE_LENGTH (result_type) == 0) |
| 758 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; |
| 759 | |
| 760 | return (result_type); |
| 761 | } |
| 762 | |
| 763 | /* Create a string type using either a blank type supplied in RESULT_TYPE, |
| 764 | or creating a new type. String types are similar enough to array of |
| 765 | char types that we can use create_array_type to build the basic type |
| 766 | and then bash it into a string type. |
| 767 | |
| 768 | For fixed length strings, the range type contains 0 as the lower |
| 769 | bound and the length of the string minus one as the upper bound. |
| 770 | |
| 771 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
| 772 | sure it is TYPE_CODE_UNDEF before we bash it into a string type? */ |
| 773 | |
| 774 | struct type * |
| 775 | create_string_type (struct type *result_type, struct type *range_type) |
| 776 | { |
| 777 | result_type = create_array_type (result_type, |
| 778 | *current_language->string_char_type, |
| 779 | range_type); |
| 780 | TYPE_CODE (result_type) = TYPE_CODE_STRING; |
| 781 | return (result_type); |
| 782 | } |
| 783 | |
| 784 | struct type * |
| 785 | create_set_type (struct type *result_type, struct type *domain_type) |
| 786 | { |
| 787 | LONGEST low_bound, high_bound, bit_length; |
| 788 | if (result_type == NULL) |
| 789 | { |
| 790 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); |
| 791 | } |
| 792 | TYPE_CODE (result_type) = TYPE_CODE_SET; |
| 793 | TYPE_NFIELDS (result_type) = 1; |
| 794 | TYPE_FIELDS (result_type) = (struct field *) |
| 795 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); |
| 796 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); |
| 797 | |
| 798 | if (!TYPE_STUB (domain_type)) |
| 799 | { |
| 800 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) |
| 801 | low_bound = high_bound = 0; |
| 802 | bit_length = high_bound - low_bound + 1; |
| 803 | TYPE_LENGTH (result_type) |
| 804 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; |
| 805 | } |
| 806 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; |
| 807 | |
| 808 | if (low_bound >= 0) |
| 809 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
| 810 | |
| 811 | return (result_type); |
| 812 | } |
| 813 | |
| 814 | /* Construct and return a type of the form: |
| 815 | struct NAME { ELT_TYPE ELT_NAME[N]; } |
| 816 | We use these types for SIMD registers. For example, the type of |
| 817 | the SSE registers on the late x86-family processors is: |
| 818 | struct __builtin_v4sf { float f[4]; } |
| 819 | built by the function call: |
| 820 | init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4) |
| 821 | The type returned is a permanent type, allocated using malloc; it |
| 822 | doesn't live in any objfile's obstack. */ |
| 823 | static struct type * |
| 824 | init_simd_type (char *name, |
| 825 | struct type *elt_type, |
| 826 | char *elt_name, |
| 827 | int n) |
| 828 | { |
| 829 | struct type *simd_type; |
| 830 | struct type *array_type; |
| 831 | |
| 832 | simd_type = init_composite_type (name, TYPE_CODE_STRUCT); |
| 833 | array_type = create_array_type (0, elt_type, |
| 834 | create_range_type (0, builtin_type_int, |
| 835 | 0, n-1)); |
| 836 | append_composite_type_field (simd_type, elt_name, array_type); |
| 837 | return simd_type; |
| 838 | } |
| 839 | |
| 840 | static struct type * |
| 841 | init_vector_type (struct type *elt_type, int n) |
| 842 | { |
| 843 | struct type *array_type; |
| 844 | |
| 845 | array_type = create_array_type (0, elt_type, |
| 846 | create_range_type (0, builtin_type_int, |
| 847 | 0, n-1)); |
| 848 | TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR; |
| 849 | return array_type; |
| 850 | } |
| 851 | |
| 852 | static struct type * |
| 853 | build_builtin_type_vec64 (void) |
| 854 | { |
| 855 | /* Construct a type for the 64 bit registers. The type we're |
| 856 | building is this: */ |
| 857 | #if 0 |
| 858 | union __gdb_builtin_type_vec64 |
| 859 | { |
| 860 | int64_t uint64; |
| 861 | float v2_float[2]; |
| 862 | int32_t v2_int32[2]; |
| 863 | int16_t v4_int16[4]; |
| 864 | int8_t v8_int8[8]; |
| 865 | }; |
| 866 | #endif |
| 867 | |
| 868 | struct type *t; |
| 869 | |
| 870 | t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION); |
| 871 | append_composite_type_field (t, "uint64", builtin_type_int64); |
| 872 | append_composite_type_field (t, "v2_float", builtin_type_v2_float); |
| 873 | append_composite_type_field (t, "v2_int32", builtin_type_v2_int32); |
| 874 | append_composite_type_field (t, "v4_int16", builtin_type_v4_int16); |
| 875 | append_composite_type_field (t, "v8_int8", builtin_type_v8_int8); |
| 876 | |
| 877 | TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR; |
| 878 | TYPE_NAME (t) = "builtin_type_vec64"; |
| 879 | return t; |
| 880 | } |
| 881 | |
| 882 | static struct type * |
| 883 | build_builtin_type_vec64i (void) |
| 884 | { |
| 885 | /* Construct a type for the 64 bit registers. The type we're |
| 886 | building is this: */ |
| 887 | #if 0 |
| 888 | union __gdb_builtin_type_vec64i |
| 889 | { |
| 890 | int64_t uint64; |
| 891 | int32_t v2_int32[2]; |
| 892 | int16_t v4_int16[4]; |
| 893 | int8_t v8_int8[8]; |
| 894 | }; |
| 895 | #endif |
| 896 | |
| 897 | struct type *t; |
| 898 | |
| 899 | t = init_composite_type ("__gdb_builtin_type_vec64i", TYPE_CODE_UNION); |
| 900 | append_composite_type_field (t, "uint64", builtin_type_int64); |
| 901 | append_composite_type_field (t, "v2_int32", builtin_type_v2_int32); |
| 902 | append_composite_type_field (t, "v4_int16", builtin_type_v4_int16); |
| 903 | append_composite_type_field (t, "v8_int8", builtin_type_v8_int8); |
| 904 | |
| 905 | TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR; |
| 906 | TYPE_NAME (t) = "builtin_type_vec64i"; |
| 907 | return t; |
| 908 | } |
| 909 | |
| 910 | static struct type * |
| 911 | build_builtin_type_vec128 (void) |
| 912 | { |
| 913 | /* Construct a type for the 128 bit registers. The type we're |
| 914 | building is this: */ |
| 915 | #if 0 |
| 916 | union __gdb_builtin_type_vec128 |
| 917 | { |
| 918 | int128_t uint128; |
| 919 | float v4_float[4]; |
| 920 | int32_t v4_int32[4]; |
| 921 | int16_t v8_int16[8]; |
| 922 | int8_t v16_int8[16]; |
| 923 | }; |
| 924 | #endif |
| 925 | |
| 926 | struct type *t; |
| 927 | |
| 928 | t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION); |
| 929 | append_composite_type_field (t, "uint128", builtin_type_int128); |
| 930 | append_composite_type_field (t, "v4_float", builtin_type_v4_float); |
| 931 | append_composite_type_field (t, "v4_int32", builtin_type_v4_int32); |
| 932 | append_composite_type_field (t, "v8_int16", builtin_type_v8_int16); |
| 933 | append_composite_type_field (t, "v16_int8", builtin_type_v16_int8); |
| 934 | |
| 935 | TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR; |
| 936 | TYPE_NAME (t) = "builtin_type_vec128"; |
| 937 | return t; |
| 938 | } |
| 939 | |
| 940 | static struct type * |
| 941 | build_builtin_type_vec128i (void) |
| 942 | { |
| 943 | /* 128-bit Intel SIMD registers */ |
| 944 | struct type *t; |
| 945 | |
| 946 | t = init_composite_type ("__gdb_builtin_type_vec128i", TYPE_CODE_UNION); |
| 947 | append_composite_type_field (t, "v4_float", builtin_type_v4_float); |
| 948 | append_composite_type_field (t, "v2_double", builtin_type_v2_double); |
| 949 | append_composite_type_field (t, "v16_int8", builtin_type_v16_int8); |
| 950 | append_composite_type_field (t, "v8_int16", builtin_type_v8_int16); |
| 951 | append_composite_type_field (t, "v4_int32", builtin_type_v4_int32); |
| 952 | append_composite_type_field (t, "v2_int64", builtin_type_v2_int64); |
| 953 | append_composite_type_field (t, "uint128", builtin_type_int128); |
| 954 | |
| 955 | TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR; |
| 956 | TYPE_NAME (t) = "builtin_type_vec128i"; |
| 957 | return t; |
| 958 | } |
| 959 | |
| 960 | /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE. |
| 961 | A MEMBER is a wierd thing -- it amounts to a typed offset into |
| 962 | a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't |
| 963 | include the offset (that's the value of the MEMBER itself), but does |
| 964 | include the structure type into which it points (for some reason). |
| 965 | |
| 966 | When "smashing" the type, we preserve the objfile that the |
| 967 | old type pointed to, since we aren't changing where the type is actually |
| 968 | allocated. */ |
| 969 | |
| 970 | void |
| 971 | smash_to_member_type (struct type *type, struct type *domain, |
| 972 | struct type *to_type) |
| 973 | { |
| 974 | struct objfile *objfile; |
| 975 | |
| 976 | objfile = TYPE_OBJFILE (type); |
| 977 | |
| 978 | smash_type (type); |
| 979 | TYPE_OBJFILE (type) = objfile; |
| 980 | TYPE_TARGET_TYPE (type) = to_type; |
| 981 | TYPE_DOMAIN_TYPE (type) = domain; |
| 982 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
| 983 | TYPE_CODE (type) = TYPE_CODE_MEMBER; |
| 984 | } |
| 985 | |
| 986 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. |
| 987 | METHOD just means `function that gets an extra "this" argument'. |
| 988 | |
| 989 | When "smashing" the type, we preserve the objfile that the |
| 990 | old type pointed to, since we aren't changing where the type is actually |
| 991 | allocated. */ |
| 992 | |
| 993 | void |
| 994 | smash_to_method_type (struct type *type, struct type *domain, |
| 995 | struct type *to_type, struct field *args, |
| 996 | int nargs, int varargs) |
| 997 | { |
| 998 | struct objfile *objfile; |
| 999 | |
| 1000 | objfile = TYPE_OBJFILE (type); |
| 1001 | |
| 1002 | smash_type (type); |
| 1003 | TYPE_OBJFILE (type) = objfile; |
| 1004 | TYPE_TARGET_TYPE (type) = to_type; |
| 1005 | TYPE_DOMAIN_TYPE (type) = domain; |
| 1006 | TYPE_FIELDS (type) = args; |
| 1007 | TYPE_NFIELDS (type) = nargs; |
| 1008 | if (varargs) |
| 1009 | TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS; |
| 1010 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
| 1011 | TYPE_CODE (type) = TYPE_CODE_METHOD; |
| 1012 | } |
| 1013 | |
| 1014 | /* Return a typename for a struct/union/enum type without "struct ", |
| 1015 | "union ", or "enum ". If the type has a NULL name, return NULL. */ |
| 1016 | |
| 1017 | char * |
| 1018 | type_name_no_tag (const struct type *type) |
| 1019 | { |
| 1020 | if (TYPE_TAG_NAME (type) != NULL) |
| 1021 | return TYPE_TAG_NAME (type); |
| 1022 | |
| 1023 | /* Is there code which expects this to return the name if there is no |
| 1024 | tag name? My guess is that this is mainly used for C++ in cases where |
| 1025 | the two will always be the same. */ |
| 1026 | return TYPE_NAME (type); |
| 1027 | } |
| 1028 | |
| 1029 | /* Lookup a primitive type named NAME. |
| 1030 | Return zero if NAME is not a primitive type. */ |
| 1031 | |
| 1032 | struct type * |
| 1033 | lookup_primitive_typename (char *name) |
| 1034 | { |
| 1035 | struct type **const *p; |
| 1036 | |
| 1037 | for (p = current_language->la_builtin_type_vector; *p != NULL; p++) |
| 1038 | { |
| 1039 | if (strcmp (TYPE_NAME (**p), name) == 0) |
| 1040 | { |
| 1041 | return (**p); |
| 1042 | } |
| 1043 | } |
| 1044 | return (NULL); |
| 1045 | } |
| 1046 | |
| 1047 | /* Lookup a typedef or primitive type named NAME, |
| 1048 | visible in lexical block BLOCK. |
| 1049 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ |
| 1050 | |
| 1051 | struct type * |
| 1052 | lookup_typename (char *name, struct block *block, int noerr) |
| 1053 | { |
| 1054 | struct symbol *sym; |
| 1055 | struct type *tmp; |
| 1056 | |
| 1057 | sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL); |
| 1058 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) |
| 1059 | { |
| 1060 | tmp = lookup_primitive_typename (name); |
| 1061 | if (tmp) |
| 1062 | { |
| 1063 | return (tmp); |
| 1064 | } |
| 1065 | else if (!tmp && noerr) |
| 1066 | { |
| 1067 | return (NULL); |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 1071 | error ("No type named %s.", name); |
| 1072 | } |
| 1073 | } |
| 1074 | return (SYMBOL_TYPE (sym)); |
| 1075 | } |
| 1076 | |
| 1077 | struct type * |
| 1078 | lookup_unsigned_typename (char *name) |
| 1079 | { |
| 1080 | char *uns = alloca (strlen (name) + 10); |
| 1081 | |
| 1082 | strcpy (uns, "unsigned "); |
| 1083 | strcpy (uns + 9, name); |
| 1084 | return (lookup_typename (uns, (struct block *) NULL, 0)); |
| 1085 | } |
| 1086 | |
| 1087 | struct type * |
| 1088 | lookup_signed_typename (char *name) |
| 1089 | { |
| 1090 | struct type *t; |
| 1091 | char *uns = alloca (strlen (name) + 8); |
| 1092 | |
| 1093 | strcpy (uns, "signed "); |
| 1094 | strcpy (uns + 7, name); |
| 1095 | t = lookup_typename (uns, (struct block *) NULL, 1); |
| 1096 | /* If we don't find "signed FOO" just try again with plain "FOO". */ |
| 1097 | if (t != NULL) |
| 1098 | return t; |
| 1099 | return lookup_typename (name, (struct block *) NULL, 0); |
| 1100 | } |
| 1101 | |
| 1102 | /* Lookup a structure type named "struct NAME", |
| 1103 | visible in lexical block BLOCK. */ |
| 1104 | |
| 1105 | struct type * |
| 1106 | lookup_struct (char *name, struct block *block) |
| 1107 | { |
| 1108 | struct symbol *sym; |
| 1109 | |
| 1110 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
| 1111 | (struct symtab **) NULL); |
| 1112 | |
| 1113 | if (sym == NULL) |
| 1114 | { |
| 1115 | error ("No struct type named %s.", name); |
| 1116 | } |
| 1117 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) |
| 1118 | { |
| 1119 | error ("This context has class, union or enum %s, not a struct.", name); |
| 1120 | } |
| 1121 | return (SYMBOL_TYPE (sym)); |
| 1122 | } |
| 1123 | |
| 1124 | /* Lookup a union type named "union NAME", |
| 1125 | visible in lexical block BLOCK. */ |
| 1126 | |
| 1127 | struct type * |
| 1128 | lookup_union (char *name, struct block *block) |
| 1129 | { |
| 1130 | struct symbol *sym; |
| 1131 | struct type *t; |
| 1132 | |
| 1133 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
| 1134 | (struct symtab **) NULL); |
| 1135 | |
| 1136 | if (sym == NULL) |
| 1137 | error ("No union type named %s.", name); |
| 1138 | |
| 1139 | t = SYMBOL_TYPE (sym); |
| 1140 | |
| 1141 | if (TYPE_CODE (t) == TYPE_CODE_UNION) |
| 1142 | return (t); |
| 1143 | |
| 1144 | /* C++ unions may come out with TYPE_CODE_CLASS, but we look at |
| 1145 | * a further "declared_type" field to discover it is really a union. |
| 1146 | */ |
| 1147 | if (HAVE_CPLUS_STRUCT (t)) |
| 1148 | if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION) |
| 1149 | return (t); |
| 1150 | |
| 1151 | /* If we get here, it's not a union */ |
| 1152 | error ("This context has class, struct or enum %s, not a union.", name); |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | /* Lookup an enum type named "enum NAME", |
| 1157 | visible in lexical block BLOCK. */ |
| 1158 | |
| 1159 | struct type * |
| 1160 | lookup_enum (char *name, struct block *block) |
| 1161 | { |
| 1162 | struct symbol *sym; |
| 1163 | |
| 1164 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
| 1165 | (struct symtab **) NULL); |
| 1166 | if (sym == NULL) |
| 1167 | { |
| 1168 | error ("No enum type named %s.", name); |
| 1169 | } |
| 1170 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) |
| 1171 | { |
| 1172 | error ("This context has class, struct or union %s, not an enum.", name); |
| 1173 | } |
| 1174 | return (SYMBOL_TYPE (sym)); |
| 1175 | } |
| 1176 | |
| 1177 | /* Lookup a template type named "template NAME<TYPE>", |
| 1178 | visible in lexical block BLOCK. */ |
| 1179 | |
| 1180 | struct type * |
| 1181 | lookup_template_type (char *name, struct type *type, struct block *block) |
| 1182 | { |
| 1183 | struct symbol *sym; |
| 1184 | char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4); |
| 1185 | strcpy (nam, name); |
| 1186 | strcat (nam, "<"); |
| 1187 | strcat (nam, TYPE_NAME (type)); |
| 1188 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
| 1189 | |
| 1190 | sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL); |
| 1191 | |
| 1192 | if (sym == NULL) |
| 1193 | { |
| 1194 | error ("No template type named %s.", name); |
| 1195 | } |
| 1196 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) |
| 1197 | { |
| 1198 | error ("This context has class, union or enum %s, not a struct.", name); |
| 1199 | } |
| 1200 | return (SYMBOL_TYPE (sym)); |
| 1201 | } |
| 1202 | |
| 1203 | /* Given a type TYPE, lookup the type of the component of type named NAME. |
| 1204 | |
| 1205 | TYPE can be either a struct or union, or a pointer or reference to a struct or |
| 1206 | union. If it is a pointer or reference, its target type is automatically used. |
| 1207 | Thus '.' and '->' are interchangable, as specified for the definitions of the |
| 1208 | expression element types STRUCTOP_STRUCT and STRUCTOP_PTR. |
| 1209 | |
| 1210 | If NOERR is nonzero, return zero if NAME is not suitably defined. |
| 1211 | If NAME is the name of a baseclass type, return that type. */ |
| 1212 | |
| 1213 | struct type * |
| 1214 | lookup_struct_elt_type (struct type *type, char *name, int noerr) |
| 1215 | { |
| 1216 | int i; |
| 1217 | |
| 1218 | for (;;) |
| 1219 | { |
| 1220 | CHECK_TYPEDEF (type); |
| 1221 | if (TYPE_CODE (type) != TYPE_CODE_PTR |
| 1222 | && TYPE_CODE (type) != TYPE_CODE_REF) |
| 1223 | break; |
| 1224 | type = TYPE_TARGET_TYPE (type); |
| 1225 | } |
| 1226 | |
| 1227 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && |
| 1228 | TYPE_CODE (type) != TYPE_CODE_UNION) |
| 1229 | { |
| 1230 | target_terminal_ours (); |
| 1231 | gdb_flush (gdb_stdout); |
| 1232 | fprintf_unfiltered (gdb_stderr, "Type "); |
| 1233 | type_print (type, "", gdb_stderr, -1); |
| 1234 | error (" is not a structure or union type."); |
| 1235 | } |
| 1236 | |
| 1237 | #if 0 |
| 1238 | /* FIXME: This change put in by Michael seems incorrect for the case where |
| 1239 | the structure tag name is the same as the member name. I.E. when doing |
| 1240 | "ptype bell->bar" for "struct foo { int bar; int foo; } bell;" |
| 1241 | Disabled by fnf. */ |
| 1242 | { |
| 1243 | char *typename; |
| 1244 | |
| 1245 | typename = type_name_no_tag (type); |
| 1246 | if (typename != NULL && strcmp (typename, name) == 0) |
| 1247 | return type; |
| 1248 | } |
| 1249 | #endif |
| 1250 | |
| 1251 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) |
| 1252 | { |
| 1253 | char *t_field_name = TYPE_FIELD_NAME (type, i); |
| 1254 | |
| 1255 | if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
| 1256 | { |
| 1257 | return TYPE_FIELD_TYPE (type, i); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | /* OK, it's not in this class. Recursively check the baseclasses. */ |
| 1262 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) |
| 1263 | { |
| 1264 | struct type *t; |
| 1265 | |
| 1266 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr); |
| 1267 | if (t != NULL) |
| 1268 | { |
| 1269 | return t; |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | if (noerr) |
| 1274 | { |
| 1275 | return NULL; |
| 1276 | } |
| 1277 | |
| 1278 | target_terminal_ours (); |
| 1279 | gdb_flush (gdb_stdout); |
| 1280 | fprintf_unfiltered (gdb_stderr, "Type "); |
| 1281 | type_print (type, "", gdb_stderr, -1); |
| 1282 | fprintf_unfiltered (gdb_stderr, " has no component named "); |
| 1283 | fputs_filtered (name, gdb_stderr); |
| 1284 | error ("."); |
| 1285 | return (struct type *) -1; /* For lint */ |
| 1286 | } |
| 1287 | |
| 1288 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE |
| 1289 | valid. Callers should be aware that in some cases (for example, |
| 1290 | the type or one of its baseclasses is a stub type and we are |
| 1291 | debugging a .o file), this function will not be able to find the virtual |
| 1292 | function table pointer, and vptr_fieldno will remain -1 and vptr_basetype |
| 1293 | will remain NULL. */ |
| 1294 | |
| 1295 | void |
| 1296 | fill_in_vptr_fieldno (struct type *type) |
| 1297 | { |
| 1298 | CHECK_TYPEDEF (type); |
| 1299 | |
| 1300 | if (TYPE_VPTR_FIELDNO (type) < 0) |
| 1301 | { |
| 1302 | int i; |
| 1303 | |
| 1304 | /* We must start at zero in case the first (and only) baseclass is |
| 1305 | virtual (and hence we cannot share the table pointer). */ |
| 1306 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
| 1307 | { |
| 1308 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); |
| 1309 | fill_in_vptr_fieldno (baseclass); |
| 1310 | if (TYPE_VPTR_FIELDNO (baseclass) >= 0) |
| 1311 | { |
| 1312 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass); |
| 1313 | TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass); |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | /* Find the method and field indices for the destructor in class type T. |
| 1321 | Return 1 if the destructor was found, otherwise, return 0. */ |
| 1322 | |
| 1323 | int |
| 1324 | get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp) |
| 1325 | { |
| 1326 | int i; |
| 1327 | |
| 1328 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) |
| 1329 | { |
| 1330 | int j; |
| 1331 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); |
| 1332 | |
| 1333 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) |
| 1334 | { |
| 1335 | if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0) |
| 1336 | { |
| 1337 | *method_indexp = i; |
| 1338 | *field_indexp = j; |
| 1339 | return 1; |
| 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. |
| 1347 | |
| 1348 | If this is a stubbed struct (i.e. declared as struct foo *), see if |
| 1349 | we can find a full definition in some other file. If so, copy this |
| 1350 | definition, so we can use it in future. There used to be a comment (but |
| 1351 | not any code) that if we don't find a full definition, we'd set a flag |
| 1352 | so we don't spend time in the future checking the same type. That would |
| 1353 | be a mistake, though--we might load in more symbols which contain a |
| 1354 | full definition for the type. |
| 1355 | |
| 1356 | This used to be coded as a macro, but I don't think it is called |
| 1357 | often enough to merit such treatment. */ |
| 1358 | |
| 1359 | static void |
| 1360 | stub_noname_complaint (void) |
| 1361 | { |
| 1362 | complaint (&symfile_complaints, "stub type has NULL name"); |
| 1363 | } |
| 1364 | |
| 1365 | struct type * |
| 1366 | check_typedef (struct type *type) |
| 1367 | { |
| 1368 | struct type *orig_type = type; |
| 1369 | int is_const, is_volatile; |
| 1370 | |
| 1371 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
| 1372 | { |
| 1373 | if (!TYPE_TARGET_TYPE (type)) |
| 1374 | { |
| 1375 | char *name; |
| 1376 | struct symbol *sym; |
| 1377 | |
| 1378 | /* It is dangerous to call lookup_symbol if we are currently |
| 1379 | reading a symtab. Infinite recursion is one danger. */ |
| 1380 | if (currently_reading_symtab) |
| 1381 | return type; |
| 1382 | |
| 1383 | name = type_name_no_tag (type); |
| 1384 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
| 1385 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
| 1386 | as appropriate? (this code was written before TYPE_NAME and |
| 1387 | TYPE_TAG_NAME were separate). */ |
| 1388 | if (name == NULL) |
| 1389 | { |
| 1390 | stub_noname_complaint (); |
| 1391 | return type; |
| 1392 | } |
| 1393 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, |
| 1394 | (struct symtab **) NULL); |
| 1395 | if (sym) |
| 1396 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); |
| 1397 | else |
| 1398 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ |
| 1399 | } |
| 1400 | type = TYPE_TARGET_TYPE (type); |
| 1401 | } |
| 1402 | |
| 1403 | is_const = TYPE_CONST (type); |
| 1404 | is_volatile = TYPE_VOLATILE (type); |
| 1405 | |
| 1406 | /* If this is a struct/class/union with no fields, then check whether a |
| 1407 | full definition exists somewhere else. This is for systems where a |
| 1408 | type definition with no fields is issued for such types, instead of |
| 1409 | identifying them as stub types in the first place */ |
| 1410 | |
| 1411 | if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab) |
| 1412 | { |
| 1413 | char *name = type_name_no_tag (type); |
| 1414 | struct type *newtype; |
| 1415 | if (name == NULL) |
| 1416 | { |
| 1417 | stub_noname_complaint (); |
| 1418 | return type; |
| 1419 | } |
| 1420 | newtype = lookup_transparent_type (name); |
| 1421 | if (newtype) |
| 1422 | make_cv_type (is_const, is_volatile, newtype, &type); |
| 1423 | } |
| 1424 | /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ |
| 1425 | else if (TYPE_STUB (type) && !currently_reading_symtab) |
| 1426 | { |
| 1427 | char *name = type_name_no_tag (type); |
| 1428 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
| 1429 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
| 1430 | as appropriate? (this code was written before TYPE_NAME and |
| 1431 | TYPE_TAG_NAME were separate). */ |
| 1432 | struct symbol *sym; |
| 1433 | if (name == NULL) |
| 1434 | { |
| 1435 | stub_noname_complaint (); |
| 1436 | return type; |
| 1437 | } |
| 1438 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL); |
| 1439 | if (sym) |
| 1440 | make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type); |
| 1441 | } |
| 1442 | |
| 1443 | if (TYPE_TARGET_STUB (type)) |
| 1444 | { |
| 1445 | struct type *range_type; |
| 1446 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); |
| 1447 | |
| 1448 | if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) |
| 1449 | { |
| 1450 | } |
| 1451 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
| 1452 | && TYPE_NFIELDS (type) == 1 |
| 1453 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) |
| 1454 | == TYPE_CODE_RANGE)) |
| 1455 | { |
| 1456 | /* Now recompute the length of the array type, based on its |
| 1457 | number of elements and the target type's length. */ |
| 1458 | TYPE_LENGTH (type) = |
| 1459 | ((TYPE_FIELD_BITPOS (range_type, 1) |
| 1460 | - TYPE_FIELD_BITPOS (range_type, 0) |
| 1461 | + 1) |
| 1462 | * TYPE_LENGTH (target_type)); |
| 1463 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; |
| 1464 | } |
| 1465 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
| 1466 | { |
| 1467 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); |
| 1468 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; |
| 1469 | } |
| 1470 | } |
| 1471 | /* Cache TYPE_LENGTH for future use. */ |
| 1472 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); |
| 1473 | return type; |
| 1474 | } |
| 1475 | |
| 1476 | /* Parse a type expression in the string [P..P+LENGTH). If an error occurs, |
| 1477 | silently return builtin_type_void. */ |
| 1478 | |
| 1479 | static struct type * |
| 1480 | safe_parse_type (char *p, int length) |
| 1481 | { |
| 1482 | struct ui_file *saved_gdb_stderr; |
| 1483 | struct type *type; |
| 1484 | |
| 1485 | /* Suppress error messages. */ |
| 1486 | saved_gdb_stderr = gdb_stderr; |
| 1487 | gdb_stderr = ui_file_new (); |
| 1488 | |
| 1489 | /* Call parse_and_eval_type() without fear of longjmp()s. */ |
| 1490 | if (!gdb_parse_and_eval_type (p, length, &type)) |
| 1491 | type = builtin_type_void; |
| 1492 | |
| 1493 | /* Stop suppressing error messages. */ |
| 1494 | ui_file_delete (gdb_stderr); |
| 1495 | gdb_stderr = saved_gdb_stderr; |
| 1496 | |
| 1497 | return type; |
| 1498 | } |
| 1499 | |
| 1500 | /* Ugly hack to convert method stubs into method types. |
| 1501 | |
| 1502 | He ain't kiddin'. This demangles the name of the method into a string |
| 1503 | including argument types, parses out each argument type, generates |
| 1504 | a string casting a zero to that type, evaluates the string, and stuffs |
| 1505 | the resulting type into an argtype vector!!! Then it knows the type |
| 1506 | of the whole function (including argument types for overloading), |
| 1507 | which info used to be in the stab's but was removed to hack back |
| 1508 | the space required for them. */ |
| 1509 | |
| 1510 | static void |
| 1511 | check_stub_method (struct type *type, int method_id, int signature_id) |
| 1512 | { |
| 1513 | struct fn_field *f; |
| 1514 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); |
| 1515 | char *demangled_name = cplus_demangle (mangled_name, |
| 1516 | DMGL_PARAMS | DMGL_ANSI); |
| 1517 | char *argtypetext, *p; |
| 1518 | int depth = 0, argcount = 1; |
| 1519 | struct field *argtypes; |
| 1520 | struct type *mtype; |
| 1521 | |
| 1522 | /* Make sure we got back a function string that we can use. */ |
| 1523 | if (demangled_name) |
| 1524 | p = strchr (demangled_name, '('); |
| 1525 | else |
| 1526 | p = NULL; |
| 1527 | |
| 1528 | if (demangled_name == NULL || p == NULL) |
| 1529 | error ("Internal: Cannot demangle mangled name `%s'.", mangled_name); |
| 1530 | |
| 1531 | /* Now, read in the parameters that define this type. */ |
| 1532 | p += 1; |
| 1533 | argtypetext = p; |
| 1534 | while (*p) |
| 1535 | { |
| 1536 | if (*p == '(' || *p == '<') |
| 1537 | { |
| 1538 | depth += 1; |
| 1539 | } |
| 1540 | else if (*p == ')' || *p == '>') |
| 1541 | { |
| 1542 | depth -= 1; |
| 1543 | } |
| 1544 | else if (*p == ',' && depth == 0) |
| 1545 | { |
| 1546 | argcount += 1; |
| 1547 | } |
| 1548 | |
| 1549 | p += 1; |
| 1550 | } |
| 1551 | |
| 1552 | /* If we read one argument and it was ``void'', don't count it. */ |
| 1553 | if (strncmp (argtypetext, "(void)", 6) == 0) |
| 1554 | argcount -= 1; |
| 1555 | |
| 1556 | /* We need one extra slot, for the THIS pointer. */ |
| 1557 | |
| 1558 | argtypes = (struct field *) |
| 1559 | TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field)); |
| 1560 | p = argtypetext; |
| 1561 | |
| 1562 | /* Add THIS pointer for non-static methods. */ |
| 1563 | f = TYPE_FN_FIELDLIST1 (type, method_id); |
| 1564 | if (TYPE_FN_FIELD_STATIC_P (f, signature_id)) |
| 1565 | argcount = 0; |
| 1566 | else |
| 1567 | { |
| 1568 | argtypes[0].type = lookup_pointer_type (type); |
| 1569 | argcount = 1; |
| 1570 | } |
| 1571 | |
| 1572 | if (*p != ')') /* () means no args, skip while */ |
| 1573 | { |
| 1574 | depth = 0; |
| 1575 | while (*p) |
| 1576 | { |
| 1577 | if (depth <= 0 && (*p == ',' || *p == ')')) |
| 1578 | { |
| 1579 | /* Avoid parsing of ellipsis, they will be handled below. |
| 1580 | Also avoid ``void'' as above. */ |
| 1581 | if (strncmp (argtypetext, "...", p - argtypetext) != 0 |
| 1582 | && strncmp (argtypetext, "void", p - argtypetext) != 0) |
| 1583 | { |
| 1584 | argtypes[argcount].type = |
| 1585 | safe_parse_type (argtypetext, p - argtypetext); |
| 1586 | argcount += 1; |
| 1587 | } |
| 1588 | argtypetext = p + 1; |
| 1589 | } |
| 1590 | |
| 1591 | if (*p == '(' || *p == '<') |
| 1592 | { |
| 1593 | depth += 1; |
| 1594 | } |
| 1595 | else if (*p == ')' || *p == '>') |
| 1596 | { |
| 1597 | depth -= 1; |
| 1598 | } |
| 1599 | |
| 1600 | p += 1; |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
| 1605 | |
| 1606 | /* Now update the old "stub" type into a real type. */ |
| 1607 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); |
| 1608 | TYPE_DOMAIN_TYPE (mtype) = type; |
| 1609 | TYPE_FIELDS (mtype) = argtypes; |
| 1610 | TYPE_NFIELDS (mtype) = argcount; |
| 1611 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; |
| 1612 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; |
| 1613 | if (p[-2] == '.') |
| 1614 | TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS; |
| 1615 | |
| 1616 | xfree (demangled_name); |
| 1617 | } |
| 1618 | |
| 1619 | /* This is the external interface to check_stub_method, above. This function |
| 1620 | unstubs all of the signatures for TYPE's METHOD_ID method name. After |
| 1621 | calling this function TYPE_FN_FIELD_STUB will be cleared for each signature |
| 1622 | and TYPE_FN_FIELDLIST_NAME will be correct. |
| 1623 | |
| 1624 | This function unfortunately can not die until stabs do. */ |
| 1625 | |
| 1626 | void |
| 1627 | check_stub_method_group (struct type *type, int method_id) |
| 1628 | { |
| 1629 | int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id); |
| 1630 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); |
| 1631 | int j, found_stub = 0; |
| 1632 | |
| 1633 | for (j = 0; j < len; j++) |
| 1634 | if (TYPE_FN_FIELD_STUB (f, j)) |
| 1635 | { |
| 1636 | found_stub = 1; |
| 1637 | check_stub_method (type, method_id, j); |
| 1638 | } |
| 1639 | |
| 1640 | /* GNU v3 methods with incorrect names were corrected when we read in |
| 1641 | type information, because it was cheaper to do it then. The only GNU v2 |
| 1642 | methods with incorrect method names are operators and destructors; |
| 1643 | destructors were also corrected when we read in type information. |
| 1644 | |
| 1645 | Therefore the only thing we need to handle here are v2 operator |
| 1646 | names. */ |
| 1647 | if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0) |
| 1648 | { |
| 1649 | int ret; |
| 1650 | char dem_opname[256]; |
| 1651 | |
| 1652 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id), |
| 1653 | dem_opname, DMGL_ANSI); |
| 1654 | if (!ret) |
| 1655 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id), |
| 1656 | dem_opname, 0); |
| 1657 | if (ret) |
| 1658 | TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname); |
| 1659 | } |
| 1660 | } |
| 1661 | |
| 1662 | const struct cplus_struct_type cplus_struct_default; |
| 1663 | |
| 1664 | void |
| 1665 | allocate_cplus_struct_type (struct type *type) |
| 1666 | { |
| 1667 | if (!HAVE_CPLUS_STRUCT (type)) |
| 1668 | { |
| 1669 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) |
| 1670 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); |
| 1671 | *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default; |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | /* Helper function to initialize the standard scalar types. |
| 1676 | |
| 1677 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy |
| 1678 | of the string pointed to by name in the objfile_obstack for that objfile, |
| 1679 | and initialize the type name to that copy. There are places (mipsread.c |
| 1680 | in particular, where init_type is called with a NULL value for NAME). */ |
| 1681 | |
| 1682 | struct type * |
| 1683 | init_type (enum type_code code, int length, int flags, char *name, |
| 1684 | struct objfile *objfile) |
| 1685 | { |
| 1686 | struct type *type; |
| 1687 | |
| 1688 | type = alloc_type (objfile); |
| 1689 | TYPE_CODE (type) = code; |
| 1690 | TYPE_LENGTH (type) = length; |
| 1691 | TYPE_FLAGS (type) |= flags; |
| 1692 | if ((name != NULL) && (objfile != NULL)) |
| 1693 | { |
| 1694 | TYPE_NAME (type) = |
| 1695 | obsavestring (name, strlen (name), &objfile->objfile_obstack); |
| 1696 | } |
| 1697 | else |
| 1698 | { |
| 1699 | TYPE_NAME (type) = name; |
| 1700 | } |
| 1701 | |
| 1702 | /* C++ fancies. */ |
| 1703 | |
| 1704 | if (name && strcmp (name, "char") == 0) |
| 1705 | TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN; |
| 1706 | |
| 1707 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION |
| 1708 | || code == TYPE_CODE_NAMESPACE) |
| 1709 | { |
| 1710 | INIT_CPLUS_SPECIFIC (type); |
| 1711 | } |
| 1712 | return (type); |
| 1713 | } |
| 1714 | |
| 1715 | /* Helper function. Create an empty composite type. */ |
| 1716 | |
| 1717 | struct type * |
| 1718 | init_composite_type (char *name, enum type_code code) |
| 1719 | { |
| 1720 | struct type *t; |
| 1721 | gdb_assert (code == TYPE_CODE_STRUCT |
| 1722 | || code == TYPE_CODE_UNION); |
| 1723 | t = init_type (code, 0, 0, NULL, NULL); |
| 1724 | TYPE_TAG_NAME (t) = name; |
| 1725 | return t; |
| 1726 | } |
| 1727 | |
| 1728 | /* Helper function. Append a field to a composite type. */ |
| 1729 | |
| 1730 | void |
| 1731 | append_composite_type_field (struct type *t, char *name, struct type *field) |
| 1732 | { |
| 1733 | struct field *f; |
| 1734 | TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1; |
| 1735 | TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t), |
| 1736 | sizeof (struct field) * TYPE_NFIELDS (t)); |
| 1737 | f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]); |
| 1738 | memset (f, 0, sizeof f[0]); |
| 1739 | FIELD_TYPE (f[0]) = field; |
| 1740 | FIELD_NAME (f[0]) = name; |
| 1741 | if (TYPE_CODE (t) == TYPE_CODE_UNION) |
| 1742 | { |
| 1743 | if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) |
| 1744 | TYPE_LENGTH (t) = TYPE_LENGTH (field); |
| 1745 | } |
| 1746 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT) |
| 1747 | { |
| 1748 | TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field); |
| 1749 | if (TYPE_NFIELDS (t) > 1) |
| 1750 | { |
| 1751 | FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1]) |
| 1752 | + TYPE_LENGTH (field) * TARGET_CHAR_BIT); |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | /* Look up a fundamental type for the specified objfile. |
| 1758 | May need to construct such a type if this is the first use. |
| 1759 | |
| 1760 | Some object file formats (ELF, COFF, etc) do not define fundamental |
| 1761 | types such as "int" or "double". Others (stabs for example), do |
| 1762 | define fundamental types. |
| 1763 | |
| 1764 | For the formats which don't provide fundamental types, gdb can create |
| 1765 | such types, using defaults reasonable for the current language and |
| 1766 | the current target machine. |
| 1767 | |
| 1768 | NOTE: This routine is obsolescent. Each debugging format reader |
| 1769 | should manage it's own fundamental types, either creating them from |
| 1770 | suitable defaults or reading them from the debugging information, |
| 1771 | whichever is appropriate. The DWARF reader has already been |
| 1772 | fixed to do this. Once the other readers are fixed, this routine |
| 1773 | will go away. Also note that fundamental types should be managed |
| 1774 | on a compilation unit basis in a multi-language environment, not |
| 1775 | on a linkage unit basis as is done here. */ |
| 1776 | |
| 1777 | |
| 1778 | struct type * |
| 1779 | lookup_fundamental_type (struct objfile *objfile, int typeid) |
| 1780 | { |
| 1781 | struct type **typep; |
| 1782 | int nbytes; |
| 1783 | |
| 1784 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) |
| 1785 | { |
| 1786 | error ("internal error - invalid fundamental type id %d", typeid); |
| 1787 | } |
| 1788 | |
| 1789 | /* If this is the first time we need a fundamental type for this objfile |
| 1790 | then we need to initialize the vector of type pointers. */ |
| 1791 | |
| 1792 | if (objfile->fundamental_types == NULL) |
| 1793 | { |
| 1794 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); |
| 1795 | objfile->fundamental_types = (struct type **) |
| 1796 | obstack_alloc (&objfile->objfile_obstack, nbytes); |
| 1797 | memset ((char *) objfile->fundamental_types, 0, nbytes); |
| 1798 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
| 1799 | } |
| 1800 | |
| 1801 | /* Look for this particular type in the fundamental type vector. If one is |
| 1802 | not found, create and install one appropriate for the current language. */ |
| 1803 | |
| 1804 | typep = objfile->fundamental_types + typeid; |
| 1805 | if (*typep == NULL) |
| 1806 | { |
| 1807 | *typep = create_fundamental_type (objfile, typeid); |
| 1808 | } |
| 1809 | |
| 1810 | return (*typep); |
| 1811 | } |
| 1812 | |
| 1813 | int |
| 1814 | can_dereference (struct type *t) |
| 1815 | { |
| 1816 | /* FIXME: Should we return true for references as well as pointers? */ |
| 1817 | CHECK_TYPEDEF (t); |
| 1818 | return |
| 1819 | (t != NULL |
| 1820 | && TYPE_CODE (t) == TYPE_CODE_PTR |
| 1821 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); |
| 1822 | } |
| 1823 | |
| 1824 | int |
| 1825 | is_integral_type (struct type *t) |
| 1826 | { |
| 1827 | CHECK_TYPEDEF (t); |
| 1828 | return |
| 1829 | ((t != NULL) |
| 1830 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
| 1831 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) |
| 1832 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) |
| 1833 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) |
| 1834 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); |
| 1835 | } |
| 1836 | |
| 1837 | /* Check whether BASE is an ancestor or base class or DCLASS |
| 1838 | Return 1 if so, and 0 if not. |
| 1839 | Note: callers may want to check for identity of the types before |
| 1840 | calling this function -- identical types are considered to satisfy |
| 1841 | the ancestor relationship even if they're identical */ |
| 1842 | |
| 1843 | int |
| 1844 | is_ancestor (struct type *base, struct type *dclass) |
| 1845 | { |
| 1846 | int i; |
| 1847 | |
| 1848 | CHECK_TYPEDEF (base); |
| 1849 | CHECK_TYPEDEF (dclass); |
| 1850 | |
| 1851 | if (base == dclass) |
| 1852 | return 1; |
| 1853 | if (TYPE_NAME (base) && TYPE_NAME (dclass) && |
| 1854 | !strcmp (TYPE_NAME (base), TYPE_NAME (dclass))) |
| 1855 | return 1; |
| 1856 | |
| 1857 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1858 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) |
| 1859 | return 1; |
| 1860 | |
| 1861 | return 0; |
| 1862 | } |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | /* See whether DCLASS has a virtual table. This routine is aimed at |
| 1867 | the HP/Taligent ANSI C++ runtime model, and may not work with other |
| 1868 | runtime models. Return 1 => Yes, 0 => No. */ |
| 1869 | |
| 1870 | int |
| 1871 | has_vtable (struct type *dclass) |
| 1872 | { |
| 1873 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it |
| 1874 | has virtual functions or virtual bases. */ |
| 1875 | |
| 1876 | int i; |
| 1877 | |
| 1878 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
| 1879 | return 0; |
| 1880 | |
| 1881 | /* First check for the presence of virtual bases */ |
| 1882 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
| 1883 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1884 | if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) |
| 1885 | return 1; |
| 1886 | |
| 1887 | /* Next check for virtual functions */ |
| 1888 | if (TYPE_FN_FIELDLISTS (dclass)) |
| 1889 | for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++) |
| 1890 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0)) |
| 1891 | return 1; |
| 1892 | |
| 1893 | /* Recurse on non-virtual bases to see if any of them needs a vtable */ |
| 1894 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
| 1895 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1896 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) && |
| 1897 | (has_vtable (TYPE_FIELD_TYPE (dclass, i)))) |
| 1898 | return 1; |
| 1899 | |
| 1900 | /* Well, maybe we don't need a virtual table */ |
| 1901 | return 0; |
| 1902 | } |
| 1903 | |
| 1904 | /* Return a pointer to the "primary base class" of DCLASS. |
| 1905 | |
| 1906 | A NULL return indicates that DCLASS has no primary base, or that it |
| 1907 | couldn't be found (insufficient information). |
| 1908 | |
| 1909 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
| 1910 | and may not work with other runtime models. */ |
| 1911 | |
| 1912 | struct type * |
| 1913 | primary_base_class (struct type *dclass) |
| 1914 | { |
| 1915 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class |
| 1916 | is the first directly inherited, non-virtual base class that |
| 1917 | requires a virtual table */ |
| 1918 | |
| 1919 | int i; |
| 1920 | |
| 1921 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
| 1922 | return NULL; |
| 1923 | |
| 1924 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1925 | if (!TYPE_FIELD_VIRTUAL (dclass, i) && |
| 1926 | has_vtable (TYPE_FIELD_TYPE (dclass, i))) |
| 1927 | return TYPE_FIELD_TYPE (dclass, i); |
| 1928 | |
| 1929 | return NULL; |
| 1930 | } |
| 1931 | |
| 1932 | /* Global manipulated by virtual_base_list[_aux]() */ |
| 1933 | |
| 1934 | static struct vbase *current_vbase_list = NULL; |
| 1935 | |
| 1936 | /* Return a pointer to a null-terminated list of struct vbase |
| 1937 | items. The vbasetype pointer of each item in the list points to the |
| 1938 | type information for a virtual base of the argument DCLASS. |
| 1939 | |
| 1940 | Helper function for virtual_base_list(). |
| 1941 | Note: the list goes backward, right-to-left. virtual_base_list() |
| 1942 | copies the items out in reverse order. */ |
| 1943 | |
| 1944 | static void |
| 1945 | virtual_base_list_aux (struct type *dclass) |
| 1946 | { |
| 1947 | struct vbase *tmp_vbase; |
| 1948 | int i; |
| 1949 | |
| 1950 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
| 1951 | return; |
| 1952 | |
| 1953 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
| 1954 | { |
| 1955 | /* Recurse on this ancestor, first */ |
| 1956 | virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i)); |
| 1957 | |
| 1958 | /* If this current base is itself virtual, add it to the list */ |
| 1959 | if (BASETYPE_VIA_VIRTUAL (dclass, i)) |
| 1960 | { |
| 1961 | struct type *basetype = TYPE_FIELD_TYPE (dclass, i); |
| 1962 | |
| 1963 | /* Check if base already recorded */ |
| 1964 | tmp_vbase = current_vbase_list; |
| 1965 | while (tmp_vbase) |
| 1966 | { |
| 1967 | if (tmp_vbase->vbasetype == basetype) |
| 1968 | break; /* found it */ |
| 1969 | tmp_vbase = tmp_vbase->next; |
| 1970 | } |
| 1971 | |
| 1972 | if (!tmp_vbase) /* normal exit from loop */ |
| 1973 | { |
| 1974 | /* Allocate new item for this virtual base */ |
| 1975 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); |
| 1976 | |
| 1977 | /* Stick it on at the end of the list */ |
| 1978 | tmp_vbase->vbasetype = basetype; |
| 1979 | tmp_vbase->next = current_vbase_list; |
| 1980 | current_vbase_list = tmp_vbase; |
| 1981 | } |
| 1982 | } /* if virtual */ |
| 1983 | } /* for loop over bases */ |
| 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | /* Compute the list of virtual bases in the right order. Virtual |
| 1988 | bases are laid out in the object's memory area in order of their |
| 1989 | occurrence in a depth-first, left-to-right search through the |
| 1990 | ancestors. |
| 1991 | |
| 1992 | Argument DCLASS is the type whose virtual bases are required. |
| 1993 | Return value is the address of a null-terminated array of pointers |
| 1994 | to struct type items. |
| 1995 | |
| 1996 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
| 1997 | and may not work with other runtime models. |
| 1998 | |
| 1999 | This routine merely hands off the argument to virtual_base_list_aux() |
| 2000 | and then copies the result into an array to save space. */ |
| 2001 | |
| 2002 | struct type ** |
| 2003 | virtual_base_list (struct type *dclass) |
| 2004 | { |
| 2005 | struct vbase *tmp_vbase; |
| 2006 | struct vbase *tmp_vbase_2; |
| 2007 | int i; |
| 2008 | int count; |
| 2009 | struct type **vbase_array; |
| 2010 | |
| 2011 | current_vbase_list = NULL; |
| 2012 | virtual_base_list_aux (dclass); |
| 2013 | |
| 2014 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
| 2015 | /* no body */ ; |
| 2016 | |
| 2017 | count = i; |
| 2018 | |
| 2019 | vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *)); |
| 2020 | |
| 2021 | for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next) |
| 2022 | vbase_array[i] = tmp_vbase->vbasetype; |
| 2023 | |
| 2024 | /* Get rid of constructed chain */ |
| 2025 | tmp_vbase_2 = tmp_vbase = current_vbase_list; |
| 2026 | while (tmp_vbase) |
| 2027 | { |
| 2028 | tmp_vbase = tmp_vbase->next; |
| 2029 | xfree (tmp_vbase_2); |
| 2030 | tmp_vbase_2 = tmp_vbase; |
| 2031 | } |
| 2032 | |
| 2033 | vbase_array[count] = NULL; |
| 2034 | return vbase_array; |
| 2035 | } |
| 2036 | |
| 2037 | /* Return the length of the virtual base list of the type DCLASS. */ |
| 2038 | |
| 2039 | int |
| 2040 | virtual_base_list_length (struct type *dclass) |
| 2041 | { |
| 2042 | int i; |
| 2043 | struct vbase *tmp_vbase; |
| 2044 | |
| 2045 | current_vbase_list = NULL; |
| 2046 | virtual_base_list_aux (dclass); |
| 2047 | |
| 2048 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
| 2049 | /* no body */ ; |
| 2050 | return i; |
| 2051 | } |
| 2052 | |
| 2053 | /* Return the number of elements of the virtual base list of the type |
| 2054 | DCLASS, ignoring those appearing in the primary base (and its |
| 2055 | primary base, recursively). */ |
| 2056 | |
| 2057 | int |
| 2058 | virtual_base_list_length_skip_primaries (struct type *dclass) |
| 2059 | { |
| 2060 | int i; |
| 2061 | struct vbase *tmp_vbase; |
| 2062 | struct type *primary; |
| 2063 | |
| 2064 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
| 2065 | |
| 2066 | if (!primary) |
| 2067 | return virtual_base_list_length (dclass); |
| 2068 | |
| 2069 | current_vbase_list = NULL; |
| 2070 | virtual_base_list_aux (dclass); |
| 2071 | |
| 2072 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next) |
| 2073 | { |
| 2074 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) |
| 2075 | continue; |
| 2076 | i++; |
| 2077 | } |
| 2078 | return i; |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | /* Return the index (position) of type BASE, which is a virtual base |
| 2083 | class of DCLASS, in the latter's virtual base list. A return of -1 |
| 2084 | indicates "not found" or a problem. */ |
| 2085 | |
| 2086 | int |
| 2087 | virtual_base_index (struct type *base, struct type *dclass) |
| 2088 | { |
| 2089 | struct type *vbase; |
| 2090 | int i; |
| 2091 | |
| 2092 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
| 2093 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) |
| 2094 | return -1; |
| 2095 | |
| 2096 | i = 0; |
| 2097 | vbase = virtual_base_list (dclass)[0]; |
| 2098 | while (vbase) |
| 2099 | { |
| 2100 | if (vbase == base) |
| 2101 | break; |
| 2102 | vbase = virtual_base_list (dclass)[++i]; |
| 2103 | } |
| 2104 | |
| 2105 | return vbase ? i : -1; |
| 2106 | } |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | /* Return the index (position) of type BASE, which is a virtual base |
| 2111 | class of DCLASS, in the latter's virtual base list. Skip over all |
| 2112 | bases that may appear in the virtual base list of the primary base |
| 2113 | class of DCLASS (recursively). A return of -1 indicates "not |
| 2114 | found" or a problem. */ |
| 2115 | |
| 2116 | int |
| 2117 | virtual_base_index_skip_primaries (struct type *base, struct type *dclass) |
| 2118 | { |
| 2119 | struct type *vbase; |
| 2120 | int i, j; |
| 2121 | struct type *primary; |
| 2122 | |
| 2123 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
| 2124 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) |
| 2125 | return -1; |
| 2126 | |
| 2127 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
| 2128 | |
| 2129 | j = -1; |
| 2130 | i = 0; |
| 2131 | vbase = virtual_base_list (dclass)[0]; |
| 2132 | while (vbase) |
| 2133 | { |
| 2134 | if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0)) |
| 2135 | j++; |
| 2136 | if (vbase == base) |
| 2137 | break; |
| 2138 | vbase = virtual_base_list (dclass)[++i]; |
| 2139 | } |
| 2140 | |
| 2141 | return vbase ? j : -1; |
| 2142 | } |
| 2143 | |
| 2144 | /* Return position of a derived class DCLASS in the list of |
| 2145 | * primary bases starting with the remotest ancestor. |
| 2146 | * Position returned is 0-based. */ |
| 2147 | |
| 2148 | int |
| 2149 | class_index_in_primary_list (struct type *dclass) |
| 2150 | { |
| 2151 | struct type *pbc; /* primary base class */ |
| 2152 | |
| 2153 | /* Simply recurse on primary base */ |
| 2154 | pbc = TYPE_PRIMARY_BASE (dclass); |
| 2155 | if (pbc) |
| 2156 | return 1 + class_index_in_primary_list (pbc); |
| 2157 | else |
| 2158 | return 0; |
| 2159 | } |
| 2160 | |
| 2161 | /* Return a count of the number of virtual functions a type has. |
| 2162 | * This includes all the virtual functions it inherits from its |
| 2163 | * base classes too. |
| 2164 | */ |
| 2165 | |
| 2166 | /* pai: FIXME This doesn't do the right thing: count redefined virtual |
| 2167 | * functions only once (latest redefinition) |
| 2168 | */ |
| 2169 | |
| 2170 | int |
| 2171 | count_virtual_fns (struct type *dclass) |
| 2172 | { |
| 2173 | int fn, oi; /* function and overloaded instance indices */ |
| 2174 | int vfuncs; /* count to return */ |
| 2175 | |
| 2176 | /* recurse on bases that can share virtual table */ |
| 2177 | struct type *pbc = primary_base_class (dclass); |
| 2178 | if (pbc) |
| 2179 | vfuncs = count_virtual_fns (pbc); |
| 2180 | else |
| 2181 | vfuncs = 0; |
| 2182 | |
| 2183 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
| 2184 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) |
| 2185 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) |
| 2186 | vfuncs++; |
| 2187 | |
| 2188 | return vfuncs; |
| 2189 | } |
| 2190 | \f |
| 2191 | |
| 2192 | |
| 2193 | /* Functions for overload resolution begin here */ |
| 2194 | |
| 2195 | /* Compare two badness vectors A and B and return the result. |
| 2196 | * 0 => A and B are identical |
| 2197 | * 1 => A and B are incomparable |
| 2198 | * 2 => A is better than B |
| 2199 | * 3 => A is worse than B */ |
| 2200 | |
| 2201 | int |
| 2202 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
| 2203 | { |
| 2204 | int i; |
| 2205 | int tmp; |
| 2206 | short found_pos = 0; /* any positives in c? */ |
| 2207 | short found_neg = 0; /* any negatives in c? */ |
| 2208 | |
| 2209 | /* differing lengths => incomparable */ |
| 2210 | if (a->length != b->length) |
| 2211 | return 1; |
| 2212 | |
| 2213 | /* Subtract b from a */ |
| 2214 | for (i = 0; i < a->length; i++) |
| 2215 | { |
| 2216 | tmp = a->rank[i] - b->rank[i]; |
| 2217 | if (tmp > 0) |
| 2218 | found_pos = 1; |
| 2219 | else if (tmp < 0) |
| 2220 | found_neg = 1; |
| 2221 | } |
| 2222 | |
| 2223 | if (found_pos) |
| 2224 | { |
| 2225 | if (found_neg) |
| 2226 | return 1; /* incomparable */ |
| 2227 | else |
| 2228 | return 3; /* A > B */ |
| 2229 | } |
| 2230 | else |
| 2231 | /* no positives */ |
| 2232 | { |
| 2233 | if (found_neg) |
| 2234 | return 2; /* A < B */ |
| 2235 | else |
| 2236 | return 0; /* A == B */ |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | /* Rank a function by comparing its parameter types (PARMS, length NPARMS), |
| 2241 | * to the types of an argument list (ARGS, length NARGS). |
| 2242 | * Return a pointer to a badness vector. This has NARGS + 1 entries. */ |
| 2243 | |
| 2244 | struct badness_vector * |
| 2245 | rank_function (struct type **parms, int nparms, struct type **args, int nargs) |
| 2246 | { |
| 2247 | int i; |
| 2248 | struct badness_vector *bv; |
| 2249 | int min_len = nparms < nargs ? nparms : nargs; |
| 2250 | |
| 2251 | bv = xmalloc (sizeof (struct badness_vector)); |
| 2252 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
| 2253 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
| 2254 | |
| 2255 | /* First compare the lengths of the supplied lists. |
| 2256 | * If there is a mismatch, set it to a high value. */ |
| 2257 | |
| 2258 | /* pai/1997-06-03 FIXME: when we have debug info about default |
| 2259 | * arguments and ellipsis parameter lists, we should consider those |
| 2260 | * and rank the length-match more finely. */ |
| 2261 | |
| 2262 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; |
| 2263 | |
| 2264 | /* Now rank all the parameters of the candidate function */ |
| 2265 | for (i = 1; i <= min_len; i++) |
| 2266 | bv->rank[i] = rank_one_type (parms[i-1], args[i-1]); |
| 2267 | |
| 2268 | /* If more arguments than parameters, add dummy entries */ |
| 2269 | for (i = min_len + 1; i <= nargs; i++) |
| 2270 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
| 2271 | |
| 2272 | return bv; |
| 2273 | } |
| 2274 | |
| 2275 | /* Compare the names of two integer types, assuming that any sign |
| 2276 | qualifiers have been checked already. We do it this way because |
| 2277 | there may be an "int" in the name of one of the types. */ |
| 2278 | |
| 2279 | static int |
| 2280 | integer_types_same_name_p (const char *first, const char *second) |
| 2281 | { |
| 2282 | int first_p, second_p; |
| 2283 | |
| 2284 | /* If both are shorts, return 1; if neither is a short, keep checking. */ |
| 2285 | first_p = (strstr (first, "short") != NULL); |
| 2286 | second_p = (strstr (second, "short") != NULL); |
| 2287 | if (first_p && second_p) |
| 2288 | return 1; |
| 2289 | if (first_p || second_p) |
| 2290 | return 0; |
| 2291 | |
| 2292 | /* Likewise for long. */ |
| 2293 | first_p = (strstr (first, "long") != NULL); |
| 2294 | second_p = (strstr (second, "long") != NULL); |
| 2295 | if (first_p && second_p) |
| 2296 | return 1; |
| 2297 | if (first_p || second_p) |
| 2298 | return 0; |
| 2299 | |
| 2300 | /* Likewise for char. */ |
| 2301 | first_p = (strstr (first, "char") != NULL); |
| 2302 | second_p = (strstr (second, "char") != NULL); |
| 2303 | if (first_p && second_p) |
| 2304 | return 1; |
| 2305 | if (first_p || second_p) |
| 2306 | return 0; |
| 2307 | |
| 2308 | /* They must both be ints. */ |
| 2309 | return 1; |
| 2310 | } |
| 2311 | |
| 2312 | /* Compare one type (PARM) for compatibility with another (ARG). |
| 2313 | * PARM is intended to be the parameter type of a function; and |
| 2314 | * ARG is the supplied argument's type. This function tests if |
| 2315 | * the latter can be converted to the former. |
| 2316 | * |
| 2317 | * Return 0 if they are identical types; |
| 2318 | * Otherwise, return an integer which corresponds to how compatible |
| 2319 | * PARM is to ARG. The higher the return value, the worse the match. |
| 2320 | * Generally the "bad" conversions are all uniformly assigned a 100 */ |
| 2321 | |
| 2322 | int |
| 2323 | rank_one_type (struct type *parm, struct type *arg) |
| 2324 | { |
| 2325 | /* Identical type pointers */ |
| 2326 | /* However, this still doesn't catch all cases of same type for arg |
| 2327 | * and param. The reason is that builtin types are different from |
| 2328 | * the same ones constructed from the object. */ |
| 2329 | if (parm == arg) |
| 2330 | return 0; |
| 2331 | |
| 2332 | /* Resolve typedefs */ |
| 2333 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) |
| 2334 | parm = check_typedef (parm); |
| 2335 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) |
| 2336 | arg = check_typedef (arg); |
| 2337 | |
| 2338 | /* |
| 2339 | Well, damnit, if the names are exactly the same, |
| 2340 | i'll say they are exactly the same. This happens when we generate |
| 2341 | method stubs. The types won't point to the same address, but they |
| 2342 | really are the same. |
| 2343 | */ |
| 2344 | |
| 2345 | if (TYPE_NAME (parm) && TYPE_NAME (arg) && |
| 2346 | !strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) |
| 2347 | return 0; |
| 2348 | |
| 2349 | /* Check if identical after resolving typedefs */ |
| 2350 | if (parm == arg) |
| 2351 | return 0; |
| 2352 | |
| 2353 | /* See through references, since we can almost make non-references |
| 2354 | references. */ |
| 2355 | if (TYPE_CODE (arg) == TYPE_CODE_REF) |
| 2356 | return (rank_one_type (parm, TYPE_TARGET_TYPE (arg)) |
| 2357 | + REFERENCE_CONVERSION_BADNESS); |
| 2358 | if (TYPE_CODE (parm) == TYPE_CODE_REF) |
| 2359 | return (rank_one_type (TYPE_TARGET_TYPE (parm), arg) |
| 2360 | + REFERENCE_CONVERSION_BADNESS); |
| 2361 | if (overload_debug) |
| 2362 | /* Debugging only. */ |
| 2363 | fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n", |
| 2364 | TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm)); |
| 2365 | |
| 2366 | /* x -> y means arg of type x being supplied for parameter of type y */ |
| 2367 | |
| 2368 | switch (TYPE_CODE (parm)) |
| 2369 | { |
| 2370 | case TYPE_CODE_PTR: |
| 2371 | switch (TYPE_CODE (arg)) |
| 2372 | { |
| 2373 | case TYPE_CODE_PTR: |
| 2374 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) |
| 2375 | return VOID_PTR_CONVERSION_BADNESS; |
| 2376 | else |
| 2377 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); |
| 2378 | case TYPE_CODE_ARRAY: |
| 2379 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); |
| 2380 | case TYPE_CODE_FUNC: |
| 2381 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); |
| 2382 | case TYPE_CODE_INT: |
| 2383 | case TYPE_CODE_ENUM: |
| 2384 | case TYPE_CODE_CHAR: |
| 2385 | case TYPE_CODE_RANGE: |
| 2386 | case TYPE_CODE_BOOL: |
| 2387 | return POINTER_CONVERSION_BADNESS; |
| 2388 | default: |
| 2389 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2390 | } |
| 2391 | case TYPE_CODE_ARRAY: |
| 2392 | switch (TYPE_CODE (arg)) |
| 2393 | { |
| 2394 | case TYPE_CODE_PTR: |
| 2395 | case TYPE_CODE_ARRAY: |
| 2396 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); |
| 2397 | default: |
| 2398 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2399 | } |
| 2400 | case TYPE_CODE_FUNC: |
| 2401 | switch (TYPE_CODE (arg)) |
| 2402 | { |
| 2403 | case TYPE_CODE_PTR: /* funcptr -> func */ |
| 2404 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); |
| 2405 | default: |
| 2406 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2407 | } |
| 2408 | case TYPE_CODE_INT: |
| 2409 | switch (TYPE_CODE (arg)) |
| 2410 | { |
| 2411 | case TYPE_CODE_INT: |
| 2412 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) |
| 2413 | { |
| 2414 | /* Deal with signed, unsigned, and plain chars and |
| 2415 | signed and unsigned ints */ |
| 2416 | if (TYPE_NOSIGN (parm)) |
| 2417 | { |
| 2418 | /* This case only for character types */ |
| 2419 | if (TYPE_NOSIGN (arg)) /* plain char -> plain char */ |
| 2420 | return 0; |
| 2421 | else |
| 2422 | return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */ |
| 2423 | } |
| 2424 | else if (TYPE_UNSIGNED (parm)) |
| 2425 | { |
| 2426 | if (TYPE_UNSIGNED (arg)) |
| 2427 | { |
| 2428 | /* unsigned int -> unsigned int, or unsigned long -> unsigned long */ |
| 2429 | if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg))) |
| 2430 | return 0; |
| 2431 | else if (integer_types_same_name_p (TYPE_NAME (arg), "int") |
| 2432 | && integer_types_same_name_p (TYPE_NAME (parm), "long")) |
| 2433 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ |
| 2434 | else |
| 2435 | return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */ |
| 2436 | } |
| 2437 | else |
| 2438 | { |
| 2439 | if (integer_types_same_name_p (TYPE_NAME (arg), "long") |
| 2440 | && integer_types_same_name_p (TYPE_NAME (parm), "int")) |
| 2441 | return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */ |
| 2442 | else |
| 2443 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ |
| 2444 | } |
| 2445 | } |
| 2446 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) |
| 2447 | { |
| 2448 | if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg))) |
| 2449 | return 0; |
| 2450 | else if (integer_types_same_name_p (TYPE_NAME (arg), "int") |
| 2451 | && integer_types_same_name_p (TYPE_NAME (parm), "long")) |
| 2452 | return INTEGER_PROMOTION_BADNESS; |
| 2453 | else |
| 2454 | return INTEGER_CONVERSION_BADNESS; |
| 2455 | } |
| 2456 | else |
| 2457 | return INTEGER_CONVERSION_BADNESS; |
| 2458 | } |
| 2459 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
| 2460 | return INTEGER_PROMOTION_BADNESS; |
| 2461 | else |
| 2462 | return INTEGER_CONVERSION_BADNESS; |
| 2463 | case TYPE_CODE_ENUM: |
| 2464 | case TYPE_CODE_CHAR: |
| 2465 | case TYPE_CODE_RANGE: |
| 2466 | case TYPE_CODE_BOOL: |
| 2467 | return INTEGER_PROMOTION_BADNESS; |
| 2468 | case TYPE_CODE_FLT: |
| 2469 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2470 | case TYPE_CODE_PTR: |
| 2471 | return NS_POINTER_CONVERSION_BADNESS; |
| 2472 | default: |
| 2473 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2474 | } |
| 2475 | break; |
| 2476 | case TYPE_CODE_ENUM: |
| 2477 | switch (TYPE_CODE (arg)) |
| 2478 | { |
| 2479 | case TYPE_CODE_INT: |
| 2480 | case TYPE_CODE_CHAR: |
| 2481 | case TYPE_CODE_RANGE: |
| 2482 | case TYPE_CODE_BOOL: |
| 2483 | case TYPE_CODE_ENUM: |
| 2484 | return INTEGER_CONVERSION_BADNESS; |
| 2485 | case TYPE_CODE_FLT: |
| 2486 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2487 | default: |
| 2488 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2489 | } |
| 2490 | break; |
| 2491 | case TYPE_CODE_CHAR: |
| 2492 | switch (TYPE_CODE (arg)) |
| 2493 | { |
| 2494 | case TYPE_CODE_RANGE: |
| 2495 | case TYPE_CODE_BOOL: |
| 2496 | case TYPE_CODE_ENUM: |
| 2497 | return INTEGER_CONVERSION_BADNESS; |
| 2498 | case TYPE_CODE_FLT: |
| 2499 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2500 | case TYPE_CODE_INT: |
| 2501 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) |
| 2502 | return INTEGER_CONVERSION_BADNESS; |
| 2503 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
| 2504 | return INTEGER_PROMOTION_BADNESS; |
| 2505 | /* >>> !! else fall through !! <<< */ |
| 2506 | case TYPE_CODE_CHAR: |
| 2507 | /* Deal with signed, unsigned, and plain chars for C++ |
| 2508 | and with int cases falling through from previous case */ |
| 2509 | if (TYPE_NOSIGN (parm)) |
| 2510 | { |
| 2511 | if (TYPE_NOSIGN (arg)) |
| 2512 | return 0; |
| 2513 | else |
| 2514 | return INTEGER_CONVERSION_BADNESS; |
| 2515 | } |
| 2516 | else if (TYPE_UNSIGNED (parm)) |
| 2517 | { |
| 2518 | if (TYPE_UNSIGNED (arg)) |
| 2519 | return 0; |
| 2520 | else |
| 2521 | return INTEGER_PROMOTION_BADNESS; |
| 2522 | } |
| 2523 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) |
| 2524 | return 0; |
| 2525 | else |
| 2526 | return INTEGER_CONVERSION_BADNESS; |
| 2527 | default: |
| 2528 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2529 | } |
| 2530 | break; |
| 2531 | case TYPE_CODE_RANGE: |
| 2532 | switch (TYPE_CODE (arg)) |
| 2533 | { |
| 2534 | case TYPE_CODE_INT: |
| 2535 | case TYPE_CODE_CHAR: |
| 2536 | case TYPE_CODE_RANGE: |
| 2537 | case TYPE_CODE_BOOL: |
| 2538 | case TYPE_CODE_ENUM: |
| 2539 | return INTEGER_CONVERSION_BADNESS; |
| 2540 | case TYPE_CODE_FLT: |
| 2541 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2542 | default: |
| 2543 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2544 | } |
| 2545 | break; |
| 2546 | case TYPE_CODE_BOOL: |
| 2547 | switch (TYPE_CODE (arg)) |
| 2548 | { |
| 2549 | case TYPE_CODE_INT: |
| 2550 | case TYPE_CODE_CHAR: |
| 2551 | case TYPE_CODE_RANGE: |
| 2552 | case TYPE_CODE_ENUM: |
| 2553 | case TYPE_CODE_FLT: |
| 2554 | case TYPE_CODE_PTR: |
| 2555 | return BOOLEAN_CONVERSION_BADNESS; |
| 2556 | case TYPE_CODE_BOOL: |
| 2557 | return 0; |
| 2558 | default: |
| 2559 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2560 | } |
| 2561 | break; |
| 2562 | case TYPE_CODE_FLT: |
| 2563 | switch (TYPE_CODE (arg)) |
| 2564 | { |
| 2565 | case TYPE_CODE_FLT: |
| 2566 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
| 2567 | return FLOAT_PROMOTION_BADNESS; |
| 2568 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) |
| 2569 | return 0; |
| 2570 | else |
| 2571 | return FLOAT_CONVERSION_BADNESS; |
| 2572 | case TYPE_CODE_INT: |
| 2573 | case TYPE_CODE_BOOL: |
| 2574 | case TYPE_CODE_ENUM: |
| 2575 | case TYPE_CODE_RANGE: |
| 2576 | case TYPE_CODE_CHAR: |
| 2577 | return INT_FLOAT_CONVERSION_BADNESS; |
| 2578 | default: |
| 2579 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2580 | } |
| 2581 | break; |
| 2582 | case TYPE_CODE_COMPLEX: |
| 2583 | switch (TYPE_CODE (arg)) |
| 2584 | { /* Strictly not needed for C++, but... */ |
| 2585 | case TYPE_CODE_FLT: |
| 2586 | return FLOAT_PROMOTION_BADNESS; |
| 2587 | case TYPE_CODE_COMPLEX: |
| 2588 | return 0; |
| 2589 | default: |
| 2590 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2591 | } |
| 2592 | break; |
| 2593 | case TYPE_CODE_STRUCT: |
| 2594 | /* currently same as TYPE_CODE_CLASS */ |
| 2595 | switch (TYPE_CODE (arg)) |
| 2596 | { |
| 2597 | case TYPE_CODE_STRUCT: |
| 2598 | /* Check for derivation */ |
| 2599 | if (is_ancestor (parm, arg)) |
| 2600 | return BASE_CONVERSION_BADNESS; |
| 2601 | /* else fall through */ |
| 2602 | default: |
| 2603 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2604 | } |
| 2605 | break; |
| 2606 | case TYPE_CODE_UNION: |
| 2607 | switch (TYPE_CODE (arg)) |
| 2608 | { |
| 2609 | case TYPE_CODE_UNION: |
| 2610 | default: |
| 2611 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2612 | } |
| 2613 | break; |
| 2614 | case TYPE_CODE_MEMBER: |
| 2615 | switch (TYPE_CODE (arg)) |
| 2616 | { |
| 2617 | default: |
| 2618 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2619 | } |
| 2620 | break; |
| 2621 | case TYPE_CODE_METHOD: |
| 2622 | switch (TYPE_CODE (arg)) |
| 2623 | { |
| 2624 | |
| 2625 | default: |
| 2626 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2627 | } |
| 2628 | break; |
| 2629 | case TYPE_CODE_REF: |
| 2630 | switch (TYPE_CODE (arg)) |
| 2631 | { |
| 2632 | |
| 2633 | default: |
| 2634 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2635 | } |
| 2636 | |
| 2637 | break; |
| 2638 | case TYPE_CODE_SET: |
| 2639 | switch (TYPE_CODE (arg)) |
| 2640 | { |
| 2641 | /* Not in C++ */ |
| 2642 | case TYPE_CODE_SET: |
| 2643 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0)); |
| 2644 | default: |
| 2645 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2646 | } |
| 2647 | break; |
| 2648 | case TYPE_CODE_VOID: |
| 2649 | default: |
| 2650 | return INCOMPATIBLE_TYPE_BADNESS; |
| 2651 | } /* switch (TYPE_CODE (arg)) */ |
| 2652 | } |
| 2653 | |
| 2654 | |
| 2655 | /* End of functions for overload resolution */ |
| 2656 | |
| 2657 | static void |
| 2658 | print_bit_vector (B_TYPE *bits, int nbits) |
| 2659 | { |
| 2660 | int bitno; |
| 2661 | |
| 2662 | for (bitno = 0; bitno < nbits; bitno++) |
| 2663 | { |
| 2664 | if ((bitno % 8) == 0) |
| 2665 | { |
| 2666 | puts_filtered (" "); |
| 2667 | } |
| 2668 | if (B_TST (bits, bitno)) |
| 2669 | { |
| 2670 | printf_filtered ("1"); |
| 2671 | } |
| 2672 | else |
| 2673 | { |
| 2674 | printf_filtered ("0"); |
| 2675 | } |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | /* Note the first arg should be the "this" pointer, we may not want to |
| 2680 | include it since we may get into a infinitely recursive situation. */ |
| 2681 | |
| 2682 | static void |
| 2683 | print_arg_types (struct field *args, int nargs, int spaces) |
| 2684 | { |
| 2685 | if (args != NULL) |
| 2686 | { |
| 2687 | int i; |
| 2688 | |
| 2689 | for (i = 0; i < nargs; i++) |
| 2690 | recursive_dump_type (args[i].type, spaces + 2); |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | static void |
| 2695 | dump_fn_fieldlists (struct type *type, int spaces) |
| 2696 | { |
| 2697 | int method_idx; |
| 2698 | int overload_idx; |
| 2699 | struct fn_field *f; |
| 2700 | |
| 2701 | printfi_filtered (spaces, "fn_fieldlists "); |
| 2702 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
| 2703 | printf_filtered ("\n"); |
| 2704 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) |
| 2705 | { |
| 2706 | f = TYPE_FN_FIELDLIST1 (type, method_idx); |
| 2707 | printfi_filtered (spaces + 2, "[%d] name '%s' (", |
| 2708 | method_idx, |
| 2709 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); |
| 2710 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
| 2711 | gdb_stdout); |
| 2712 | printf_filtered (") length %d\n", |
| 2713 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); |
| 2714 | for (overload_idx = 0; |
| 2715 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); |
| 2716 | overload_idx++) |
| 2717 | { |
| 2718 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", |
| 2719 | overload_idx, |
| 2720 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); |
| 2721 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
| 2722 | gdb_stdout); |
| 2723 | printf_filtered (")\n"); |
| 2724 | printfi_filtered (spaces + 8, "type "); |
| 2725 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); |
| 2726 | printf_filtered ("\n"); |
| 2727 | |
| 2728 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), |
| 2729 | spaces + 8 + 2); |
| 2730 | |
| 2731 | printfi_filtered (spaces + 8, "args "); |
| 2732 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); |
| 2733 | printf_filtered ("\n"); |
| 2734 | |
| 2735 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), |
| 2736 | TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)), |
| 2737 | spaces); |
| 2738 | printfi_filtered (spaces + 8, "fcontext "); |
| 2739 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
| 2740 | gdb_stdout); |
| 2741 | printf_filtered ("\n"); |
| 2742 | |
| 2743 | printfi_filtered (spaces + 8, "is_const %d\n", |
| 2744 | TYPE_FN_FIELD_CONST (f, overload_idx)); |
| 2745 | printfi_filtered (spaces + 8, "is_volatile %d\n", |
| 2746 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); |
| 2747 | printfi_filtered (spaces + 8, "is_private %d\n", |
| 2748 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); |
| 2749 | printfi_filtered (spaces + 8, "is_protected %d\n", |
| 2750 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); |
| 2751 | printfi_filtered (spaces + 8, "is_stub %d\n", |
| 2752 | TYPE_FN_FIELD_STUB (f, overload_idx)); |
| 2753 | printfi_filtered (spaces + 8, "voffset %u\n", |
| 2754 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); |
| 2755 | } |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | static void |
| 2760 | print_cplus_stuff (struct type *type, int spaces) |
| 2761 | { |
| 2762 | printfi_filtered (spaces, "n_baseclasses %d\n", |
| 2763 | TYPE_N_BASECLASSES (type)); |
| 2764 | printfi_filtered (spaces, "nfn_fields %d\n", |
| 2765 | TYPE_NFN_FIELDS (type)); |
| 2766 | printfi_filtered (spaces, "nfn_fields_total %d\n", |
| 2767 | TYPE_NFN_FIELDS_TOTAL (type)); |
| 2768 | if (TYPE_N_BASECLASSES (type) > 0) |
| 2769 | { |
| 2770 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", |
| 2771 | TYPE_N_BASECLASSES (type)); |
| 2772 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); |
| 2773 | printf_filtered (")"); |
| 2774 | |
| 2775 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), |
| 2776 | TYPE_N_BASECLASSES (type)); |
| 2777 | puts_filtered ("\n"); |
| 2778 | } |
| 2779 | if (TYPE_NFIELDS (type) > 0) |
| 2780 | { |
| 2781 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) |
| 2782 | { |
| 2783 | printfi_filtered (spaces, "private_field_bits (%d bits at *", |
| 2784 | TYPE_NFIELDS (type)); |
| 2785 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); |
| 2786 | printf_filtered (")"); |
| 2787 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), |
| 2788 | TYPE_NFIELDS (type)); |
| 2789 | puts_filtered ("\n"); |
| 2790 | } |
| 2791 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) |
| 2792 | { |
| 2793 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", |
| 2794 | TYPE_NFIELDS (type)); |
| 2795 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); |
| 2796 | printf_filtered (")"); |
| 2797 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), |
| 2798 | TYPE_NFIELDS (type)); |
| 2799 | puts_filtered ("\n"); |
| 2800 | } |
| 2801 | } |
| 2802 | if (TYPE_NFN_FIELDS (type) > 0) |
| 2803 | { |
| 2804 | dump_fn_fieldlists (type, spaces); |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | static void |
| 2809 | print_bound_type (int bt) |
| 2810 | { |
| 2811 | switch (bt) |
| 2812 | { |
| 2813 | case BOUND_CANNOT_BE_DETERMINED: |
| 2814 | printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)"); |
| 2815 | break; |
| 2816 | case BOUND_BY_REF_ON_STACK: |
| 2817 | printf_filtered ("(BOUND_BY_REF_ON_STACK)"); |
| 2818 | break; |
| 2819 | case BOUND_BY_VALUE_ON_STACK: |
| 2820 | printf_filtered ("(BOUND_BY_VALUE_ON_STACK)"); |
| 2821 | break; |
| 2822 | case BOUND_BY_REF_IN_REG: |
| 2823 | printf_filtered ("(BOUND_BY_REF_IN_REG)"); |
| 2824 | break; |
| 2825 | case BOUND_BY_VALUE_IN_REG: |
| 2826 | printf_filtered ("(BOUND_BY_VALUE_IN_REG)"); |
| 2827 | break; |
| 2828 | case BOUND_SIMPLE: |
| 2829 | printf_filtered ("(BOUND_SIMPLE)"); |
| 2830 | break; |
| 2831 | default: |
| 2832 | printf_filtered ("(unknown bound type)"); |
| 2833 | break; |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | static struct obstack dont_print_type_obstack; |
| 2838 | |
| 2839 | void |
| 2840 | recursive_dump_type (struct type *type, int spaces) |
| 2841 | { |
| 2842 | int idx; |
| 2843 | |
| 2844 | if (spaces == 0) |
| 2845 | obstack_begin (&dont_print_type_obstack, 0); |
| 2846 | |
| 2847 | if (TYPE_NFIELDS (type) > 0 |
| 2848 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) |
| 2849 | { |
| 2850 | struct type **first_dont_print |
| 2851 | = (struct type **) obstack_base (&dont_print_type_obstack); |
| 2852 | |
| 2853 | int i = (struct type **) obstack_next_free (&dont_print_type_obstack) |
| 2854 | - first_dont_print; |
| 2855 | |
| 2856 | while (--i >= 0) |
| 2857 | { |
| 2858 | if (type == first_dont_print[i]) |
| 2859 | { |
| 2860 | printfi_filtered (spaces, "type node "); |
| 2861 | gdb_print_host_address (type, gdb_stdout); |
| 2862 | printf_filtered (" <same as already seen type>\n"); |
| 2863 | return; |
| 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | obstack_ptr_grow (&dont_print_type_obstack, type); |
| 2868 | } |
| 2869 | |
| 2870 | printfi_filtered (spaces, "type node "); |
| 2871 | gdb_print_host_address (type, gdb_stdout); |
| 2872 | printf_filtered ("\n"); |
| 2873 | printfi_filtered (spaces, "name '%s' (", |
| 2874 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); |
| 2875 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
| 2876 | printf_filtered (")\n"); |
| 2877 | printfi_filtered (spaces, "tagname '%s' (", |
| 2878 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>"); |
| 2879 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); |
| 2880 | printf_filtered (")\n"); |
| 2881 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
| 2882 | switch (TYPE_CODE (type)) |
| 2883 | { |
| 2884 | case TYPE_CODE_UNDEF: |
| 2885 | printf_filtered ("(TYPE_CODE_UNDEF)"); |
| 2886 | break; |
| 2887 | case TYPE_CODE_PTR: |
| 2888 | printf_filtered ("(TYPE_CODE_PTR)"); |
| 2889 | break; |
| 2890 | case TYPE_CODE_ARRAY: |
| 2891 | printf_filtered ("(TYPE_CODE_ARRAY)"); |
| 2892 | break; |
| 2893 | case TYPE_CODE_STRUCT: |
| 2894 | printf_filtered ("(TYPE_CODE_STRUCT)"); |
| 2895 | break; |
| 2896 | case TYPE_CODE_UNION: |
| 2897 | printf_filtered ("(TYPE_CODE_UNION)"); |
| 2898 | break; |
| 2899 | case TYPE_CODE_ENUM: |
| 2900 | printf_filtered ("(TYPE_CODE_ENUM)"); |
| 2901 | break; |
| 2902 | case TYPE_CODE_FUNC: |
| 2903 | printf_filtered ("(TYPE_CODE_FUNC)"); |
| 2904 | break; |
| 2905 | case TYPE_CODE_INT: |
| 2906 | printf_filtered ("(TYPE_CODE_INT)"); |
| 2907 | break; |
| 2908 | case TYPE_CODE_FLT: |
| 2909 | printf_filtered ("(TYPE_CODE_FLT)"); |
| 2910 | break; |
| 2911 | case TYPE_CODE_VOID: |
| 2912 | printf_filtered ("(TYPE_CODE_VOID)"); |
| 2913 | break; |
| 2914 | case TYPE_CODE_SET: |
| 2915 | printf_filtered ("(TYPE_CODE_SET)"); |
| 2916 | break; |
| 2917 | case TYPE_CODE_RANGE: |
| 2918 | printf_filtered ("(TYPE_CODE_RANGE)"); |
| 2919 | break; |
| 2920 | case TYPE_CODE_STRING: |
| 2921 | printf_filtered ("(TYPE_CODE_STRING)"); |
| 2922 | break; |
| 2923 | case TYPE_CODE_BITSTRING: |
| 2924 | printf_filtered ("(TYPE_CODE_BITSTRING)"); |
| 2925 | break; |
| 2926 | case TYPE_CODE_ERROR: |
| 2927 | printf_filtered ("(TYPE_CODE_ERROR)"); |
| 2928 | break; |
| 2929 | case TYPE_CODE_MEMBER: |
| 2930 | printf_filtered ("(TYPE_CODE_MEMBER)"); |
| 2931 | break; |
| 2932 | case TYPE_CODE_METHOD: |
| 2933 | printf_filtered ("(TYPE_CODE_METHOD)"); |
| 2934 | break; |
| 2935 | case TYPE_CODE_REF: |
| 2936 | printf_filtered ("(TYPE_CODE_REF)"); |
| 2937 | break; |
| 2938 | case TYPE_CODE_CHAR: |
| 2939 | printf_filtered ("(TYPE_CODE_CHAR)"); |
| 2940 | break; |
| 2941 | case TYPE_CODE_BOOL: |
| 2942 | printf_filtered ("(TYPE_CODE_BOOL)"); |
| 2943 | break; |
| 2944 | case TYPE_CODE_COMPLEX: |
| 2945 | printf_filtered ("(TYPE_CODE_COMPLEX)"); |
| 2946 | break; |
| 2947 | case TYPE_CODE_TYPEDEF: |
| 2948 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); |
| 2949 | break; |
| 2950 | case TYPE_CODE_TEMPLATE: |
| 2951 | printf_filtered ("(TYPE_CODE_TEMPLATE)"); |
| 2952 | break; |
| 2953 | case TYPE_CODE_TEMPLATE_ARG: |
| 2954 | printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)"); |
| 2955 | break; |
| 2956 | case TYPE_CODE_NAMESPACE: |
| 2957 | printf_filtered ("(TYPE_CODE_NAMESPACE)"); |
| 2958 | break; |
| 2959 | default: |
| 2960 | printf_filtered ("(UNKNOWN TYPE CODE)"); |
| 2961 | break; |
| 2962 | } |
| 2963 | puts_filtered ("\n"); |
| 2964 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); |
| 2965 | printfi_filtered (spaces, "upper_bound_type 0x%x ", |
| 2966 | TYPE_ARRAY_UPPER_BOUND_TYPE (type)); |
| 2967 | print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type)); |
| 2968 | puts_filtered ("\n"); |
| 2969 | printfi_filtered (spaces, "lower_bound_type 0x%x ", |
| 2970 | TYPE_ARRAY_LOWER_BOUND_TYPE (type)); |
| 2971 | print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type)); |
| 2972 | puts_filtered ("\n"); |
| 2973 | printfi_filtered (spaces, "objfile "); |
| 2974 | gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout); |
| 2975 | printf_filtered ("\n"); |
| 2976 | printfi_filtered (spaces, "target_type "); |
| 2977 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
| 2978 | printf_filtered ("\n"); |
| 2979 | if (TYPE_TARGET_TYPE (type) != NULL) |
| 2980 | { |
| 2981 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); |
| 2982 | } |
| 2983 | printfi_filtered (spaces, "pointer_type "); |
| 2984 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
| 2985 | printf_filtered ("\n"); |
| 2986 | printfi_filtered (spaces, "reference_type "); |
| 2987 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
| 2988 | printf_filtered ("\n"); |
| 2989 | printfi_filtered (spaces, "type_chain "); |
| 2990 | gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout); |
| 2991 | printf_filtered ("\n"); |
| 2992 | printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type)); |
| 2993 | if (TYPE_CONST (type)) |
| 2994 | { |
| 2995 | puts_filtered (" TYPE_FLAG_CONST"); |
| 2996 | } |
| 2997 | if (TYPE_VOLATILE (type)) |
| 2998 | { |
| 2999 | puts_filtered (" TYPE_FLAG_VOLATILE"); |
| 3000 | } |
| 3001 | if (TYPE_CODE_SPACE (type)) |
| 3002 | { |
| 3003 | puts_filtered (" TYPE_FLAG_CODE_SPACE"); |
| 3004 | } |
| 3005 | if (TYPE_DATA_SPACE (type)) |
| 3006 | { |
| 3007 | puts_filtered (" TYPE_FLAG_DATA_SPACE"); |
| 3008 | } |
| 3009 | if (TYPE_ADDRESS_CLASS_1 (type)) |
| 3010 | { |
| 3011 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1"); |
| 3012 | } |
| 3013 | if (TYPE_ADDRESS_CLASS_2 (type)) |
| 3014 | { |
| 3015 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2"); |
| 3016 | } |
| 3017 | puts_filtered ("\n"); |
| 3018 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); |
| 3019 | if (TYPE_UNSIGNED (type)) |
| 3020 | { |
| 3021 | puts_filtered (" TYPE_FLAG_UNSIGNED"); |
| 3022 | } |
| 3023 | if (TYPE_NOSIGN (type)) |
| 3024 | { |
| 3025 | puts_filtered (" TYPE_FLAG_NOSIGN"); |
| 3026 | } |
| 3027 | if (TYPE_STUB (type)) |
| 3028 | { |
| 3029 | puts_filtered (" TYPE_FLAG_STUB"); |
| 3030 | } |
| 3031 | if (TYPE_TARGET_STUB (type)) |
| 3032 | { |
| 3033 | puts_filtered (" TYPE_FLAG_TARGET_STUB"); |
| 3034 | } |
| 3035 | if (TYPE_STATIC (type)) |
| 3036 | { |
| 3037 | puts_filtered (" TYPE_FLAG_STATIC"); |
| 3038 | } |
| 3039 | if (TYPE_PROTOTYPED (type)) |
| 3040 | { |
| 3041 | puts_filtered (" TYPE_FLAG_PROTOTYPED"); |
| 3042 | } |
| 3043 | if (TYPE_INCOMPLETE (type)) |
| 3044 | { |
| 3045 | puts_filtered (" TYPE_FLAG_INCOMPLETE"); |
| 3046 | } |
| 3047 | if (TYPE_VARARGS (type)) |
| 3048 | { |
| 3049 | puts_filtered (" TYPE_FLAG_VARARGS"); |
| 3050 | } |
| 3051 | /* This is used for things like AltiVec registers on ppc. Gcc emits |
| 3052 | an attribute for the array type, which tells whether or not we |
| 3053 | have a vector, instead of a regular array. */ |
| 3054 | if (TYPE_VECTOR (type)) |
| 3055 | { |
| 3056 | puts_filtered (" TYPE_FLAG_VECTOR"); |
| 3057 | } |
| 3058 | puts_filtered ("\n"); |
| 3059 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); |
| 3060 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
| 3061 | puts_filtered ("\n"); |
| 3062 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) |
| 3063 | { |
| 3064 | printfi_filtered (spaces + 2, |
| 3065 | "[%d] bitpos %d bitsize %d type ", |
| 3066 | idx, TYPE_FIELD_BITPOS (type, idx), |
| 3067 | TYPE_FIELD_BITSIZE (type, idx)); |
| 3068 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
| 3069 | printf_filtered (" name '%s' (", |
| 3070 | TYPE_FIELD_NAME (type, idx) != NULL |
| 3071 | ? TYPE_FIELD_NAME (type, idx) |
| 3072 | : "<NULL>"); |
| 3073 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
| 3074 | printf_filtered (")\n"); |
| 3075 | if (TYPE_FIELD_TYPE (type, idx) != NULL) |
| 3076 | { |
| 3077 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); |
| 3078 | } |
| 3079 | } |
| 3080 | printfi_filtered (spaces, "vptr_basetype "); |
| 3081 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
| 3082 | puts_filtered ("\n"); |
| 3083 | if (TYPE_VPTR_BASETYPE (type) != NULL) |
| 3084 | { |
| 3085 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); |
| 3086 | } |
| 3087 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); |
| 3088 | switch (TYPE_CODE (type)) |
| 3089 | { |
| 3090 | case TYPE_CODE_STRUCT: |
| 3091 | printfi_filtered (spaces, "cplus_stuff "); |
| 3092 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
| 3093 | puts_filtered ("\n"); |
| 3094 | print_cplus_stuff (type, spaces); |
| 3095 | break; |
| 3096 | |
| 3097 | case TYPE_CODE_FLT: |
| 3098 | printfi_filtered (spaces, "floatformat "); |
| 3099 | if (TYPE_FLOATFORMAT (type) == NULL |
| 3100 | || TYPE_FLOATFORMAT (type)->name == NULL) |
| 3101 | puts_filtered ("(null)"); |
| 3102 | else |
| 3103 | puts_filtered (TYPE_FLOATFORMAT (type)->name); |
| 3104 | puts_filtered ("\n"); |
| 3105 | break; |
| 3106 | |
| 3107 | default: |
| 3108 | /* We have to pick one of the union types to be able print and test |
| 3109 | the value. Pick cplus_struct_type, even though we know it isn't |
| 3110 | any particular one. */ |
| 3111 | printfi_filtered (spaces, "type_specific "); |
| 3112 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
| 3113 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
| 3114 | { |
| 3115 | printf_filtered (" (unknown data form)"); |
| 3116 | } |
| 3117 | printf_filtered ("\n"); |
| 3118 | break; |
| 3119 | |
| 3120 | } |
| 3121 | if (spaces == 0) |
| 3122 | obstack_free (&dont_print_type_obstack, NULL); |
| 3123 | } |
| 3124 | |
| 3125 | static void build_gdbtypes (void); |
| 3126 | static void |
| 3127 | build_gdbtypes (void) |
| 3128 | { |
| 3129 | builtin_type_void = |
| 3130 | init_type (TYPE_CODE_VOID, 1, |
| 3131 | 0, |
| 3132 | "void", (struct objfile *) NULL); |
| 3133 | builtin_type_char = |
| 3134 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 3135 | (TYPE_FLAG_NOSIGN |
| 3136 | | (TARGET_CHAR_SIGNED ? 0 : TYPE_FLAG_UNSIGNED)), |
| 3137 | "char", (struct objfile *) NULL); |
| 3138 | builtin_type_true_char = |
| 3139 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 3140 | 0, |
| 3141 | "true character", (struct objfile *) NULL); |
| 3142 | builtin_type_signed_char = |
| 3143 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 3144 | 0, |
| 3145 | "signed char", (struct objfile *) NULL); |
| 3146 | builtin_type_unsigned_char = |
| 3147 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 3148 | TYPE_FLAG_UNSIGNED, |
| 3149 | "unsigned char", (struct objfile *) NULL); |
| 3150 | builtin_type_short = |
| 3151 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 3152 | 0, |
| 3153 | "short", (struct objfile *) NULL); |
| 3154 | builtin_type_unsigned_short = |
| 3155 | init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT, |
| 3156 | TYPE_FLAG_UNSIGNED, |
| 3157 | "unsigned short", (struct objfile *) NULL); |
| 3158 | builtin_type_int = |
| 3159 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 3160 | 0, |
| 3161 | "int", (struct objfile *) NULL); |
| 3162 | builtin_type_unsigned_int = |
| 3163 | init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, |
| 3164 | TYPE_FLAG_UNSIGNED, |
| 3165 | "unsigned int", (struct objfile *) NULL); |
| 3166 | builtin_type_long = |
| 3167 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 3168 | 0, |
| 3169 | "long", (struct objfile *) NULL); |
| 3170 | builtin_type_unsigned_long = |
| 3171 | init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT, |
| 3172 | TYPE_FLAG_UNSIGNED, |
| 3173 | "unsigned long", (struct objfile *) NULL); |
| 3174 | builtin_type_long_long = |
| 3175 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 3176 | 0, |
| 3177 | "long long", (struct objfile *) NULL); |
| 3178 | builtin_type_unsigned_long_long = |
| 3179 | init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT, |
| 3180 | TYPE_FLAG_UNSIGNED, |
| 3181 | "unsigned long long", (struct objfile *) NULL); |
| 3182 | builtin_type_float = |
| 3183 | init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 3184 | 0, |
| 3185 | "float", (struct objfile *) NULL); |
| 3186 | /* vinschen@redhat.com 2002-02-08: |
| 3187 | The below lines are disabled since they are doing the wrong |
| 3188 | thing for non-multiarch targets. They are setting the correct |
| 3189 | type of floats for the target but while on multiarch targets |
| 3190 | this is done everytime the architecture changes, it's done on |
| 3191 | non-multiarch targets only on startup, leaving the wrong values |
| 3192 | in even if the architecture changes (eg. from big-endian to |
| 3193 | little-endian). */ |
| 3194 | #if 0 |
| 3195 | TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT; |
| 3196 | #endif |
| 3197 | builtin_type_double = |
| 3198 | init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 3199 | 0, |
| 3200 | "double", (struct objfile *) NULL); |
| 3201 | #if 0 |
| 3202 | TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT; |
| 3203 | #endif |
| 3204 | builtin_type_long_double = |
| 3205 | init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 3206 | 0, |
| 3207 | "long double", (struct objfile *) NULL); |
| 3208 | #if 0 |
| 3209 | TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT; |
| 3210 | #endif |
| 3211 | builtin_type_complex = |
| 3212 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT, |
| 3213 | 0, |
| 3214 | "complex", (struct objfile *) NULL); |
| 3215 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; |
| 3216 | builtin_type_double_complex = |
| 3217 | init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT, |
| 3218 | 0, |
| 3219 | "double complex", (struct objfile *) NULL); |
| 3220 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; |
| 3221 | builtin_type_string = |
| 3222 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 3223 | 0, |
| 3224 | "string", (struct objfile *) NULL); |
| 3225 | builtin_type_int0 = |
| 3226 | init_type (TYPE_CODE_INT, 0 / 8, |
| 3227 | 0, |
| 3228 | "int0_t", (struct objfile *) NULL); |
| 3229 | builtin_type_int8 = |
| 3230 | init_type (TYPE_CODE_INT, 8 / 8, |
| 3231 | 0, |
| 3232 | "int8_t", (struct objfile *) NULL); |
| 3233 | builtin_type_uint8 = |
| 3234 | init_type (TYPE_CODE_INT, 8 / 8, |
| 3235 | TYPE_FLAG_UNSIGNED, |
| 3236 | "uint8_t", (struct objfile *) NULL); |
| 3237 | builtin_type_int16 = |
| 3238 | init_type (TYPE_CODE_INT, 16 / 8, |
| 3239 | 0, |
| 3240 | "int16_t", (struct objfile *) NULL); |
| 3241 | builtin_type_uint16 = |
| 3242 | init_type (TYPE_CODE_INT, 16 / 8, |
| 3243 | TYPE_FLAG_UNSIGNED, |
| 3244 | "uint16_t", (struct objfile *) NULL); |
| 3245 | builtin_type_int32 = |
| 3246 | init_type (TYPE_CODE_INT, 32 / 8, |
| 3247 | 0, |
| 3248 | "int32_t", (struct objfile *) NULL); |
| 3249 | builtin_type_uint32 = |
| 3250 | init_type (TYPE_CODE_INT, 32 / 8, |
| 3251 | TYPE_FLAG_UNSIGNED, |
| 3252 | "uint32_t", (struct objfile *) NULL); |
| 3253 | builtin_type_int64 = |
| 3254 | init_type (TYPE_CODE_INT, 64 / 8, |
| 3255 | 0, |
| 3256 | "int64_t", (struct objfile *) NULL); |
| 3257 | builtin_type_uint64 = |
| 3258 | init_type (TYPE_CODE_INT, 64 / 8, |
| 3259 | TYPE_FLAG_UNSIGNED, |
| 3260 | "uint64_t", (struct objfile *) NULL); |
| 3261 | builtin_type_int128 = |
| 3262 | init_type (TYPE_CODE_INT, 128 / 8, |
| 3263 | 0, |
| 3264 | "int128_t", (struct objfile *) NULL); |
| 3265 | builtin_type_uint128 = |
| 3266 | init_type (TYPE_CODE_INT, 128 / 8, |
| 3267 | TYPE_FLAG_UNSIGNED, |
| 3268 | "uint128_t", (struct objfile *) NULL); |
| 3269 | builtin_type_bool = |
| 3270 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
| 3271 | 0, |
| 3272 | "bool", (struct objfile *) NULL); |
| 3273 | |
| 3274 | /* Add user knob for controlling resolution of opaque types */ |
| 3275 | add_show_from_set |
| 3276 | (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution, |
| 3277 | "Set resolution of opaque struct/class/union types (if set before loading symbols).", |
| 3278 | &setlist), |
| 3279 | &showlist); |
| 3280 | opaque_type_resolution = 1; |
| 3281 | |
| 3282 | /* Build SIMD types. */ |
| 3283 | builtin_type_v4sf |
| 3284 | = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4); |
| 3285 | builtin_type_v4si |
| 3286 | = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4); |
| 3287 | builtin_type_v16qi |
| 3288 | = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16); |
| 3289 | builtin_type_v8qi |
| 3290 | = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8); |
| 3291 | builtin_type_v8hi |
| 3292 | = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8); |
| 3293 | builtin_type_v4hi |
| 3294 | = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4); |
| 3295 | builtin_type_v2si |
| 3296 | = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2); |
| 3297 | |
| 3298 | /* 128 bit vectors. */ |
| 3299 | builtin_type_v2_double = init_vector_type (builtin_type_double, 2); |
| 3300 | builtin_type_v4_float = init_vector_type (builtin_type_float, 4); |
| 3301 | builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2); |
| 3302 | builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4); |
| 3303 | builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8); |
| 3304 | builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16); |
| 3305 | /* 64 bit vectors. */ |
| 3306 | builtin_type_v2_float = init_vector_type (builtin_type_float, 2); |
| 3307 | builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2); |
| 3308 | builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4); |
| 3309 | builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8); |
| 3310 | |
| 3311 | /* Vector types. */ |
| 3312 | builtin_type_vec64 = build_builtin_type_vec64 (); |
| 3313 | builtin_type_vec64i = build_builtin_type_vec64i (); |
| 3314 | builtin_type_vec128 = build_builtin_type_vec128 (); |
| 3315 | builtin_type_vec128i = build_builtin_type_vec128i (); |
| 3316 | |
| 3317 | /* Pointer/Address types. */ |
| 3318 | |
| 3319 | /* NOTE: on some targets, addresses and pointers are not necessarily |
| 3320 | the same --- for example, on the D10V, pointers are 16 bits long, |
| 3321 | but addresses are 32 bits long. See doc/gdbint.texinfo, |
| 3322 | ``Pointers Are Not Always Addresses''. |
| 3323 | |
| 3324 | The upshot is: |
| 3325 | - gdb's `struct type' always describes the target's |
| 3326 | representation. |
| 3327 | - gdb's `struct value' objects should always hold values in |
| 3328 | target form. |
| 3329 | - gdb's CORE_ADDR values are addresses in the unified virtual |
| 3330 | address space that the assembler and linker work with. Thus, |
| 3331 | since target_read_memory takes a CORE_ADDR as an argument, it |
| 3332 | can access any memory on the target, even if the processor has |
| 3333 | separate code and data address spaces. |
| 3334 | |
| 3335 | So, for example: |
| 3336 | - If v is a value holding a D10V code pointer, its contents are |
| 3337 | in target form: a big-endian address left-shifted two bits. |
| 3338 | - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as |
| 3339 | sizeof (void *) == 2 on the target. |
| 3340 | |
| 3341 | In this context, builtin_type_CORE_ADDR is a bit odd: it's a |
| 3342 | target type for a value the target will never see. It's only |
| 3343 | used to hold the values of (typeless) linker symbols, which are |
| 3344 | indeed in the unified virtual address space. */ |
| 3345 | builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL); |
| 3346 | builtin_type_void_func_ptr |
| 3347 | = lookup_pointer_type (lookup_function_type (builtin_type_void)); |
| 3348 | builtin_type_CORE_ADDR = |
| 3349 | init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8, |
| 3350 | TYPE_FLAG_UNSIGNED, |
| 3351 | "__CORE_ADDR", (struct objfile *) NULL); |
| 3352 | builtin_type_bfd_vma = |
| 3353 | init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8, |
| 3354 | TYPE_FLAG_UNSIGNED, |
| 3355 | "__bfd_vma", (struct objfile *) NULL); |
| 3356 | } |
| 3357 | |
| 3358 | extern void _initialize_gdbtypes (void); |
| 3359 | void |
| 3360 | _initialize_gdbtypes (void) |
| 3361 | { |
| 3362 | struct cmd_list_element *c; |
| 3363 | build_gdbtypes (); |
| 3364 | |
| 3365 | /* FIXME - For the moment, handle types by swapping them in and out. |
| 3366 | Should be using the per-architecture data-pointer and a large |
| 3367 | struct. */ |
| 3368 | register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL); |
| 3369 | register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL); |
| 3370 | register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL); |
| 3371 | register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL); |
| 3372 | register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL); |
| 3373 | register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL); |
| 3374 | register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL); |
| 3375 | register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL); |
| 3376 | register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL); |
| 3377 | register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL); |
| 3378 | register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL); |
| 3379 | register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL); |
| 3380 | register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL); |
| 3381 | register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL); |
| 3382 | register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL); |
| 3383 | register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL); |
| 3384 | register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL); |
| 3385 | register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL); |
| 3386 | register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL); |
| 3387 | register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL); |
| 3388 | register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL); |
| 3389 | register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL); |
| 3390 | register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL); |
| 3391 | register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL); |
| 3392 | register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL); |
| 3393 | register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL); |
| 3394 | register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL); |
| 3395 | register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL); |
| 3396 | register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL); |
| 3397 | register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL); |
| 3398 | register_gdbarch_swap (&builtin_type_v16qi, sizeof (struct type *), NULL); |
| 3399 | register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL); |
| 3400 | register_gdbarch_swap (&builtin_type_v8hi, sizeof (struct type *), NULL); |
| 3401 | register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL); |
| 3402 | register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL); |
| 3403 | register_gdbarch_swap (&builtin_type_v2_double, sizeof (struct type *), NULL); |
| 3404 | register_gdbarch_swap (&builtin_type_v4_float, sizeof (struct type *), NULL); |
| 3405 | register_gdbarch_swap (&builtin_type_v2_int64, sizeof (struct type *), NULL); |
| 3406 | register_gdbarch_swap (&builtin_type_v4_int32, sizeof (struct type *), NULL); |
| 3407 | register_gdbarch_swap (&builtin_type_v8_int16, sizeof (struct type *), NULL); |
| 3408 | register_gdbarch_swap (&builtin_type_v16_int8, sizeof (struct type *), NULL); |
| 3409 | register_gdbarch_swap (&builtin_type_v2_float, sizeof (struct type *), NULL); |
| 3410 | register_gdbarch_swap (&builtin_type_v2_int32, sizeof (struct type *), NULL); |
| 3411 | register_gdbarch_swap (&builtin_type_v8_int8, sizeof (struct type *), NULL); |
| 3412 | register_gdbarch_swap (&builtin_type_v4_int16, sizeof (struct type *), NULL); |
| 3413 | register_gdbarch_swap (&builtin_type_vec128, sizeof (struct type *), NULL); |
| 3414 | register_gdbarch_swap (&builtin_type_vec128i, sizeof (struct type *), NULL); |
| 3415 | REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr); |
| 3416 | REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr); |
| 3417 | REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR); |
| 3418 | REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma); |
| 3419 | register_gdbarch_swap (NULL, 0, build_gdbtypes); |
| 3420 | |
| 3421 | /* Note: These types do not need to be swapped - they are target |
| 3422 | neutral. */ |
| 3423 | builtin_type_ieee_single_big = |
| 3424 | init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8, |
| 3425 | 0, "builtin_type_ieee_single_big", NULL); |
| 3426 | TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big; |
| 3427 | builtin_type_ieee_single_little = |
| 3428 | init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8, |
| 3429 | 0, "builtin_type_ieee_single_little", NULL); |
| 3430 | TYPE_FLOATFORMAT (builtin_type_ieee_single_little) = &floatformat_ieee_single_little; |
| 3431 | builtin_type_ieee_double_big = |
| 3432 | init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8, |
| 3433 | 0, "builtin_type_ieee_double_big", NULL); |
| 3434 | TYPE_FLOATFORMAT (builtin_type_ieee_double_big) = &floatformat_ieee_double_big; |
| 3435 | builtin_type_ieee_double_little = |
| 3436 | init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8, |
| 3437 | 0, "builtin_type_ieee_double_little", NULL); |
| 3438 | TYPE_FLOATFORMAT (builtin_type_ieee_double_little) = &floatformat_ieee_double_little; |
| 3439 | builtin_type_ieee_double_littlebyte_bigword = |
| 3440 | init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8, |
| 3441 | 0, "builtin_type_ieee_double_littlebyte_bigword", NULL); |
| 3442 | TYPE_FLOATFORMAT (builtin_type_ieee_double_littlebyte_bigword) = &floatformat_ieee_double_littlebyte_bigword; |
| 3443 | builtin_type_i387_ext = |
| 3444 | init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8, |
| 3445 | 0, "builtin_type_i387_ext", NULL); |
| 3446 | TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext; |
| 3447 | builtin_type_m68881_ext = |
| 3448 | init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8, |
| 3449 | 0, "builtin_type_m68881_ext", NULL); |
| 3450 | TYPE_FLOATFORMAT (builtin_type_m68881_ext) = &floatformat_m68881_ext; |
| 3451 | builtin_type_i960_ext = |
| 3452 | init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8, |
| 3453 | 0, "builtin_type_i960_ext", NULL); |
| 3454 | TYPE_FLOATFORMAT (builtin_type_i960_ext) = &floatformat_i960_ext; |
| 3455 | builtin_type_m88110_ext = |
| 3456 | init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8, |
| 3457 | 0, "builtin_type_m88110_ext", NULL); |
| 3458 | TYPE_FLOATFORMAT (builtin_type_m88110_ext) = &floatformat_m88110_ext; |
| 3459 | builtin_type_m88110_harris_ext = |
| 3460 | init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8, |
| 3461 | 0, "builtin_type_m88110_harris_ext", NULL); |
| 3462 | TYPE_FLOATFORMAT (builtin_type_m88110_harris_ext) = &floatformat_m88110_harris_ext; |
| 3463 | builtin_type_arm_ext_big = |
| 3464 | init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8, |
| 3465 | 0, "builtin_type_arm_ext_big", NULL); |
| 3466 | TYPE_FLOATFORMAT (builtin_type_arm_ext_big) = &floatformat_arm_ext_big; |
| 3467 | builtin_type_arm_ext_littlebyte_bigword = |
| 3468 | init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8, |
| 3469 | 0, "builtin_type_arm_ext_littlebyte_bigword", NULL); |
| 3470 | TYPE_FLOATFORMAT (builtin_type_arm_ext_littlebyte_bigword) = &floatformat_arm_ext_littlebyte_bigword; |
| 3471 | builtin_type_ia64_spill_big = |
| 3472 | init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8, |
| 3473 | 0, "builtin_type_ia64_spill_big", NULL); |
| 3474 | TYPE_FLOATFORMAT (builtin_type_ia64_spill_big) = &floatformat_ia64_spill_big; |
| 3475 | builtin_type_ia64_spill_little = |
| 3476 | init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8, |
| 3477 | 0, "builtin_type_ia64_spill_little", NULL); |
| 3478 | TYPE_FLOATFORMAT (builtin_type_ia64_spill_little) = &floatformat_ia64_spill_little; |
| 3479 | builtin_type_ia64_quad_big = |
| 3480 | init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8, |
| 3481 | 0, "builtin_type_ia64_quad_big", NULL); |
| 3482 | TYPE_FLOATFORMAT (builtin_type_ia64_quad_big) = &floatformat_ia64_quad_big; |
| 3483 | builtin_type_ia64_quad_little = |
| 3484 | init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8, |
| 3485 | 0, "builtin_type_ia64_quad_little", NULL); |
| 3486 | TYPE_FLOATFORMAT (builtin_type_ia64_quad_little) = &floatformat_ia64_quad_little; |
| 3487 | |
| 3488 | add_show_from_set ( |
| 3489 | add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug, |
| 3490 | "Set debugging of C++ overloading.\n\ |
| 3491 | When enabled, ranking of the functions\n\ |
| 3492 | is displayed.", &setdebuglist), |
| 3493 | &showdebuglist); |
| 3494 | } |