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