Commit | Line | Data |
---|---|---|
162dce55 TT |
1 | /* DWARF attributes |
2 | ||
3 | Copyright (C) 1994-2020 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 | #include "defs.h" | |
28 | #include "dwarf2/attribute.h" | |
29 | ||
30 | /* See attribute.h. */ | |
31 | ||
32 | CORE_ADDR | |
cd6c91b4 | 33 | attribute::value_as_address () const |
162dce55 TT |
34 | { |
35 | CORE_ADDR addr; | |
36 | ||
cd6c91b4 TT |
37 | if (form != DW_FORM_addr && form != DW_FORM_addrx |
38 | && form != DW_FORM_GNU_addr_index) | |
162dce55 TT |
39 | { |
40 | /* Aside from a few clearly defined exceptions, attributes that | |
41 | contain an address must always be in DW_FORM_addr form. | |
42 | Unfortunately, some compilers happen to be violating this | |
43 | requirement by encoding addresses using other forms, such | |
44 | as DW_FORM_data4 for example. For those broken compilers, | |
45 | we try to do our best, without any guarantee of success, | |
46 | to interpret the address correctly. It would also be nice | |
47 | to generate a complaint, but that would require us to maintain | |
48 | a list of legitimate cases where a non-address form is allowed, | |
49 | as well as update callers to pass in at least the CU's DWARF | |
50 | version. This is more overhead than what we're willing to | |
51 | expand for a pretty rare case. */ | |
cd6c91b4 | 52 | addr = DW_UNSND (this); |
162dce55 TT |
53 | } |
54 | else | |
cd6c91b4 | 55 | addr = DW_ADDR (this); |
162dce55 TT |
56 | |
57 | return addr; | |
58 | } | |
59 | ||
60 | /* See attribute.h. */ | |
61 | ||
62 | int | |
63 | attr_form_is_block (const struct attribute *attr) | |
64 | { | |
65 | return (attr == NULL ? 0 : | |
66 | attr->form == DW_FORM_block1 | |
67 | || attr->form == DW_FORM_block2 | |
68 | || attr->form == DW_FORM_block4 | |
69 | || attr->form == DW_FORM_block | |
70 | || attr->form == DW_FORM_exprloc); | |
71 | } | |
72 | ||
73 | /* See attribute.h. */ | |
74 | ||
cd6c91b4 TT |
75 | bool |
76 | attribute::form_is_section_offset () const | |
162dce55 | 77 | { |
cd6c91b4 TT |
78 | return (form == DW_FORM_data4 |
79 | || form == DW_FORM_data8 | |
80 | || form == DW_FORM_sec_offset); | |
162dce55 TT |
81 | } |
82 | ||
83 | /* See attribute.h. */ | |
84 | ||
cd6c91b4 TT |
85 | bool |
86 | attribute::form_is_constant () const | |
162dce55 | 87 | { |
cd6c91b4 | 88 | switch (form) |
162dce55 TT |
89 | { |
90 | case DW_FORM_sdata: | |
91 | case DW_FORM_udata: | |
92 | case DW_FORM_data1: | |
93 | case DW_FORM_data2: | |
94 | case DW_FORM_data4: | |
95 | case DW_FORM_data8: | |
96 | case DW_FORM_implicit_const: | |
cd6c91b4 | 97 | return true; |
162dce55 | 98 | default: |
cd6c91b4 | 99 | return false; |
162dce55 TT |
100 | } |
101 | } | |
102 | ||
103 | /* DW_ADDR is always stored already as sect_offset; despite for the forms | |
104 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
105 | ||
cd6c91b4 TT |
106 | bool |
107 | attribute::form_is_ref () const | |
162dce55 | 108 | { |
cd6c91b4 | 109 | switch (form) |
162dce55 TT |
110 | { |
111 | case DW_FORM_ref_addr: | |
112 | case DW_FORM_ref1: | |
113 | case DW_FORM_ref2: | |
114 | case DW_FORM_ref4: | |
115 | case DW_FORM_ref8: | |
116 | case DW_FORM_ref_udata: | |
117 | case DW_FORM_GNU_ref_alt: | |
cd6c91b4 | 118 | return true; |
162dce55 | 119 | default: |
cd6c91b4 | 120 | return false; |
162dce55 TT |
121 | } |
122 | } |