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