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