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