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