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