3 Copyright (C) 2003-2024 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 /* Dump this DIE and any children to MAX_LEVEL. They are written to
34 gdb_stdlog. Note this is called from the pdie user command in
36 void dump (int max_level
);
38 /* Shallowly dump this DIE to gdb_stderr. */
41 /* Return the named attribute or NULL if not there, but do not
42 follow DW_AT_specification, etc. */
43 struct attribute
*attr (dwarf_attribute name
)
45 for (unsigned i
= 0; i
< num_attrs
; ++i
)
46 if (attrs
[i
].name
== name
)
51 /* Return the address base of the compile unit, which, if exists, is
52 stored either at the attribute DW_AT_GNU_addr_base, or
54 std::optional
<ULONGEST
> addr_base ()
56 for (unsigned i
= 0; i
< num_attrs
; ++i
)
57 if (attrs
[i
].name
== DW_AT_addr_base
58 || attrs
[i
].name
== DW_AT_GNU_addr_base
)
60 if (attrs
[i
].form_is_unsigned ())
62 /* If both exist, just use the first one. */
63 return attrs
[i
].as_unsigned ();
65 complaint (_("address base attribute (offset %s) as wrong form"),
66 sect_offset_str (sect_off
));
68 return std::optional
<ULONGEST
> ();
71 /* Return the base address of the compile unit into the .debug_ranges section,
72 which, if exists, is stored in the DW_AT_GNU_ranges_base attribute. This
73 value is only relevant in pre-DWARF 5 split-unit scenarios. */
74 ULONGEST
gnu_ranges_base ()
76 for (unsigned i
= 0; i
< num_attrs
; ++i
)
77 if (attrs
[i
].name
== DW_AT_GNU_ranges_base
)
79 if (attrs
[i
].form_is_unsigned ())
80 return attrs
[i
].as_unsigned ();
82 complaint (_("ranges base attribute (offset %s) has wrong form"),
83 sect_offset_str (sect_off
));
89 /* Return the rnglists base of the compile unit, which, if exists, is stored
90 in the DW_AT_rnglists_base attribute. */
91 ULONGEST
rnglists_base ()
93 for (unsigned i
= 0; i
< num_attrs
; ++i
)
94 if (attrs
[i
].name
== DW_AT_rnglists_base
)
96 if (attrs
[i
].form_is_unsigned ())
97 return attrs
[i
].as_unsigned ();
99 complaint (_("rnglists base attribute (offset %s) has wrong form"),
100 sect_offset_str (sect_off
));
106 /* DWARF-2 tag for this DIE. */
107 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
109 /* Number of attributes */
110 unsigned char num_attrs
;
112 /* True if we're presently building the full type name for the
113 type derived from this DIE. */
114 unsigned char building_fullname
: 1;
116 /* True if this die is in process. PR 16581. */
117 unsigned char in_process
: 1;
119 /* True if this DIE has children. */
120 unsigned char has_children
: 1;
125 /* Offset in .debug_info or .debug_types section. */
126 sect_offset sect_off
;
128 /* The dies in a compilation unit form an n-ary tree. PARENT
129 points to this die's parent; CHILD points to the first child of
130 this node; and all the children of a given node are chained
131 together via their SIBLING fields. */
132 struct die_info
*child
; /* Its first child, if any. */
133 struct die_info
*sibling
; /* Its next sibling, if any. */
134 struct die_info
*parent
; /* Its parent, if any. */
136 /* An array of attributes, with NUM_ATTRS elements. There may be
137 zero, but it's not common and zero-sized arrays are not
138 sufficiently portable C. */
139 struct attribute attrs
[1];
142 /* Key hash type to store die_info objects in gdb::unordered_set, identified by
143 their section offsets. */
145 struct die_info_hash_sect_off final
147 using is_transparent
= void;
149 std::size_t operator() (const die_info
*die
) const noexcept
150 { return (*this) (die
->sect_off
); }
152 std::size_t operator() (sect_offset offset
) const noexcept
153 { return std::hash
<sect_offset
> () (offset
); }
156 /* Key equal type to store die_info objects in gdb::unordered_set, identified by
157 their section offsets. */
159 struct die_info_eq_sect_off final
161 using is_transparent
= void;
163 bool operator() (const die_info
*a
, const die_info
*b
) const noexcept
164 { return (*this) (a
->sect_off
, b
); }
166 bool operator() (sect_offset offset
, const die_info
*die
) const noexcept
167 { return offset
== die
->sect_off
; }
170 #endif /* GDB_DWARF2_DIE_H */