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