1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
24 #include <unordered_map>
25 #include "dwarf2/comp-unit-head.h"
26 #include "dwarf2/file-and-dir.h"
27 #include "dwarf2/index-cache.h"
28 #include "dwarf2/mapped-index.h"
29 #include "dwarf2/section.h"
30 #include "dwarf2/cu.h"
31 #include "filename-seen-cache.h"
32 #include "gdbsupport/gdb_obstack.h"
33 #include "gdbsupport/hash_enum.h"
34 #include "gdbsupport/function-view.h"
35 #include "gdbsupport/packed.h"
37 /* Hold 'maintenance (set|show) dwarf' commands. */
38 extern struct cmd_list_element
*set_dwarf_cmdlist
;
39 extern struct cmd_list_element
*show_dwarf_cmdlist
;
43 int nr_uniq_abbrev_tables
;
45 int nr_symtab_sharers
;
46 int nr_stmt_less_type_units
;
47 int nr_all_type_units_reallocs
;
52 struct dwarf2_debug_sections
;
53 struct dwarf2_per_bfd
;
54 struct dwarf2_per_cu_data
;
56 struct mapped_debug_names
;
57 struct signatured_type
;
58 struct type_unit_group
;
60 /* One item on the queue of compilation units to read in full symbols
62 struct dwarf2_queue_item
64 dwarf2_queue_item (dwarf2_per_cu_data
*cu
, dwarf2_per_objfile
*per_objfile
,
67 per_objfile (per_objfile
),
68 pretend_language (lang
)
72 ~dwarf2_queue_item ();
74 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_item
);
76 dwarf2_per_cu_data
*per_cu
;
77 dwarf2_per_objfile
*per_objfile
;
78 enum language pretend_language
;
81 /* A deleter for dwarf2_per_cu_data that knows to downcast to
82 signatured_type as appropriate. This approach lets us avoid a
83 virtual destructor, which saves a bit of space. */
85 struct dwarf2_per_cu_data_deleter
87 void operator() (dwarf2_per_cu_data
*data
);
90 /* A specialization of unique_ptr for dwarf2_per_cu_data and
92 typedef std::unique_ptr
<dwarf2_per_cu_data
, dwarf2_per_cu_data_deleter
>
93 dwarf2_per_cu_data_up
;
95 /* Persistent data held for a compilation unit, even when not
96 processing it. We put a pointer to this structure in the
99 struct dwarf2_per_cu_data
101 dwarf2_per_cu_data ()
102 : is_debug_types (false),
104 reading_dwo_directly (false),
107 m_header_read_in (false),
114 /* The start offset and length of this compilation unit.
115 NOTE: Unlike comp_unit_head.length, this length includes
117 If the DIE refers to a DWO file, this is always of the original die,
119 sect_offset sect_off
{};
122 unsigned int m_length
= 0;
124 /* DWARF standard version this data has been read from (such as 4 or 5). */
125 unsigned char m_dwarf_version
= 0;
128 /* Non-zero if this CU is from .debug_types.
129 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
131 unsigned int is_debug_types
: 1;
133 /* Non-zero if this CU is from the .dwz file. */
134 unsigned int is_dwz
: 1;
136 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
137 This flag is only valid if is_debug_types is true.
138 We can't read a CU directly from a DWO file: There are required
139 attributes in the stub. */
140 unsigned int reading_dwo_directly
: 1;
142 /* Non-zero if the TU has been read.
143 This is used to assist the "Stay in DWO Optimization" for Fission:
144 When reading a DWO, it's faster to read TUs from the DWO instead of
145 fetching them from random other DWOs (due to comdat folding).
146 If the TU has already been read, the optimization is unnecessary
147 (and unwise - we don't want to change where gdb thinks the TU lives
149 This flag is only valid if is_debug_types is true. */
150 unsigned int tu_read
: 1;
152 /* Wrap the following in struct packed instead of bitfields to avoid
153 data races when the bitfields end up on the same memory location
154 (per C++ memory model). */
156 /* If addresses have been read for this CU (usually from
157 .debug_aranges), then this flag is set. */
158 packed
<bool, 1> addresses_seen
= false;
160 /* Flag indicating this compilation unit will be read in before
161 any of the current compilation units are processed. */
162 packed
<bool, 1> queued
;
164 /* True if HEADER has been read in.
166 Don't access this field directly. It should be private, but we can't make
167 it private at the moment. */
168 mutable packed
<bool, 1> m_header_read_in
;
170 /* A temporary mark bit used when iterating over all CUs in
171 expand_symtabs_matching. */
172 packed
<unsigned int, 1> mark
;
174 /* True if we've tried to read the file table. There will be no
175 point in trying to read it again next time. */
176 packed
<bool, 1> files_read
;
179 /* The unit type of this CU. */
180 std::atomic
<packed
<dwarf_unit_type
, 1>> m_unit_type
{(dwarf_unit_type
)0};
182 /* The language of this CU. */
183 std::atomic
<packed
<language
, LANGUAGE_BYTES
>> m_lang
{language_unknown
};
185 /* The original DW_LANG_* value of the CU, as provided to us by
186 DW_AT_language. It is interesting to keep this value around in cases where
187 we can't use the values from the language enum, as the mapping to them is
188 lossy, and, while that is usually fine, things like the index have an
189 understandable bias towards not exposing internal GDB structures to the
190 outside world, and so prefer to use DWARF constants in their stead. */
191 std::atomic
<packed
<dwarf_source_language
, 2>> m_dw_lang
192 { (dwarf_source_language
) 0 };
195 /* True if this CU has been scanned by the indexer; false if
197 std::atomic
<bool> scanned
;
199 /* Our index in the unshared "symtabs" vector. */
202 /* The section this CU/TU lives in.
203 If the DIE refers to a DWO file, this is always the original die,
205 struct dwarf2_section_info
*section
= nullptr;
207 /* Backlink to the owner of this. */
208 dwarf2_per_bfd
*per_bfd
= nullptr;
210 /* DWARF header of this CU. Note that dwarf2_cu reads its own version of the
211 header, which may differ from this one, since it may pass rcuh_kind::TYPE
212 to read_comp_unit_head, whereas for dwarf2_per_cu_data we always pass
215 Don't access this field directly, use the get_header method instead. It
216 should be private, but we can't make it private at the moment. */
217 mutable comp_unit_head m_header
;
219 /* The file and directory for this CU. This is cached so that we
220 don't need to re-examine the DWO in some situations. This may be
221 nullptr, depending on the CU; for example a partial unit won't
223 std::unique_ptr
<file_and_directory
> fnd
;
225 /* The file table. This can be NULL if there was no file table
226 or it's currently not read in.
227 NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */
228 struct quick_file_names
*file_names
= nullptr;
230 /* The CUs we import using DW_TAG_imported_unit.
232 This is also used to work around a difference between the way gold
233 generates .gdb_index version <=7 and the way gdb does. Arguably this
234 is a gold bug. For symbols coming from TUs, gold records in the index
235 the CU that includes the TU instead of the TU itself. This breaks
236 dw2_lookup_symbol: It assumes that if the index says symbol X lives
237 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
238 will find X. Alas TUs live in their own symtab, so after expanding CU Y
239 we need to look in TU Z to find X. Fortunately, this is akin to
240 DW_TAG_imported_unit, so we just use the same mechanism: For
241 .gdb_index version <=7 this also records the TUs that the CU referred
242 to. Concurrently with this change gdb was modified to emit version 8
243 indices so we only pay a price for gold generated indices.
244 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
245 std::vector
<dwarf2_per_cu_data
*> imported_symtabs
;
247 /* Get the header of this per_cu, reading it if necessary. */
248 const comp_unit_head
*get_header () const;
250 /* Return the address size given in the compilation unit header for
252 int addr_size () const;
254 /* Return the offset size given in the compilation unit header for
256 int offset_size () const;
258 /* Return the DW_FORM_ref_addr size given in the compilation unit
259 header for this CU. */
260 int ref_addr_size () const;
262 /* Return length of this CU. */
263 unsigned int length () const
265 /* Make sure it's set already. */
266 gdb_assert (m_length
!= 0);
270 void set_length (unsigned int length
, bool strict_p
= true)
273 /* Set if not set already. */
276 /* If already set, verify that it's the same value. */
277 gdb_assert (m_length
== length
);
280 /* Return DWARF version number of this CU. */
281 short version () const
283 /* Make sure it's set already. */
284 gdb_assert (m_dwarf_version
!= 0);
285 return m_dwarf_version
;
288 void set_version (short version
)
290 if (m_dwarf_version
== 0)
291 /* Set if not set already. */
292 m_dwarf_version
= version
;
294 /* If already set, verify that it's the same value. */
295 gdb_assert (m_dwarf_version
== version
);
298 dwarf_unit_type
unit_type (bool strict_p
= true) const
300 dwarf_unit_type ut
= m_unit_type
.load ();
302 gdb_assert (ut
!= 0);
306 void set_unit_type (dwarf_unit_type unit_type
)
308 /* Set if not set already. */
309 packed
<dwarf_unit_type
, 1> nope
= (dwarf_unit_type
)0;
310 if (m_unit_type
.compare_exchange_strong (nope
, unit_type
))
313 /* If already set, verify that it's the same value. */
315 if (m_unit_type
.compare_exchange_strong (nope
, unit_type
))
317 gdb_assert_not_reached ();
320 enum language
lang (bool strict_p
= true) const
322 enum language l
= m_lang
.load ();
324 gdb_assert (l
!= language_unknown
);
328 /* Return the language of this CU, as a DWARF DW_LANG_* value. This
329 may be 0 in some situations. */
330 dwarf_source_language
dw_lang () const
331 { return m_dw_lang
.load (); }
333 /* Set the language of this CU. LANG is the language in gdb terms,
334 and DW_LANG is the language as a DW_LANG_* value. These may
335 differ, as DW_LANG can be 0 for included units, whereas in this
336 situation LANG would be set by the importing CU. */
337 void set_lang (enum language lang
, dwarf_source_language dw_lang
);
339 /* Free any cached file names. */
340 void free_cached_file_names ();
343 /* Entry in the signatured_types hash table. */
345 struct signatured_type
: public dwarf2_per_cu_data
347 signatured_type (ULONGEST signature
)
348 : signature (signature
)
351 /* The type's signature. */
354 /* Offset in the TU of the type's DIE, as read from the TU header.
355 If this TU is a DWO stub and the definition lives in a DWO file
356 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
357 cu_offset type_offset_in_tu
{};
359 /* Offset in the section of the type's DIE.
360 If the definition lives in a DWO file, this is the offset in the
361 .debug_types.dwo section.
362 The value is zero until the actual value is known.
363 Zero is otherwise not a valid section offset. */
364 sect_offset type_offset_in_section
{};
366 /* Type units are grouped by their DW_AT_stmt_list entry so that they
367 can share them. This points to the containing symtab. */
368 struct type_unit_group
*type_unit_group
= nullptr;
370 /* Containing DWO unit.
371 This field is valid iff per_cu.reading_dwo_directly. */
372 struct dwo_unit
*dwo_unit
= nullptr;
375 using signatured_type_up
= std::unique_ptr
<signatured_type
>;
377 /* Some DWARF data can be shared across objfiles who share the same BFD,
378 this data is stored in this object.
380 Two dwarf2_per_objfile objects representing objfiles sharing the same BFD
381 will point to the same instance of dwarf2_per_bfd, unless the BFD requires
384 struct dwarf2_per_bfd
386 /* Construct a dwarf2_per_bfd for OBFD. NAMES points to the
387 dwarf2 section names, or is NULL if the standard ELF names are
388 used. CAN_COPY is true for formats where symbol
389 interposition is possible and so symbol values must follow copy
391 dwarf2_per_bfd (bfd
*obfd
, const dwarf2_debug_sections
*names
, bool can_copy
);
395 DISABLE_COPY_AND_ASSIGN (dwarf2_per_bfd
);
397 /* Return the CU given its index. */
398 dwarf2_per_cu_data
*get_cu (int index
) const
400 return this->all_units
[index
].get ();
403 /* Return the CU given its index in the CU table in the index. */
404 dwarf2_per_cu_data
*get_index_cu (int index
) const
406 if (this->all_comp_units_index_cus
.empty ())
407 return get_cu (index
);
409 return this->all_comp_units_index_cus
[index
];
412 dwarf2_per_cu_data
*get_index_tu (int index
) const
414 return this->all_comp_units_index_tus
[index
];
417 /* A convenience function to allocate a dwarf2_per_cu_data. The
418 returned object has its "index" field set properly. The object
419 is allocated on the dwarf2_per_bfd obstack. */
420 dwarf2_per_cu_data_up
allocate_per_cu ();
422 /* A convenience function to allocate a signatured_type. The
423 returned object has its "index" field set properly. The object
424 is allocated on the dwarf2_per_bfd obstack. */
425 signatured_type_up
allocate_signatured_type (ULONGEST signature
);
427 /* Map all the DWARF section data needed when scanning
429 void map_info_sections (struct objfile
*objfile
);
432 /* This function is mapped across the sections and remembers the
433 offset and size of each of the debugging sections we are
435 void locate_sections (bfd
*abfd
, asection
*sectp
,
436 const dwarf2_debug_sections
&names
);
439 /* The corresponding BFD. */
442 /* Objects that can be shared across objfiles may be stored in this
443 obstack, while objects that are objfile-specific are stored on
444 the objfile obstack. */
445 auto_obstack obstack
;
447 dwarf2_section_info info
{};
448 dwarf2_section_info abbrev
{};
449 dwarf2_section_info line
{};
450 dwarf2_section_info loc
{};
451 dwarf2_section_info loclists
{};
452 dwarf2_section_info macinfo
{};
453 dwarf2_section_info macro
{};
454 dwarf2_section_info str
{};
455 dwarf2_section_info str_offsets
{};
456 dwarf2_section_info line_str
{};
457 dwarf2_section_info ranges
{};
458 dwarf2_section_info rnglists
{};
459 dwarf2_section_info addr
{};
460 dwarf2_section_info frame
{};
461 dwarf2_section_info eh_frame
{};
462 dwarf2_section_info gdb_index
{};
463 dwarf2_section_info debug_names
{};
464 dwarf2_section_info debug_aranges
{};
466 std::vector
<dwarf2_section_info
> types
;
468 /* Table of all the compilation units. This is used to locate
469 the target compilation unit of a particular reference. */
470 std::vector
<dwarf2_per_cu_data_up
> all_units
;
472 /* The all_units vector contains both CUs and TUs. Provide views on the
473 vector that are limited to either the CU part or the TU part. */
474 gdb::array_view
<dwarf2_per_cu_data_up
> all_comp_units
;
475 gdb::array_view
<dwarf2_per_cu_data_up
> all_type_units
;
477 std::vector
<dwarf2_per_cu_data
*> all_comp_units_index_cus
;
478 std::vector
<dwarf2_per_cu_data
*> all_comp_units_index_tus
;
480 /* Table of struct type_unit_group objects.
481 The hash key is the DW_AT_stmt_list value. */
482 htab_up type_unit_groups
;
484 /* A table mapping .debug_types signatures to its signatured_type entry.
485 This is NULL if the .debug_types section hasn't been read in yet. */
486 htab_up signatured_types
;
488 /* Type unit statistics, to see how well the scaling improvements
490 struct tu_stats tu_stats
{};
492 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
493 This is NULL if the table hasn't been allocated yet. */
496 /* True if we've checked for whether there is a DWP file. */
497 bool dwp_checked
= false;
499 /* The DWP file if there is one, or NULL. */
500 std::unique_ptr
<struct dwp_file
> dwp_file
;
502 /* The shared '.dwz' file, if one exists. This is used when the
503 original data was compressed using 'dwz -m'. */
504 std::optional
<std::unique_ptr
<struct dwz_file
>> dwz_file
;
506 /* Whether copy relocations are supported by this object format. */
509 /* A flag indicating whether this objfile has a section loaded at a
511 bool has_section_at_zero
= false;
513 /* The mapped index, or NULL in the readnow case. */
514 std::unique_ptr
<dwarf_scanner_base
> index_table
;
516 /* When using index_table, this keeps track of all quick_file_names entries.
517 TUs typically share line table entries with a CU, so we maintain a
518 separate table of all line table entries to support the sharing.
519 Note that while there can be way more TUs than CUs, we've already
520 sorted all the TUs into "type unit groups", grouped by their
521 DW_AT_stmt_list value. Therefore the only sharing done here is with a
522 CU and its associated TU group if there is one. */
523 htab_up quick_file_names_table
;
525 /* The CUs we recently read. */
526 std::vector
<dwarf2_per_cu_data
*> just_read_cus
;
528 /* If we loaded the index from an external file, this contains the
529 resources associated to the open file, memory mapping, etc. */
530 std::unique_ptr
<index_cache_resource
> index_cache_res
;
532 /* Mapping from abstract origin DIE to concrete DIEs that reference it as
533 DW_AT_abstract_origin. */
534 std::unordered_map
<sect_offset
, std::vector
<sect_offset
>,
535 gdb::hash_enum
<sect_offset
>>
536 abstract_to_concrete
;
538 /* The address map that is used by the DWARF index code. */
539 struct addrmap
*index_addrmap
= nullptr;
542 /* An iterator for all_units that is based on index. This
543 approach makes it possible to iterate over all_units safely,
544 when some caller in the loop may add new units. */
546 class all_units_iterator
550 all_units_iterator (dwarf2_per_bfd
*per_bfd
, bool start
)
551 : m_per_bfd (per_bfd
),
552 m_index (start
? 0 : per_bfd
->all_units
.size ())
556 all_units_iterator
&operator++ ()
562 dwarf2_per_cu_data
*operator* () const
564 return m_per_bfd
->get_cu (m_index
);
567 bool operator== (const all_units_iterator
&other
) const
569 return m_index
== other
.m_index
;
573 bool operator!= (const all_units_iterator
&other
) const
575 return m_index
!= other
.m_index
;
580 dwarf2_per_bfd
*m_per_bfd
;
584 /* A range adapter for the all_units_iterator. */
585 class all_units_range
589 all_units_range (dwarf2_per_bfd
*per_bfd
)
590 : m_per_bfd (per_bfd
)
594 all_units_iterator
begin ()
596 return all_units_iterator (m_per_bfd
, true);
599 all_units_iterator
end ()
601 return all_units_iterator (m_per_bfd
, false);
606 dwarf2_per_bfd
*m_per_bfd
;
609 /* This is the per-objfile data associated with a type_unit_group. */
611 struct type_unit_group_unshareable
613 /* The compunit symtab.
614 Type units in a group needn't all be defined in the same source file,
615 so we create an essentially anonymous symtab as the compunit symtab. */
616 struct compunit_symtab
*compunit_symtab
= nullptr;
618 /* The number of symtabs from the line header.
619 The value here must match line_header.num_file_names. */
620 unsigned int num_symtabs
= 0;
622 /* The symbol tables for this TU (obtained from the files listed in
624 WARNING: The order of entries here must match the order of entries
625 in the line header. After the first TU using this type_unit_group, the
626 line header for the subsequent TUs is recreated from this. This is done
627 because we need to use the same symtabs for each TU using the same
628 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
629 there's no guarantee the line header doesn't have duplicate entries. */
630 struct symtab
**symtabs
= nullptr;
633 /* Collection of data recorded per objfile.
634 This hangs off of dwarf2_objfile_data_key.
636 Some DWARF data cannot (currently) be shared across objfiles. Such
637 data is stored in this object. */
639 struct dwarf2_per_objfile
641 dwarf2_per_objfile (struct objfile
*objfile
, dwarf2_per_bfd
*per_bfd
)
642 : objfile (objfile
), per_bfd (per_bfd
)
645 ~dwarf2_per_objfile ();
647 /* Return pointer to string at .debug_line_str offset as read from BUF.
648 BUF is assumed to be in a compilation unit described by CU_HEADER.
649 Return *BYTES_READ_PTR count of bytes read from BUF. */
650 const char *read_line_string (const gdb_byte
*buf
,
651 const struct comp_unit_head
*cu_header
,
652 unsigned int *bytes_read_ptr
);
654 /* Return pointer to string at .debug_line_str offset as read from BUF.
655 The offset_size is OFFSET_SIZE. */
656 const char *read_line_string (const gdb_byte
*buf
,
657 unsigned int offset_size
);
659 /* Return true if the symtab corresponding to PER_CU has been set,
661 bool symtab_set_p (const dwarf2_per_cu_data
*per_cu
) const;
663 /* Return the compunit_symtab associated to PER_CU, if it has been created. */
664 compunit_symtab
*get_symtab (const dwarf2_per_cu_data
*per_cu
) const;
666 /* Set the compunit_symtab associated to PER_CU. */
667 void set_symtab (const dwarf2_per_cu_data
*per_cu
, compunit_symtab
*symtab
);
669 /* Get the type_unit_group_unshareable corresponding to TU_GROUP. If one
670 does not exist, create it. */
671 type_unit_group_unshareable
*get_type_unit_group_unshareable
672 (type_unit_group
*tu_group
);
674 struct type
*get_type_for_signatured_type (signatured_type
*sig_type
) const;
676 void set_type_for_signatured_type (signatured_type
*sig_type
,
679 /* Get the dwarf2_cu matching PER_CU for this objfile. */
680 dwarf2_cu
*get_cu (dwarf2_per_cu_data
*per_cu
);
682 /* Set the dwarf2_cu matching PER_CU for this objfile. */
683 void set_cu (dwarf2_per_cu_data
*per_cu
, std::unique_ptr
<dwarf2_cu
> cu
);
685 /* Remove/free the dwarf2_cu matching PER_CU for this objfile. */
686 void remove_cu (dwarf2_per_cu_data
*per_cu
);
688 /* Free all cached compilation units. */
689 void remove_all_cus ();
691 /* Increase the age counter on each CU compilation unit and free
692 any that are too old. */
693 void age_comp_units ();
695 /* Apply any needed adjustments to ADDR, returning an adjusted but
696 still unrelocated address. */
697 unrelocated_addr
adjust (unrelocated_addr addr
);
699 /* Apply any needed adjustments to ADDR and then relocate the
700 address according to the objfile's section offsets, returning a
701 relocated address. */
702 CORE_ADDR
relocate (unrelocated_addr addr
);
705 struct objfile
*objfile
;
707 /* Pointer to the data that is (possibly) shared between this objfile and
708 other objfiles backed by the same BFD. */
709 struct dwarf2_per_bfd
*per_bfd
;
711 /* Table mapping type DIEs to their struct type *.
712 This is nullptr if not allocated yet.
713 The mapping is done via (CU/TU + DIE offset) -> type. */
714 htab_up die_type_hash
;
716 /* Table containing line_header indexed by offset and offset_in_dwz. */
717 htab_up line_header_hash
;
719 /* The CU containing the m_builder in scope. */
720 dwarf2_cu
*sym_cu
= nullptr;
722 /* CUs that are queued to be read. */
723 std::optional
<std::queue
<dwarf2_queue_item
>> queue
;
726 /* Hold the corresponding compunit_symtab for each CU or TU. This
727 is indexed by dwarf2_per_cu_data::index. A NULL value means
728 that the CU/TU has not been expanded yet. */
729 std::vector
<compunit_symtab
*> m_symtabs
;
731 /* Map from a type unit group to the corresponding unshared
733 typedef std::unique_ptr
<type_unit_group_unshareable
>
734 type_unit_group_unshareable_up
;
736 std::unordered_map
<type_unit_group
*, type_unit_group_unshareable_up
>
739 /* Map from signatured types to the corresponding struct type. */
740 std::unordered_map
<signatured_type
*, struct type
*> m_type_map
;
742 /* Map from the objfile-independent dwarf2_per_cu_data instances to the
743 corresponding objfile-dependent dwarf2_cu instances. */
744 std::unordered_map
<dwarf2_per_cu_data
*,
745 std::unique_ptr
<dwarf2_cu
>> m_dwarf2_cus
;
748 /* Converts DWARF language names to GDB language names. */
750 enum language
dwarf_lang_to_enum_language (unsigned int lang
);
752 /* Get the dwarf2_per_objfile associated to OBJFILE. */
754 dwarf2_per_objfile
*get_dwarf2_per_objfile (struct objfile
*objfile
);
756 /* Return the type of the DIE at DIE_OFFSET in the CU named by
759 struct type
*dwarf2_get_die_type (cu_offset die_offset
,
760 dwarf2_per_cu_data
*per_cu
,
761 dwarf2_per_objfile
*per_objfile
);
763 /* Given an index in .debug_addr, fetch the value.
764 NOTE: This can be called during dwarf expression evaluation,
765 long after the debug information has been read, and thus per_cu->cu
766 may no longer exist. */
768 unrelocated_addr
dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
,
769 dwarf2_per_objfile
*per_objfile
,
770 unsigned int addr_index
);
772 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
773 Returned value is intended for DW_OP_call*. Returned
774 dwarf2_locexpr_baton->data has lifetime of
775 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
777 struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_sect_off
778 (sect_offset sect_off
, dwarf2_per_cu_data
*per_cu
,
779 dwarf2_per_objfile
*per_objfile
,
780 gdb::function_view
<CORE_ADDR ()> get_frame_pc
,
781 bool resolve_abstract_p
= false);
783 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
786 struct dwarf2_locexpr_baton dwarf2_fetch_die_loc_cu_off
787 (cu_offset offset_in_cu
, dwarf2_per_cu_data
*per_cu
,
788 dwarf2_per_objfile
*per_objfile
,
789 gdb::function_view
<CORE_ADDR ()> get_frame_pc
);
791 /* If the DIE at SECT_OFF in PER_CU has a DW_AT_const_value, return a
792 pointer to the constant bytes and set LEN to the length of the
793 data. If memory is needed, allocate it on OBSTACK. If the DIE
794 does not have a DW_AT_const_value, return NULL. */
796 extern const gdb_byte
*dwarf2_fetch_constant_bytes
797 (sect_offset sect_off
, dwarf2_per_cu_data
*per_cu
,
798 dwarf2_per_objfile
*per_objfile
, obstack
*obstack
,
801 /* Return the type of the die at SECT_OFF in PER_CU. Return NULL if no
802 valid type for this die is found. If VAR_NAME is non-null, and if
803 the DIE in question is a variable declaration (definitions are
804 excluded), then *VAR_NAME is set to the variable's name. */
806 struct type
*dwarf2_fetch_die_type_sect_off
807 (sect_offset sect_off
, dwarf2_per_cu_data
*per_cu
,
808 dwarf2_per_objfile
*per_objfile
,
809 const char **var_name
= nullptr);
811 /* When non-zero, dump line number entries as they are read in. */
812 extern unsigned int dwarf_line_debug
;
814 /* Dwarf2 sections that can be accessed by dwarf2_get_section_info. */
815 enum dwarf2_section_enum
{
820 extern void dwarf2_get_section_info (struct objfile
*,
821 enum dwarf2_section_enum
,
822 asection
**, const gdb_byte
**,
825 /* Return true if the producer of the inferior is clang. */
826 extern bool producer_is_clang (struct dwarf2_cu
*cu
);
828 /* Interface for DWARF indexing methods. */
830 struct dwarf2_base_index_functions
: public quick_symbol_functions
832 bool has_symbols (struct objfile
*objfile
) override
;
834 bool has_unexpanded_symtabs (struct objfile
*objfile
) override
;
836 struct symtab
*find_last_source_symtab (struct objfile
*objfile
) override
;
838 void forget_cached_source_info (struct objfile
*objfile
) override
;
840 enum language
lookup_global_symbol_language (struct objfile
*objfile
,
842 domain_search_flags domain
,
843 bool *symbol_found_p
) override
845 *symbol_found_p
= false;
846 return language_unknown
;
849 void print_stats (struct objfile
*objfile
, bool print_bcache
) override
;
851 void expand_all_symtabs (struct objfile
*objfile
) override
;
853 /* A helper function that finds the per-cu object from an "adjusted"
854 PC -- a PC with the base text offset removed. */
855 virtual dwarf2_per_cu_data
*find_per_cu (dwarf2_per_bfd
*per_bfd
,
856 unrelocated_addr adjusted_pc
);
858 struct compunit_symtab
*find_pc_sect_compunit_symtab
859 (struct objfile
*objfile
, struct bound_minimal_symbol msymbol
,
860 CORE_ADDR pc
, struct obj_section
*section
, int warn_if_readin
)
863 struct compunit_symtab
*find_compunit_symtab_by_address
864 (struct objfile
*objfile
, CORE_ADDR address
) override
869 void map_symbol_filenames (struct objfile
*objfile
,
870 gdb::function_view
<symbol_filename_ftype
> fun
,
871 bool need_fullname
) override
;
874 /* If FILE_MATCHER is NULL or if PER_CU has
875 dwarf2_per_cu_quick_data::MARK set (see
876 dw_expand_symtabs_matching_file_matcher), expand the CU and call
877 EXPANSION_NOTIFY on it. */
879 extern bool dw2_expand_symtabs_matching_one
880 (dwarf2_per_cu_data
*per_cu
,
881 dwarf2_per_objfile
*per_objfile
,
882 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
883 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
);
885 /* Helper for dw2_expand_symtabs_matching that works with a
886 mapped_index_base instead of the containing objfile. This is split
887 to a separate function in order to be able to unit test the
888 name_components matching using a mock mapped_index_base. For each
889 symbol name that matches, calls MATCH_CALLBACK, passing it the
890 symbol's index in the mapped_index_base symbol table. */
892 extern bool dw2_expand_symtabs_matching_symbol
893 (mapped_index_base
&index
,
894 const lookup_name_info
&lookup_name_in
,
895 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
896 gdb::function_view
<bool (offset_type
)> match_callback
,
897 dwarf2_per_objfile
*per_objfile
);
899 /* If FILE_MATCHER is non-NULL, set all the
900 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
901 that match FILE_MATCHER. */
903 extern void dw_expand_symtabs_matching_file_matcher
904 (dwarf2_per_objfile
*per_objfile
,
905 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
);
907 /* Return pointer to string at .debug_str offset STR_OFFSET. */
909 extern const char *read_indirect_string_at_offset
910 (dwarf2_per_objfile
*per_objfile
, LONGEST str_offset
);
912 /* Allocate a hash table for signatured types. */
914 extern htab_up
allocate_signatured_type_table ();
916 /* Return a new dwarf2_per_cu_data allocated on the per-bfd
917 obstack, and constructed with the specified field values. */
919 extern dwarf2_per_cu_data_up create_cu_from_index_list
920 (dwarf2_per_bfd
*per_bfd
, struct dwarf2_section_info
*section
,
921 int is_dwz
, sect_offset sect_off
, ULONGEST length
);
923 /* Initialize the views on all_units. */
925 extern void finalize_all_units (dwarf2_per_bfd
*per_bfd
);
927 /* Create a list of all compilation units in OBJFILE. */
929 extern void create_all_units (dwarf2_per_objfile
*per_objfile
);
931 /* Create a quick_file_names hash table. */
933 extern htab_up
create_quick_file_names_table (unsigned int nr_initial_entries
);
935 #endif /* DWARF2READ_H */