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