3 Copyright (C) 1994-2021 Free Software Foundation, Inc.
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
12 This file is part of GDB.
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.
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.
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/>. */
27 #ifndef GDB_DWARF2_ATTRIBUTE_H
28 #define GDB_DWARF2_ATTRIBUTE_H
32 #include "gdbsupport/gdb_optional.h"
34 /* Blocks are a bunch of untyped bytes. */
39 /* Valid only if SIZE is not zero. */
43 /* Attributes have a name and a value. */
46 /* Read the given attribute value as an address, taking the
47 attribute's form into account. */
48 CORE_ADDR
as_address () const;
50 /* If the attribute has a string form, return the string value;
51 otherwise return NULL. */
52 const char *as_string () const;
54 /* Return the block value. The attribute must have block form. */
55 dwarf_block
*as_block () const
57 gdb_assert (form_is_block ());
61 /* Return the signature. The attribute must have signature
63 ULONGEST
as_signature () const
65 gdb_assert (form
== DW_FORM_ref_sig8
);
69 /* Return the signed value. The attribute must have the appropriate
71 LONGEST
as_signed () const
73 gdb_assert (form
== DW_FORM_sdata
|| form
== DW_FORM_implicit_const
);
77 /* Return the unsigned value, but only for attributes requiring
79 ULONGEST
as_unsigned_reprocess () const
81 gdb_assert (form_requires_reprocessing ());
82 gdb_assert (requires_reprocessing
);
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
90 gdb_assert (form_is_unsigned ());
91 gdb_assert (!requires_reprocessing
);
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.
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
104 bool form_is_section_offset () const;
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.
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.
119 DW_FORM_data16 is not considered as constant_value cannot handle
122 bool form_is_constant () const;
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
128 bool form_is_ref () const
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
);
139 /* Check if the attribute's form is a DW_FORM_block*
140 if so return true else false. */
142 bool form_is_block () const;
144 /* Check if the attribute's form is a string form. */
145 bool form_is_string () const;
147 /* Check if the attribute's form is an unsigned integer form. */
148 bool form_is_unsigned () const;
150 /* Check if the attribute's form is a form that requires
152 bool form_requires_reprocessing () const;
154 /* Return DIE offset of this attribute. Return 0 with complaint if
155 the attribute is not of the required kind. */
157 sect_offset
get_ref_die_offset () const
160 return (sect_offset
) u
.unsnd
;
161 get_ref_die_offset_complaint ();
165 /* Return the constant value held by this attribute. Return
166 DEFAULT_VALUE if the value held by the attribute is not
169 LONGEST
constant_value (int default_value
) const;
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
178 gdb_assert (form_is_string ());
179 return string_is_canonical
;
182 /* Initialize this attribute to hold a non-canonical string
184 void set_string_noncanonical (const char *str
)
186 gdb_assert (form_is_string ());
188 string_is_canonical
= 0;
189 requires_reprocessing
= 0;
192 /* Set the canonical string value for this attribute. */
193 void set_string_canonical (const char *str
)
195 gdb_assert (form_is_string ());
197 string_is_canonical
= 1;
200 /* Set the block value for this attribute. */
201 void set_block (dwarf_block
*blk
)
203 gdb_assert (form_is_block ());
207 /* Set the signature value for this attribute. */
208 void set_signature (ULONGEST signature
)
210 gdb_assert (form
== DW_FORM_ref_sig8
);
211 u
.signature
= signature
;
214 /* Set this attribute to a signed integer. */
215 void set_signed (LONGEST snd
)
217 gdb_assert (form
== DW_FORM_sdata
|| form
== DW_FORM_implicit_const
);
221 /* Set this attribute to an unsigned integer. */
222 void set_unsigned (ULONGEST unsnd
)
224 gdb_assert (form_is_unsigned ());
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
)
232 gdb_assert (form_requires_reprocessing ());
234 requires_reprocessing
= 1;
237 /* Set this attribute to an address. */
238 void set_address (CORE_ADDR addr
)
240 gdb_assert (form
== DW_FORM_addr
241 || ((form
== DW_FORM_addrx
242 || form
== DW_FORM_GNU_addr_index
)
243 && requires_reprocessing
));
245 requires_reprocessing
= 0;
248 /* True if this attribute requires reprocessing. */
249 bool requires_reprocessing_p () const
251 return requires_reprocessing
;
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
259 dwarf_defaulted_attribute
defaulted () const;
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;
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;
270 ENUM_BITFIELD(dwarf_attribute
) name
: 15;
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
281 unsigned int requires_reprocessing
: 1;
283 ENUM_BITFIELD(dwarf_form
) form
: 15;
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;
293 struct dwarf_block
*blk
;
303 /* Used by get_ref_die_offset to issue a complaint. */
305 void get_ref_die_offset_complaint () const;
308 #endif /* GDB_DWARF2_ATTRIBUTE_H */