Use new to allocate mapped_index
[deliverable/binutils-gdb.git] / gdb / dwarf2read.h
CommitLineData
cd4fb1b2
SM
1/* DWARF 2 debugging format support for GDB.
2
3 Copyright (C) 1994-2018 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 DWARF2READ_H
21#define DWARF2READ_H
22
23#include "filename-seen-cache.h"
24#include "gdb_obstack.h"
25
26typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
27DEF_VEC_P (dwarf2_per_cu_ptr);
28
29/* A descriptor for dwarf sections.
30
31 S.ASECTION, SIZE are typically initialized when the objfile is first
32 scanned. BUFFER, READIN are filled in later when the section is read.
33 If the section contained compressed data then SIZE is updated to record
34 the uncompressed size of the section.
35
36 DWP file format V2 introduces a wrinkle that is easiest to handle by
37 creating the concept of virtual sections contained within a real section.
38 In DWP V2 the sections of the input DWO files are concatenated together
39 into one section, but section offsets are kept relative to the original
40 input section.
41 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
42 the real section this "virtual" section is contained in, and BUFFER,SIZE
43 describe the virtual section. */
44
45struct dwarf2_section_info
46{
47 union
48 {
49 /* If this is a real section, the bfd section. */
50 asection *section;
51 /* If this is a virtual section, pointer to the containing ("real")
52 section. */
53 struct dwarf2_section_info *containing_section;
54 } s;
55 /* Pointer to section data, only valid if readin. */
56 const gdb_byte *buffer;
57 /* The size of the section, real or virtual. */
58 bfd_size_type size;
59 /* If this is a virtual section, the offset in the real section.
60 Only valid if is_virtual. */
61 bfd_size_type virtual_offset;
62 /* True if we have tried to read this section. */
63 char readin;
64 /* True if this is a virtual section, False otherwise.
65 This specifies which of s.section and s.containing_section to use. */
66 char is_virtual;
67};
68
69typedef struct dwarf2_section_info dwarf2_section_info_def;
70DEF_VEC_O (dwarf2_section_info_def);
71
72/* Read the contents of the section INFO.
73 OBJFILE is the main object file, but not necessarily the file where
74 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
75 of the DWO file.
76 If the section is compressed, uncompress it before returning. */
77
78void dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info);
79
80struct tu_stats
81{
82 int nr_uniq_abbrev_tables;
83 int nr_symtabs;
84 int nr_symtab_sharers;
85 int nr_stmt_less_type_units;
86 int nr_all_type_units_reallocs;
87};
88
89struct dwarf2_debug_sections;
90struct mapped_index;
91struct mapped_debug_names;
ff4c9fec 92struct signatured_type;
cd4fb1b2
SM
93
94/* Collection of data recorded per objfile.
95 This hangs off of dwarf2_objfile_data_key. */
96
97struct dwarf2_per_objfile : public allocate_on_obstack
98{
99 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
100 dwarf2 section names, or is NULL if the standard ELF names are
101 used. */
102 dwarf2_per_objfile (struct objfile *objfile,
103 const dwarf2_debug_sections *names);
104
105 ~dwarf2_per_objfile ();
106
107 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile);
108
ff4c9fec
SM
109 /* Return the CU/TU given its index.
110
111 This is intended for loops like:
112
113 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
114 + dwarf2_per_objfile->n_type_units); ++i)
115 {
116 dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
117
118 ...;
119 }
120 */
121 dwarf2_per_cu_data *get_cutu (int index);
122
123 /* Return the CU given its index.
124 This differs from get_cutu in that it's for when you know INDEX refers to a
125 CU. */
126 dwarf2_per_cu_data *get_cu (int index);
127
128 /* Return the TU given its index.
129 This differs from get_cutu in that it's for when you know INDEX refers to a
130 TU. */
131 signatured_type *get_tu (int index);
132
cd4fb1b2
SM
133 /* Free all cached compilation units. */
134 void free_cached_comp_units ();
135private:
136 /* This function is mapped across the sections and remembers the
137 offset and size of each of the debugging sections we are
138 interested in. */
139 void locate_sections (bfd *abfd, asection *sectp,
140 const dwarf2_debug_sections &names);
141
142public:
143 dwarf2_section_info info {};
144 dwarf2_section_info abbrev {};
145 dwarf2_section_info line {};
146 dwarf2_section_info loc {};
147 dwarf2_section_info loclists {};
148 dwarf2_section_info macinfo {};
149 dwarf2_section_info macro {};
150 dwarf2_section_info str {};
151 dwarf2_section_info line_str {};
152 dwarf2_section_info ranges {};
153 dwarf2_section_info rnglists {};
154 dwarf2_section_info addr {};
155 dwarf2_section_info frame {};
156 dwarf2_section_info eh_frame {};
157 dwarf2_section_info gdb_index {};
158 dwarf2_section_info debug_names {};
159 dwarf2_section_info debug_aranges {};
160
161 VEC (dwarf2_section_info_def) *types = NULL;
162
163 /* Back link. */
164 struct objfile *objfile = NULL;
165
166 /* Table of all the compilation units. This is used to locate
167 the target compilation unit of a particular reference. */
b76e467d 168 std::vector<dwarf2_per_cu_data *> all_comp_units;
cd4fb1b2 169
b2bdb8cf
SM
170 /* The .debug_types-related CUs (TUs). */
171 std::vector<signatured_type *> all_type_units;
cd4fb1b2
SM
172
173 /* Table of struct type_unit_group objects.
174 The hash key is the DW_AT_stmt_list value. */
175 htab_t type_unit_groups {};
176
177 /* A table mapping .debug_types signatures to its signatured_type entry.
178 This is NULL if the .debug_types section hasn't been read in yet. */
179 htab_t signatured_types {};
180
181 /* Type unit statistics, to see how well the scaling improvements
182 are doing. */
183 struct tu_stats tu_stats {};
184
185 /* A chain of compilation units that are currently read in, so that
186 they can be freed later. */
187 dwarf2_per_cu_data *read_in_chain = NULL;
188
189 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
190 This is NULL if the table hasn't been allocated yet. */
191 htab_t dwo_files {};
192
193 /* True if we've checked for whether there is a DWP file. */
194 bool dwp_checked = false;
195
196 /* The DWP file if there is one, or NULL. */
197 struct dwp_file *dwp_file = NULL;
198
199 /* The shared '.dwz' file, if one exists. This is used when the
200 original data was compressed using 'dwz -m'. */
201 struct dwz_file *dwz_file = NULL;
202
203 /* A flag indicating whether this objfile has a section loaded at a
204 VMA of 0. */
205 bool has_section_at_zero = false;
206
207 /* True if we are using the mapped index,
208 or we are faking it for OBJF_READNOW's sake. */
209 bool using_index = false;
210
211 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
3063847f 212 std::unique_ptr<mapped_index> index_table;
cd4fb1b2
SM
213
214 /* The mapped index, or NULL if .debug_names is missing or not being used. */
215 std::unique_ptr<mapped_debug_names> debug_names_table;
216
217 /* When using index_table, this keeps track of all quick_file_names entries.
218 TUs typically share line table entries with a CU, so we maintain a
219 separate table of all line table entries to support the sharing.
220 Note that while there can be way more TUs than CUs, we've already
221 sorted all the TUs into "type unit groups", grouped by their
222 DW_AT_stmt_list value. Therefore the only sharing done here is with a
223 CU and its associated TU group if there is one. */
224 htab_t quick_file_names_table {};
225
226 /* Set during partial symbol reading, to prevent queueing of full
227 symbols. */
228 bool reading_partial_symbols = false;
229
230 /* Table mapping type DIEs to their struct type *.
231 This is NULL if not allocated yet.
232 The mapping is done via (CU/TU + DIE offset) -> type. */
233 htab_t die_type_hash {};
234
235 /* The CUs we recently read. */
236 VEC (dwarf2_per_cu_ptr) *just_read_cus = NULL;
237
238 /* Table containing line_header indexed by offset and offset_in_dwz. */
239 htab_t line_header_hash {};
240
241 /* Table containing all filenames. This is an optional because the
242 table is lazily constructed on first access. */
243 gdb::optional<filename_seen_cache> filenames_cache;
244};
245
246/* Get the dwarf2_per_objfile associated to OBJFILE. */
247
248dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
249
250/* Persistent data held for a compilation unit, even when not
251 processing it. We put a pointer to this structure in the
252 read_symtab_private field of the psymtab. */
253
254struct dwarf2_per_cu_data
255{
256 /* The start offset and length of this compilation unit.
257 NOTE: Unlike comp_unit_head.length, this length includes
258 initial_length_size.
259 If the DIE refers to a DWO file, this is always of the original die,
260 not the DWO file. */
261 sect_offset sect_off;
262 unsigned int length;
263
264 /* DWARF standard version this data has been read from (such as 4 or 5). */
265 short dwarf_version;
266
267 /* Flag indicating this compilation unit will be read in before
268 any of the current compilation units are processed. */
269 unsigned int queued : 1;
270
271 /* This flag will be set when reading partial DIEs if we need to load
272 absolutely all DIEs for this compilation unit, instead of just the ones
273 we think are interesting. It gets set if we look for a DIE in the
274 hash table and don't find it. */
275 unsigned int load_all_dies : 1;
276
277 /* Non-zero if this CU is from .debug_types.
278 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
279 this is non-zero. */
280 unsigned int is_debug_types : 1;
281
282 /* Non-zero if this CU is from the .dwz file. */
283 unsigned int is_dwz : 1;
284
285 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
286 This flag is only valid if is_debug_types is true.
287 We can't read a CU directly from a DWO file: There are required
288 attributes in the stub. */
289 unsigned int reading_dwo_directly : 1;
290
291 /* Non-zero if the TU has been read.
292 This is used to assist the "Stay in DWO Optimization" for Fission:
293 When reading a DWO, it's faster to read TUs from the DWO instead of
294 fetching them from random other DWOs (due to comdat folding).
295 If the TU has already been read, the optimization is unnecessary
296 (and unwise - we don't want to change where gdb thinks the TU lives
297 "midflight").
298 This flag is only valid if is_debug_types is true. */
299 unsigned int tu_read : 1;
300
301 /* The section this CU/TU lives in.
302 If the DIE refers to a DWO file, this is always the original die,
303 not the DWO file. */
304 struct dwarf2_section_info *section;
305
306 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
307 of the CU cache it gets reset to NULL again. This is left as NULL for
308 dummy CUs (a CU header, but nothing else). */
309 struct dwarf2_cu *cu;
310
311 /* The corresponding dwarf2_per_objfile. */
312 struct dwarf2_per_objfile *dwarf2_per_objfile;
313
314 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
315 is active. Otherwise, the 'psymtab' field is active. */
316 union
317 {
318 /* The partial symbol table associated with this compilation unit,
319 or NULL for unread partial units. */
320 struct partial_symtab *psymtab;
321
322 /* Data needed by the "quick" functions. */
323 struct dwarf2_per_cu_quick_data *quick;
324 } v;
325
326 /* The CUs we import using DW_TAG_imported_unit. This is filled in
327 while reading psymtabs, used to compute the psymtab dependencies,
328 and then cleared. Then it is filled in again while reading full
329 symbols, and only deleted when the objfile is destroyed.
330
331 This is also used to work around a difference between the way gold
332 generates .gdb_index version <=7 and the way gdb does. Arguably this
333 is a gold bug. For symbols coming from TUs, gold records in the index
334 the CU that includes the TU instead of the TU itself. This breaks
335 dw2_lookup_symbol: It assumes that if the index says symbol X lives
336 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
337 will find X. Alas TUs live in their own symtab, so after expanding CU Y
338 we need to look in TU Z to find X. Fortunately, this is akin to
339 DW_TAG_imported_unit, so we just use the same mechanism: For
340 .gdb_index version <=7 this also records the TUs that the CU referred
341 to. Concurrently with this change gdb was modified to emit version 8
342 indices so we only pay a price for gold generated indices.
343 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
344 VEC (dwarf2_per_cu_ptr) *imported_symtabs;
345};
346
347/* Entry in the signatured_types hash table. */
348
349struct signatured_type
350{
351 /* The "per_cu" object of this type.
352 This struct is used iff per_cu.is_debug_types.
353 N.B.: This is the first member so that it's easy to convert pointers
354 between them. */
355 struct dwarf2_per_cu_data per_cu;
356
357 /* The type's signature. */
358 ULONGEST signature;
359
360 /* Offset in the TU of the type's DIE, as read from the TU header.
361 If this TU is a DWO stub and the definition lives in a DWO file
362 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
363 cu_offset type_offset_in_tu;
364
365 /* Offset in the section of the type's DIE.
366 If the definition lives in a DWO file, this is the offset in the
367 .debug_types.dwo section.
368 The value is zero until the actual value is known.
369 Zero is otherwise not a valid section offset. */
370 sect_offset type_offset_in_section;
371
372 /* Type units are grouped by their DW_AT_stmt_list entry so that they
373 can share them. This points to the containing symtab. */
374 struct type_unit_group *type_unit_group;
375
376 /* The type.
377 The first time we encounter this type we fully read it in and install it
378 in the symbol tables. Subsequent times we only need the type. */
379 struct type *type;
380
381 /* Containing DWO unit.
382 This field is valid iff per_cu.reading_dwo_directly. */
383 struct dwo_unit *dwo_unit;
384};
385
386typedef struct signatured_type *sig_type_ptr;
387DEF_VEC_P (sig_type_ptr);
388
389#endif /* DWARF2READ_H */
This page took 0.05002 seconds and 4 git commands to generate.