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