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