gdb: remove TYPE_FIELD_STATIC_PHYSADDR
[binutils-gdb.git] / gdb / gdbtypes.h
1
2 /* Internal type definitions for GDB.
3
4 Copyright (C) 1992-2021 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 #if !defined (GDBTYPES_H)
24 #define GDBTYPES_H 1
25
26 /* * \page gdbtypes GDB Types
27
28 GDB represents all the different kinds of types in programming
29 languages using a common representation defined in gdbtypes.h.
30
31 The main data structure is main_type; it consists of a code (such
32 as #TYPE_CODE_ENUM for enumeration types), a number of
33 generally-useful fields such as the printable name, and finally a
34 field main_type::type_specific that is a union of info specific to
35 particular languages or other special cases (such as calling
36 convention).
37
38 The available type codes are defined in enum #type_code. The enum
39 includes codes both for types that are common across a variety
40 of languages, and for types that are language-specific.
41
42 Most accesses to type fields go through macros such as
43 #TYPE_CODE(thistype) and #TYPE_FN_FIELD_CONST(thisfn, n). These are
44 written such that they can be used as both rvalues and lvalues.
45 */
46
47 #include "hashtab.h"
48 #include "gdbsupport/array-view.h"
49 #include "gdbsupport/gdb_optional.h"
50 #include "gdbsupport/offset-type.h"
51 #include "gdbsupport/enum-flags.h"
52 #include "gdbsupport/underlying.h"
53 #include "gdbsupport/print-utils.h"
54 #include "dwarf2.h"
55 #include "gdb_obstack.h"
56 #include "gmp-utils.h"
57
58 /* Forward declarations for prototypes. */
59 struct field;
60 struct block;
61 struct value_print_options;
62 struct language_defn;
63 struct dwarf2_per_cu_data;
64 struct dwarf2_per_objfile;
65
66 /* These declarations are DWARF-specific as some of the gdbtypes.h data types
67 are already DWARF-specific. */
68
69 /* * Offset relative to the start of its containing CU (compilation
70 unit). */
71 DEFINE_OFFSET_TYPE (cu_offset, unsigned int);
72
73 /* * Offset relative to the start of its .debug_info or .debug_types
74 section. */
75 DEFINE_OFFSET_TYPE (sect_offset, uint64_t);
76
77 static inline char *
78 sect_offset_str (sect_offset offset)
79 {
80 return hex_string (to_underlying (offset));
81 }
82
83 /* Some macros for char-based bitfields. */
84
85 #define B_SET(a,x) ((a)[(x)>>3] |= (1 << ((x)&7)))
86 #define B_CLR(a,x) ((a)[(x)>>3] &= ~(1 << ((x)&7)))
87 #define B_TST(a,x) ((a)[(x)>>3] & (1 << ((x)&7)))
88 #define B_TYPE unsigned char
89 #define B_BYTES(x) ( 1 + ((x)>>3) )
90 #define B_CLRALL(a,x) memset ((a), 0, B_BYTES(x))
91
92 /* * Different kinds of data types are distinguished by the `code'
93 field. */
94
95 enum type_code
96 {
97 TYPE_CODE_BITSTRING = -1, /**< Deprecated */
98 TYPE_CODE_UNDEF = 0, /**< Not used; catches errors */
99 TYPE_CODE_PTR, /**< Pointer type */
100
101 /* * Array type with lower & upper bounds.
102
103 Regardless of the language, GDB represents multidimensional
104 array types the way C does: as arrays of arrays. So an
105 instance of a GDB array type T can always be seen as a series
106 of instances of TYPE_TARGET_TYPE (T) laid out sequentially in
107 memory.
108
109 Row-major languages like C lay out multi-dimensional arrays so
110 that incrementing the rightmost index in a subscripting
111 expression results in the smallest change in the address of the
112 element referred to. Column-major languages like Fortran lay
113 them out so that incrementing the leftmost index results in the
114 smallest change.
115
116 This means that, in column-major languages, working our way
117 from type to target type corresponds to working through indices
118 from right to left, not left to right. */
119 TYPE_CODE_ARRAY,
120
121 TYPE_CODE_STRUCT, /**< C struct or Pascal record */
122 TYPE_CODE_UNION, /**< C union or Pascal variant part */
123 TYPE_CODE_ENUM, /**< Enumeration type */
124 TYPE_CODE_FLAGS, /**< Bit flags type */
125 TYPE_CODE_FUNC, /**< Function type */
126 TYPE_CODE_INT, /**< Integer type */
127
128 /* * Floating type. This is *NOT* a complex type. */
129 TYPE_CODE_FLT,
130
131 /* * Void type. The length field specifies the length (probably
132 always one) which is used in pointer arithmetic involving
133 pointers to this type, but actually dereferencing such a
134 pointer is invalid; a void type has no length and no actual
135 representation in memory or registers. A pointer to a void
136 type is a generic pointer. */
137 TYPE_CODE_VOID,
138
139 TYPE_CODE_SET, /**< Pascal sets */
140 TYPE_CODE_RANGE, /**< Range (integers within spec'd bounds). */
141
142 /* * A string type which is like an array of character but prints
143 differently. It does not contain a length field as Pascal
144 strings (for many Pascals, anyway) do; if we want to deal with
145 such strings, we should use a new type code. */
146 TYPE_CODE_STRING,
147
148 /* * Unknown type. The length field is valid if we were able to
149 deduce that much about the type, or 0 if we don't even know
150 that. */
151 TYPE_CODE_ERROR,
152
153 /* C++ */
154 TYPE_CODE_METHOD, /**< Method type */
155
156 /* * Pointer-to-member-function type. This describes how to access a
157 particular member function of a class (possibly a virtual
158 member function). The representation may vary between different
159 C++ ABIs. */
160 TYPE_CODE_METHODPTR,
161
162 /* * Pointer-to-member type. This is the offset within a class to
163 some particular data member. The only currently supported
164 representation uses an unbiased offset, with -1 representing
165 NULL; this is used by the Itanium C++ ABI (used by GCC on all
166 platforms). */
167 TYPE_CODE_MEMBERPTR,
168
169 TYPE_CODE_REF, /**< C++ Reference types */
170
171 TYPE_CODE_RVALUE_REF, /**< C++ rvalue reference types */
172
173 TYPE_CODE_CHAR, /**< *real* character type */
174
175 /* * Boolean type. 0 is false, 1 is true, and other values are
176 non-boolean (e.g. FORTRAN "logical" used as unsigned int). */
177 TYPE_CODE_BOOL,
178
179 /* Fortran */
180 TYPE_CODE_COMPLEX, /**< Complex float */
181
182 TYPE_CODE_TYPEDEF,
183
184 TYPE_CODE_NAMESPACE, /**< C++ namespace. */
185
186 TYPE_CODE_DECFLOAT, /**< Decimal floating point. */
187
188 TYPE_CODE_MODULE, /**< Fortran module. */
189
190 /* * Internal function type. */
191 TYPE_CODE_INTERNAL_FUNCTION,
192
193 /* * Methods implemented in extension languages. */
194 TYPE_CODE_XMETHOD,
195
196 /* * Fixed Point type. */
197 TYPE_CODE_FIXED_POINT,
198 };
199
200 /* * Some bits for the type's instance_flags word. See the macros
201 below for documentation on each bit. */
202
203 enum type_instance_flag_value : unsigned
204 {
205 TYPE_INSTANCE_FLAG_CONST = (1 << 0),
206 TYPE_INSTANCE_FLAG_VOLATILE = (1 << 1),
207 TYPE_INSTANCE_FLAG_CODE_SPACE = (1 << 2),
208 TYPE_INSTANCE_FLAG_DATA_SPACE = (1 << 3),
209 TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 = (1 << 4),
210 TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2 = (1 << 5),
211 TYPE_INSTANCE_FLAG_NOTTEXT = (1 << 6),
212 TYPE_INSTANCE_FLAG_RESTRICT = (1 << 7),
213 TYPE_INSTANCE_FLAG_ATOMIC = (1 << 8)
214 };
215
216 DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
217
218 /* * Not textual. By default, GDB treats all single byte integers as
219 characters (or elements of strings) unless this flag is set. */
220
221 #define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
222
223 /* * Constant type. If this is set, the corresponding type has a
224 const modifier. */
225
226 #define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0)
227
228 /* * Volatile type. If this is set, the corresponding type has a
229 volatile modifier. */
230
231 #define TYPE_VOLATILE(t) \
232 ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)
233
234 /* * Restrict type. If this is set, the corresponding type has a
235 restrict modifier. */
236
237 #define TYPE_RESTRICT(t) \
238 ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)
239
240 /* * Atomic type. If this is set, the corresponding type has an
241 _Atomic modifier. */
242
243 #define TYPE_ATOMIC(t) \
244 ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)
245
246 /* * True if this type represents either an lvalue or lvalue reference type. */
247
248 #define TYPE_IS_REFERENCE(t) \
249 ((t)->code () == TYPE_CODE_REF || (t)->code () == TYPE_CODE_RVALUE_REF)
250
251 /* * True if this type is allocatable. */
252 #define TYPE_IS_ALLOCATABLE(t) \
253 ((t)->dyn_prop (DYN_PROP_ALLOCATED) != NULL)
254
255 /* * True if this type has variant parts. */
256 #define TYPE_HAS_VARIANT_PARTS(t) \
257 ((t)->dyn_prop (DYN_PROP_VARIANT_PARTS) != nullptr)
258
259 /* * True if this type has a dynamic length. */
260 #define TYPE_HAS_DYNAMIC_LENGTH(t) \
261 ((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr)
262
263 /* * Instruction-space delimited type. This is for Harvard architectures
264 which have separate instruction and data address spaces (and perhaps
265 others).
266
267 GDB usually defines a flat address space that is a superset of the
268 architecture's two (or more) address spaces, but this is an extension
269 of the architecture's model.
270
271 If TYPE_INSTANCE_FLAG_CODE_SPACE is set, an object of the corresponding type
272 resides in instruction memory, even if its address (in the extended
273 flat address space) does not reflect this.
274
275 Similarly, if TYPE_INSTANCE_FLAG_DATA_SPACE is set, then an object of the
276 corresponding type resides in the data memory space, even if
277 this is not indicated by its (flat address space) address.
278
279 If neither flag is set, the default space for functions / methods
280 is instruction space, and for data objects is data memory. */
281
282 #define TYPE_CODE_SPACE(t) \
283 ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
284
285 #define TYPE_DATA_SPACE(t) \
286 ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
287
288 /* * Address class flags. Some environments provide for pointers
289 whose size is different from that of a normal pointer or address
290 types where the bits are interpreted differently than normal
291 addresses. The TYPE_INSTANCE_FLAG_ADDRESS_CLASS_n flags may be used in
292 target specific ways to represent these different types of address
293 classes. */
294
295 #define TYPE_ADDRESS_CLASS_1(t) (((t)->instance_flags ()) \
296 & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
297 #define TYPE_ADDRESS_CLASS_2(t) (((t)->instance_flags ()) \
298 & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
299 #define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL \
300 (TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
301 #define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \
302 & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
303
304 /* * Information about a single discriminant. */
305
306 struct discriminant_range
307 {
308 /* * The range of values for the variant. This is an inclusive
309 range. */
310 ULONGEST low, high;
311
312 /* * Return true if VALUE is contained in this range. IS_UNSIGNED
313 is true if this should be an unsigned comparison; false for
314 signed. */
315 bool contains (ULONGEST value, bool is_unsigned) const
316 {
317 if (is_unsigned)
318 return value >= low && value <= high;
319 LONGEST valuel = (LONGEST) value;
320 return valuel >= (LONGEST) low && valuel <= (LONGEST) high;
321 }
322 };
323
324 struct variant_part;
325
326 /* * A single variant. A variant has a list of discriminant values.
327 When the discriminator matches one of these, the variant is
328 enabled. Each variant controls zero or more fields; and may also
329 control other variant parts as well. This struct corresponds to
330 DW_TAG_variant in DWARF. */
331
332 struct variant : allocate_on_obstack
333 {
334 /* * The discriminant ranges for this variant. */
335 gdb::array_view<discriminant_range> discriminants;
336
337 /* * The fields controlled by this variant. This is inclusive on
338 the low end and exclusive on the high end. A variant may not
339 control any fields, in which case the two values will be equal.
340 These are indexes into the type's array of fields. */
341 int first_field;
342 int last_field;
343
344 /* * Variant parts controlled by this variant. */
345 gdb::array_view<variant_part> parts;
346
347 /* * Return true if this is the default variant. The default
348 variant can be recognized because it has no associated
349 discriminants. */
350 bool is_default () const
351 {
352 return discriminants.empty ();
353 }
354
355 /* * Return true if this variant matches VALUE. IS_UNSIGNED is true
356 if this should be an unsigned comparison; false for signed. */
357 bool matches (ULONGEST value, bool is_unsigned) const;
358 };
359
360 /* * A variant part. Each variant part has an optional discriminant
361 and holds an array of variants. This struct corresponds to
362 DW_TAG_variant_part in DWARF. */
363
364 struct variant_part : allocate_on_obstack
365 {
366 /* * The index of the discriminant field in the outer type. This is
367 an index into the type's array of fields. If this is -1, there
368 is no discriminant, and only the default variant can be
369 considered to be selected. */
370 int discriminant_index;
371
372 /* * True if this discriminant is unsigned; false if signed. This
373 comes from the type of the discriminant. */
374 bool is_unsigned;
375
376 /* * The variants that are controlled by this variant part. Note
377 that these will always be sorted by field number. */
378 gdb::array_view<variant> variants;
379 };
380
381
382 enum dynamic_prop_kind
383 {
384 PROP_UNDEFINED, /* Not defined. */
385 PROP_CONST, /* Constant. */
386 PROP_ADDR_OFFSET, /* Address offset. */
387 PROP_LOCEXPR, /* Location expression. */
388 PROP_LOCLIST, /* Location list. */
389 PROP_VARIANT_PARTS, /* Variant parts. */
390 PROP_TYPE, /* Type. */
391 PROP_VARIABLE_NAME, /* Variable name. */
392 };
393
394 union dynamic_prop_data
395 {
396 /* Storage for constant property. */
397
398 LONGEST const_val;
399
400 /* Storage for dynamic property. */
401
402 void *baton;
403
404 /* Storage of variant parts for a type. A type with variant parts
405 has all its fields "linearized" -- stored in a single field
406 array, just as if they had all been declared that way. The
407 variant parts are attached via a dynamic property, and then are
408 used to control which fields end up in the final type during
409 dynamic type resolution. */
410
411 const gdb::array_view<variant_part> *variant_parts;
412
413 /* Once a variant type is resolved, we may want to be able to go
414 from the resolved type to the original type. In this case we
415 rewrite the property's kind and set this field. */
416
417 struct type *original_type;
418
419 /* Name of a variable to look up; the variable holds the value of
420 this property. */
421
422 const char *variable_name;
423 };
424
425 /* * Used to store a dynamic property. */
426
427 struct dynamic_prop
428 {
429 dynamic_prop_kind kind () const
430 {
431 return m_kind;
432 }
433
434 void set_undefined ()
435 {
436 m_kind = PROP_UNDEFINED;
437 }
438
439 LONGEST const_val () const
440 {
441 gdb_assert (m_kind == PROP_CONST);
442
443 return m_data.const_val;
444 }
445
446 void set_const_val (LONGEST const_val)
447 {
448 m_kind = PROP_CONST;
449 m_data.const_val = const_val;
450 }
451
452 void *baton () const
453 {
454 gdb_assert (m_kind == PROP_LOCEXPR
455 || m_kind == PROP_LOCLIST
456 || m_kind == PROP_ADDR_OFFSET);
457
458 return m_data.baton;
459 }
460
461 void set_locexpr (void *baton)
462 {
463 m_kind = PROP_LOCEXPR;
464 m_data.baton = baton;
465 }
466
467 void set_loclist (void *baton)
468 {
469 m_kind = PROP_LOCLIST;
470 m_data.baton = baton;
471 }
472
473 void set_addr_offset (void *baton)
474 {
475 m_kind = PROP_ADDR_OFFSET;
476 m_data.baton = baton;
477 }
478
479 const gdb::array_view<variant_part> *variant_parts () const
480 {
481 gdb_assert (m_kind == PROP_VARIANT_PARTS);
482
483 return m_data.variant_parts;
484 }
485
486 void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
487 {
488 m_kind = PROP_VARIANT_PARTS;
489 m_data.variant_parts = variant_parts;
490 }
491
492 struct type *original_type () const
493 {
494 gdb_assert (m_kind == PROP_TYPE);
495
496 return m_data.original_type;
497 }
498
499 void set_original_type (struct type *original_type)
500 {
501 m_kind = PROP_TYPE;
502 m_data.original_type = original_type;
503 }
504
505 /* Return the name of the variable that holds this property's value.
506 Only valid for PROP_VARIABLE_NAME. */
507 const char *variable_name () const
508 {
509 gdb_assert (m_kind == PROP_VARIABLE_NAME);
510 return m_data.variable_name;
511 }
512
513 /* Set the name of the variable that holds this property's value,
514 and set this property to be of kind PROP_VARIABLE_NAME. */
515 void set_variable_name (const char *name)
516 {
517 m_kind = PROP_VARIABLE_NAME;
518 m_data.variable_name = name;
519 }
520
521 /* Determine which field of the union dynamic_prop.data is used. */
522 enum dynamic_prop_kind m_kind;
523
524 /* Storage for dynamic or static value. */
525 union dynamic_prop_data m_data;
526 };
527
528 /* Compare two dynamic_prop objects for equality. dynamic_prop
529 instances are equal iff they have the same type and storage. */
530 extern bool operator== (const dynamic_prop &l, const dynamic_prop &r);
531
532 /* Compare two dynamic_prop objects for inequality. */
533 static inline bool operator!= (const dynamic_prop &l, const dynamic_prop &r)
534 {
535 return !(l == r);
536 }
537
538 /* * Define a type's dynamic property node kind. */
539 enum dynamic_prop_node_kind
540 {
541 /* A property providing a type's data location.
542 Evaluating this field yields to the location of an object's data. */
543 DYN_PROP_DATA_LOCATION,
544
545 /* A property representing DW_AT_allocated. The presence of this attribute
546 indicates that the object of the type can be allocated/deallocated. */
547 DYN_PROP_ALLOCATED,
548
549 /* A property representing DW_AT_associated. The presence of this attribute
550 indicated that the object of the type can be associated. */
551 DYN_PROP_ASSOCIATED,
552
553 /* A property providing an array's byte stride. */
554 DYN_PROP_BYTE_STRIDE,
555
556 /* A property holding variant parts. */
557 DYN_PROP_VARIANT_PARTS,
558
559 /* A property holding the size of the type. */
560 DYN_PROP_BYTE_SIZE,
561 };
562
563 /* * List for dynamic type attributes. */
564 struct dynamic_prop_list
565 {
566 /* The kind of dynamic prop in this node. */
567 enum dynamic_prop_node_kind prop_kind;
568
569 /* The dynamic property itself. */
570 struct dynamic_prop prop;
571
572 /* A pointer to the next dynamic property. */
573 struct dynamic_prop_list *next;
574 };
575
576 /* * Determine which field of the union main_type.fields[x].loc is
577 used. */
578
579 enum field_loc_kind
580 {
581 FIELD_LOC_KIND_BITPOS, /**< bitpos */
582 FIELD_LOC_KIND_ENUMVAL, /**< enumval */
583 FIELD_LOC_KIND_PHYSADDR, /**< physaddr */
584 FIELD_LOC_KIND_PHYSNAME, /**< physname */
585 FIELD_LOC_KIND_DWARF_BLOCK /**< dwarf_block */
586 };
587
588 /* * A discriminant to determine which field in the
589 main_type.type_specific union is being used, if any.
590
591 For types such as TYPE_CODE_FLT, the use of this
592 discriminant is really redundant, as we know from the type code
593 which field is going to be used. As such, it would be possible to
594 reduce the size of this enum in order to save a bit or two for
595 other fields of struct main_type. But, since we still have extra
596 room , and for the sake of clarity and consistency, we treat all fields
597 of the union the same way. */
598
599 enum type_specific_kind
600 {
601 TYPE_SPECIFIC_NONE,
602 TYPE_SPECIFIC_CPLUS_STUFF,
603 TYPE_SPECIFIC_GNAT_STUFF,
604 TYPE_SPECIFIC_FLOATFORMAT,
605 /* Note: This is used by TYPE_CODE_FUNC and TYPE_CODE_METHOD. */
606 TYPE_SPECIFIC_FUNC,
607 TYPE_SPECIFIC_SELF_TYPE,
608 TYPE_SPECIFIC_INT,
609 TYPE_SPECIFIC_FIXED_POINT,
610 };
611
612 union type_owner
613 {
614 struct objfile *objfile;
615 struct gdbarch *gdbarch;
616 };
617
618 union field_location
619 {
620 /* * Position of this field, counting in bits from start of
621 containing structure. For big-endian targets, it is the bit
622 offset to the MSB. For little-endian targets, it is the bit
623 offset to the LSB. */
624
625 LONGEST bitpos;
626
627 /* * Enum value. */
628 LONGEST enumval;
629
630 /* * For a static field, if TYPE_FIELD_STATIC_HAS_ADDR then
631 physaddr is the location (in the target) of the static
632 field. Otherwise, physname is the mangled label of the
633 static field. */
634
635 CORE_ADDR physaddr;
636 const char *physname;
637
638 /* * The field location can be computed by evaluating the
639 following DWARF block. Its DATA is allocated on
640 objfile_obstack - no CU load is needed to access it. */
641
642 struct dwarf2_locexpr_baton *dwarf_block;
643 };
644
645 struct field
646 {
647 struct type *type () const
648 {
649 return this->m_type;
650 }
651
652 void set_type (struct type *type)
653 {
654 this->m_type = type;
655 }
656
657 const char *name () const
658 {
659 return m_name;
660 }
661
662 void set_name (const char *name)
663 {
664 m_name = name;
665 }
666
667 /* Location getters / setters. */
668
669 field_loc_kind loc_kind () const
670 {
671 return m_loc_kind;
672 }
673
674 LONGEST loc_bitpos () const
675 {
676 gdb_assert (m_loc_kind == FIELD_LOC_KIND_BITPOS);
677 return m_loc.bitpos;
678 }
679
680 void set_loc_bitpos (LONGEST bitpos)
681 {
682 m_loc_kind = FIELD_LOC_KIND_BITPOS;
683 m_loc.bitpos = bitpos;
684 }
685
686 LONGEST loc_enumval () const
687 {
688 gdb_assert (m_loc_kind == FIELD_LOC_KIND_ENUMVAL);
689 return m_loc.enumval;
690 }
691
692 void set_loc_enumval (LONGEST enumval)
693 {
694 m_loc_kind = FIELD_LOC_KIND_ENUMVAL;
695 m_loc.enumval = enumval;
696 }
697
698 CORE_ADDR loc_physaddr () const
699 {
700 gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
701 return m_loc.physaddr;
702 }
703
704 void set_loc_physaddr (CORE_ADDR physaddr)
705 {
706 m_loc_kind = FIELD_LOC_KIND_PHYSADDR;
707 m_loc.physaddr = physaddr;
708 }
709
710 const char *loc_physname () const
711 {
712 gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSNAME);
713 return m_loc.physname;
714 }
715
716 void set_loc_physname (const char *physname)
717 {
718 m_loc_kind = FIELD_LOC_KIND_PHYSNAME;
719 m_loc.physname = physname;
720 }
721
722 dwarf2_locexpr_baton *loc_dwarf_block () const
723 {
724 gdb_assert (m_loc_kind == FIELD_LOC_KIND_DWARF_BLOCK);
725 return m_loc.dwarf_block;
726 }
727
728 void set_loc_dwarf_block (dwarf2_locexpr_baton *dwarf_block)
729 {
730 m_loc_kind = FIELD_LOC_KIND_DWARF_BLOCK;
731 m_loc.dwarf_block = dwarf_block;
732 }
733
734 union field_location m_loc;
735
736 /* * For a function or member type, this is 1 if the argument is
737 marked artificial. Artificial arguments should not be shown
738 to the user. For TYPE_CODE_RANGE it is set if the specific
739 bound is not defined. */
740
741 unsigned int artificial : 1;
742
743 /* * Discriminant for union field_location. */
744
745 ENUM_BITFIELD(field_loc_kind) m_loc_kind : 3;
746
747 /* * Size of this field, in bits, or zero if not packed.
748 If non-zero in an array type, indicates the element size in
749 bits (used only in Ada at the moment).
750 For an unpacked field, the field's type's length
751 says how many bytes the field occupies. */
752
753 unsigned int bitsize : 28;
754
755 /* * In a struct or union type, type of this field.
756 - In a function or member type, type of this argument.
757 - In an array type, the domain-type of the array. */
758
759 struct type *m_type;
760
761 /* * Name of field, value or argument.
762 NULL for range bounds, array domains, and member function
763 arguments. */
764
765 const char *m_name;
766 };
767
768 struct range_bounds
769 {
770 ULONGEST bit_stride () const
771 {
772 if (this->flag_is_byte_stride)
773 return this->stride.const_val () * 8;
774 else
775 return this->stride.const_val ();
776 }
777
778 /* * Low bound of range. */
779
780 struct dynamic_prop low;
781
782 /* * High bound of range. */
783
784 struct dynamic_prop high;
785
786 /* The stride value for this range. This can be stored in bits or bytes
787 based on the value of BYTE_STRIDE_P. It is optional to have a stride
788 value, if this range has no stride value defined then this will be set
789 to the constant zero. */
790
791 struct dynamic_prop stride;
792
793 /* * The bias. Sometimes a range value is biased before storage.
794 The bias is added to the stored bits to form the true value. */
795
796 LONGEST bias;
797
798 /* True if HIGH range bound contains the number of elements in the
799 subrange. This affects how the final high bound is computed. */
800
801 unsigned int flag_upper_bound_is_count : 1;
802
803 /* True if LOW or/and HIGH are resolved into a static bound from
804 a dynamic one. */
805
806 unsigned int flag_bound_evaluated : 1;
807
808 /* If this is true this STRIDE is in bytes, otherwise STRIDE is in bits. */
809
810 unsigned int flag_is_byte_stride : 1;
811 };
812
813 /* Compare two range_bounds objects for equality. Simply does
814 memberwise comparison. */
815 extern bool operator== (const range_bounds &l, const range_bounds &r);
816
817 /* Compare two range_bounds objects for inequality. */
818 static inline bool operator!= (const range_bounds &l, const range_bounds &r)
819 {
820 return !(l == r);
821 }
822
823 union type_specific
824 {
825 /* * CPLUS_STUFF is for TYPE_CODE_STRUCT. It is initialized to
826 point to cplus_struct_default, a default static instance of a
827 struct cplus_struct_type. */
828
829 struct cplus_struct_type *cplus_stuff;
830
831 /* * GNAT_STUFF is for types for which the GNAT Ada compiler
832 provides additional information. */
833
834 struct gnat_aux_type *gnat_stuff;
835
836 /* * FLOATFORMAT is for TYPE_CODE_FLT. It is a pointer to a
837 floatformat object that describes the floating-point value
838 that resides within the type. */
839
840 const struct floatformat *floatformat;
841
842 /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types. */
843
844 struct func_type *func_stuff;
845
846 /* * For types that are pointer to member types (TYPE_CODE_METHODPTR,
847 TYPE_CODE_MEMBERPTR), SELF_TYPE is the type that this pointer
848 is a member of. */
849
850 struct type *self_type;
851
852 /* * For TYPE_CODE_FIXED_POINT types, the info necessary to decode
853 values of that type. */
854 struct fixed_point_type_info *fixed_point_info;
855
856 /* * An integer-like scalar type may be stored in just part of its
857 enclosing storage bytes. This structure describes this
858 situation. */
859 struct
860 {
861 /* * The bit size of the integer. This can be 0. For integers
862 that fill their storage (the ordinary case), this field holds
863 the byte size times 8. */
864 unsigned short bit_size;
865 /* * The bit offset of the integer. This is ordinarily 0, and can
866 only be non-zero if the bit size is less than the storage
867 size. */
868 unsigned short bit_offset;
869 } int_stuff;
870 };
871
872 /* * Main structure representing a type in GDB.
873
874 This structure is space-critical. Its layout has been tweaked to
875 reduce the space used. */
876
877 struct main_type
878 {
879 /* * Code for kind of type. */
880
881 ENUM_BITFIELD(type_code) code : 8;
882
883 /* * Flags about this type. These fields appear at this location
884 because they packs nicely here. See the TYPE_* macros for
885 documentation about these fields. */
886
887 unsigned int m_flag_unsigned : 1;
888 unsigned int m_flag_nosign : 1;
889 unsigned int m_flag_stub : 1;
890 unsigned int m_flag_target_stub : 1;
891 unsigned int m_flag_prototyped : 1;
892 unsigned int m_flag_varargs : 1;
893 unsigned int m_flag_vector : 1;
894 unsigned int m_flag_stub_supported : 1;
895 unsigned int m_flag_gnu_ifunc : 1;
896 unsigned int m_flag_fixed_instance : 1;
897 unsigned int m_flag_objfile_owned : 1;
898 unsigned int m_flag_endianity_not_default : 1;
899
900 /* * True if this type was declared with "class" rather than
901 "struct". */
902
903 unsigned int m_flag_declared_class : 1;
904
905 /* * True if this is an enum type with disjoint values. This
906 affects how the enum is printed. */
907
908 unsigned int m_flag_flag_enum : 1;
909
910 /* * A discriminant telling us which field of the type_specific
911 union is being used for this type, if any. */
912
913 ENUM_BITFIELD(type_specific_kind) type_specific_field : 3;
914
915 /* * Number of fields described for this type. This field appears
916 at this location because it packs nicely here. */
917
918 short nfields;
919
920 /* * Name of this type, or NULL if none.
921
922 This is used for printing only. For looking up a name, look for
923 a symbol in the VAR_DOMAIN. This is generally allocated in the
924 objfile's obstack. However coffread.c uses malloc. */
925
926 const char *name;
927
928 /* * Every type is now associated with a particular objfile, and the
929 type is allocated on the objfile_obstack for that objfile. One
930 problem however, is that there are times when gdb allocates new
931 types while it is not in the process of reading symbols from a
932 particular objfile. Fortunately, these happen when the type
933 being created is a derived type of an existing type, such as in
934 lookup_pointer_type(). So we can just allocate the new type
935 using the same objfile as the existing type, but to do this we
936 need a backpointer to the objfile from the existing type. Yes
937 this is somewhat ugly, but without major overhaul of the internal
938 type system, it can't be avoided for now. */
939
940 union type_owner m_owner;
941
942 /* * For a pointer type, describes the type of object pointed to.
943 - For an array type, describes the type of the elements.
944 - For a function or method type, describes the type of the return value.
945 - For a range type, describes the type of the full range.
946 - For a complex type, describes the type of each coordinate.
947 - For a special record or union type encoding a dynamic-sized type
948 in GNAT, a memoized pointer to a corresponding static version of
949 the type.
950 - Unused otherwise. */
951
952 struct type *target_type;
953
954 /* * For structure and union types, a description of each field.
955 For set and pascal array types, there is one "field",
956 whose type is the domain type of the set or array.
957 For range types, there are two "fields",
958 the minimum and maximum values (both inclusive).
959 For enum types, each possible value is described by one "field".
960 For a function or method type, a "field" for each parameter.
961 For C++ classes, there is one field for each base class (if it is
962 a derived class) plus one field for each class data member. Member
963 functions are recorded elsewhere.
964
965 Using a pointer to a separate array of fields
966 allows all types to have the same size, which is useful
967 because we can allocate the space for a type before
968 we know what to put in it. */
969
970 union
971 {
972 struct field *fields;
973
974 /* * Union member used for range types. */
975
976 struct range_bounds *bounds;
977
978 /* If this is a scalar type, then this is its corresponding
979 complex type. */
980 struct type *complex_type;
981
982 } flds_bnds;
983
984 /* * Slot to point to additional language-specific fields of this
985 type. */
986
987 union type_specific type_specific;
988
989 /* * Contains all dynamic type properties. */
990 struct dynamic_prop_list *dyn_prop_list;
991 };
992
993 /* * Number of bits allocated for alignment. */
994
995 #define TYPE_ALIGN_BITS 8
996
997 /* * A ``struct type'' describes a particular instance of a type, with
998 some particular qualification. */
999
1000 struct type
1001 {
1002 /* Get the type code of this type.
1003
1004 Note that the code can be TYPE_CODE_TYPEDEF, so if you want the real
1005 type, you need to do `check_typedef (type)->code ()`. */
1006 type_code code () const
1007 {
1008 return this->main_type->code;
1009 }
1010
1011 /* Set the type code of this type. */
1012 void set_code (type_code code)
1013 {
1014 this->main_type->code = code;
1015 }
1016
1017 /* Get the name of this type. */
1018 const char *name () const
1019 {
1020 return this->main_type->name;
1021 }
1022
1023 /* Set the name of this type. */
1024 void set_name (const char *name)
1025 {
1026 this->main_type->name = name;
1027 }
1028
1029 /* Get the number of fields of this type. */
1030 int num_fields () const
1031 {
1032 return this->main_type->nfields;
1033 }
1034
1035 /* Set the number of fields of this type. */
1036 void set_num_fields (int num_fields)
1037 {
1038 this->main_type->nfields = num_fields;
1039 }
1040
1041 /* Get the fields array of this type. */
1042 struct field *fields () const
1043 {
1044 return this->main_type->flds_bnds.fields;
1045 }
1046
1047 /* Get the field at index IDX. */
1048 struct field &field (int idx) const
1049 {
1050 gdb_assert (idx >= 0 && idx < num_fields ());
1051 return this->fields ()[idx];
1052 }
1053
1054 /* Set the fields array of this type. */
1055 void set_fields (struct field *fields)
1056 {
1057 this->main_type->flds_bnds.fields = fields;
1058 }
1059
1060 type *index_type () const
1061 {
1062 return this->field (0).type ();
1063 }
1064
1065 void set_index_type (type *index_type)
1066 {
1067 this->field (0).set_type (index_type);
1068 }
1069
1070 /* Return the instance flags converted to the correct type. */
1071 const type_instance_flags instance_flags () const
1072 {
1073 return (enum type_instance_flag_value) this->m_instance_flags;
1074 }
1075
1076 /* Set the instance flags. */
1077 void set_instance_flags (type_instance_flags flags)
1078 {
1079 this->m_instance_flags = flags;
1080 }
1081
1082 /* Get the bounds bounds of this type. The type must be a range type. */
1083 range_bounds *bounds () const
1084 {
1085 switch (this->code ())
1086 {
1087 case TYPE_CODE_RANGE:
1088 return this->main_type->flds_bnds.bounds;
1089
1090 case TYPE_CODE_ARRAY:
1091 case TYPE_CODE_STRING:
1092 return this->index_type ()->bounds ();
1093
1094 default:
1095 gdb_assert_not_reached
1096 ("type::bounds called on type with invalid code");
1097 }
1098 }
1099
1100 /* Set the bounds of this type. The type must be a range type. */
1101 void set_bounds (range_bounds *bounds)
1102 {
1103 gdb_assert (this->code () == TYPE_CODE_RANGE);
1104
1105 this->main_type->flds_bnds.bounds = bounds;
1106 }
1107
1108 ULONGEST bit_stride () const
1109 {
1110 if (this->code () == TYPE_CODE_ARRAY && this->field (0).bitsize != 0)
1111 return this->field (0).bitsize;
1112 return this->bounds ()->bit_stride ();
1113 }
1114
1115 /* Unsigned integer type. If this is not set for a TYPE_CODE_INT,
1116 the type is signed (unless TYPE_NOSIGN is set). */
1117
1118 bool is_unsigned () const
1119 {
1120 return this->main_type->m_flag_unsigned;
1121 }
1122
1123 void set_is_unsigned (bool is_unsigned)
1124 {
1125 this->main_type->m_flag_unsigned = is_unsigned;
1126 }
1127
1128 /* No sign for this type. In C++, "char", "signed char", and
1129 "unsigned char" are distinct types; so we need an extra flag to
1130 indicate the absence of a sign! */
1131
1132 bool has_no_signedness () const
1133 {
1134 return this->main_type->m_flag_nosign;
1135 }
1136
1137 void set_has_no_signedness (bool has_no_signedness)
1138 {
1139 this->main_type->m_flag_nosign = has_no_signedness;
1140 }
1141
1142 /* This appears in a type's flags word if it is a stub type (e.g.,
1143 if someone referenced a type that wasn't defined in a source file
1144 via (struct sir_not_appearing_in_this_film *)). */
1145
1146 bool is_stub () const
1147 {
1148 return this->main_type->m_flag_stub;
1149 }
1150
1151 void set_is_stub (bool is_stub)
1152 {
1153 this->main_type->m_flag_stub = is_stub;
1154 }
1155
1156 /* The target type of this type is a stub type, and this type needs
1157 to be updated if it gets un-stubbed in check_typedef. Used for
1158 arrays and ranges, in which TYPE_LENGTH of the array/range gets set
1159 based on the TYPE_LENGTH of the target type. Also, set for
1160 TYPE_CODE_TYPEDEF. */
1161
1162 bool target_is_stub () const
1163 {
1164 return this->main_type->m_flag_target_stub;
1165 }
1166
1167 void set_target_is_stub (bool target_is_stub)
1168 {
1169 this->main_type->m_flag_target_stub = target_is_stub;
1170 }
1171
1172 /* This is a function type which appears to have a prototype. We
1173 need this for function calls in order to tell us if it's necessary
1174 to coerce the args, or to just do the standard conversions. This
1175 is used with a short field. */
1176
1177 bool is_prototyped () const
1178 {
1179 return this->main_type->m_flag_prototyped;
1180 }
1181
1182 void set_is_prototyped (bool is_prototyped)
1183 {
1184 this->main_type->m_flag_prototyped = is_prototyped;
1185 }
1186
1187 /* FIXME drow/2002-06-03: Only used for methods, but applies as well
1188 to functions. */
1189
1190 bool has_varargs () const
1191 {
1192 return this->main_type->m_flag_varargs;
1193 }
1194
1195 void set_has_varargs (bool has_varargs)
1196 {
1197 this->main_type->m_flag_varargs = has_varargs;
1198 }
1199
1200 /* Identify a vector type. Gcc is handling this by adding an extra
1201 attribute to the array type. We slurp that in as a new flag of a
1202 type. This is used only in dwarf2read.c. */
1203
1204 bool is_vector () const
1205 {
1206 return this->main_type->m_flag_vector;
1207 }
1208
1209 void set_is_vector (bool is_vector)
1210 {
1211 this->main_type->m_flag_vector = is_vector;
1212 }
1213
1214 /* This debug target supports TYPE_STUB(t). In the unsupported case
1215 we have to rely on NFIELDS to be zero etc., see TYPE_IS_OPAQUE().
1216 TYPE_STUB(t) with !TYPE_STUB_SUPPORTED(t) may exist if we only
1217 guessed the TYPE_STUB(t) value (see dwarfread.c). */
1218
1219 bool stub_is_supported () const
1220 {
1221 return this->main_type->m_flag_stub_supported;
1222 }
1223
1224 void set_stub_is_supported (bool stub_is_supported)
1225 {
1226 this->main_type->m_flag_stub_supported = stub_is_supported;
1227 }
1228
1229 /* Used only for TYPE_CODE_FUNC where it specifies the real function
1230 address is returned by this function call. TYPE_TARGET_TYPE
1231 determines the final returned function type to be presented to
1232 user. */
1233
1234 bool is_gnu_ifunc () const
1235 {
1236 return this->main_type->m_flag_gnu_ifunc;
1237 }
1238
1239 void set_is_gnu_ifunc (bool is_gnu_ifunc)
1240 {
1241 this->main_type->m_flag_gnu_ifunc = is_gnu_ifunc;
1242 }
1243
1244 /* The debugging formats (especially STABS) do not contain enough
1245 information to represent all Ada types---especially those whose
1246 size depends on dynamic quantities. Therefore, the GNAT Ada
1247 compiler includes extra information in the form of additional type
1248 definitions connected by naming conventions. This flag indicates
1249 that the type is an ordinary (unencoded) GDB type that has been
1250 created from the necessary run-time information, and does not need
1251 further interpretation. Optionally marks ordinary, fixed-size GDB
1252 type. */
1253
1254 bool is_fixed_instance () const
1255 {
1256 return this->main_type->m_flag_fixed_instance;
1257 }
1258
1259 void set_is_fixed_instance (bool is_fixed_instance)
1260 {
1261 this->main_type->m_flag_fixed_instance = is_fixed_instance;
1262 }
1263
1264 /* A compiler may supply dwarf instrumentation that indicates the desired
1265 endian interpretation of the variable differs from the native endian
1266 representation. */
1267
1268 bool endianity_is_not_default () const
1269 {
1270 return this->main_type->m_flag_endianity_not_default;
1271 }
1272
1273 void set_endianity_is_not_default (bool endianity_is_not_default)
1274 {
1275 this->main_type->m_flag_endianity_not_default = endianity_is_not_default;
1276 }
1277
1278
1279 /* True if this type was declared using the "class" keyword. This is
1280 only valid for C++ structure and enum types. If false, a structure
1281 was declared as a "struct"; if true it was declared "class". For
1282 enum types, this is true when "enum class" or "enum struct" was
1283 used to declare the type. */
1284
1285 bool is_declared_class () const
1286 {
1287 return this->main_type->m_flag_declared_class;
1288 }
1289
1290 void set_is_declared_class (bool is_declared_class) const
1291 {
1292 this->main_type->m_flag_declared_class = is_declared_class;
1293 }
1294
1295 /* True if this type is a "flag" enum. A flag enum is one where all
1296 the values are pairwise disjoint when "and"ed together. This
1297 affects how enum values are printed. */
1298
1299 bool is_flag_enum () const
1300 {
1301 return this->main_type->m_flag_flag_enum;
1302 }
1303
1304 void set_is_flag_enum (bool is_flag_enum)
1305 {
1306 this->main_type->m_flag_flag_enum = is_flag_enum;
1307 }
1308
1309 /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference
1310 to this type's fixed_point_info. */
1311
1312 struct fixed_point_type_info &fixed_point_info () const
1313 {
1314 gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
1315 gdb_assert (this->main_type->type_specific.fixed_point_info != nullptr);
1316
1317 return *this->main_type->type_specific.fixed_point_info;
1318 }
1319
1320 /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, set this type's
1321 fixed_point_info to INFO. */
1322
1323 void set_fixed_point_info (struct fixed_point_type_info *info) const
1324 {
1325 gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
1326
1327 this->main_type->type_specific.fixed_point_info = info;
1328 }
1329
1330 /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its base type.
1331
1332 In other words, this returns the type after having peeled all
1333 intermediate type layers (such as TYPE_CODE_RANGE, for instance).
1334 The TYPE_CODE of the type returned is guaranteed to be
1335 a TYPE_CODE_FIXED_POINT. */
1336
1337 struct type *fixed_point_type_base_type ();
1338
1339 /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its scaling
1340 factor. */
1341
1342 const gdb_mpq &fixed_point_scaling_factor ();
1343
1344 /* * Return the dynamic property of the requested KIND from this type's
1345 list of dynamic properties. */
1346 dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
1347
1348 /* * Given a dynamic property PROP of a given KIND, add this dynamic
1349 property to this type.
1350
1351 This function assumes that this type is objfile-owned. */
1352 void add_dyn_prop (dynamic_prop_node_kind kind, dynamic_prop prop);
1353
1354 /* * Remove dynamic property of kind KIND from this type, if it exists. */
1355 void remove_dyn_prop (dynamic_prop_node_kind kind);
1356
1357 /* Return true if this type is owned by an objfile. Return false if it is
1358 owned by an architecture. */
1359 bool is_objfile_owned () const
1360 {
1361 return this->main_type->m_flag_objfile_owned;
1362 }
1363
1364 /* Set the owner of the type to be OBJFILE. */
1365 void set_owner (objfile *objfile)
1366 {
1367 gdb_assert (objfile != nullptr);
1368
1369 this->main_type->m_owner.objfile = objfile;
1370 this->main_type->m_flag_objfile_owned = true;
1371 }
1372
1373 /* Set the owner of the type to be ARCH. */
1374 void set_owner (gdbarch *arch)
1375 {
1376 gdb_assert (arch != nullptr);
1377
1378 this->main_type->m_owner.gdbarch = arch;
1379 this->main_type->m_flag_objfile_owned = false;
1380 }
1381
1382 /* Return the objfile owner of this type.
1383
1384 Return nullptr if this type is not objfile-owned. */
1385 struct objfile *objfile_owner () const
1386 {
1387 if (!this->is_objfile_owned ())
1388 return nullptr;
1389
1390 return this->main_type->m_owner.objfile;
1391 }
1392
1393 /* Return the gdbarch owner of this type.
1394
1395 Return nullptr if this type is not gdbarch-owned. */
1396 gdbarch *arch_owner () const
1397 {
1398 if (this->is_objfile_owned ())
1399 return nullptr;
1400
1401 return this->main_type->m_owner.gdbarch;
1402 }
1403
1404 /* Return the type's architecture. For types owned by an
1405 architecture, that architecture is returned. For types owned by an
1406 objfile, that objfile's architecture is returned.
1407
1408 The return value is always non-nullptr. */
1409 gdbarch *arch () const;
1410
1411 /* * Return true if this is an integer type whose logical (bit) size
1412 differs from its storage size; false otherwise. Always return
1413 false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types. */
1414 bool bit_size_differs_p () const
1415 {
1416 return (main_type->type_specific_field == TYPE_SPECIFIC_INT
1417 && main_type->type_specific.int_stuff.bit_size != 8 * length);
1418 }
1419
1420 /* * Return the logical (bit) size for this integer type. Only
1421 valid for integer (TYPE_SPECIFIC_INT) types. */
1422 unsigned short bit_size () const
1423 {
1424 gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
1425 return main_type->type_specific.int_stuff.bit_size;
1426 }
1427
1428 /* * Return the bit offset for this integer type. Only valid for
1429 integer (TYPE_SPECIFIC_INT) types. */
1430 unsigned short bit_offset () const
1431 {
1432 gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
1433 return main_type->type_specific.int_stuff.bit_offset;
1434 }
1435
1436 /* Return true if this is a pointer or reference type. */
1437 bool is_pointer_or_reference () const
1438 {
1439 return this->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (this);
1440 }
1441
1442 /* * Type that is a pointer to this type.
1443 NULL if no such pointer-to type is known yet.
1444 The debugger may add the address of such a type
1445 if it has to construct one later. */
1446
1447 struct type *pointer_type;
1448
1449 /* * C++: also need a reference type. */
1450
1451 struct type *reference_type;
1452
1453 /* * A C++ rvalue reference type added in C++11. */
1454
1455 struct type *rvalue_reference_type;
1456
1457 /* * Variant chain. This points to a type that differs from this
1458 one only in qualifiers and length. Currently, the possible
1459 qualifiers are const, volatile, code-space, data-space, and
1460 address class. The length may differ only when one of the
1461 address class flags are set. The variants are linked in a
1462 circular ring and share MAIN_TYPE. */
1463
1464 struct type *chain;
1465
1466 /* * The alignment for this type. Zero means that the alignment was
1467 not specified in the debug info. Note that this is stored in a
1468 funny way: as the log base 2 (plus 1) of the alignment; so a
1469 value of 1 means the alignment is 1, and a value of 9 means the
1470 alignment is 256. */
1471
1472 unsigned align_log2 : TYPE_ALIGN_BITS;
1473
1474 /* * Flags specific to this instance of the type, indicating where
1475 on the ring we are.
1476
1477 For TYPE_CODE_TYPEDEF the flags of the typedef type should be
1478 binary or-ed with the target type, with a special case for
1479 address class and space class. For example if this typedef does
1480 not specify any new qualifiers, TYPE_INSTANCE_FLAGS is 0 and the
1481 instance flags are completely inherited from the target type. No
1482 qualifiers can be cleared by the typedef. See also
1483 check_typedef. */
1484 unsigned m_instance_flags : 9;
1485
1486 /* * Length of storage for a value of this type. The value is the
1487 expression in host bytes of what sizeof(type) would return. This
1488 size includes padding. For example, an i386 extended-precision
1489 floating point value really only occupies ten bytes, but most
1490 ABI's declare its size to be 12 bytes, to preserve alignment.
1491 A `struct type' representing such a floating-point type would
1492 have a `length' value of 12, even though the last two bytes are
1493 unused.
1494
1495 Since this field is expressed in host bytes, its value is appropriate
1496 to pass to memcpy and such (it is assumed that GDB itself always runs
1497 on an 8-bits addressable architecture). However, when using it for
1498 target address arithmetic (e.g. adding it to a target address), the
1499 type_length_units function should be used in order to get the length
1500 expressed in target addressable memory units. */
1501
1502 ULONGEST length;
1503
1504 /* * Core type, shared by a group of qualified types. */
1505
1506 struct main_type *main_type;
1507 };
1508
1509 struct fn_fieldlist
1510 {
1511
1512 /* * The overloaded name.
1513 This is generally allocated in the objfile's obstack.
1514 However stabsread.c sometimes uses malloc. */
1515
1516 const char *name;
1517
1518 /* * The number of methods with this name. */
1519
1520 int length;
1521
1522 /* * The list of methods. */
1523
1524 struct fn_field *fn_fields;
1525 };
1526
1527
1528
1529 struct fn_field
1530 {
1531 /* * If is_stub is clear, this is the mangled name which we can look
1532 up to find the address of the method (FIXME: it would be cleaner
1533 to have a pointer to the struct symbol here instead).
1534
1535 If is_stub is set, this is the portion of the mangled name which
1536 specifies the arguments. For example, "ii", if there are two int
1537 arguments, or "" if there are no arguments. See gdb_mangle_name
1538 for the conversion from this format to the one used if is_stub is
1539 clear. */
1540
1541 const char *physname;
1542
1543 /* * The function type for the method.
1544
1545 (This comment used to say "The return value of the method", but
1546 that's wrong. The function type is expected here, i.e. something
1547 with TYPE_CODE_METHOD, and *not* the return-value type). */
1548
1549 struct type *type;
1550
1551 /* * For virtual functions. First baseclass that defines this
1552 virtual function. */
1553
1554 struct type *fcontext;
1555
1556 /* Attributes. */
1557
1558 unsigned int is_const:1;
1559 unsigned int is_volatile:1;
1560 unsigned int is_private:1;
1561 unsigned int is_protected:1;
1562 unsigned int is_artificial:1;
1563
1564 /* * A stub method only has some fields valid (but they are enough
1565 to reconstruct the rest of the fields). */
1566
1567 unsigned int is_stub:1;
1568
1569 /* * True if this function is a constructor, false otherwise. */
1570
1571 unsigned int is_constructor : 1;
1572
1573 /* * True if this function is deleted, false otherwise. */
1574
1575 unsigned int is_deleted : 1;
1576
1577 /* * DW_AT_defaulted attribute for this function. The value is one
1578 of the DW_DEFAULTED constants. */
1579
1580 ENUM_BITFIELD (dwarf_defaulted_attribute) defaulted : 2;
1581
1582 /* * Unused. */
1583
1584 unsigned int dummy:6;
1585
1586 /* * Index into that baseclass's virtual function table, minus 2;
1587 else if static: VOFFSET_STATIC; else: 0. */
1588
1589 unsigned int voffset:16;
1590
1591 #define VOFFSET_STATIC 1
1592
1593 };
1594
1595 struct decl_field
1596 {
1597 /* * Unqualified name to be prefixed by owning class qualified
1598 name. */
1599
1600 const char *name;
1601
1602 /* * Type this typedef named NAME represents. */
1603
1604 struct type *type;
1605
1606 /* * True if this field was declared protected, false otherwise. */
1607 unsigned int is_protected : 1;
1608
1609 /* * True if this field was declared private, false otherwise. */
1610 unsigned int is_private : 1;
1611 };
1612
1613 /* * C++ language-specific information for TYPE_CODE_STRUCT and
1614 TYPE_CODE_UNION nodes. */
1615
1616 struct cplus_struct_type
1617 {
1618 /* * Number of base classes this type derives from. The
1619 baseclasses are stored in the first N_BASECLASSES fields
1620 (i.e. the `fields' field of the struct type). The only fields
1621 of struct field that are used are: type, name, loc.bitpos. */
1622
1623 short n_baseclasses;
1624
1625 /* * Field number of the virtual function table pointer in VPTR_BASETYPE.
1626 All access to this field must be through TYPE_VPTR_FIELDNO as one
1627 thing it does is check whether the field has been initialized.
1628 Initially TYPE_RAW_CPLUS_SPECIFIC has the value of cplus_struct_default,
1629 which for portability reasons doesn't initialize this field.
1630 TYPE_VPTR_FIELDNO returns -1 for this case.
1631
1632 If -1, we were unable to find the virtual function table pointer in
1633 initial symbol reading, and get_vptr_fieldno should be called to find
1634 it if possible. get_vptr_fieldno will update this field if possible.
1635 Otherwise the value is left at -1.
1636
1637 Unused if this type does not have virtual functions. */
1638
1639 short vptr_fieldno;
1640
1641 /* * Number of methods with unique names. All overloaded methods
1642 with the same name count only once. */
1643
1644 short nfn_fields;
1645
1646 /* * Number of template arguments. */
1647
1648 unsigned short n_template_arguments;
1649
1650 /* * One if this struct is a dynamic class, as defined by the
1651 Itanium C++ ABI: if it requires a virtual table pointer,
1652 because it or any of its base classes have one or more virtual
1653 member functions or virtual base classes. Minus one if not
1654 dynamic. Zero if not yet computed. */
1655
1656 int is_dynamic : 2;
1657
1658 /* * The calling convention for this type, fetched from the
1659 DW_AT_calling_convention attribute. The value is one of the
1660 DW_CC constants. */
1661
1662 ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;
1663
1664 /* * The base class which defined the virtual function table pointer. */
1665
1666 struct type *vptr_basetype;
1667
1668 /* * For derived classes, the number of base classes is given by
1669 n_baseclasses and virtual_field_bits is a bit vector containing
1670 one bit per base class. If the base class is virtual, the
1671 corresponding bit will be set.
1672 I.E, given:
1673
1674 class A{};
1675 class B{};
1676 class C : public B, public virtual A {};
1677
1678 B is a baseclass of C; A is a virtual baseclass for C.
1679 This is a C++ 2.0 language feature. */
1680
1681 B_TYPE *virtual_field_bits;
1682
1683 /* * For classes with private fields, the number of fields is
1684 given by nfields and private_field_bits is a bit vector
1685 containing one bit per field.
1686
1687 If the field is private, the corresponding bit will be set. */
1688
1689 B_TYPE *private_field_bits;
1690
1691 /* * For classes with protected fields, the number of fields is
1692 given by nfields and protected_field_bits is a bit vector
1693 containing one bit per field.
1694
1695 If the field is private, the corresponding bit will be set. */
1696
1697 B_TYPE *protected_field_bits;
1698
1699 /* * For classes with fields to be ignored, either this is
1700 optimized out or this field has length 0. */
1701
1702 B_TYPE *ignore_field_bits;
1703
1704 /* * For classes, structures, and unions, a description of each
1705 field, which consists of an overloaded name, followed by the
1706 types of arguments that the method expects, and then the name
1707 after it has been renamed to make it distinct.
1708
1709 fn_fieldlists points to an array of nfn_fields of these. */
1710
1711 struct fn_fieldlist *fn_fieldlists;
1712
1713 /* * typedefs defined inside this class. typedef_field points to
1714 an array of typedef_field_count elements. */
1715
1716 struct decl_field *typedef_field;
1717
1718 unsigned typedef_field_count;
1719
1720 /* * The nested types defined by this type. nested_types points to
1721 an array of nested_types_count elements. */
1722
1723 struct decl_field *nested_types;
1724
1725 unsigned nested_types_count;
1726
1727 /* * The template arguments. This is an array with
1728 N_TEMPLATE_ARGUMENTS elements. This is NULL for non-template
1729 classes. */
1730
1731 struct symbol **template_arguments;
1732 };
1733
1734 /* * Struct used to store conversion rankings. */
1735
1736 struct rank
1737 {
1738 short rank;
1739
1740 /* * When two conversions are of the same type and therefore have
1741 the same rank, subrank is used to differentiate the two.
1742
1743 Eg: Two derived-class-pointer to base-class-pointer conversions
1744 would both have base pointer conversion rank, but the
1745 conversion with the shorter distance to the ancestor is
1746 preferable. 'subrank' would be used to reflect that. */
1747
1748 short subrank;
1749 };
1750
1751 /* * Used for ranking a function for overload resolution. */
1752
1753 typedef std::vector<rank> badness_vector;
1754
1755 /* * GNAT Ada-specific information for various Ada types. */
1756
1757 struct gnat_aux_type
1758 {
1759 /* * Parallel type used to encode information about dynamic types
1760 used in Ada (such as variant records, variable-size array,
1761 etc). */
1762 struct type* descriptive_type;
1763 };
1764
1765 /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types. */
1766
1767 struct func_type
1768 {
1769 /* * The calling convention for targets supporting multiple ABIs.
1770 Right now this is only fetched from the Dwarf-2
1771 DW_AT_calling_convention attribute. The value is one of the
1772 DW_CC constants. */
1773
1774 ENUM_BITFIELD (dwarf_calling_convention) calling_convention : 8;
1775
1776 /* * Whether this function normally returns to its caller. It is
1777 set from the DW_AT_noreturn attribute if set on the
1778 DW_TAG_subprogram. */
1779
1780 unsigned int is_noreturn : 1;
1781
1782 /* * Only those DW_TAG_call_site's in this function that have
1783 DW_AT_call_tail_call set are linked in this list. Function
1784 without its tail call list complete
1785 (DW_AT_call_all_tail_calls or its superset
1786 DW_AT_call_all_calls) has TAIL_CALL_LIST NULL, even if some
1787 DW_TAG_call_site's exist in such function. */
1788
1789 struct call_site *tail_call_list;
1790
1791 /* * For method types (TYPE_CODE_METHOD), the aggregate type that
1792 contains the method. */
1793
1794 struct type *self_type;
1795 };
1796
1797 /* struct call_site_parameter can be referenced in callees by several ways. */
1798
1799 enum call_site_parameter_kind
1800 {
1801 /* * Use field call_site_parameter.u.dwarf_reg. */
1802 CALL_SITE_PARAMETER_DWARF_REG,
1803
1804 /* * Use field call_site_parameter.u.fb_offset. */
1805 CALL_SITE_PARAMETER_FB_OFFSET,
1806
1807 /* * Use field call_site_parameter.u.param_offset. */
1808 CALL_SITE_PARAMETER_PARAM_OFFSET
1809 };
1810
1811 struct call_site_target
1812 {
1813 field_loc_kind loc_kind () const
1814 {
1815 return m_loc_kind;
1816 }
1817
1818 CORE_ADDR loc_physaddr () const
1819 {
1820 gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSADDR);
1821 return m_loc.physaddr;
1822 }
1823
1824 void set_loc_physaddr (CORE_ADDR physaddr)
1825 {
1826 m_loc_kind = FIELD_LOC_KIND_PHYSADDR;
1827 m_loc.physaddr = physaddr;
1828 }
1829
1830 const char *loc_physname () const
1831 {
1832 gdb_assert (m_loc_kind == FIELD_LOC_KIND_PHYSNAME);
1833 return m_loc.physname;
1834 }
1835
1836 void set_loc_physname (const char *physname)
1837 {
1838 m_loc_kind = FIELD_LOC_KIND_PHYSNAME;
1839 m_loc.physname = physname;
1840 }
1841
1842 dwarf2_locexpr_baton *loc_dwarf_block () const
1843 {
1844 gdb_assert (m_loc_kind == FIELD_LOC_KIND_DWARF_BLOCK);
1845 return m_loc.dwarf_block;
1846 }
1847
1848 void set_loc_dwarf_block (dwarf2_locexpr_baton *dwarf_block)
1849 {
1850 m_loc_kind = FIELD_LOC_KIND_DWARF_BLOCK;
1851 m_loc.dwarf_block = dwarf_block;
1852 }
1853
1854 union field_location m_loc;
1855
1856 /* * Discriminant for union field_location. */
1857
1858 ENUM_BITFIELD(field_loc_kind) m_loc_kind : 3;
1859 };
1860
1861 union call_site_parameter_u
1862 {
1863 /* * DW_TAG_formal_parameter's DW_AT_location's DW_OP_regX
1864 as DWARF register number, for register passed
1865 parameters. */
1866
1867 int dwarf_reg;
1868
1869 /* * Offset from the callee's frame base, for stack passed
1870 parameters. This equals offset from the caller's stack
1871 pointer. */
1872
1873 CORE_ADDR fb_offset;
1874
1875 /* * Offset relative to the start of this PER_CU to
1876 DW_TAG_formal_parameter which is referenced by both
1877 caller and the callee. */
1878
1879 cu_offset param_cu_off;
1880 };
1881
1882 struct call_site_parameter
1883 {
1884 ENUM_BITFIELD (call_site_parameter_kind) kind : 2;
1885
1886 union call_site_parameter_u u;
1887
1888 /* * DW_TAG_formal_parameter's DW_AT_call_value. It is never NULL. */
1889
1890 const gdb_byte *value;
1891 size_t value_size;
1892
1893 /* * DW_TAG_formal_parameter's DW_AT_call_data_value.
1894 It may be NULL if not provided by DWARF. */
1895
1896 const gdb_byte *data_value;
1897 size_t data_value_size;
1898 };
1899
1900 /* * A place where a function gets called from, represented by
1901 DW_TAG_call_site. It can be looked up from symtab->call_site_htab. */
1902
1903 struct call_site
1904 {
1905 call_site (CORE_ADDR pc, dwarf2_per_cu_data *per_cu,
1906 dwarf2_per_objfile *per_objfile)
1907 : per_cu (per_cu), per_objfile (per_objfile), m_unrelocated_pc (pc)
1908 {}
1909
1910 static int
1911 eq (const call_site *a, const call_site *b)
1912 {
1913 return core_addr_eq (&a->m_unrelocated_pc, &b->m_unrelocated_pc);
1914 }
1915
1916 static hashval_t
1917 hash (const call_site *a)
1918 {
1919 return core_addr_hash (&a->m_unrelocated_pc);
1920 }
1921
1922 static int
1923 eq (const void *a, const void *b)
1924 {
1925 return eq ((const call_site *)a, (const call_site *)b);
1926 }
1927
1928 static hashval_t
1929 hash (const void *a)
1930 {
1931 return hash ((const call_site *)a);
1932 }
1933
1934 /* Return the address of the first instruction after this call. */
1935
1936 CORE_ADDR pc () const;
1937
1938 /* * List successor with head in FUNC_TYPE.TAIL_CALL_LIST. */
1939
1940 struct call_site *tail_call_next = nullptr;
1941
1942 /* * Describe DW_AT_call_target. Missing attribute uses
1943 FIELD_LOC_KIND_DWARF_BLOCK with FIELD_DWARF_BLOCK == NULL. */
1944
1945 struct call_site_target target {};
1946
1947 /* * Size of the PARAMETER array. */
1948
1949 unsigned parameter_count = 0;
1950
1951 /* * CU of the function where the call is located. It gets used
1952 for DWARF blocks execution in the parameter array below. */
1953
1954 dwarf2_per_cu_data *const per_cu = nullptr;
1955
1956 /* objfile of the function where the call is located. */
1957
1958 dwarf2_per_objfile *const per_objfile = nullptr;
1959
1960 private:
1961 /* Unrelocated address of the first instruction after this call. */
1962 const CORE_ADDR m_unrelocated_pc;
1963
1964 public:
1965 /* * Describe DW_TAG_call_site's DW_TAG_formal_parameter. */
1966
1967 struct call_site_parameter parameter[];
1968 };
1969
1970 /* The type-specific info for TYPE_CODE_FIXED_POINT types. */
1971
1972 struct fixed_point_type_info
1973 {
1974 /* The fixed point type's scaling factor. */
1975 gdb_mpq scaling_factor;
1976 };
1977
1978 /* * The default value of TYPE_CPLUS_SPECIFIC(T) points to this shared
1979 static structure. */
1980
1981 extern const struct cplus_struct_type cplus_struct_default;
1982
1983 extern void allocate_cplus_struct_type (struct type *);
1984
1985 #define INIT_CPLUS_SPECIFIC(type) \
1986 (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF, \
1987 TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type*) \
1988 &cplus_struct_default)
1989
1990 #define ALLOCATE_CPLUS_STRUCT_TYPE(type) allocate_cplus_struct_type (type)
1991
1992 #define HAVE_CPLUS_STRUCT(type) \
1993 (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF \
1994 && TYPE_RAW_CPLUS_SPECIFIC (type) != &cplus_struct_default)
1995
1996 #define INIT_NONE_SPECIFIC(type) \
1997 (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_NONE, \
1998 TYPE_MAIN_TYPE (type)->type_specific = {})
1999
2000 extern const struct gnat_aux_type gnat_aux_default;
2001
2002 extern void allocate_gnat_aux_type (struct type *);
2003
2004 #define INIT_GNAT_SPECIFIC(type) \
2005 (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF, \
2006 TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *) &gnat_aux_default)
2007 #define ALLOCATE_GNAT_AUX_TYPE(type) allocate_gnat_aux_type (type)
2008 /* * A macro that returns non-zero if the type-specific data should be
2009 read as "gnat-stuff". */
2010 #define HAVE_GNAT_AUX_INFO(type) \
2011 (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_GNAT_STUFF)
2012
2013 /* * True if TYPE is known to be an Ada type of some kind. */
2014 #define ADA_TYPE_P(type) \
2015 (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_GNAT_STUFF \
2016 || (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE \
2017 && (type)->is_fixed_instance ()))
2018
2019 #define INIT_FUNC_SPECIFIC(type) \
2020 (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FUNC, \
2021 TYPE_MAIN_TYPE (type)->type_specific.func_stuff = (struct func_type *) \
2022 TYPE_ZALLOC (type, \
2023 sizeof (*TYPE_MAIN_TYPE (type)->type_specific.func_stuff)))
2024
2025 /* "struct fixed_point_type_info" has a field that has a destructor.
2026 See allocate_fixed_point_type_info to understand how this is
2027 handled. */
2028 #define INIT_FIXED_POINT_SPECIFIC(type) \
2029 (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FIXED_POINT, \
2030 allocate_fixed_point_type_info (type))
2031
2032 #define TYPE_MAIN_TYPE(thistype) (thistype)->main_type
2033 #define TYPE_TARGET_TYPE(thistype) TYPE_MAIN_TYPE(thistype)->target_type
2034 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
2035 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
2036 #define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type
2037 #define TYPE_CHAIN(thistype) (thistype)->chain
2038 /* * Note that if thistype is a TYPEDEF type, you have to call check_typedef.
2039 But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
2040 so you only have to call check_typedef once. Since allocate_value
2041 calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
2042 #define TYPE_LENGTH(thistype) (thistype)->length
2043
2044 /* * Return the alignment of the type in target addressable memory
2045 units, or 0 if no alignment was specified. */
2046 #define TYPE_RAW_ALIGN(thistype) type_raw_align (thistype)
2047
2048 /* * Return the alignment of the type in target addressable memory
2049 units, or 0 if no alignment was specified. */
2050 extern unsigned type_raw_align (struct type *);
2051
2052 /* * Return the alignment of the type in target addressable memory
2053 units. Return 0 if the alignment cannot be determined; but note
2054 that this makes an effort to compute the alignment even it it was
2055 not specified in the debug info. */
2056 extern unsigned type_align (struct type *);
2057
2058 /* * Set the alignment of the type. The alignment must be a power of
2059 2. Returns false if the given value does not fit in the available
2060 space in struct type. */
2061 extern bool set_type_align (struct type *, ULONGEST);
2062
2063 /* Property accessors for the type data location. */
2064 #define TYPE_DATA_LOCATION(thistype) \
2065 ((thistype)->dyn_prop (DYN_PROP_DATA_LOCATION))
2066 #define TYPE_DATA_LOCATION_BATON(thistype) \
2067 TYPE_DATA_LOCATION (thistype)->data.baton
2068 #define TYPE_DATA_LOCATION_ADDR(thistype) \
2069 (TYPE_DATA_LOCATION (thistype)->const_val ())
2070 #define TYPE_DATA_LOCATION_KIND(thistype) \
2071 (TYPE_DATA_LOCATION (thistype)->kind ())
2072 #define TYPE_DYNAMIC_LENGTH(thistype) \
2073 ((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))
2074
2075 /* Property accessors for the type allocated/associated. */
2076 #define TYPE_ALLOCATED_PROP(thistype) \
2077 ((thistype)->dyn_prop (DYN_PROP_ALLOCATED))
2078 #define TYPE_ASSOCIATED_PROP(thistype) \
2079 ((thistype)->dyn_prop (DYN_PROP_ASSOCIATED))
2080
2081 /* C++ */
2082
2083 #define TYPE_SELF_TYPE(thistype) internal_type_self_type (thistype)
2084 /* Do not call this, use TYPE_SELF_TYPE. */
2085 extern struct type *internal_type_self_type (struct type *);
2086 extern void set_type_self_type (struct type *, struct type *);
2087
2088 extern int internal_type_vptr_fieldno (struct type *);
2089 extern void set_type_vptr_fieldno (struct type *, int);
2090 extern struct type *internal_type_vptr_basetype (struct type *);
2091 extern void set_type_vptr_basetype (struct type *, struct type *);
2092 #define TYPE_VPTR_FIELDNO(thistype) internal_type_vptr_fieldno (thistype)
2093 #define TYPE_VPTR_BASETYPE(thistype) internal_type_vptr_basetype (thistype)
2094
2095 #define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields
2096 #define TYPE_SPECIFIC_FIELD(thistype) \
2097 TYPE_MAIN_TYPE(thistype)->type_specific_field
2098 /* We need this tap-dance with the TYPE_RAW_SPECIFIC because of the case
2099 where we're trying to print an Ada array using the C language.
2100 In that case, there is no "cplus_stuff", but the C language assumes
2101 that there is. What we do, in that case, is pretend that there is
2102 an implicit one which is the default cplus stuff. */
2103 #define TYPE_CPLUS_SPECIFIC(thistype) \
2104 (!HAVE_CPLUS_STRUCT(thistype) \
2105 ? (struct cplus_struct_type*)&cplus_struct_default \
2106 : TYPE_RAW_CPLUS_SPECIFIC(thistype))
2107 #define TYPE_RAW_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
2108 #define TYPE_CPLUS_CALLING_CONVENTION(thistype) \
2109 TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff->calling_convention
2110 #define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
2111 #define TYPE_GNAT_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.gnat_stuff
2112 #define TYPE_DESCRIPTIVE_TYPE(thistype) TYPE_GNAT_SPECIFIC(thistype)->descriptive_type
2113 #define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->calling_convention
2114 #define TYPE_NO_RETURN(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->is_noreturn
2115 #define TYPE_TAIL_CALL_LIST(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->tail_call_list
2116 #define TYPE_BASECLASS(thistype,index) ((thistype)->field (index).type ())
2117 #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
2118 #define TYPE_BASECLASS_NAME(thistype,index) (thistype->field (index).name ())
2119 #define TYPE_BASECLASS_BITPOS(thistype,index) (thistype->field (index).loc_bitpos ())
2120 #define BASETYPE_VIA_PUBLIC(thistype, index) \
2121 ((!TYPE_FIELD_PRIVATE(thistype, index)) && (!TYPE_FIELD_PROTECTED(thistype, index)))
2122 #define TYPE_CPLUS_DYNAMIC(thistype) TYPE_CPLUS_SPECIFIC (thistype)->is_dynamic
2123
2124 #define BASETYPE_VIA_VIRTUAL(thistype, index) \
2125 (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
2126 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (index)))
2127
2128 #define FIELD_ARTIFICIAL(thisfld) ((thisfld).artificial)
2129 #define FIELD_BITSIZE(thisfld) ((thisfld).bitsize)
2130
2131 #define TYPE_FIELD_DWARF_BLOCK(thistype, n) ((thistype)->field (n).loc_dwarf_block ())
2132 #define TYPE_FIELD_ARTIFICIAL(thistype, n) FIELD_ARTIFICIAL((thistype)->field (n))
2133 #define TYPE_FIELD_BITSIZE(thistype, n) FIELD_BITSIZE((thistype)->field (n))
2134 #define TYPE_FIELD_PACKED(thistype, n) (FIELD_BITSIZE((thistype)->field (n))!=0)
2135
2136 #define TYPE_FIELD_PRIVATE_BITS(thistype) \
2137 TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits
2138 #define TYPE_FIELD_PROTECTED_BITS(thistype) \
2139 TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits
2140 #define TYPE_FIELD_IGNORE_BITS(thistype) \
2141 TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits
2142 #define TYPE_FIELD_VIRTUAL_BITS(thistype) \
2143 TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits
2144 #define SET_TYPE_FIELD_PRIVATE(thistype, n) \
2145 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n))
2146 #define SET_TYPE_FIELD_PROTECTED(thistype, n) \
2147 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n))
2148 #define SET_TYPE_FIELD_IGNORE(thistype, n) \
2149 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits, (n))
2150 #define SET_TYPE_FIELD_VIRTUAL(thistype, n) \
2151 B_SET (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n))
2152 #define TYPE_FIELD_PRIVATE(thistype, n) \
2153 (TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits == NULL ? 0 \
2154 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->private_field_bits, (n)))
2155 #define TYPE_FIELD_PROTECTED(thistype, n) \
2156 (TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits == NULL ? 0 \
2157 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->protected_field_bits, (n)))
2158 #define TYPE_FIELD_IGNORE(thistype, n) \
2159 (TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits == NULL ? 0 \
2160 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->ignore_field_bits, (n)))
2161 #define TYPE_FIELD_VIRTUAL(thistype, n) \
2162 (TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits == NULL ? 0 \
2163 : B_TST(TYPE_CPLUS_SPECIFIC(thistype)->virtual_field_bits, (n)))
2164
2165 #define TYPE_FN_FIELDLISTS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists
2166 #define TYPE_FN_FIELDLIST(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n]
2167 #define TYPE_FN_FIELDLIST1(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].fn_fields
2168 #define TYPE_FN_FIELDLIST_NAME(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].name
2169 #define TYPE_FN_FIELDLIST_LENGTH(thistype, n) TYPE_CPLUS_SPECIFIC(thistype)->fn_fieldlists[n].length
2170
2171 #define TYPE_N_TEMPLATE_ARGUMENTS(thistype) \
2172 TYPE_CPLUS_SPECIFIC (thistype)->n_template_arguments
2173 #define TYPE_TEMPLATE_ARGUMENTS(thistype) \
2174 TYPE_CPLUS_SPECIFIC (thistype)->template_arguments
2175 #define TYPE_TEMPLATE_ARGUMENT(thistype, n) \
2176 TYPE_CPLUS_SPECIFIC (thistype)->template_arguments[n]
2177
2178 #define TYPE_FN_FIELD(thisfn, n) (thisfn)[n]
2179 #define TYPE_FN_FIELD_PHYSNAME(thisfn, n) (thisfn)[n].physname
2180 #define TYPE_FN_FIELD_TYPE(thisfn, n) (thisfn)[n].type
2181 #define TYPE_FN_FIELD_ARGS(thisfn, n) (((thisfn)[n].type)->fields ())
2182 #define TYPE_FN_FIELD_CONST(thisfn, n) ((thisfn)[n].is_const)
2183 #define TYPE_FN_FIELD_VOLATILE(thisfn, n) ((thisfn)[n].is_volatile)
2184 #define TYPE_FN_FIELD_PRIVATE(thisfn, n) ((thisfn)[n].is_private)
2185 #define TYPE_FN_FIELD_PROTECTED(thisfn, n) ((thisfn)[n].is_protected)
2186 #define TYPE_FN_FIELD_ARTIFICIAL(thisfn, n) ((thisfn)[n].is_artificial)
2187 #define TYPE_FN_FIELD_STUB(thisfn, n) ((thisfn)[n].is_stub)
2188 #define TYPE_FN_FIELD_CONSTRUCTOR(thisfn, n) ((thisfn)[n].is_constructor)
2189 #define TYPE_FN_FIELD_FCONTEXT(thisfn, n) ((thisfn)[n].fcontext)
2190 #define TYPE_FN_FIELD_VOFFSET(thisfn, n) ((thisfn)[n].voffset-2)
2191 #define TYPE_FN_FIELD_VIRTUAL_P(thisfn, n) ((thisfn)[n].voffset > 1)
2192 #define TYPE_FN_FIELD_STATIC_P(thisfn, n) ((thisfn)[n].voffset == VOFFSET_STATIC)
2193 #define TYPE_FN_FIELD_DEFAULTED(thisfn, n) ((thisfn)[n].defaulted)
2194 #define TYPE_FN_FIELD_DELETED(thisfn, n) ((thisfn)[n].is_deleted)
2195
2196 /* Accessors for typedefs defined by a class. */
2197 #define TYPE_TYPEDEF_FIELD_ARRAY(thistype) \
2198 TYPE_CPLUS_SPECIFIC (thistype)->typedef_field
2199 #define TYPE_TYPEDEF_FIELD(thistype, n) \
2200 TYPE_CPLUS_SPECIFIC (thistype)->typedef_field[n]
2201 #define TYPE_TYPEDEF_FIELD_NAME(thistype, n) \
2202 TYPE_TYPEDEF_FIELD (thistype, n).name
2203 #define TYPE_TYPEDEF_FIELD_TYPE(thistype, n) \
2204 TYPE_TYPEDEF_FIELD (thistype, n).type
2205 #define TYPE_TYPEDEF_FIELD_COUNT(thistype) \
2206 TYPE_CPLUS_SPECIFIC (thistype)->typedef_field_count
2207 #define TYPE_TYPEDEF_FIELD_PROTECTED(thistype, n) \
2208 TYPE_TYPEDEF_FIELD (thistype, n).is_protected
2209 #define TYPE_TYPEDEF_FIELD_PRIVATE(thistype, n) \
2210 TYPE_TYPEDEF_FIELD (thistype, n).is_private
2211
2212 #define TYPE_NESTED_TYPES_ARRAY(thistype) \
2213 TYPE_CPLUS_SPECIFIC (thistype)->nested_types
2214 #define TYPE_NESTED_TYPES_FIELD(thistype, n) \
2215 TYPE_CPLUS_SPECIFIC (thistype)->nested_types[n]
2216 #define TYPE_NESTED_TYPES_FIELD_NAME(thistype, n) \
2217 TYPE_NESTED_TYPES_FIELD (thistype, n).name
2218 #define TYPE_NESTED_TYPES_FIELD_TYPE(thistype, n) \
2219 TYPE_NESTED_TYPES_FIELD (thistype, n).type
2220 #define TYPE_NESTED_TYPES_COUNT(thistype) \
2221 TYPE_CPLUS_SPECIFIC (thistype)->nested_types_count
2222 #define TYPE_NESTED_TYPES_FIELD_PROTECTED(thistype, n) \
2223 TYPE_NESTED_TYPES_FIELD (thistype, n).is_protected
2224 #define TYPE_NESTED_TYPES_FIELD_PRIVATE(thistype, n) \
2225 TYPE_NESTED_TYPES_FIELD (thistype, n).is_private
2226
2227 #define TYPE_IS_OPAQUE(thistype) \
2228 ((((thistype)->code () == TYPE_CODE_STRUCT) \
2229 || ((thistype)->code () == TYPE_CODE_UNION)) \
2230 && ((thistype)->num_fields () == 0) \
2231 && (!HAVE_CPLUS_STRUCT (thistype) \
2232 || TYPE_NFN_FIELDS (thistype) == 0) \
2233 && ((thistype)->is_stub () || !(thistype)->stub_is_supported ()))
2234
2235 /* * A helper macro that returns the name of a type or "unnamed type"
2236 if the type has no name. */
2237
2238 #define TYPE_SAFE_NAME(type) \
2239 (type->name () != nullptr ? type->name () : _("<unnamed type>"))
2240
2241 /* * A helper macro that returns the name of an error type. If the
2242 type has a name, it is used; otherwise, a default is used. */
2243
2244 #define TYPE_ERROR_NAME(type) \
2245 (type->name () ? type->name () : _("<error type>"))
2246
2247 /* Given TYPE, return its floatformat. */
2248 const struct floatformat *floatformat_from_type (const struct type *type);
2249
2250 struct builtin_type
2251 {
2252 /* Integral types. */
2253
2254 /* Implicit size/sign (based on the architecture's ABI). */
2255 struct type *builtin_void;
2256 struct type *builtin_char;
2257 struct type *builtin_short;
2258 struct type *builtin_int;
2259 struct type *builtin_long;
2260 struct type *builtin_signed_char;
2261 struct type *builtin_unsigned_char;
2262 struct type *builtin_unsigned_short;
2263 struct type *builtin_unsigned_int;
2264 struct type *builtin_unsigned_long;
2265 struct type *builtin_bfloat16;
2266 struct type *builtin_half;
2267 struct type *builtin_float;
2268 struct type *builtin_double;
2269 struct type *builtin_long_double;
2270 struct type *builtin_complex;
2271 struct type *builtin_double_complex;
2272 struct type *builtin_string;
2273 struct type *builtin_bool;
2274 struct type *builtin_long_long;
2275 struct type *builtin_unsigned_long_long;
2276 struct type *builtin_decfloat;
2277 struct type *builtin_decdouble;
2278 struct type *builtin_declong;
2279
2280 /* "True" character types.
2281 We use these for the '/c' print format, because c_char is just a
2282 one-byte integral type, which languages less laid back than C
2283 will print as ... well, a one-byte integral type. */
2284 struct type *builtin_true_char;
2285 struct type *builtin_true_unsigned_char;
2286
2287 /* Explicit sizes - see C9X <intypes.h> for naming scheme. The "int0"
2288 is for when an architecture needs to describe a register that has
2289 no size. */
2290 struct type *builtin_int0;
2291 struct type *builtin_int8;
2292 struct type *builtin_uint8;
2293 struct type *builtin_int16;
2294 struct type *builtin_uint16;
2295 struct type *builtin_int24;
2296 struct type *builtin_uint24;
2297 struct type *builtin_int32;
2298 struct type *builtin_uint32;
2299 struct type *builtin_int64;
2300 struct type *builtin_uint64;
2301 struct type *builtin_int128;
2302 struct type *builtin_uint128;
2303
2304 /* Wide character types. */
2305 struct type *builtin_char16;
2306 struct type *builtin_char32;
2307 struct type *builtin_wchar;
2308
2309 /* Pointer types. */
2310
2311 /* * `pointer to data' type. Some target platforms use an implicitly
2312 {sign,zero} -extended 32-bit ABI pointer on a 64-bit ISA. */
2313 struct type *builtin_data_ptr;
2314
2315 /* * `pointer to function (returning void)' type. Harvard
2316 architectures mean that ABI function and code pointers are not
2317 interconvertible. Similarly, since ANSI, C standards have
2318 explicitly said that pointers to functions and pointers to data
2319 are not interconvertible --- that is, you can't cast a function
2320 pointer to void * and back, and expect to get the same value.
2321 However, all function pointer types are interconvertible, so void
2322 (*) () can server as a generic function pointer. */
2323
2324 struct type *builtin_func_ptr;
2325
2326 /* * `function returning pointer to function (returning void)' type.
2327 The final void return type is not significant for it. */
2328
2329 struct type *builtin_func_func;
2330
2331 /* Special-purpose types. */
2332
2333 /* * This type is used to represent a GDB internal function. */
2334
2335 struct type *internal_fn;
2336
2337 /* * This type is used to represent an xmethod. */
2338 struct type *xmethod;
2339 };
2340
2341 /* * Return the type table for the specified architecture. */
2342
2343 extern const struct builtin_type *builtin_type (struct gdbarch *gdbarch);
2344
2345 /* * Per-objfile types used by symbol readers. */
2346
2347 struct objfile_type
2348 {
2349 /* Basic types based on the objfile architecture. */
2350 struct type *builtin_void;
2351 struct type *builtin_char;
2352 struct type *builtin_short;
2353 struct type *builtin_int;
2354 struct type *builtin_long;
2355 struct type *builtin_long_long;
2356 struct type *builtin_signed_char;
2357 struct type *builtin_unsigned_char;
2358 struct type *builtin_unsigned_short;
2359 struct type *builtin_unsigned_int;
2360 struct type *builtin_unsigned_long;
2361 struct type *builtin_unsigned_long_long;
2362 struct type *builtin_half;
2363 struct type *builtin_float;
2364 struct type *builtin_double;
2365 struct type *builtin_long_double;
2366
2367 /* * This type is used to represent symbol addresses. */
2368 struct type *builtin_core_addr;
2369
2370 /* * This type represents a type that was unrecognized in symbol
2371 read-in. */
2372 struct type *builtin_error;
2373
2374 /* * Types used for symbols with no debug information. */
2375 struct type *nodebug_text_symbol;
2376 struct type *nodebug_text_gnu_ifunc_symbol;
2377 struct type *nodebug_got_plt_symbol;
2378 struct type *nodebug_data_symbol;
2379 struct type *nodebug_unknown_symbol;
2380 struct type *nodebug_tls_symbol;
2381 };
2382
2383 /* * Return the type table for the specified objfile. */
2384
2385 extern const struct objfile_type *objfile_type (struct objfile *objfile);
2386
2387 /* Explicit floating-point formats. See "floatformat.h". */
2388 extern const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN];
2389 extern const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN];
2390 extern const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN];
2391 extern const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN];
2392 extern const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN];
2393 extern const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN];
2394 extern const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN];
2395 extern const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN];
2396 extern const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN];
2397 extern const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN];
2398 extern const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN];
2399 extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN];
2400 extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
2401
2402 /* Allocate space for storing data associated with a particular
2403 type. We ensure that the space is allocated using the same
2404 mechanism that was used to allocate the space for the type
2405 structure itself. I.e. if the type is on an objfile's
2406 objfile_obstack, then the space for data associated with that type
2407 will also be allocated on the objfile_obstack. If the type is
2408 associated with a gdbarch, then the space for data associated with that
2409 type will also be allocated on the gdbarch_obstack.
2410
2411 If a type is not associated with neither an objfile or a gdbarch then
2412 you should not use this macro to allocate space for data, instead you
2413 should call xmalloc directly, and ensure the memory is correctly freed
2414 when it is no longer needed. */
2415
2416 #define TYPE_ALLOC(t,size) \
2417 (obstack_alloc (((t)->is_objfile_owned () \
2418 ? &((t)->objfile_owner ()->objfile_obstack) \
2419 : gdbarch_obstack ((t)->arch_owner ())), \
2420 size))
2421
2422
2423 /* See comment on TYPE_ALLOC. */
2424
2425 #define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size))
2426
2427 /* Use alloc_type to allocate a type owned by an objfile. Use
2428 alloc_type_arch to allocate a type owned by an architecture. Use
2429 alloc_type_copy to allocate a type with the same owner as a
2430 pre-existing template type, no matter whether objfile or
2431 gdbarch. */
2432 extern struct type *alloc_type (struct objfile *);
2433 extern struct type *alloc_type_arch (struct gdbarch *);
2434 extern struct type *alloc_type_copy (const struct type *);
2435
2436 /* * This returns the target type (or NULL) of TYPE, also skipping
2437 past typedefs. */
2438
2439 extern struct type *get_target_type (struct type *type);
2440
2441 /* Return the equivalent of TYPE_LENGTH, but in number of target
2442 addressable memory units of the associated gdbarch instead of bytes. */
2443
2444 extern unsigned int type_length_units (struct type *type);
2445
2446 /* * Helper function to construct objfile-owned types. */
2447
2448 extern struct type *init_type (struct objfile *, enum type_code, int,
2449 const char *);
2450 extern struct type *init_integer_type (struct objfile *, int, int,
2451 const char *);
2452 extern struct type *init_character_type (struct objfile *, int, int,
2453 const char *);
2454 extern struct type *init_boolean_type (struct objfile *, int, int,
2455 const char *);
2456 extern struct type *init_float_type (struct objfile *, int, const char *,
2457 const struct floatformat **,
2458 enum bfd_endian = BFD_ENDIAN_UNKNOWN);
2459 extern struct type *init_decfloat_type (struct objfile *, int, const char *);
2460 extern bool can_create_complex_type (struct type *);
2461 extern struct type *init_complex_type (const char *, struct type *);
2462 extern struct type *init_pointer_type (struct objfile *, int, const char *,
2463 struct type *);
2464 extern struct type *init_fixed_point_type (struct objfile *, int, int,
2465 const char *);
2466
2467 /* Helper functions to construct architecture-owned types. */
2468 extern struct type *arch_type (struct gdbarch *, enum type_code, int,
2469 const char *);
2470 extern struct type *arch_integer_type (struct gdbarch *, int, int,
2471 const char *);
2472 extern struct type *arch_character_type (struct gdbarch *, int, int,
2473 const char *);
2474 extern struct type *arch_boolean_type (struct gdbarch *, int, int,
2475 const char *);
2476 extern struct type *arch_float_type (struct gdbarch *, int, const char *,
2477 const struct floatformat **);
2478 extern struct type *arch_decfloat_type (struct gdbarch *, int, const char *);
2479 extern struct type *arch_pointer_type (struct gdbarch *, int, const char *,
2480 struct type *);
2481
2482 /* Helper functions to construct a struct or record type. An
2483 initially empty type is created using arch_composite_type().
2484 Fields are then added using append_composite_type_field*(). A union
2485 type has its size set to the largest field. A struct type has each
2486 field packed against the previous. */
2487
2488 extern struct type *arch_composite_type (struct gdbarch *gdbarch,
2489 const char *name, enum type_code code);
2490 extern void append_composite_type_field (struct type *t, const char *name,
2491 struct type *field);
2492 extern void append_composite_type_field_aligned (struct type *t,
2493 const char *name,
2494 struct type *field,
2495 int alignment);
2496 struct field *append_composite_type_field_raw (struct type *t, const char *name,
2497 struct type *field);
2498
2499 /* Helper functions to construct a bit flags type. An initially empty
2500 type is created using arch_flag_type(). Flags are then added using
2501 append_flag_type_field() and append_flag_type_flag(). */
2502 extern struct type *arch_flags_type (struct gdbarch *gdbarch,
2503 const char *name, int bit);
2504 extern void append_flags_type_field (struct type *type,
2505 int start_bitpos, int nr_bits,
2506 struct type *field_type, const char *name);
2507 extern void append_flags_type_flag (struct type *type, int bitpos,
2508 const char *name);
2509
2510 extern void make_vector_type (struct type *array_type);
2511 extern struct type *init_vector_type (struct type *elt_type, int n);
2512
2513 extern struct type *lookup_reference_type (struct type *, enum type_code);
2514 extern struct type *lookup_lvalue_reference_type (struct type *);
2515 extern struct type *lookup_rvalue_reference_type (struct type *);
2516
2517
2518 extern struct type *make_reference_type (struct type *, struct type **,
2519 enum type_code);
2520
2521 extern struct type *make_cv_type (int, int, struct type *, struct type **);
2522
2523 extern struct type *make_restrict_type (struct type *);
2524
2525 extern struct type *make_unqualified_type (struct type *);
2526
2527 extern struct type *make_atomic_type (struct type *);
2528
2529 extern void replace_type (struct type *, struct type *);
2530
2531 extern type_instance_flags address_space_name_to_type_instance_flags
2532 (struct gdbarch *, const char *);
2533
2534 extern const char *address_space_type_instance_flags_to_name
2535 (struct gdbarch *, type_instance_flags);
2536
2537 extern struct type *make_type_with_address_space
2538 (struct type *type, type_instance_flags space_identifier);
2539
2540 extern struct type *lookup_memberptr_type (struct type *, struct type *);
2541
2542 extern struct type *lookup_methodptr_type (struct type *);
2543
2544 extern void smash_to_method_type (struct type *type, struct type *self_type,
2545 struct type *to_type, struct field *args,
2546 int nargs, int varargs);
2547
2548 extern void smash_to_memberptr_type (struct type *, struct type *,
2549 struct type *);
2550
2551 extern void smash_to_methodptr_type (struct type *, struct type *);
2552
2553 extern struct type *allocate_stub_method (struct type *);
2554
2555 extern const char *type_name_or_error (struct type *type);
2556
2557 struct struct_elt
2558 {
2559 /* The field of the element, or NULL if no element was found. */
2560 struct field *field;
2561
2562 /* The bit offset of the element in the parent structure. */
2563 LONGEST offset;
2564 };
2565
2566 /* Given a type TYPE, lookup the field and offset of the component named
2567 NAME.
2568
2569 TYPE can be either a struct or union, or a pointer or reference to
2570 a struct or union. If it is a pointer or reference, its target
2571 type is automatically used. Thus '.' and '->' are interchangable,
2572 as specified for the definitions of the expression element types
2573 STRUCTOP_STRUCT and STRUCTOP_PTR.
2574
2575 If NOERR is nonzero, the returned structure will have field set to
2576 NULL if there is no component named NAME.
2577
2578 If the component NAME is a field in an anonymous substructure of
2579 TYPE, the returned offset is a "global" offset relative to TYPE
2580 rather than an offset within the substructure. */
2581
2582 extern struct_elt lookup_struct_elt (struct type *, const char *, int);
2583
2584 /* Given a type TYPE, lookup the type of the component named NAME.
2585
2586 TYPE can be either a struct or union, or a pointer or reference to
2587 a struct or union. If it is a pointer or reference, its target
2588 type is automatically used. Thus '.' and '->' are interchangable,
2589 as specified for the definitions of the expression element types
2590 STRUCTOP_STRUCT and STRUCTOP_PTR.
2591
2592 If NOERR is nonzero, return NULL if there is no component named
2593 NAME. */
2594
2595 extern struct type *lookup_struct_elt_type (struct type *, const char *, int);
2596
2597 extern struct type *make_pointer_type (struct type *, struct type **);
2598
2599 extern struct type *lookup_pointer_type (struct type *);
2600
2601 extern struct type *make_function_type (struct type *, struct type **);
2602
2603 extern struct type *lookup_function_type (struct type *);
2604
2605 extern struct type *lookup_function_type_with_arguments (struct type *,
2606 int,
2607 struct type **);
2608
2609 extern struct type *create_static_range_type (struct type *, struct type *,
2610 LONGEST, LONGEST);
2611
2612
2613 extern struct type *create_array_type_with_stride
2614 (struct type *, struct type *, struct type *,
2615 struct dynamic_prop *, unsigned int);
2616
2617 extern struct type *create_range_type (struct type *, struct type *,
2618 const struct dynamic_prop *,
2619 const struct dynamic_prop *,
2620 LONGEST);
2621
2622 /* Like CREATE_RANGE_TYPE but also sets up a stride. When BYTE_STRIDE_P
2623 is true the value in STRIDE is a byte stride, otherwise STRIDE is a bit
2624 stride. */
2625
2626 extern struct type * create_range_type_with_stride
2627 (struct type *result_type, struct type *index_type,
2628 const struct dynamic_prop *low_bound,
2629 const struct dynamic_prop *high_bound, LONGEST bias,
2630 const struct dynamic_prop *stride, bool byte_stride_p);
2631
2632 extern struct type *create_array_type (struct type *, struct type *,
2633 struct type *);
2634
2635 extern struct type *lookup_array_range_type (struct type *, LONGEST, LONGEST);
2636
2637 extern struct type *create_string_type (struct type *, struct type *,
2638 struct type *);
2639 extern struct type *lookup_string_range_type (struct type *, LONGEST, LONGEST);
2640
2641 extern struct type *create_set_type (struct type *, struct type *);
2642
2643 extern struct type *lookup_unsigned_typename (const struct language_defn *,
2644 const char *);
2645
2646 extern struct type *lookup_signed_typename (const struct language_defn *,
2647 const char *);
2648
2649 extern ULONGEST get_unsigned_type_max (struct type *);
2650
2651 extern void get_signed_type_minmax (struct type *, LONGEST *, LONGEST *);
2652
2653 extern CORE_ADDR get_pointer_type_max (struct type *);
2654
2655 /* * Resolve all dynamic values of a type e.g. array bounds to static values.
2656 ADDR specifies the location of the variable the type is bound to.
2657 If TYPE has no dynamic properties return TYPE; otherwise a new type with
2658 static properties is returned.
2659
2660 For an array type, if the element type is dynamic, then that will
2661 not be resolved. This is done because each individual element may
2662 have a different type when resolved (depending on the contents of
2663 memory). In this situation, 'is_dynamic_type' will still return
2664 true for the return value of this function. */
2665 extern struct type *resolve_dynamic_type
2666 (struct type *type, gdb::array_view<const gdb_byte> valaddr,
2667 CORE_ADDR addr);
2668
2669 /* * Predicate if the type has dynamic values, which are not resolved yet.
2670 See the caveat in 'resolve_dynamic_type' to understand a scenario
2671 where an apparently-resolved type may still be considered
2672 "dynamic". */
2673 extern int is_dynamic_type (struct type *type);
2674
2675 extern struct type *check_typedef (struct type *);
2676
2677 extern void check_stub_method_group (struct type *, int);
2678
2679 extern char *gdb_mangle_name (struct type *, int, int);
2680
2681 extern struct type *lookup_typename (const struct language_defn *,
2682 const char *, const struct block *, int);
2683
2684 extern struct type *lookup_template_type (const char *, struct type *,
2685 const struct block *);
2686
2687 extern int get_vptr_fieldno (struct type *, struct type **);
2688
2689 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
2690 TYPE.
2691
2692 Return true if the two bounds are available, false otherwise. */
2693
2694 extern bool get_discrete_bounds (struct type *type, LONGEST *lowp,
2695 LONGEST *highp);
2696
2697 /* If TYPE's low bound is a known constant, return it, else return nullopt. */
2698
2699 extern gdb::optional<LONGEST> get_discrete_low_bound (struct type *type);
2700
2701 /* If TYPE's high bound is a known constant, return it, else return nullopt. */
2702
2703 extern gdb::optional<LONGEST> get_discrete_high_bound (struct type *type);
2704
2705 /* Assuming TYPE is a simple, non-empty array type, compute its upper
2706 and lower bound. Save the low bound into LOW_BOUND if not NULL.
2707 Save the high bound into HIGH_BOUND if not NULL.
2708
2709 Return true if the operation was successful. Return false otherwise,
2710 in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. */
2711
2712 extern bool get_array_bounds (struct type *type, LONGEST *low_bound,
2713 LONGEST *high_bound);
2714
2715 extern gdb::optional<LONGEST> discrete_position (struct type *type,
2716 LONGEST val);
2717
2718 extern int class_types_same_p (const struct type *, const struct type *);
2719
2720 extern int is_ancestor (struct type *, struct type *);
2721
2722 extern int is_public_ancestor (struct type *, struct type *);
2723
2724 extern int is_unique_ancestor (struct type *, struct value *);
2725
2726 /* Overload resolution */
2727
2728 /* * Badness if parameter list length doesn't match arg list length. */
2729 extern const struct rank LENGTH_MISMATCH_BADNESS;
2730
2731 /* * Dummy badness value for nonexistent parameter positions. */
2732 extern const struct rank TOO_FEW_PARAMS_BADNESS;
2733 /* * Badness if no conversion among types. */
2734 extern const struct rank INCOMPATIBLE_TYPE_BADNESS;
2735
2736 /* * Badness of an exact match. */
2737 extern const struct rank EXACT_MATCH_BADNESS;
2738
2739 /* * Badness of integral promotion. */
2740 extern const struct rank INTEGER_PROMOTION_BADNESS;
2741 /* * Badness of floating promotion. */
2742 extern const struct rank FLOAT_PROMOTION_BADNESS;
2743 /* * Badness of converting a derived class pointer
2744 to a base class pointer. */
2745 extern const struct rank BASE_PTR_CONVERSION_BADNESS;
2746 /* * Badness of integral conversion. */
2747 extern const struct rank INTEGER_CONVERSION_BADNESS;
2748 /* * Badness of floating conversion. */
2749 extern const struct rank FLOAT_CONVERSION_BADNESS;
2750 /* * Badness of integer<->floating conversions. */
2751 extern const struct rank INT_FLOAT_CONVERSION_BADNESS;
2752 /* * Badness of conversion of pointer to void pointer. */
2753 extern const struct rank VOID_PTR_CONVERSION_BADNESS;
2754 /* * Badness of conversion to boolean. */
2755 extern const struct rank BOOL_CONVERSION_BADNESS;
2756 /* * Badness of converting derived to base class. */
2757 extern const struct rank BASE_CONVERSION_BADNESS;
2758 /* * Badness of converting from non-reference to reference. Subrank
2759 is the type of reference conversion being done. */
2760 extern const struct rank REFERENCE_CONVERSION_BADNESS;
2761 extern const struct rank REFERENCE_SEE_THROUGH_BADNESS;
2762 /* * Conversion to rvalue reference. */
2763 #define REFERENCE_CONVERSION_RVALUE 1
2764 /* * Conversion to const lvalue reference. */
2765 #define REFERENCE_CONVERSION_CONST_LVALUE 2
2766
2767 /* * Badness of converting integer 0 to NULL pointer. */
2768 extern const struct rank NULL_POINTER_CONVERSION;
2769 /* * Badness of cv-conversion. Subrank is a flag describing the conversions
2770 being done. */
2771 extern const struct rank CV_CONVERSION_BADNESS;
2772 #define CV_CONVERSION_CONST 1
2773 #define CV_CONVERSION_VOLATILE 2
2774
2775 /* Non-standard conversions allowed by the debugger */
2776
2777 /* * Converting a pointer to an int is usually OK. */
2778 extern const struct rank NS_POINTER_CONVERSION_BADNESS;
2779
2780 /* * Badness of converting a (non-zero) integer constant
2781 to a pointer. */
2782 extern const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS;
2783
2784 extern struct rank sum_ranks (struct rank a, struct rank b);
2785 extern int compare_ranks (struct rank a, struct rank b);
2786
2787 extern int compare_badness (const badness_vector &,
2788 const badness_vector &);
2789
2790 extern badness_vector rank_function (gdb::array_view<type *> parms,
2791 gdb::array_view<value *> args);
2792
2793 extern struct rank rank_one_type (struct type *, struct type *,
2794 struct value *);
2795
2796 extern void recursive_dump_type (struct type *, int);
2797
2798 extern int field_is_static (struct field *);
2799
2800 /* printcmd.c */
2801
2802 extern void print_scalar_formatted (const gdb_byte *, struct type *,
2803 const struct value_print_options *,
2804 int, struct ui_file *);
2805
2806 extern int can_dereference (struct type *);
2807
2808 extern int is_integral_type (struct type *);
2809
2810 extern int is_floating_type (struct type *);
2811
2812 extern int is_scalar_type (struct type *type);
2813
2814 extern int is_scalar_type_recursive (struct type *);
2815
2816 extern int class_or_union_p (const struct type *);
2817
2818 extern void maintenance_print_type (const char *, int);
2819
2820 extern htab_up create_copied_types_hash (struct objfile *objfile);
2821
2822 extern struct type *copy_type_recursive (struct objfile *objfile,
2823 struct type *type,
2824 htab_t copied_types);
2825
2826 extern struct type *copy_type (const struct type *type);
2827
2828 extern bool types_equal (struct type *, struct type *);
2829
2830 extern bool types_deeply_equal (struct type *, struct type *);
2831
2832 extern int type_not_allocated (const struct type *type);
2833
2834 extern int type_not_associated (const struct type *type);
2835
2836 /* Return True if TYPE is a TYPE_CODE_FIXED_POINT or if TYPE is
2837 a range type whose base type is a TYPE_CODE_FIXED_POINT. */
2838 extern bool is_fixed_point_type (struct type *type);
2839
2840 /* Allocate a fixed-point type info for TYPE. This should only be
2841 called by INIT_FIXED_POINT_SPECIFIC. */
2842 extern void allocate_fixed_point_type_info (struct type *type);
2843
2844 /* * When the type includes explicit byte ordering, return that.
2845 Otherwise, the byte ordering from gdbarch_byte_order for
2846 the type's arch is returned. */
2847
2848 extern enum bfd_endian type_byte_order (const struct type *type);
2849
2850 /* A flag to enable printing of debugging information of C++
2851 overloading. */
2852
2853 extern unsigned int overload_debug;
2854
2855 #endif /* GDBTYPES_H */