gdb/dwarf: add assertion in maybe_queue_comp_unit
[deliverable/binutils-gdb.git] / gdb / dwarf2 / attribute.h
1 /* DWARF attributes
2
3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
4
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support.
11
12 This file is part of GDB.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26
27 #ifndef GDB_DWARF2_ATTRIBUTE_H
28 #define GDB_DWARF2_ATTRIBUTE_H
29
30 #include "dwarf2.h"
31 #include "gdbtypes.h"
32 #include "gdbsupport/gdb_optional.h"
33
34 /* Blocks are a bunch of untyped bytes. */
35 struct dwarf_block
36 {
37 size_t size;
38
39 /* Valid only if SIZE is not zero. */
40 const gdb_byte *data;
41 };
42
43 /* Attributes have a name and a value. */
44 struct attribute
45 {
46 /* Read the given attribute value as an address, taking the
47 attribute's form into account. */
48 CORE_ADDR as_address () const;
49
50 /* If the attribute has a string form, return the string value;
51 otherwise return NULL. */
52 const char *as_string () const;
53
54 /* Return the block value. The attribute must have block form. */
55 dwarf_block *as_block () const
56 {
57 gdb_assert (form_is_block ());
58 return u.blk;
59 }
60
61 /* Return the signature. The attribute must have signature
62 form. */
63 ULONGEST as_signature () const
64 {
65 gdb_assert (form == DW_FORM_ref_sig8);
66 return u.signature;
67 }
68
69 /* Return the signed value. The attribute must have the appropriate
70 form. */
71 LONGEST as_signed () const
72 {
73 gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
74 return u.snd;
75 }
76
77 /* Return the unsigned value, but only for attributes requiring
78 reprocessing. */
79 ULONGEST as_unsigned_reprocess () const
80 {
81 gdb_assert (form_requires_reprocessing ());
82 gdb_assert (requires_reprocessing);
83 return u.unsnd;
84 }
85
86 /* Return the unsigned value. Requires that the form be an unsigned
87 form, and that reprocessing not be needed. */
88 ULONGEST as_unsigned () const
89 {
90 gdb_assert (form_is_unsigned ());
91 gdb_assert (!requires_reprocessing);
92 return u.unsnd;
93 }
94
95 /* Return non-zero if ATTR's value is a section offset --- classes
96 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
97 You may use the as_unsigned method to retrieve such offsets.
98
99 Section 7.5.4, "Attribute Encodings", explains that no attribute
100 may have a value that belongs to more than one of these classes; it
101 would be ambiguous if we did, because we use the same forms for all
102 of them. */
103
104 bool form_is_section_offset () const;
105
106 /* Return non-zero if ATTR's value falls in the 'constant' class, or
107 zero otherwise. When this function returns true, you can apply
108 the constant_value method to it.
109
110 However, note that for some attributes you must check
111 attr_form_is_section_offset before using this test. DW_FORM_data4
112 and DW_FORM_data8 are members of both the constant class, and of
113 the classes that contain offsets into other debug sections
114 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
115 that, if an attribute's can be either a constant or one of the
116 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
117 taken as section offsets, not constants.
118
119 DW_FORM_data16 is not considered as constant_value cannot handle
120 that. */
121
122 bool form_is_constant () const;
123
124 /* The address is always stored already as sect_offset; despite for
125 the forms besides DW_FORM_ref_addr it is stored as cu_offset in
126 the DWARF file. */
127
128 bool form_is_ref () const
129 {
130 return (form == DW_FORM_ref_addr
131 || form == DW_FORM_ref1
132 || form == DW_FORM_ref2
133 || form == DW_FORM_ref4
134 || form == DW_FORM_ref8
135 || form == DW_FORM_ref_udata
136 || form == DW_FORM_GNU_ref_alt);
137 }
138
139 /* Check if the attribute's form is a DW_FORM_block*
140 if so return true else false. */
141
142 bool form_is_block () const;
143
144 /* Check if the attribute's form is a string form. */
145 bool form_is_string () const;
146
147 /* Check if the attribute's form is an unsigned integer form. */
148 bool form_is_unsigned () const;
149
150 /* Check if the attribute's form is a form that requires
151 "reprocessing". */
152 bool form_requires_reprocessing () const;
153
154 /* Return DIE offset of this attribute. Return 0 with complaint if
155 the attribute is not of the required kind. */
156
157 sect_offset get_ref_die_offset () const
158 {
159 if (form_is_ref ())
160 return (sect_offset) u.unsnd;
161 get_ref_die_offset_complaint ();
162 return {};
163 }
164
165 /* Return the constant value held by this attribute. Return
166 DEFAULT_VALUE if the value held by the attribute is not
167 constant. */
168
169 LONGEST constant_value (int default_value) const;
170
171 /* Return true if this attribute holds a canonical string. In some
172 cases, like C++ names, gdb will rewrite the name of a DIE to a
173 canonical form. This makes lookups robust when a name can be
174 spelled different ways (e.g., "signed" or "signed int"). This
175 flag indicates whether the value has been canonicalized. */
176 bool canonical_string_p () const
177 {
178 gdb_assert (form_is_string ());
179 return string_is_canonical;
180 }
181
182 /* Initialize this attribute to hold a non-canonical string
183 value. */
184 void set_string_noncanonical (const char *str)
185 {
186 gdb_assert (form_is_string ());
187 u.str = str;
188 string_is_canonical = 0;
189 requires_reprocessing = 0;
190 }
191
192 /* Set the canonical string value for this attribute. */
193 void set_string_canonical (const char *str)
194 {
195 gdb_assert (form_is_string ());
196 u.str = str;
197 string_is_canonical = 1;
198 }
199
200 /* Set the block value for this attribute. */
201 void set_block (dwarf_block *blk)
202 {
203 gdb_assert (form_is_block ());
204 u.blk = blk;
205 }
206
207 /* Set the signature value for this attribute. */
208 void set_signature (ULONGEST signature)
209 {
210 gdb_assert (form == DW_FORM_ref_sig8);
211 u.signature = signature;
212 }
213
214 /* Set this attribute to a signed integer. */
215 void set_signed (LONGEST snd)
216 {
217 gdb_assert (form == DW_FORM_sdata || form == DW_FORM_implicit_const);
218 u.snd = snd;
219 }
220
221 /* Set this attribute to an unsigned integer. */
222 void set_unsigned (ULONGEST unsnd)
223 {
224 gdb_assert (form_is_unsigned ());
225 u.unsnd = unsnd;
226 }
227
228 /* Temporarily set this attribute to an unsigned integer. This is
229 used only for those forms that require reprocessing. */
230 void set_unsigned_reprocess (ULONGEST unsnd)
231 {
232 gdb_assert (form_requires_reprocessing ());
233 u.unsnd = unsnd;
234 requires_reprocessing = 1;
235 }
236
237 /* Set this attribute to an address. */
238 void set_address (CORE_ADDR addr)
239 {
240 gdb_assert (form == DW_FORM_addr
241 || ((form == DW_FORM_addrx
242 || form == DW_FORM_GNU_addr_index)
243 && requires_reprocessing));
244 u.addr = addr;
245 requires_reprocessing = 0;
246 }
247
248 /* True if this attribute requires reprocessing. */
249 bool requires_reprocessing_p () const
250 {
251 return requires_reprocessing;
252 }
253
254 /* Return the value as one of the recognized enum
255 dwarf_defaulted_attribute constants according to DWARF5 spec,
256 Table 7.24. If the value is incorrect, or if this attribute has
257 the wrong form, then a complaint is issued and DW_DEFAULTED_no is
258 returned. */
259 dwarf_defaulted_attribute defaulted () const;
260
261 /* Return the attribute's value as a dwarf_virtuality_attribute
262 constant according to DWARF spec. An unrecognized value will
263 issue a complaint and return DW_VIRTUALITY_none. */
264 dwarf_virtuality_attribute as_virtuality () const;
265
266 /* Return the attribute's value as a boolean. An unrecognized form
267 will issue a complaint and return false. */
268 bool as_boolean () const;
269
270 ENUM_BITFIELD(dwarf_attribute) name : 15;
271
272 /* A boolean that is used for forms that require reprocessing. A
273 form may require data not directly available in the attribute.
274 E.g., DW_FORM_strx requires the corresponding
275 DW_AT_str_offsets_base. In this case, the processing for the
276 attribute must be done in two passes. In the first past, this
277 flag is set and the value is an unsigned. In the second pass,
278 the unsigned value is turned into the correct value for the form,
279 and this flag is cleared. This flag is unused for other
280 forms. */
281 unsigned int requires_reprocessing : 1;
282
283 ENUM_BITFIELD(dwarf_form) form : 15;
284
285 /* Has u.str already been updated by dwarf2_canonicalize_name? This
286 field should be in u.str but it is kept here for better struct
287 attribute alignment. */
288 unsigned int string_is_canonical : 1;
289
290 union
291 {
292 const char *str;
293 struct dwarf_block *blk;
294 ULONGEST unsnd;
295 LONGEST snd;
296 CORE_ADDR addr;
297 ULONGEST signature;
298 }
299 u;
300
301 private:
302
303 /* Used by get_ref_die_offset to issue a complaint. */
304
305 void get_ref_die_offset_complaint () const;
306 };
307
308 #endif /* GDB_DWARF2_ATTRIBUTE_H */
This page took 0.036543 seconds and 4 git commands to generate.