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 | #ifndef GDB_DWARF2_ATTRIBUTE_H | |
28 | #define GDB_DWARF2_ATTRIBUTE_H | |
29 | ||
30 | #include "dwarf2.h" | |
0826b30a | 31 | #include "gdbtypes.h" |
162dce55 TT |
32 | |
33 | /* Blocks are a bunch of untyped bytes. */ | |
34 | struct dwarf_block | |
35 | { | |
36 | size_t size; | |
37 | ||
38 | /* Valid only if SIZE is not zero. */ | |
39 | const gdb_byte *data; | |
40 | }; | |
41 | ||
42 | /* Attributes have a name and a value. */ | |
43 | struct attribute | |
44 | { | |
cd6c91b4 TT |
45 | /* Read the given attribute value as an address, taking the |
46 | attribute's form into account. */ | |
47 | CORE_ADDR value_as_address () const; | |
48 | ||
49 | /* Return non-zero if ATTR's value is a section offset --- classes | |
50 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
51 | You may use DW_UNSND (attr) to retrieve such offsets. | |
52 | ||
53 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
54 | may have a value that belongs to more than one of these classes; it | |
55 | would be ambiguous if we did, because we use the same forms for all | |
56 | of them. */ | |
57 | ||
58 | bool form_is_section_offset () const; | |
59 | ||
60 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
61 | zero otherwise. When this function returns true, you can apply | |
4d1b9ab6 | 62 | the constant_value method to it. |
cd6c91b4 TT |
63 | |
64 | However, note that for some attributes you must check | |
65 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
66 | and DW_FORM_data8 are members of both the constant class, and of | |
67 | the classes that contain offsets into other debug sections | |
68 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
69 | that, if an attribute's can be either a constant or one of the | |
70 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
71 | taken as section offsets, not constants. | |
72 | ||
4d1b9ab6 TT |
73 | DW_FORM_data16 is not considered as constant_value cannot handle |
74 | that. */ | |
cd6c91b4 TT |
75 | |
76 | bool form_is_constant () const; | |
77 | ||
78 | /* DW_ADDR is always stored already as sect_offset; despite for the forms | |
79 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
80 | ||
81 | bool form_is_ref () const; | |
82 | ||
4fc6c0d5 TT |
83 | /* Check if the attribute's form is a DW_FORM_block* |
84 | if so return true else false. */ | |
85 | ||
86 | bool form_is_block () const; | |
87 | ||
0826b30a TT |
88 | /* Return DIE offset of this attribute. Return 0 with complaint if |
89 | the attribute is not of the required kind. */ | |
90 | ||
91 | sect_offset get_ref_die_offset () const; | |
92 | ||
93 | /* Return the constant value held by this attribute. Return | |
94 | DEFAULT_VALUE if the value held by the attribute is not | |
95 | constant. */ | |
96 | ||
97 | LONGEST constant_value (int default_value) const; | |
98 | ||
cd6c91b4 | 99 | |
162dce55 TT |
100 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
101 | ENUM_BITFIELD(dwarf_form) form : 15; | |
102 | ||
103 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
104 | field should be in u.str (existing only for DW_STRING) but it is kept | |
105 | here for better struct attribute alignment. */ | |
106 | unsigned int string_is_canonical : 1; | |
107 | ||
108 | union | |
109 | { | |
110 | const char *str; | |
111 | struct dwarf_block *blk; | |
112 | ULONGEST unsnd; | |
113 | LONGEST snd; | |
114 | CORE_ADDR addr; | |
115 | ULONGEST signature; | |
116 | } | |
117 | u; | |
118 | }; | |
119 | ||
120 | /* Get at parts of an attribute structure. */ | |
121 | ||
122 | #define DW_STRING(attr) ((attr)->u.str) | |
123 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) | |
124 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
125 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
126 | #define DW_SND(attr) ((attr)->u.snd) | |
127 | #define DW_ADDR(attr) ((attr)->u.addr) | |
128 | #define DW_SIGNATURE(attr) ((attr)->u.signature) | |
129 | ||
162dce55 | 130 | #endif /* GDB_DWARF2_ATTRIBUTE_H */ |