1 /* Reading code for .debug_names
3 Copyright (C) 2023 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/>. */
21 #include "read-debug-names.h"
23 #include "complaints.h"
24 #include "cp-support.h"
26 #include "mapped-index.h"
28 #include "stringify.h"
30 /* A description of the mapped .debug_names.
31 Uninitialized map has CU_COUNT 0. */
33 struct mapped_debug_names final
: public mapped_index_base
35 bfd_endian dwarf5_byte_order
;
36 bool dwarf5_is_dwarf64
;
37 bool augmentation_is_gdb
;
39 uint32_t cu_count
= 0;
40 uint32_t tu_count
, bucket_count
, name_count
;
41 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
42 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
43 const gdb_byte
*name_table_string_offs_reordered
;
44 const gdb_byte
*name_table_entry_offs_reordered
;
45 const gdb_byte
*entry_pool
;
52 /* Attribute name DW_IDX_*. */
55 /* Attribute form DW_FORM_*. */
58 /* Value if FORM is DW_FORM_implicit_const. */
59 LONGEST implicit_const
;
61 std::vector
<attr
> attr_vec
;
64 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
66 const char *namei_to_name
67 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const;
69 /* Implementation of the mapped_index_base virtual interface, for
70 the name_components cache. */
72 const char *symbol_name_at
73 (offset_type idx
, dwarf2_per_objfile
*per_objfile
) const override
74 { return namei_to_name (idx
, per_objfile
); }
76 size_t symbol_name_count () const override
77 { return this->name_count
; }
79 quick_symbol_functions_up
make_quick_functions () const override
;
82 struct dwarf2_debug_names_index
: public dwarf2_base_index_functions
84 void dump (struct objfile
*objfile
) override
;
86 void expand_matching_symbols
88 const lookup_name_info
&lookup_name
,
91 symbol_compare_ftype
*ordered_compare
) override
;
93 bool expand_symtabs_matching
94 (struct objfile
*objfile
,
95 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
96 const lookup_name_info
*lookup_name
,
97 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
98 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
99 block_search_flags search_flags
,
101 enum search_domain kind
) override
;
104 quick_symbol_functions_up
105 mapped_debug_names::make_quick_functions () const
107 return quick_symbol_functions_up (new dwarf2_debug_names_index
);
110 /* Create the signatured type hash table from .debug_names. */
113 create_signatured_type_table_from_debug_names
114 (dwarf2_per_objfile
*per_objfile
,
115 const mapped_debug_names
&map
,
116 struct dwarf2_section_info
*section
,
117 struct dwarf2_section_info
*abbrev_section
)
119 struct objfile
*objfile
= per_objfile
->objfile
;
121 section
->read (objfile
);
122 abbrev_section
->read (objfile
);
124 htab_up sig_types_hash
= allocate_signatured_type_table ();
126 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
128 signatured_type_up sig_type
;
132 = (sect_offset
) (extract_unsigned_integer
133 (map
.tu_table_reordered
+ i
* map
.offset_size
,
135 map
.dwarf5_byte_order
));
137 comp_unit_head cu_header
;
138 read_and_check_comp_unit_head (per_objfile
, &cu_header
, section
,
140 section
->buffer
+ to_underlying (sect_off
),
143 sig_type
= per_objfile
->per_bfd
->allocate_signatured_type
144 (cu_header
.signature
);
145 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
146 sig_type
->section
= section
;
147 sig_type
->sect_off
= sect_off
;
149 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
.get (), INSERT
);
150 *slot
= sig_type
.get ();
152 per_objfile
->per_bfd
->all_units
.emplace_back (sig_type
.release ());
155 per_objfile
->per_bfd
->signatured_types
= std::move (sig_types_hash
);
158 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
159 populate the index_addrmap. */
162 create_addrmap_from_aranges (dwarf2_per_objfile
*per_objfile
,
163 struct dwarf2_section_info
*section
)
165 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
167 addrmap_mutable mutable_map
;
169 if (read_addrmap_from_aranges (per_objfile
, section
, &mutable_map
))
170 per_bfd
->index_addrmap
171 = new (&per_bfd
->obstack
) addrmap_fixed (&per_bfd
->obstack
,
175 /* DWARF-5 debug_names reader. */
177 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
178 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
180 /* A helper function that reads the .debug_names section in SECTION
181 and fills in MAP. FILENAME is the name of the file containing the
182 section; it is used for error reporting.
184 Returns true if all went well, false otherwise. */
187 read_debug_names_from_section (struct objfile
*objfile
,
188 const char *filename
,
189 struct dwarf2_section_info
*section
,
190 mapped_debug_names
&map
)
192 if (section
->empty ())
195 /* Older elfutils strip versions could keep the section in the main
196 executable while splitting it for the separate debug info file. */
197 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
200 section
->read (objfile
);
202 map
.dwarf5_byte_order
= gdbarch_byte_order (objfile
->arch ());
204 const gdb_byte
*addr
= section
->buffer
;
206 bfd
*const abfd
= section
->get_bfd_owner ();
208 unsigned int bytes_read
;
209 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
212 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
213 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
214 if (bytes_read
+ length
!= section
->size
)
216 /* There may be multiple per-CU indices. */
217 warning (_("Section .debug_names in %s length %s does not match "
218 "section length %s, ignoring .debug_names."),
219 filename
, plongest (bytes_read
+ length
),
220 pulongest (section
->size
));
224 /* The version number. */
225 uint16_t version
= read_2_bytes (abfd
, addr
);
229 warning (_("Section .debug_names in %s has unsupported version %d, "
230 "ignoring .debug_names."),
236 uint16_t padding
= read_2_bytes (abfd
, addr
);
240 warning (_("Section .debug_names in %s has unsupported padding %d, "
241 "ignoring .debug_names."),
246 /* comp_unit_count - The number of CUs in the CU list. */
247 map
.cu_count
= read_4_bytes (abfd
, addr
);
250 /* local_type_unit_count - The number of TUs in the local TU
252 map
.tu_count
= read_4_bytes (abfd
, addr
);
255 /* foreign_type_unit_count - The number of TUs in the foreign TU
257 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
259 if (foreign_tu_count
!= 0)
261 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
262 "ignoring .debug_names."),
263 filename
, static_cast<unsigned long> (foreign_tu_count
));
267 /* bucket_count - The number of hash buckets in the hash lookup
269 map
.bucket_count
= read_4_bytes (abfd
, addr
);
272 /* name_count - The number of unique names in the index. */
273 map
.name_count
= read_4_bytes (abfd
, addr
);
276 /* abbrev_table_size - The size in bytes of the abbreviations
278 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
281 /* augmentation_string_size - The size in bytes of the augmentation
282 string. This value is rounded up to a multiple of 4. */
283 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
285 map
.augmentation_is_gdb
= ((augmentation_string_size
286 == sizeof (dwarf5_augmentation
))
287 && memcmp (addr
, dwarf5_augmentation
,
288 sizeof (dwarf5_augmentation
)) == 0);
289 augmentation_string_size
+= (-augmentation_string_size
) & 3;
290 addr
+= augmentation_string_size
;
293 map
.cu_table_reordered
= addr
;
294 addr
+= map
.cu_count
* map
.offset_size
;
296 /* List of Local TUs */
297 map
.tu_table_reordered
= addr
;
298 addr
+= map
.tu_count
* map
.offset_size
;
300 /* Hash Lookup Table */
301 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
302 addr
+= map
.bucket_count
* 4;
303 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
304 addr
+= map
.name_count
* 4;
307 map
.name_table_string_offs_reordered
= addr
;
308 addr
+= map
.name_count
* map
.offset_size
;
309 map
.name_table_entry_offs_reordered
= addr
;
310 addr
+= map
.name_count
* map
.offset_size
;
312 const gdb_byte
*abbrev_table_start
= addr
;
315 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
320 const auto insertpair
321 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
322 if (!insertpair
.second
)
324 warning (_("Section .debug_names in %s has duplicate index %s, "
325 "ignoring .debug_names."),
326 filename
, pulongest (index_num
));
329 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
330 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
335 mapped_debug_names::index_val::attr attr
;
336 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
338 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
340 if (attr
.form
== DW_FORM_implicit_const
)
342 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
346 if (attr
.dw_idx
== 0 && attr
.form
== 0)
348 indexval
.attr_vec
.push_back (std::move (attr
));
351 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
353 warning (_("Section .debug_names in %s has abbreviation_table "
354 "of size %s vs. written as %u, ignoring .debug_names."),
355 filename
, plongest (addr
- abbrev_table_start
),
359 map
.entry_pool
= addr
;
364 /* A helper for create_cus_from_debug_names that handles the MAP's CU
368 create_cus_from_debug_names_list (dwarf2_per_bfd
*per_bfd
,
369 const mapped_debug_names
&map
,
370 dwarf2_section_info
§ion
,
373 if (!map
.augmentation_is_gdb
)
375 for (uint32_t i
= 0; i
< map
.cu_count
; ++i
)
378 = (sect_offset
) (extract_unsigned_integer
379 (map
.cu_table_reordered
+ i
* map
.offset_size
,
381 map
.dwarf5_byte_order
));
382 /* We don't know the length of the CU, because the CU list in a
383 .debug_names index can be incomplete, so we can't use the start
384 of the next CU as end of this CU. We create the CUs here with
385 length 0, and in cutu_reader::cutu_reader we'll fill in the
387 dwarf2_per_cu_data_up per_cu
388 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
390 per_bfd
->all_units
.push_back (std::move (per_cu
));
395 sect_offset sect_off_prev
;
396 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
398 sect_offset sect_off_next
;
399 if (i
< map
.cu_count
)
402 = (sect_offset
) (extract_unsigned_integer
403 (map
.cu_table_reordered
+ i
* map
.offset_size
,
405 map
.dwarf5_byte_order
));
408 sect_off_next
= (sect_offset
) section
.size
;
411 if (sect_off_next
== sect_off_prev
)
413 warning (_("Section .debug_names has duplicate entry in CU table,"
414 " ignoring .debug_names."));
417 if (sect_off_next
< sect_off_prev
)
419 warning (_("Section .debug_names has non-ascending CU table,"
420 " ignoring .debug_names."));
423 /* Note: we're not using length = sect_off_next - sect_off_prev,
424 to gracefully handle an incomplete CU list. */
425 const ULONGEST length
= 0;
426 dwarf2_per_cu_data_up per_cu
427 = create_cu_from_index_list (per_bfd
, §ion
, is_dwz
,
428 sect_off_prev
, length
);
429 per_bfd
->all_units
.push_back (std::move (per_cu
));
431 sect_off_prev
= sect_off_next
;
437 /* Read the CU list from the mapped index, and use it to create all
438 the CU objects for this dwarf2_per_objfile. */
441 create_cus_from_debug_names (dwarf2_per_bfd
*per_bfd
,
442 const mapped_debug_names
&map
,
443 const mapped_debug_names
&dwz_map
)
445 gdb_assert (per_bfd
->all_units
.empty ());
446 per_bfd
->all_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
448 if (!create_cus_from_debug_names_list (per_bfd
, map
, per_bfd
->info
,
452 if (dwz_map
.cu_count
== 0)
455 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
456 return create_cus_from_debug_names_list (per_bfd
, dwz_map
, dwz
->info
,
460 /* See read-debug-names.h. */
463 dwarf2_read_debug_names (dwarf2_per_objfile
*per_objfile
)
465 std::unique_ptr
<mapped_debug_names
> map (new mapped_debug_names
);
466 mapped_debug_names dwz_map
;
467 struct objfile
*objfile
= per_objfile
->objfile
;
468 dwarf2_per_bfd
*per_bfd
= per_objfile
->per_bfd
;
470 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
471 &per_bfd
->debug_names
, *map
))
474 /* Don't use the index if it's empty. */
475 if (map
->name_count
== 0)
478 /* If there is a .dwz file, read it so we can get its CU list as
480 dwz_file
*dwz
= dwarf2_get_dwz_file (per_bfd
);
483 if (!read_debug_names_from_section (objfile
,
484 bfd_get_filename (dwz
->dwz_bfd
.get ()),
485 &dwz
->debug_names
, dwz_map
))
487 warning (_("could not read '.debug_names' section from %s; skipping"),
488 bfd_get_filename (dwz
->dwz_bfd
.get ()));
493 if (!create_cus_from_debug_names (per_bfd
, *map
, dwz_map
))
495 per_bfd
->all_units
.clear ();
499 if (map
->tu_count
!= 0)
501 /* We can only handle a single .debug_types when we have an
503 if (per_bfd
->types
.size () > 1)
505 per_bfd
->all_units
.clear ();
509 dwarf2_section_info
*section
510 = (per_bfd
->types
.size () == 1
514 create_signatured_type_table_from_debug_names
515 (per_objfile
, *map
, section
, &per_bfd
->abbrev
);
518 finalize_all_units (per_bfd
);
520 create_addrmap_from_aranges (per_objfile
, &per_bfd
->debug_aranges
);
522 per_bfd
->index_table
= std::move (map
);
523 per_bfd
->quick_file_names_table
=
524 create_quick_file_names_table (per_bfd
->all_units
.size ());
529 /* Type used to manage iterating over all CUs looking for a symbol for
532 class dw2_debug_names_iterator
535 dw2_debug_names_iterator (const mapped_debug_names
&map
,
536 block_search_flags block_index
,
538 const char *name
, dwarf2_per_objfile
*per_objfile
)
539 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
540 m_addr (find_vec_in_debug_names (map
, name
, per_objfile
)),
541 m_per_objfile (per_objfile
)
544 dw2_debug_names_iterator (const mapped_debug_names
&map
,
545 search_domain search
, uint32_t namei
,
546 dwarf2_per_objfile
*per_objfile
,
547 domain_enum domain
= UNDEF_DOMAIN
)
551 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
552 m_per_objfile (per_objfile
)
555 dw2_debug_names_iterator (const mapped_debug_names
&map
,
556 block_search_flags block_index
, domain_enum domain
,
557 uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
558 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
559 m_addr (find_vec_in_debug_names (map
, namei
, per_objfile
)),
560 m_per_objfile (per_objfile
)
563 /* Return the next matching CU or NULL if there are no more. */
564 dwarf2_per_cu_data
*next ();
567 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
569 dwarf2_per_objfile
*per_objfile
);
570 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
572 dwarf2_per_objfile
*per_objfile
);
574 /* The internalized form of .debug_names. */
575 const mapped_debug_names
&m_map
;
577 /* Restrict the search to these blocks. */
578 block_search_flags m_block_index
= (SEARCH_GLOBAL_BLOCK
579 | SEARCH_STATIC_BLOCK
);
581 /* The kind of symbol we're looking for. */
582 const domain_enum m_domain
= UNDEF_DOMAIN
;
583 const search_domain m_search
= ALL_DOMAIN
;
585 /* The list of CUs from the index entry of the symbol, or NULL if
587 const gdb_byte
*m_addr
;
589 dwarf2_per_objfile
*m_per_objfile
;
593 mapped_debug_names::namei_to_name
594 (uint32_t namei
, dwarf2_per_objfile
*per_objfile
) const
596 const ULONGEST namei_string_offs
597 = extract_unsigned_integer ((name_table_string_offs_reordered
598 + namei
* offset_size
),
601 return read_indirect_string_at_offset (per_objfile
, namei_string_offs
);
604 /* Find a slot in .debug_names for the object named NAME. If NAME is
605 found, return pointer to its pool data. If NAME cannot be found,
609 dw2_debug_names_iterator::find_vec_in_debug_names
610 (const mapped_debug_names
&map
, const char *name
,
611 dwarf2_per_objfile
*per_objfile
)
613 int (*cmp
) (const char *, const char *);
615 gdb::unique_xmalloc_ptr
<char> without_params
;
616 if (current_language
->la_language
== language_cplus
617 || current_language
->la_language
== language_fortran
618 || current_language
->la_language
== language_d
)
620 /* NAME is already canonical. Drop any qualifiers as
621 .debug_names does not contain any. */
623 if (strchr (name
, '(') != NULL
)
625 without_params
= cp_remove_params (name
);
626 if (without_params
!= NULL
)
627 name
= without_params
.get ();
631 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
633 const uint32_t full_hash
= dwarf5_djb_hash (name
);
635 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
636 (map
.bucket_table_reordered
637 + (full_hash
% map
.bucket_count
)), 4,
638 map
.dwarf5_byte_order
);
642 if (namei
>= map
.name_count
)
644 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
646 namei
, map
.name_count
,
647 objfile_name (per_objfile
->objfile
));
653 const uint32_t namei_full_hash
654 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
655 (map
.hash_table_reordered
+ namei
), 4,
656 map
.dwarf5_byte_order
);
657 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
660 if (full_hash
== namei_full_hash
)
662 const char *const namei_string
= map
.namei_to_name (namei
, per_objfile
);
664 #if 0 /* An expensive sanity check. */
665 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
667 complaint (_("Wrong .debug_names hash for string at index %u "
669 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
674 if (cmp (namei_string
, name
) == 0)
676 const ULONGEST namei_entry_offs
677 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
678 + namei
* map
.offset_size
),
679 map
.offset_size
, map
.dwarf5_byte_order
);
680 return map
.entry_pool
+ namei_entry_offs
;
685 if (namei
>= map
.name_count
)
691 dw2_debug_names_iterator::find_vec_in_debug_names
692 (const mapped_debug_names
&map
, uint32_t namei
, dwarf2_per_objfile
*per_objfile
)
694 if (namei
>= map
.name_count
)
696 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
698 namei
, map
.name_count
,
699 objfile_name (per_objfile
->objfile
));
703 const ULONGEST namei_entry_offs
704 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
705 + namei
* map
.offset_size
),
706 map
.offset_size
, map
.dwarf5_byte_order
);
707 return map
.entry_pool
+ namei_entry_offs
;
710 /* See dw2_debug_names_iterator. */
713 dw2_debug_names_iterator::next ()
718 dwarf2_per_bfd
*per_bfd
= m_per_objfile
->per_bfd
;
719 struct objfile
*objfile
= m_per_objfile
->objfile
;
720 bfd
*const abfd
= objfile
->obfd
.get ();
724 unsigned int bytes_read
;
725 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
726 m_addr
+= bytes_read
;
730 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
731 if (indexval_it
== m_map
.abbrev_map
.cend ())
733 complaint (_("Wrong .debug_names undefined abbrev code %s "
735 pulongest (abbrev
), objfile_name (objfile
));
738 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
739 enum class symbol_linkage
{
743 } symbol_linkage_
= symbol_linkage::unknown
;
744 dwarf2_per_cu_data
*per_cu
= NULL
;
745 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
750 case DW_FORM_implicit_const
:
751 ull
= attr
.implicit_const
;
753 case DW_FORM_flag_present
:
757 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
758 m_addr
+= bytes_read
;
761 ull
= read_4_bytes (abfd
, m_addr
);
765 ull
= read_8_bytes (abfd
, m_addr
);
768 case DW_FORM_ref_sig8
:
769 ull
= read_8_bytes (abfd
, m_addr
);
773 complaint (_("Unsupported .debug_names form %s [in module %s]"),
774 dwarf_form_name (attr
.form
),
775 objfile_name (objfile
));
780 case DW_IDX_compile_unit
:
782 /* Don't crash on bad data. */
783 if (ull
>= per_bfd
->all_comp_units
.size ())
785 complaint (_(".debug_names entry has bad CU index %s"
788 objfile_name (objfile
));
792 per_cu
= per_bfd
->get_cu (ull
);
794 case DW_IDX_type_unit
:
795 /* Don't crash on bad data. */
796 if (ull
>= per_bfd
->all_type_units
.size ())
798 complaint (_(".debug_names entry has bad TU index %s"
801 objfile_name (objfile
));
805 int nr_cus
= per_bfd
->all_comp_units
.size ();
806 per_cu
= per_bfd
->get_cu (nr_cus
+ ull
);
809 case DW_IDX_die_offset
:
810 /* In a per-CU index (as opposed to a per-module index), index
811 entries without CU attribute implicitly refer to the single CU. */
813 per_cu
= per_bfd
->get_cu (0);
815 case DW_IDX_GNU_internal
:
816 if (!m_map
.augmentation_is_gdb
)
818 symbol_linkage_
= symbol_linkage::static_
;
820 case DW_IDX_GNU_external
:
821 if (!m_map
.augmentation_is_gdb
)
823 symbol_linkage_
= symbol_linkage::extern_
;
828 /* Skip if we couldn't find a valid CU/TU index. */
829 if (per_cu
== nullptr)
832 /* Skip if already read in. */
833 if (m_per_objfile
->symtab_set_p (per_cu
))
836 /* Check static vs global. */
837 if (symbol_linkage_
!= symbol_linkage::unknown
)
839 if (symbol_linkage_
== symbol_linkage::static_
)
841 if ((m_block_index
& SEARCH_STATIC_BLOCK
) == 0)
846 if ((m_block_index
& SEARCH_GLOBAL_BLOCK
) == 0)
851 /* Match dw2_symtab_iter_next, symbol_kind
852 and debug_names::psymbol_tag. */
856 switch (indexval
.dwarf_tag
)
858 case DW_TAG_variable
:
859 case DW_TAG_subprogram
:
860 /* Some types are also in VAR_DOMAIN. */
862 case DW_TAG_structure_type
:
869 switch (indexval
.dwarf_tag
)
872 case DW_TAG_structure_type
:
879 switch (indexval
.dwarf_tag
)
882 case DW_TAG_variable
:
889 switch (indexval
.dwarf_tag
)
901 /* Match dw2_expand_symtabs_matching, symbol_kind and
902 debug_names::psymbol_tag. */
905 case VARIABLES_DOMAIN
:
906 switch (indexval
.dwarf_tag
)
908 case DW_TAG_variable
:
914 case FUNCTIONS_DOMAIN
:
915 switch (indexval
.dwarf_tag
)
917 case DW_TAG_subprogram
:
924 switch (indexval
.dwarf_tag
)
927 case DW_TAG_structure_type
:
934 switch (indexval
.dwarf_tag
)
948 /* This dumps minimal information about .debug_names. It is called
949 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
950 uses this to verify that .debug_names has been loaded. */
953 dwarf2_debug_names_index::dump (struct objfile
*objfile
)
955 gdb_printf (".debug_names: exists\n");
959 dwarf2_debug_names_index::expand_matching_symbols
960 (struct objfile
*objfile
,
961 const lookup_name_info
&name
, domain_enum domain
,
963 symbol_compare_ftype
*ordered_compare
)
965 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
967 mapped_debug_names
&map
968 = *(gdb::checked_static_cast
<mapped_debug_names
*>
969 (per_objfile
->per_bfd
->index_table
.get ()));
970 const block_search_flags block_flags
971 = global
? SEARCH_GLOBAL_BLOCK
: SEARCH_STATIC_BLOCK
;
973 const char *match_name
= name
.ada ().lookup_name ().c_str ();
974 auto matcher
= [&] (const char *symname
)
976 if (ordered_compare
== nullptr)
978 return ordered_compare (symname
, match_name
) == 0;
981 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
,
982 [&] (offset_type namei
)
984 /* The name was matched, now expand corresponding CUs that were
986 dw2_debug_names_iterator
iter (map
, block_flags
, domain
, namei
,
989 struct dwarf2_per_cu_data
*per_cu
;
990 while ((per_cu
= iter
.next ()) != NULL
)
991 dw2_expand_symtabs_matching_one (per_cu
, per_objfile
, nullptr,
998 dwarf2_debug_names_index::expand_symtabs_matching
999 (struct objfile
*objfile
,
1000 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
1001 const lookup_name_info
*lookup_name
,
1002 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
1003 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
1004 block_search_flags search_flags
,
1006 enum search_domain kind
)
1008 dwarf2_per_objfile
*per_objfile
= get_dwarf2_per_objfile (objfile
);
1010 dw_expand_symtabs_matching_file_matcher (per_objfile
, file_matcher
);
1012 /* This invariant is documented in quick-functions.h. */
1013 gdb_assert (lookup_name
!= nullptr || symbol_matcher
== nullptr);
1014 if (lookup_name
== nullptr)
1016 for (dwarf2_per_cu_data
*per_cu
1017 : all_units_range (per_objfile
->per_bfd
))
1021 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,
1029 mapped_debug_names
&map
1030 = *(gdb::checked_static_cast
<mapped_debug_names
*>
1031 (per_objfile
->per_bfd
->index_table
.get ()));
1034 = dw2_expand_symtabs_matching_symbol (map
, *lookup_name
,
1036 [&] (offset_type namei
)
1038 /* The name was matched, now expand corresponding CUs that were
1040 dw2_debug_names_iterator
iter (map
, kind
, namei
, per_objfile
, domain
);
1042 struct dwarf2_per_cu_data
*per_cu
;
1043 while ((per_cu
= iter
.next ()) != NULL
)
1044 if (!dw2_expand_symtabs_matching_one (per_cu
, per_objfile
,