3 Copyright (C) 1994-2024 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/>. */
28 #include "dwarf2/attribute.h"
29 #include "dwarf2/stringify.h"
30 #include "complaints.h"
32 /* See attribute.h. */
35 attribute::as_address () const
37 unrelocated_addr addr
;
39 gdb_assert (!requires_reprocessing
);
41 if (form
!= DW_FORM_addr
&& form
!= DW_FORM_addrx
42 && form
!= DW_FORM_GNU_addr_index
)
44 /* Aside from a few clearly defined exceptions, attributes that
45 contain an address must always be in DW_FORM_addr form.
46 Unfortunately, some compilers happen to be violating this
47 requirement by encoding addresses using other forms, such
48 as DW_FORM_data4 for example. For those broken compilers,
49 we try to do our best, without any guarantee of success,
50 to interpret the address correctly. It would also be nice
51 to generate a complaint, but that would require us to maintain
52 a list of legitimate cases where a non-address form is allowed,
53 as well as update callers to pass in at least the CU's DWARF
54 version. This is more overhead than what we're willing to
55 expand for a pretty rare case. */
56 addr
= (unrelocated_addr
) u
.unsnd
;
64 /* See attribute.h. */
67 attribute::form_is_string () const
69 return (form
== DW_FORM_strp
|| form
== DW_FORM_line_strp
70 || form
== DW_FORM_string
71 || form
== DW_FORM_strx
72 || form
== DW_FORM_strx1
73 || form
== DW_FORM_strx2
74 || form
== DW_FORM_strx3
75 || form
== DW_FORM_strx4
76 || form
== DW_FORM_GNU_str_index
77 || form
== DW_FORM_GNU_strp_alt
);
80 /* See attribute.h. */
83 attribute::as_string () const
85 gdb_assert (!requires_reprocessing
);
86 if (form_is_string ())
91 /* See attribute.h. */
94 attribute::form_is_block () const
96 return (form
== DW_FORM_block1
97 || form
== DW_FORM_block2
98 || form
== DW_FORM_block4
99 || form
== DW_FORM_block
100 || form
== DW_FORM_exprloc
101 || form
== DW_FORM_data16
);
104 /* See attribute.h. */
107 attribute::form_is_section_offset () const
109 return (form
== DW_FORM_data4
110 || form
== DW_FORM_data8
111 || form
== DW_FORM_sec_offset
112 || form
== DW_FORM_loclistx
);
115 /* See attribute.h. */
118 attribute::form_is_constant () const
128 case DW_FORM_implicit_const
:
135 /* See attribute.h. */
138 attribute::get_ref_die_offset_complaint () const
140 complaint (_("unsupported die ref attribute form: '%s'"),
141 dwarf_form_name (form
));
144 /* See attribute.h. */
147 attribute::constant_value (int default_value
) const
149 if (form
== DW_FORM_sdata
|| form
== DW_FORM_implicit_const
)
151 else if (form
== DW_FORM_udata
152 || form
== DW_FORM_data1
153 || form
== DW_FORM_data2
154 || form
== DW_FORM_data4
155 || form
== DW_FORM_data8
)
159 /* For DW_FORM_data16 see attribute::form_is_constant. */
160 complaint (_("Attribute value is not a constant (%s)"),
161 dwarf_form_name (form
));
162 return default_value
;
166 /* See attribute.h. */
169 attribute::form_is_unsigned () const
171 return (form
== DW_FORM_ref_addr
172 || form
== DW_FORM_GNU_ref_alt
173 || form
== DW_FORM_data2
174 || form
== DW_FORM_data4
175 || form
== DW_FORM_data8
176 || form
== DW_FORM_sec_offset
177 || form
== DW_FORM_data1
178 || form
== DW_FORM_flag
179 || form
== DW_FORM_flag_present
180 || form
== DW_FORM_udata
181 || form
== DW_FORM_rnglistx
182 || form
== DW_FORM_loclistx
183 || form
== DW_FORM_ref1
184 || form
== DW_FORM_ref2
185 || form
== DW_FORM_ref4
186 || form
== DW_FORM_ref8
187 || form
== DW_FORM_ref_udata
);
190 /* See attribute.h. */
193 attribute::form_is_signed () const
195 return form
== DW_FORM_sdata
|| form
== DW_FORM_implicit_const
;
198 /* See attribute.h. */
201 attribute::form_requires_reprocessing () const
203 return (form
== DW_FORM_strx
204 || form
== DW_FORM_strx1
205 || form
== DW_FORM_strx2
206 || form
== DW_FORM_strx3
207 || form
== DW_FORM_strx4
208 || form
== DW_FORM_GNU_str_index
209 || form
== DW_FORM_addrx
210 || form
== DW_FORM_GNU_addr_index
211 || form
== DW_FORM_rnglistx
212 || form
== DW_FORM_loclistx
);
215 /* See attribute.h. */
217 dwarf_defaulted_attribute
218 attribute::defaulted () const
220 LONGEST value
= constant_value (-1);
224 case DW_DEFAULTED_no
:
225 case DW_DEFAULTED_in_class
:
226 case DW_DEFAULTED_out_of_class
:
227 return (dwarf_defaulted_attribute
) value
;
230 /* If the form was not constant, we already complained in
231 constant_value, so there's no need to complain again. */
232 if (form_is_constant ())
233 complaint (_("unrecognized DW_AT_defaulted value (%s)"),
235 return DW_DEFAULTED_no
;
238 /* See attribute.h. */
240 dwarf_virtuality_attribute
241 attribute::as_virtuality () const
243 LONGEST value
= constant_value (-1);
247 case DW_VIRTUALITY_none
:
248 case DW_VIRTUALITY_virtual
:
249 case DW_VIRTUALITY_pure_virtual
:
250 return (dwarf_virtuality_attribute
) value
;
253 /* If the form was not constant, we already complained in
254 constant_value, so there's no need to complain again. */
255 if (form_is_constant ())
256 complaint (_("unrecognized DW_AT_virtuality value (%s)"),
258 return DW_VIRTUALITY_none
;
261 /* See attribute.h. */
264 attribute::as_boolean () const
266 if (form
== DW_FORM_flag_present
)
268 else if (form
== DW_FORM_flag
)
270 return constant_value (0) != 0;