]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/dwarf2/cu.h
gdb: Fix issue with Clang CLI macros
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / cu.h
1 /* DWARF CU data structure
2
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef GDB_DWARF2_CU_H
21 #define GDB_DWARF2_CU_H
22
23 #include "buildsym.h"
24 #include "dwarf2/comp-unit-head.h"
25 #include "gdbsupport/gdb_optional.h"
26 #include "language.h"
27
28 /* Type used for delaying computation of method physnames.
29 See comments for compute_delayed_physnames. */
30 struct delayed_method_info
31 {
32 /* The type to which the method is attached, i.e., its parent class. */
33 struct type *type;
34
35 /* The index of the method in the type's function fieldlists. */
36 int fnfield_index;
37
38 /* The index of the method in the fieldlist. */
39 int index;
40
41 /* The name of the DIE. */
42 const char *name;
43
44 /* The DIE associated with this method. */
45 struct die_info *die;
46 };
47
48 /* Internal state when decoding a particular compilation unit. */
49 struct dwarf2_cu
50 {
51 explicit dwarf2_cu (dwarf2_per_cu_data *per_cu,
52 dwarf2_per_objfile *per_objfile);
53
54 DISABLE_COPY_AND_ASSIGN (dwarf2_cu);
55
56 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
57 Create the set of symtabs used by this TU, or if this TU is sharing
58 symtabs with another TU and the symtabs have already been created
59 then restore those symtabs in the line header.
60 We don't need the pc/line-number mapping for type units. */
61 void setup_type_unit_groups (struct die_info *die);
62
63 /* Start a compunit_symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to
64 the buildsym_compunit constructor. */
65 struct compunit_symtab *start_compunit_symtab (const char *name,
66 const char *comp_dir,
67 CORE_ADDR low_pc);
68
69 /* Reset the builder. */
70 void reset_builder () { m_builder.reset (); }
71
72 /* Return a type that is a generic pointer type, the size of which
73 matches the address size given in the compilation unit header for
74 this CU. */
75 struct type *addr_type () const;
76
77 /* Find an integer type the same size as the address size given in
78 the compilation unit header for this CU. UNSIGNED_P controls if
79 the integer is unsigned or not. */
80 struct type *addr_sized_int_type (bool unsigned_p) const;
81
82 /* Mark this CU as used. */
83 void mark ();
84
85 /* Clear the mark on this CU. */
86 void clear_mark ()
87 {
88 m_mark = false;
89 }
90
91 /* True if this CU has been marked. */
92 bool is_marked () const
93 {
94 return m_mark;
95 }
96
97 /* Add a dependence relationship from this cu to REF_PER_CU. */
98 void add_dependence (struct dwarf2_per_cu_data *ref_per_cu);
99
100 /* The header of the compilation unit. */
101 struct comp_unit_head header {};
102
103 /* Base address of this compilation unit. */
104 gdb::optional<CORE_ADDR> base_address;
105
106 /* The language we are debugging. */
107 const struct language_defn *language_defn = nullptr;
108
109 enum language lang () const
110 {
111 gdb_assert (language_defn != language_def (language_unknown));
112 return language_defn->la_language;
113 }
114
115 const char *producer = nullptr;
116
117 private:
118 /* The symtab builder for this CU. This is only non-NULL when full
119 symbols are being read. */
120 std::unique_ptr<buildsym_compunit> m_builder;
121
122 /* A set of pointers to dwarf2_per_cu_data objects for compilation
123 units referenced by this one. Only set during full symbol processing;
124 partial symbol tables do not have dependencies. */
125 htab_t m_dependencies = nullptr;
126
127 public:
128 /* The generic symbol table building routines have separate lists for
129 file scope symbols and all all other scopes (local scopes). So
130 we need to select the right one to pass to add_symbol_to_list().
131 We do it by keeping a pointer to the correct list in list_in_scope.
132
133 FIXME: The original dwarf code just treated the file scope as the
134 first local scope, and all other local scopes as nested local
135 scopes, and worked fine. Check to see if we really need to
136 distinguish these in buildsym.c. */
137 struct pending **list_in_scope = nullptr;
138
139 /* Hash table holding all the loaded partial DIEs
140 with partial_die->offset.SECT_OFF as hash. */
141 htab_t partial_dies = nullptr;
142
143 /* Storage for things with the same lifetime as this read-in compilation
144 unit, including partial DIEs. */
145 auto_obstack comp_unit_obstack;
146
147 /* Backlink to our per_cu entry. */
148 struct dwarf2_per_cu_data *per_cu;
149
150 /* The dwarf2_per_objfile that owns this. */
151 dwarf2_per_objfile *per_objfile;
152
153 /* How many compilation units ago was this CU last referenced? */
154 int last_used = 0;
155
156 /* A hash table of DIE cu_offset for following references with
157 die_info->offset.sect_off as hash. */
158 htab_t die_hash = nullptr;
159
160 /* Full DIEs if read in. */
161 struct die_info *dies = nullptr;
162
163 /* Header data from the line table, during full symbol processing. */
164 struct line_header *line_header = nullptr;
165 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
166 it's owned by dwarf2_per_bfd::line_header_hash. If non-NULL,
167 this is the DW_TAG_compile_unit die for this CU. We'll hold on
168 to the line header as long as this DIE is being processed. See
169 process_die_scope. */
170 die_info *line_header_die_owner = nullptr;
171
172 /* A list of methods which need to have physnames computed
173 after all type information has been read. */
174 std::vector<delayed_method_info> method_list;
175
176 /* To be copied to symtab->call_site_htab. */
177 htab_t call_site_htab = nullptr;
178
179 /* Non-NULL if this CU came from a DWO file.
180 There is an invariant here that is important to remember:
181 Except for attributes copied from the top level DIE in the "main"
182 (or "stub") file in preparation for reading the DWO file
183 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
184 Either there isn't a DWO file (in which case this is NULL and the point
185 is moot), or there is and either we're not going to read it (in which
186 case this is NULL) or there is and we are reading it (in which case this
187 is non-NULL). */
188 struct dwo_unit *dwo_unit = nullptr;
189
190 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
191 Note this value comes from the Fission stub CU/TU's DIE. */
192 gdb::optional<ULONGEST> addr_base;
193
194 /* The DW_AT_GNU_ranges_base attribute, if present.
195
196 This is only relevant in the context of pre-DWARF 5 split units. In this
197 context, there is a .debug_ranges section in the linked executable,
198 containing all the ranges data for all the compilation units. Each
199 skeleton/stub unit has (if needed) a DW_AT_GNU_ranges_base attribute that
200 indicates the base of its contribution to that section. The DW_AT_ranges
201 attributes in the split-unit are of the form DW_FORM_sec_offset and point
202 into the .debug_ranges section of the linked file. However, they are not
203 "true" DW_FORM_sec_offset, because they are relative to the base of their
204 compilation unit's contribution, rather than relative to the beginning of
205 the section. The DW_AT_GNU_ranges_base value must be added to it to make
206 it relative to the beginning of the section.
207
208 Note that the value is zero when we are not in a pre-DWARF 5 split-unit
209 case, so this value can be added without needing to know whether we are in
210 this case or not.
211
212 N.B. If a DW_AT_ranges attribute is found on the DW_TAG_compile_unit in the
213 skeleton/stub, it must not have the base added, as it already points to the
214 right place. And since the DW_TAG_compile_unit DIE in the split-unit can't
215 have a DW_AT_ranges attribute, we can use the
216
217 die->tag != DW_AT_compile_unit
218
219 to determine whether the base should be added or not. */
220 ULONGEST gnu_ranges_base = 0;
221
222 /* The DW_AT_rnglists_base attribute, if present.
223
224 This is used when processing attributes of form DW_FORM_rnglistx in
225 non-split units. Attributes of this form found in a split unit don't
226 use it, as split-unit files have their own non-shared .debug_rnglists.dwo
227 section. */
228 ULONGEST rnglists_base = 0;
229
230 /* The DW_AT_loclists_base attribute if present. */
231 ULONGEST loclist_base = 0;
232
233 /* When reading debug info generated by older versions of rustc, we
234 have to rewrite some union types to be struct types with a
235 variant part. This rewriting must be done after the CU is fully
236 read in, because otherwise at the point of rewriting some struct
237 type might not have been fully processed. So, we keep a list of
238 all such types here and process them after expansion. */
239 std::vector<struct type *> rust_unions;
240
241 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
242 files, the value is implicitly zero. For DWARF 5 version DWO files, the
243 value is often implicit and is the size of the header of
244 .debug_str_offsets section (8 or 4, depending on the address size). */
245 gdb::optional<ULONGEST> str_offsets_base;
246
247 /* Mark used when releasing cached dies. */
248 bool m_mark : 1;
249
250 /* This CU references .debug_loc. See the symtab->locations_valid field.
251 This test is imperfect as there may exist optimized debug code not using
252 any location list and still facing inlining issues if handled as
253 unoptimized code. For a future better test see GCC PR other/32998. */
254 bool has_loclist : 1;
255
256 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
257 if all the producer_is_* fields are valid. This information is cached
258 because profiling CU expansion showed excessive time spent in
259 producer_is_gxx_lt_4_6. */
260 bool checked_producer : 1;
261 bool producer_is_gxx_lt_4_6 : 1;
262 bool producer_is_gcc_lt_4_3 : 1;
263 bool producer_is_gcc_11 : 1;
264 bool producer_is_icc : 1;
265 bool producer_is_icc_lt_14 : 1;
266 bool producer_is_codewarrior : 1;
267 bool producer_is_clang : 1;
268
269 /* When true, the file that we're processing is known to have
270 debugging info for C++ namespaces. GCC 3.3.x did not produce
271 this information, but later versions do. */
272
273 bool processing_has_namespace_info : 1;
274
275 /* This flag will be set when reading partial DIEs if we need to load
276 absolutely all DIEs for this compilation unit, instead of just the ones
277 we think are interesting. It gets set if we look for a DIE in the
278 hash table and don't find it. */
279 bool load_all_dies : 1;
280
281 struct partial_die_info *find_partial_die (sect_offset sect_off);
282
283 /* Get the buildsym_compunit for this CU. */
284 buildsym_compunit *get_builder ();
285 };
286
287 #endif /* GDB_DWARF2_CU_H */