3 Copyright (C) 2003-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GDB_DWARF2_DIE_H
21 #define GDB_DWARF2_DIE_H
23 #include "complaints.h"
24 #include "dwarf2/attribute.h"
26 /* This data structure holds a complete die structure. */
29 /* Allocate a new die_info on OBSTACK. NUM_ATTRS is the number of
30 attributes that are needed. */
31 static die_info
*allocate (struct obstack
*obstack
, int num_attrs
);
33 /* Trivial hash function for die_info: the hash value of a DIE is
34 its offset in .debug_info for this objfile. */
35 static hashval_t
hash (const void *item
);
37 /* Trivial comparison function for die_info structures: two DIEs
38 are equal if they have the same offset. */
39 static int eq (const void *item_lhs
, const void *item_rhs
);
41 /* Dump this DIE and any children to MAX_LEVEL. They are written to
42 gdb_stdlog. Note this is called from the pdie user command in
44 void dump (int max_level
);
46 /* Shallowly dump this DIE to gdb_stderr. */
49 /* Return the named attribute or NULL if not there, but do not
50 follow DW_AT_specification, etc. */
51 struct attribute
*attr (dwarf_attribute name
)
53 for (unsigned i
= 0; i
< num_attrs
; ++i
)
54 if (attrs
[i
].name
== name
)
59 /* Return the address base of the compile unit, which, if exists, is
60 stored either at the attribute DW_AT_GNU_addr_base, or
62 gdb::optional
<ULONGEST
> addr_base ()
64 for (unsigned i
= 0; i
< num_attrs
; ++i
)
65 if (attrs
[i
].name
== DW_AT_addr_base
66 || attrs
[i
].name
== DW_AT_GNU_addr_base
)
68 if (attrs
[i
].form_is_unsigned ())
70 /* If both exist, just use the first one. */
71 return attrs
[i
].as_unsigned ();
73 complaint (_("address base attribute (offset %s) as wrong form"),
74 sect_offset_str (sect_off
));
76 return gdb::optional
<ULONGEST
> ();
79 /* Return the base address of the compile unit into the .debug_ranges section,
80 which, if exists, is stored in the DW_AT_GNU_ranges_base attribute. This
81 value is only relevant in pre-DWARF 5 split-unit scenarios. */
82 ULONGEST
gnu_ranges_base ()
84 for (unsigned i
= 0; i
< num_attrs
; ++i
)
85 if (attrs
[i
].name
== DW_AT_GNU_ranges_base
)
87 if (attrs
[i
].form_is_unsigned ())
88 return attrs
[i
].as_unsigned ();
90 complaint (_("ranges base attribute (offset %s) has wrong form"),
91 sect_offset_str (sect_off
));
97 /* Return the rnglists base of the compile unit, which, if exists, is stored
98 in the DW_AT_rnglists_base attribute. */
99 ULONGEST
rnglists_base ()
101 for (unsigned i
= 0; i
< num_attrs
; ++i
)
102 if (attrs
[i
].name
== DW_AT_rnglists_base
)
104 if (attrs
[i
].form_is_unsigned ())
105 return attrs
[i
].as_unsigned ();
107 complaint (_("rnglists base attribute (offset %s) has wrong form"),
108 sect_offset_str (sect_off
));
114 /* DWARF-2 tag for this DIE. */
115 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
117 /* Number of attributes */
118 unsigned char num_attrs
;
120 /* True if we're presently building the full type name for the
121 type derived from this DIE. */
122 unsigned char building_fullname
: 1;
124 /* True if this die is in process. PR 16581. */
125 unsigned char in_process
: 1;
127 /* True if this DIE has children. */
128 unsigned char has_children
: 1;
133 /* Offset in .debug_info or .debug_types section. */
134 sect_offset sect_off
;
136 /* The dies in a compilation unit form an n-ary tree. PARENT
137 points to this die's parent; CHILD points to the first child of
138 this node; and all the children of a given node are chained
139 together via their SIBLING fields. */
140 struct die_info
*child
; /* Its first child, if any. */
141 struct die_info
*sibling
; /* Its next sibling, if any. */
142 struct die_info
*parent
; /* Its parent, if any. */
144 /* An array of attributes, with NUM_ATTRS elements. There may be
145 zero, but it's not common and zero-sized arrays are not
146 sufficiently portable C. */
147 struct attribute attrs
[1];
150 #endif /* GDB_DWARF2_DIE_H */