Change how dwarf2_per_cu_data is deleted
[deliverable/binutils-gdb.git] / gdb / dwarf2 / read.h
CommitLineData
cd4fb1b2
SM
1/* DWARF 2 debugging format support for GDB.
2
3666a048 3 Copyright (C) 1994-2021 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>
2e6a9f79 25#include "dwarf2/comp-unit.h"
82ca8957 26#include "dwarf2/index-cache.h"
2c86cff9 27#include "dwarf2/section.h"
cd4fb1b2
SM
28#include "filename-seen-cache.h"
29#include "gdb_obstack.h"
268a13a5 30#include "gdbsupport/hash_enum.h"
041d9819 31#include "gdbsupport/function-view.h"
891813be 32#include "psympriv.h"
cd4fb1b2 33
3c3bb058
AB
34/* Hold 'maintenance (set|show) dwarf' commands. */
35extern struct cmd_list_element *set_dwarf_cmdlist;
36extern struct cmd_list_element *show_dwarf_cmdlist;
37
cd4fb1b2
SM
38struct tu_stats
39{
40 int nr_uniq_abbrev_tables;
41 int nr_symtabs;
42 int nr_symtab_sharers;
43 int nr_stmt_less_type_units;
44 int nr_all_type_units_reallocs;
91eea9cc 45 int nr_tus;
cd4fb1b2
SM
46};
47
7188ed02 48struct dwarf2_cu;
cd4fb1b2 49struct dwarf2_debug_sections;
39856def 50struct dwarf2_per_cu_data;
cd4fb1b2
SM
51struct mapped_index;
52struct mapped_debug_names;
ff4c9fec 53struct signatured_type;
8adb8487 54struct type_unit_group;
cd4fb1b2 55
39856def
TT
56/* One item on the queue of compilation units to read in full symbols
57 for. */
58struct dwarf2_queue_item
59{
120ce1b5
SM
60 dwarf2_queue_item (dwarf2_per_cu_data *cu, dwarf2_per_objfile *per_objfile,
61 enum language lang)
39856def 62 : per_cu (cu),
120ce1b5 63 per_objfile (per_objfile),
39856def
TT
64 pretend_language (lang)
65 {
66 }
67
68 ~dwarf2_queue_item ();
69
70 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_item);
71
120ce1b5
SM
72 dwarf2_per_cu_data *per_cu;
73 dwarf2_per_objfile *per_objfile;
39856def
TT
74 enum language pretend_language;
75};
76
473ab964
TT
77/* A deleter for dwarf2_per_cu_data that knows to downcast to
78 signatured_type as appropriate. This approach lets us avoid a
79 virtual destructor, which saves a bit of space. */
80
81struct dwarf2_per_cu_data_deleter
82{
83 void operator() (dwarf2_per_cu_data *data);
84};
85
86/* A specialization of unique_ptr for dwarf2_per_cu_data and
87 subclasses. */
88typedef std::unique_ptr<dwarf2_per_cu_data, dwarf2_per_cu_data_deleter>
89 dwarf2_per_cu_data_up;
90
5989a64e
SM
91/* Some DWARF data can be shared across objfiles who share the same BFD,
92 this data is stored in this object.
cd4fb1b2 93
5989a64e
SM
94 Two dwarf2_per_objfile objects representing objfiles sharing the same BFD
95 will point to the same instance of dwarf2_per_bfd, unless the BFD requires
96 relocation. */
97
98struct dwarf2_per_bfd
cd4fb1b2 99{
5989a64e 100 /* Construct a dwarf2_per_bfd for OBFD. NAMES points to the
cd4fb1b2 101 dwarf2 section names, or is NULL if the standard ELF names are
4b610737
TT
102 used. CAN_COPY is true for formats where symbol
103 interposition is possible and so symbol values must follow copy
104 relocation rules. */
5989a64e 105 dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names, bool can_copy);
cd4fb1b2 106
5989a64e 107 ~dwarf2_per_bfd ();
cd4fb1b2 108
5989a64e 109 DISABLE_COPY_AND_ASSIGN (dwarf2_per_bfd);
cd4fb1b2 110
91eea9cc
TT
111 /* Return the CU given its index. */
112 dwarf2_per_cu_data *get_cu (int index) const
113 {
114 return this->all_comp_units[index].get ();
115 }
ff4c9fec 116
d3473f0c
TT
117 /* A convenience function to allocate a dwarf2_per_cu_data. The
118 returned object has its "index" field set properly. The object
5989a64e 119 is allocated on the dwarf2_per_bfd obstack. */
473ab964 120 dwarf2_per_cu_data_up allocate_per_cu ();
d3473f0c
TT
121
122 /* A convenience function to allocate a signatured_type. The
123 returned object has its "index" field set properly. The object
5989a64e 124 is allocated on the dwarf2_per_bfd obstack. */
0d305d5c 125 std::unique_ptr<signatured_type> allocate_signatured_type ();
d3473f0c 126
af758d11
SM
127 /* Return the number of partial symtabs allocated with allocate_per_cu
128 and allocate_signatured_type so far. */
129 int num_psymtabs () const
130 { return m_num_psymtabs; }
131
cd4fb1b2
SM
132private:
133 /* This function is mapped across the sections and remembers the
134 offset and size of each of the debugging sections we are
135 interested in. */
136 void locate_sections (bfd *abfd, asection *sectp,
137 const dwarf2_debug_sections &names);
138
139public:
c3699833
SM
140 /* The corresponding BFD. */
141 bfd *obfd;
142
45940949
TT
143 /* Objects that can be shared across objfiles are stored in this
144 obstack or on the psymtab obstack, while objects that are
145 objfile-specific are stored on the objfile obstack. */
146 auto_obstack obstack;
147
cd4fb1b2
SM
148 dwarf2_section_info info {};
149 dwarf2_section_info abbrev {};
150 dwarf2_section_info line {};
151 dwarf2_section_info loc {};
152 dwarf2_section_info loclists {};
153 dwarf2_section_info macinfo {};
154 dwarf2_section_info macro {};
155 dwarf2_section_info str {};
18a8505e 156 dwarf2_section_info str_offsets {};
cd4fb1b2
SM
157 dwarf2_section_info line_str {};
158 dwarf2_section_info ranges {};
159 dwarf2_section_info rnglists {};
160 dwarf2_section_info addr {};
161 dwarf2_section_info frame {};
162 dwarf2_section_info eh_frame {};
163 dwarf2_section_info gdb_index {};
164 dwarf2_section_info debug_names {};
165 dwarf2_section_info debug_aranges {};
166
fd5866f6 167 std::vector<dwarf2_section_info> types;
cd4fb1b2 168
cd4fb1b2
SM
169 /* Table of all the compilation units. This is used to locate
170 the target compilation unit of a particular reference. */
473ab964 171 std::vector<dwarf2_per_cu_data_up> all_comp_units;
cd4fb1b2 172
cd4fb1b2
SM
173 /* Table of struct type_unit_group objects.
174 The hash key is the DW_AT_stmt_list value. */
eaa5fa8b 175 htab_up type_unit_groups;
cd4fb1b2
SM
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. */
b0b6a987 179 htab_up signatured_types;
cd4fb1b2
SM
180
181 /* Type unit statistics, to see how well the scaling improvements
182 are doing. */
183 struct tu_stats tu_stats {};
184
cd4fb1b2
SM
185 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
186 This is NULL if the table hasn't been allocated yet. */
51ac9db5 187 htab_up dwo_files;
cd4fb1b2
SM
188
189 /* True if we've checked for whether there is a DWP file. */
190 bool dwp_checked = false;
191
192 /* The DWP file if there is one, or NULL. */
400174b1 193 std::unique_ptr<struct dwp_file> dwp_file;
cd4fb1b2
SM
194
195 /* The shared '.dwz' file, if one exists. This is used when the
196 original data was compressed using 'dwz -m'. */
7ff8cb8c 197 std::unique_ptr<struct dwz_file> dwz_file;
cd4fb1b2 198
4b610737
TT
199 /* Whether copy relocations are supported by this object format. */
200 bool can_copy;
201
cd4fb1b2
SM
202 /* A flag indicating whether this objfile has a section loaded at a
203 VMA of 0. */
204 bool has_section_at_zero = false;
205
206 /* True if we are using the mapped index,
207 or we are faking it for OBJF_READNOW's sake. */
208 bool using_index = false;
209
210 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
3063847f 211 std::unique_ptr<mapped_index> index_table;
cd4fb1b2
SM
212
213 /* The mapped index, or NULL if .debug_names is missing or not being used. */
214 std::unique_ptr<mapped_debug_names> debug_names_table;
215
216 /* When using index_table, this keeps track of all quick_file_names entries.
217 TUs typically share line table entries with a CU, so we maintain a
218 separate table of all line table entries to support the sharing.
219 Note that while there can be way more TUs than CUs, we've already
220 sorted all the TUs into "type unit groups", grouped by their
221 DW_AT_stmt_list value. Therefore the only sharing done here is with a
222 CU and its associated TU group if there is one. */
5895093f 223 htab_up quick_file_names_table;
cd4fb1b2
SM
224
225 /* Set during partial symbol reading, to prevent queueing of full
226 symbols. */
227 bool reading_partial_symbols = false;
228
cd4fb1b2 229 /* The CUs we recently read. */
c5d0225d 230 std::vector<dwarf2_per_cu_data *> just_read_cus;
cd4fb1b2 231
87d6a7aa
SM
232 /* If we loaded the index from an external file, this contains the
233 resources associated to the open file, memory mapping, etc. */
234 std::unique_ptr<index_cache_resource> index_cache_res;
e4a62c65
TV
235
236 /* Mapping from abstract origin DIE to concrete DIEs that reference it as
237 DW_AT_abstract_origin. */
fad03f6e
TT
238 std::unordered_map<sect_offset, std::vector<sect_offset>,
239 gdb::hash_enum<sect_offset>>
e4a62c65 240 abstract_to_concrete;
39856def
TT
241
242 /* CUs that are queued to be read. */
08ac5771 243 gdb::optional<std::queue<dwarf2_queue_item>> queue;
d3473f0c 244
17ee85fc
TT
245 /* We keep a separate reference to the partial symtabs, in case we
246 are sharing them between objfiles. This is only set after
247 partial symbols have been read the first time. */
248 std::shared_ptr<psymtab_storage> partial_symtabs;
249
efd7398e
TT
250 /* The address map that is used by the DWARF index code. */
251 struct addrmap *index_addrmap = nullptr;
252
d3473f0c
TT
253private:
254
255 /* The total number of per_cu and signatured_type objects that have
256 been created so far for this reader. */
257 size_t m_num_psymtabs = 0;
cd4fb1b2
SM
258};
259
8adb8487
TT
260/* This is the per-objfile data associated with a type_unit_group. */
261
262struct type_unit_group_unshareable
263{
264 /* The compunit symtab.
265 Type units in a group needn't all be defined in the same source file,
266 so we create an essentially anonymous symtab as the compunit symtab. */
267 struct compunit_symtab *compunit_symtab = nullptr;
268
269 /* The number of symtabs from the line header.
270 The value here must match line_header.num_file_names. */
271 unsigned int num_symtabs = 0;
272
273 /* The symbol tables for this TU (obtained from the files listed in
274 DW_AT_stmt_list).
275 WARNING: The order of entries here must match the order of entries
276 in the line header. After the first TU using this type_unit_group, the
277 line header for the subsequent TUs is recreated from this. This is done
278 because we need to use the same symtabs for each TU using the same
279 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
280 there's no guarantee the line header doesn't have duplicate entries. */
281 struct symtab **symtabs = nullptr;
282};
283
5989a64e
SM
284/* Collection of data recorded per objfile.
285 This hangs off of dwarf2_objfile_data_key.
286
287 Some DWARF data cannot (currently) be shared across objfiles. Such
288 data is stored in this object. */
289
290struct dwarf2_per_objfile
291{
292 dwarf2_per_objfile (struct objfile *objfile, dwarf2_per_bfd *per_bfd)
293 : objfile (objfile), per_bfd (per_bfd)
294 {}
295
7188ed02
SM
296 ~dwarf2_per_objfile ();
297
5989a64e
SM
298 /* Return pointer to string at .debug_line_str offset as read from BUF.
299 BUF is assumed to be in a compilation unit described by CU_HEADER.
300 Return *BYTES_READ_PTR count of bytes read from BUF. */
301 const char *read_line_string (const gdb_byte *buf,
302 const struct comp_unit_head *cu_header,
303 unsigned int *bytes_read_ptr);
304
af758d11
SM
305 /* Resize the M_SYMTABS vector to the needed size (the number of partial
306 symtabs allocated by the per-bfd). */
307 void resize_symtabs ()
308 {
309 /* The symtabs vector should only grow, not shrink. */
310 gdb_assert (per_bfd->num_psymtabs () >= m_symtabs.size ());
311
312 m_symtabs.resize (per_bfd->num_psymtabs ());
313 }
314
315 /* Return true if the symtab corresponding to PER_CU has been set,
316 false otherwise. */
317 bool symtab_set_p (const dwarf2_per_cu_data *per_cu) const;
318
319 /* Return the compunit_symtab associated to PER_CU, if it has been created. */
320 compunit_symtab *get_symtab (const dwarf2_per_cu_data *per_cu) const;
321
322 /* Set the compunit_symtab associated to PER_CU. */
323 void set_symtab (const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab);
324
e286671b
TT
325 /* Get the type_unit_group_unshareable corresponding to TU_GROUP. If one
326 does not exist, create it. */
8adb8487
TT
327 type_unit_group_unshareable *get_type_unit_group_unshareable
328 (type_unit_group *tu_group);
329
e286671b
TT
330 struct type *get_type_for_signatured_type (signatured_type *sig_type) const;
331
332 void set_type_for_signatured_type (signatured_type *sig_type,
333 struct type *type);
334
293e7e51
SM
335 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
336 UNSIGNED_P controls if the integer is unsigned or not. */
337 struct type *int_type (int size_in_bytes, bool unsigned_p) const;
338
7188ed02
SM
339 /* Get the dwarf2_cu matching PER_CU for this objfile. */
340 dwarf2_cu *get_cu (dwarf2_per_cu_data *per_cu);
341
342 /* Set the dwarf2_cu matching PER_CU for this objfile. */
343 void set_cu (dwarf2_per_cu_data *per_cu, dwarf2_cu *cu);
344
345 /* Remove/free the dwarf2_cu matching PER_CU for this objfile. */
346 void remove_cu (dwarf2_per_cu_data *per_cu);
347
348 /* Free all cached compilation units. */
349 void remove_all_cus ();
350
351 /* Increase the age counter on each CU compilation unit and free
352 any that are too old. */
353 void age_comp_units ();
354
5989a64e
SM
355 /* Back link. */
356 struct objfile *objfile;
357
358 /* Pointer to the data that is (possibly) shared between this objfile and
359 other objfiles backed by the same BFD. */
360 struct dwarf2_per_bfd *per_bfd;
af758d11 361
ae090bdb
SM
362 /* Table mapping type DIEs to their struct type *.
363 This is nullptr if not allocated yet.
364 The mapping is done via (CU/TU + DIE offset) -> type. */
365 htab_up die_type_hash;
366
39b16f87
SM
367 /* Table containing line_header indexed by offset and offset_in_dwz. */
368 htab_up line_header_hash;
369
af758d11
SM
370private:
371 /* Hold the corresponding compunit_symtab for each CU or TU. This
372 is indexed by dwarf2_per_cu_data::index. A NULL value means
373 that the CU/TU has not been expanded yet. */
374 std::vector<compunit_symtab *> m_symtabs;
8adb8487
TT
375
376 /* Map from a type unit group to the corresponding unshared
377 structure. */
378 typedef std::unique_ptr<type_unit_group_unshareable>
379 type_unit_group_unshareable_up;
380
381 std::unordered_map<type_unit_group *, type_unit_group_unshareable_up>
382 m_type_units;
e286671b
TT
383
384 /* Map from signatured types to the corresponding struct type. */
385 std::unordered_map<signatured_type *, struct type *> m_type_map;
7188ed02
SM
386
387 /* Map from the objfile-independent dwarf2_per_cu_data instances to the
388 corresponding objfile-dependent dwarf2_cu instances. */
389 std::unordered_map<dwarf2_per_cu_data *, dwarf2_cu *> m_dwarf2_cus;
5989a64e
SM
390};
391
cd4fb1b2
SM
392/* Get the dwarf2_per_objfile associated to OBJFILE. */
393
394dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
395
891813be 396/* A partial symtab specialized for DWARF. */
af758d11 397struct dwarf2_psymtab : public partial_symtab
891813be 398{
7b249e47
TT
399 dwarf2_psymtab (const char *filename,
400 psymtab_storage *partial_symtabs,
0072c873 401 objfile_per_bfd_storage *objfile_per_bfd,
9f4e76a4 402 dwarf2_per_cu_data *per_cu)
0072c873 403 : partial_symtab (filename, partial_symtabs, objfile_per_bfd, 0),
9f4e76a4 404 per_cu_data (per_cu)
891813be
TT
405 {
406 }
407
408 void read_symtab (struct objfile *) override;
8566b89b 409 void expand_psymtab (struct objfile *) override;
af758d11
SM
410 bool readin_p (struct objfile *) const override;
411 compunit_symtab *get_compunit_symtab (struct objfile *) const override;
891813be
TT
412
413 struct dwarf2_per_cu_data *per_cu_data;
414};
415
cd4fb1b2
SM
416/* Persistent data held for a compilation unit, even when not
417 processing it. We put a pointer to this structure in the
891813be 418 psymtab. */
cd4fb1b2
SM
419
420struct dwarf2_per_cu_data
421{
0d305d5c
TT
422 dwarf2_per_cu_data ()
423 : queued (false),
424 load_all_dies (false),
425 is_debug_types (false),
426 is_dwz (false),
427 reading_dwo_directly (false),
428 tu_read (false),
429 m_header_read_in (false),
430 unit_type {},
431 lang (language_unknown)
432 {
433 }
434
cd4fb1b2
SM
435 /* The start offset and length of this compilation unit.
436 NOTE: Unlike comp_unit_head.length, this length includes
437 initial_length_size.
438 If the DIE refers to a DWO file, this is always of the original die,
439 not the DWO file. */
0d305d5c
TT
440 sect_offset sect_off {};
441 unsigned int length = 0;
cd4fb1b2
SM
442
443 /* DWARF standard version this data has been read from (such as 4 or 5). */
0d305d5c 444 unsigned char dwarf_version = 0;
cd4fb1b2
SM
445
446 /* Flag indicating this compilation unit will be read in before
447 any of the current compilation units are processed. */
448 unsigned int queued : 1;
449
450 /* This flag will be set when reading partial DIEs if we need to load
451 absolutely all DIEs for this compilation unit, instead of just the ones
452 we think are interesting. It gets set if we look for a DIE in the
453 hash table and don't find it. */
454 unsigned int load_all_dies : 1;
455
456 /* Non-zero if this CU is from .debug_types.
457 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
458 this is non-zero. */
459 unsigned int is_debug_types : 1;
460
461 /* Non-zero if this CU is from the .dwz file. */
462 unsigned int is_dwz : 1;
463
464 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
465 This flag is only valid if is_debug_types is true.
466 We can't read a CU directly from a DWO file: There are required
467 attributes in the stub. */
468 unsigned int reading_dwo_directly : 1;
469
470 /* Non-zero if the TU has been read.
471 This is used to assist the "Stay in DWO Optimization" for Fission:
472 When reading a DWO, it's faster to read TUs from the DWO instead of
473 fetching them from random other DWOs (due to comdat folding).
474 If the TU has already been read, the optimization is unnecessary
475 (and unwise - we don't want to change where gdb thinks the TU lives
476 "midflight").
477 This flag is only valid if is_debug_types is true. */
478 unsigned int tu_read : 1;
479
7e7a35fb
TT
480 /* True if HEADER has been read in.
481
482 Don't access this field directly. It should be private, but we can't make
483 it private at the moment. */
484 mutable bool m_header_read_in : 1;
485
486 /* The unit type of this CU. */
487 ENUM_BITFIELD (dwarf_unit_type) unit_type : 8;
488
489 /* The language of this CU. */
490 ENUM_BITFIELD (language) lang : LANGUAGE_BITS;
491
d3473f0c 492 /* Our index in the unshared "symtabs" vector. */
0d305d5c 493 unsigned index = 0;
d3473f0c 494
cd4fb1b2
SM
495 /* The section this CU/TU lives in.
496 If the DIE refers to a DWO file, this is always the original die,
497 not the DWO file. */
0d305d5c 498 struct dwarf2_section_info *section = nullptr;
cd4fb1b2 499
1859c670 500 /* Backlink to the owner of this. */
0d305d5c 501 dwarf2_per_bfd *per_bfd = nullptr;
1859c670 502
2e6a9f79
SM
503 /* DWARF header of this CU. Note that dwarf2_cu reads its own version of the
504 header, which may differ from this one, since it may pass rcuh_kind::TYPE
505 to read_comp_unit_head, whereas for dwarf2_per_cu_data we always pass
506 rcuh_kind::COMPILE.
507
508 Don't access this field directly, use the get_header method instead. It
509 should be private, but we can't make it private at the moment. */
0d305d5c 510 mutable comp_unit_head m_header {};
2e6a9f79 511
5989a64e 512 /* When dwarf2_per_bfd::using_index is true, the 'quick' field
cd4fb1b2
SM
513 is active. Otherwise, the 'psymtab' field is active. */
514 union
515 {
516 /* The partial symbol table associated with this compilation unit,
517 or NULL for unread partial units. */
891813be 518 dwarf2_psymtab *psymtab;
cd4fb1b2
SM
519
520 /* Data needed by the "quick" functions. */
521 struct dwarf2_per_cu_quick_data *quick;
0d305d5c 522 } v {};
cd4fb1b2 523
96c738c0
TT
524 /* The CUs we import using DW_TAG_imported_unit. This is filled in
525 while reading psymtabs, used to compute the psymtab dependencies,
526 and then cleared. Then it is filled in again while reading full
527 symbols, and only deleted when the objfile is destroyed.
528
529 This is also used to work around a difference between the way gold
530 generates .gdb_index version <=7 and the way gdb does. Arguably this
531 is a gold bug. For symbols coming from TUs, gold records in the index
532 the CU that includes the TU instead of the TU itself. This breaks
533 dw2_lookup_symbol: It assumes that if the index says symbol X lives
534 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
535 will find X. Alas TUs live in their own symtab, so after expanding CU Y
536 we need to look in TU Z to find X. Fortunately, this is akin to
537 DW_TAG_imported_unit, so we just use the same mechanism: For
538 .gdb_index version <=7 this also records the TUs that the CU referred
539 to. Concurrently with this change gdb was modified to emit version 8
540 indices so we only pay a price for gold generated indices.
541 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
542
543 This currently needs to be a public member due to how
544 dwarf2_per_cu_data is allocated and used. Ideally in future things
545 could be refactored to make this private. Until then please try to
546 avoid direct access to this member, and instead use the helper
547 functions above. */
0d305d5c 548 std::vector <dwarf2_per_cu_data *> *imported_symtabs = nullptr;
96c738c0 549
ae640021
AB
550 /* Return true of IMPORTED_SYMTABS is empty or not yet allocated. */
551 bool imported_symtabs_empty () const
552 {
553 return (imported_symtabs == nullptr || imported_symtabs->empty ());
554 }
555
556 /* Push P to the back of IMPORTED_SYMTABS, allocated IMPORTED_SYMTABS
557 first if required. */
558 void imported_symtabs_push (dwarf2_per_cu_data *p)
559 {
560 if (imported_symtabs == nullptr)
561 imported_symtabs = new std::vector <dwarf2_per_cu_data *>;
562 imported_symtabs->push_back (p);
563 }
564
565 /* Return the size of IMPORTED_SYMTABS if it is allocated, otherwise
566 return 0. */
567 size_t imported_symtabs_size () const
568 {
569 if (imported_symtabs == nullptr)
570 return 0;
571 return imported_symtabs->size ();
572 }
573
574 /* Delete IMPORTED_SYMTABS and set the pointer back to nullptr. */
575 void imported_symtabs_free ()
576 {
577 delete imported_symtabs;
578 imported_symtabs = nullptr;
579 }
09ba997f 580
2e6a9f79
SM
581 /* Get the header of this per_cu, reading it if necessary. */
582 const comp_unit_head *get_header () const;
583
09ba997f
TT
584 /* Return the address size given in the compilation unit header for
585 this CU. */
586 int addr_size () const;
587
588 /* Return the offset size given in the compilation unit header for
589 this CU. */
590 int offset_size () const;
591
592 /* Return the DW_FORM_ref_addr size given in the compilation unit
593 header for this CU. */
594 int ref_addr_size () const;
595
09ba997f
TT
596 /* Return DWARF version number of this CU. */
597 short version () const
598 {
599 return dwarf_version;
600 }
197400e8
TT
601
602 /* A type unit group has a per_cu object that is recognized by
603 having no section. */
604 bool type_unit_group_p () const
605 {
606 return section == nullptr;
607 }
cd4fb1b2
SM
608};
609
610/* Entry in the signatured_types hash table. */
611
0d305d5c 612struct signatured_type : public dwarf2_per_cu_data
cd4fb1b2 613{
cd4fb1b2 614 /* The type's signature. */
0d305d5c 615 ULONGEST signature = 0;
cd4fb1b2
SM
616
617 /* Offset in the TU of the type's DIE, as read from the TU header.
618 If this TU is a DWO stub and the definition lives in a DWO file
619 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
0d305d5c 620 cu_offset type_offset_in_tu {};
cd4fb1b2
SM
621
622 /* Offset in the section of the type's DIE.
623 If the definition lives in a DWO file, this is the offset in the
624 .debug_types.dwo section.
625 The value is zero until the actual value is known.
626 Zero is otherwise not a valid section offset. */
0d305d5c 627 sect_offset type_offset_in_section {};
cd4fb1b2
SM
628
629 /* Type units are grouped by their DW_AT_stmt_list entry so that they
630 can share them. This points to the containing symtab. */
0d305d5c 631 struct type_unit_group *type_unit_group = nullptr;
cd4fb1b2 632
cd4fb1b2
SM
633 /* Containing DWO unit.
634 This field is valid iff per_cu.reading_dwo_directly. */
0d305d5c 635 struct dwo_unit *dwo_unit = nullptr;
cd4fb1b2
SM
636};
637
8cb5117c
SM
638/* Return the type of the DIE at DIE_OFFSET in the CU named by
639 PER_CU. */
640
641struct type *dwarf2_get_die_type (cu_offset die_offset,
aa66c379
SM
642 dwarf2_per_cu_data *per_cu,
643 dwarf2_per_objfile *per_objfile);
8cb5117c 644
450a1bfc
SM
645/* Given an index in .debug_addr, fetch the value.
646 NOTE: This can be called during dwarf expression evaluation,
647 long after the debug information has been read, and thus per_cu->cu
648 may no longer exist. */
649
650CORE_ADDR dwarf2_read_addr_index (dwarf2_per_cu_data *per_cu,
976ca316 651 dwarf2_per_objfile *per_objfile,
450a1bfc
SM
652 unsigned int addr_index);
653
d4c9a4f8
SM
654/* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
655 Returned value is intended for DW_OP_call*. Returned
656 dwarf2_locexpr_baton->data has lifetime of
657 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
658
659struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_sect_off
660 (sect_offset sect_off, dwarf2_per_cu_data *per_cu,
14095eb3 661 dwarf2_per_objfile *per_objfile,
041d9819
SM
662 gdb::function_view<CORE_ADDR ()> get_frame_pc,
663 bool resolve_abstract_p = false);
d4c9a4f8
SM
664
665/* Like dwarf2_fetch_die_loc_sect_off, but take a CU
666 offset. */
667
668struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_cu_off
669 (cu_offset offset_in_cu, dwarf2_per_cu_data *per_cu,
14095eb3 670 dwarf2_per_objfile *per_objfile,
041d9819 671 gdb::function_view<CORE_ADDR ()> get_frame_pc);
d4c9a4f8
SM
672
673/* If the DIE at SECT_OFF in PER_CU has a DW_AT_const_value, return a
674 pointer to the constant bytes and set LEN to the length of the
675 data. If memory is needed, allocate it on OBSTACK. If the DIE
676 does not have a DW_AT_const_value, return NULL. */
677
678extern const gdb_byte *dwarf2_fetch_constant_bytes
14095eb3
SM
679 (sect_offset sect_off, dwarf2_per_cu_data *per_cu,
680 dwarf2_per_objfile *per_objfile, obstack *obstack,
d4c9a4f8
SM
681 LONGEST *len);
682
683/* Return the type of the die at SECT_OFF in PER_CU. Return NULL if no
684 valid type for this die is found. */
685
686struct type *dwarf2_fetch_die_type_sect_off
14095eb3
SM
687 (sect_offset sect_off, dwarf2_per_cu_data *per_cu,
688 dwarf2_per_objfile *per_objfile);
d4c9a4f8 689
8fdd972c
TT
690/* When non-zero, dump line number entries as they are read in. */
691extern unsigned int dwarf_line_debug;
692
18038e63
TT
693/* Dwarf2 sections that can be accessed by dwarf2_get_section_info. */
694enum dwarf2_section_enum {
695 DWARF2_DEBUG_FRAME,
696 DWARF2_EH_FRAME
697};
698
699extern void dwarf2_get_section_info (struct objfile *,
700 enum dwarf2_section_enum,
701 asection **, const gdb_byte **,
702 bfd_size_type *);
703
cd4fb1b2 704#endif /* DWARF2READ_H */
This page took 0.327615 seconds and 4 git commands to generate.