GDB (xrefs)
Loading...
Searching...
No Matches
read-debug-names.c
Go to the documentation of this file.
1/* Reading code for .debug_names
2
3 Copyright (C) 2023 Free Software Foundation, Inc.
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#include "defs.h"
21#include "read-debug-names.h"
22
23#include "complaints.h"
24#include "cp-support.h"
25#include "dwz.h"
26#include "mapped-index.h"
27#include "read.h"
28#include "stringify.h"
29
30/* A description of the mapped .debug_names.
31 Uninitialized map has CU_COUNT 0. */
32
34{
38 uint8_t offset_size;
39 uint32_t cu_count = 0;
45 const gdb_byte *entry_pool;
46
47 struct index_val
48 {
49 ULONGEST dwarf_tag;
50 struct attr
51 {
52 /* Attribute name DW_IDX_*. */
53 ULONGEST dw_idx;
54
55 /* Attribute form DW_FORM_*. */
56 ULONGEST form;
57
58 /* Value if FORM is DW_FORM_implicit_const. */
60 };
61 std::vector<attr> attr_vec;
62 };
63
64 std::unordered_map<ULONGEST, index_val> abbrev_map;
65
66 const char *namei_to_name
67 (uint32_t namei, dwarf2_per_objfile *per_objfile) const;
68
69 /* Implementation of the mapped_index_base virtual interface, for
70 the name_components cache. */
71
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); }
75
76 size_t symbol_name_count () const override
77 { return this->name_count; }
78
80};
81
83{
84 void dump (struct objfile *objfile) override;
85
87 (struct objfile *,
88 const lookup_name_info &lookup_name,
89 domain_enum domain,
90 int global,
91 symbol_compare_ftype *ordered_compare) override;
92
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,
100 domain_enum domain,
101 enum search_domain kind) override;
102};
103
109
110/* Create the signatured type hash table from .debug_names. */
111
112static void
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)
118{
119 struct objfile *objfile = per_objfile->objfile;
120
121 section->read (objfile);
122 abbrev_section->read (objfile);
123
124 htab_up sig_types_hash = allocate_signatured_type_table ();
125
126 for (uint32_t i = 0; i < map.tu_count; ++i)
127 {
128 signatured_type_up sig_type;
129 void **slot;
130
131 sect_offset sect_off
132 = (sect_offset) (extract_unsigned_integer
133 (map.tu_table_reordered + i * map.offset_size,
134 map.offset_size,
135 map.dwarf5_byte_order));
136
137 comp_unit_head cu_header;
138 read_and_check_comp_unit_head (per_objfile, &cu_header, section,
139 abbrev_section,
140 section->buffer + to_underlying (sect_off),
142
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;
148
149 slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
150 *slot = sig_type.get ();
151
152 per_objfile->per_bfd->all_units.emplace_back (sig_type.release ());
153 }
154
155 per_objfile->per_bfd->signatured_types = std::move (sig_types_hash);
156}
157
158/* Read the address map data from DWARF-5 .debug_aranges, and use it to
159 populate the index_addrmap. */
160
161static void
163 struct dwarf2_section_info *section)
164{
165 dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
166
167 addrmap_mutable mutable_map;
168
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,
172 &mutable_map);
173}
174
175/* DWARF-5 debug_names reader. */
176
177/* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
178static const gdb_byte dwarf5_augmentation[] = { 'G', 'D', 'B', 0 };
179
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.
183
184 Returns true if all went well, false otherwise. */
185
186static bool
188 const char *filename,
189 struct dwarf2_section_info *section,
191{
192 if (section->empty ())
193 return false;
194
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)
198 return false;
199
200 section->read (objfile);
201
203
204 const gdb_byte *addr = section->buffer;
205
206 bfd *const abfd = section->get_bfd_owner ();
207
208 unsigned int bytes_read;
209 LONGEST length = read_initial_length (abfd, addr, &bytes_read);
210 addr += bytes_read;
211
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)
215 {
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));
221 return false;
222 }
223
224 /* The version number. */
225 uint16_t version = read_2_bytes (abfd, addr);
226 addr += 2;
227 if (version != 5)
228 {
229 warning (_("Section .debug_names in %s has unsupported version %d, "
230 "ignoring .debug_names."),
231 filename, version);
232 return false;
233 }
234
235 /* Padding. */
236 uint16_t padding = read_2_bytes (abfd, addr);
237 addr += 2;
238 if (padding != 0)
239 {
240 warning (_("Section .debug_names in %s has unsupported padding %d, "
241 "ignoring .debug_names."),
242 filename, padding);
243 return false;
244 }
245
246 /* comp_unit_count - The number of CUs in the CU list. */
247 map.cu_count = read_4_bytes (abfd, addr);
248 addr += 4;
249
250 /* local_type_unit_count - The number of TUs in the local TU
251 list. */
252 map.tu_count = read_4_bytes (abfd, addr);
253 addr += 4;
254
255 /* foreign_type_unit_count - The number of TUs in the foreign TU
256 list. */
257 uint32_t foreign_tu_count = read_4_bytes (abfd, addr);
258 addr += 4;
259 if (foreign_tu_count != 0)
260 {
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));
264 return false;
265 }
266
267 /* bucket_count - The number of hash buckets in the hash lookup
268 table. */
269 map.bucket_count = read_4_bytes (abfd, addr);
270 addr += 4;
271
272 /* name_count - The number of unique names in the index. */
273 map.name_count = read_4_bytes (abfd, addr);
274 addr += 4;
275
276 /* abbrev_table_size - The size in bytes of the abbreviations
277 table. */
278 uint32_t abbrev_table_size = read_4_bytes (abfd, addr);
279 addr += 4;
280
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);
284 addr += 4;
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;
291
292 /* List of CUs */
293 map.cu_table_reordered = addr;
294 addr += map.cu_count * map.offset_size;
295
296 /* List of Local TUs */
297 map.tu_table_reordered = addr;
298 addr += map.tu_count * map.offset_size;
299
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;
305
306 /* Name Table */
308 addr += map.name_count * map.offset_size;
310 addr += map.name_count * map.offset_size;
311
312 const gdb_byte *abbrev_table_start = addr;
313 for (;;)
314 {
315 const ULONGEST index_num = read_unsigned_leb128 (abfd, addr, &bytes_read);
316 addr += bytes_read;
317 if (index_num == 0)
318 break;
319
320 const auto insertpair
321 = map.abbrev_map.emplace (index_num, mapped_debug_names::index_val ());
322 if (!insertpair.second)
323 {
324 warning (_("Section .debug_names in %s has duplicate index %s, "
325 "ignoring .debug_names."),
326 filename, pulongest (index_num));
327 return false;
328 }
329 mapped_debug_names::index_val &indexval = insertpair.first->second;
330 indexval.dwarf_tag = read_unsigned_leb128 (abfd, addr, &bytes_read);
331 addr += bytes_read;
332
333 for (;;)
334 {
336 attr.dw_idx = read_unsigned_leb128 (abfd, addr, &bytes_read);
337 addr += bytes_read;
338 attr.form = read_unsigned_leb128 (abfd, addr, &bytes_read);
339 addr += bytes_read;
340 if (attr.form == DW_FORM_implicit_const)
341 {
342 attr.implicit_const = read_signed_leb128 (abfd, addr,
343 &bytes_read);
344 addr += bytes_read;
345 }
346 if (attr.dw_idx == 0 && attr.form == 0)
347 break;
348 indexval.attr_vec.push_back (std::move (attr));
349 }
350 }
351 if (addr != abbrev_table_start + abbrev_table_size)
352 {
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),
356 abbrev_table_size);
357 return false;
358 }
359 map.entry_pool = addr;
360
361 return true;
362}
363
364/* A helper for create_cus_from_debug_names that handles the MAP's CU
365 list. */
366
367static bool
369 const mapped_debug_names &map,
370 dwarf2_section_info &section,
371 bool is_dwz)
372{
373 if (!map.augmentation_is_gdb)
374 {
375 for (uint32_t i = 0; i < map.cu_count; ++i)
376 {
377 sect_offset sect_off
378 = (sect_offset) (extract_unsigned_integer
379 (map.cu_table_reordered + i * map.offset_size,
380 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
386 actual length. */
388 = create_cu_from_index_list (per_bfd, &section, is_dwz,
389 sect_off, 0);
390 per_bfd->all_units.push_back (std::move (per_cu));
391 }
392 return true;
393 }
394
395 sect_offset sect_off_prev;
396 for (uint32_t i = 0; i <= map.cu_count; ++i)
397 {
398 sect_offset sect_off_next;
399 if (i < map.cu_count)
400 {
401 sect_off_next
402 = (sect_offset) (extract_unsigned_integer
403 (map.cu_table_reordered + i * map.offset_size,
404 map.offset_size,
405 map.dwarf5_byte_order));
406 }
407 else
408 sect_off_next = (sect_offset) section.size;
409 if (i >= 1)
410 {
411 if (sect_off_next == sect_off_prev)
412 {
413 warning (_("Section .debug_names has duplicate entry in CU table,"
414 " ignoring .debug_names."));
415 return false;
416 }
417 if (sect_off_next < sect_off_prev)
418 {
419 warning (_("Section .debug_names has non-ascending CU table,"
420 " ignoring .debug_names."));
421 return false;
422 }
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;
427 = create_cu_from_index_list (per_bfd, &section, is_dwz,
428 sect_off_prev, length);
429 per_bfd->all_units.push_back (std::move (per_cu));
430 }
431 sect_off_prev = sect_off_next;
432 }
433
434 return true;
435}
436
437/* Read the CU list from the mapped index, and use it to create all
438 the CU objects for this dwarf2_per_objfile. */
439
440static bool
442 const mapped_debug_names &map,
443 const mapped_debug_names &dwz_map)
444{
445 gdb_assert (per_bfd->all_units.empty ());
446 per_bfd->all_units.reserve (map.cu_count + dwz_map.cu_count);
447
449 false /* is_dwz */))
450 return false;
451
452 if (dwz_map.cu_count == 0)
453 return true;
454
456 return create_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info,
457 true /* is_dwz */);
458}
459
460/* See read-debug-names.h. */
461
462bool
464{
465 auto map = gdb::make_unique<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;
469
471 &per_bfd->debug_names, *map))
472 return false;
473
474 /* Don't use the index if it's empty. */
475 if (map->name_count == 0)
476 return false;
477
478 /* If there is a .dwz file, read it so we can get its CU list as
479 well. */
481 if (dwz != NULL)
482 {
484 bfd_get_filename (dwz->dwz_bfd.get ()),
485 &dwz->debug_names, dwz_map))
486 {
487 warning (_("could not read '.debug_names' section from %s; skipping"),
488 bfd_get_filename (dwz->dwz_bfd.get ()));
489 return false;
490 }
491 }
492
493 if (!create_cus_from_debug_names (per_bfd, *map, dwz_map))
494 {
495 per_bfd->all_units.clear ();
496 return false;
497 }
498
499 if (map->tu_count != 0)
500 {
501 /* We can only handle a single .debug_types when we have an
502 index. */
503 if (per_bfd->types.size () > 1)
504 {
505 per_bfd->all_units.clear ();
506 return false;
507 }
508
509 dwarf2_section_info *section
510 = (per_bfd->types.size () == 1
511 ? &per_bfd->types[0]
512 : &per_bfd->info);
513
515 (per_objfile, *map, section, &per_bfd->abbrev);
516 }
517
519
520 create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
521
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 ());
525
526 return true;
527}
528
529/* Type used to manage iterating over all CUs looking for a symbol for
530 .debug_names. */
531
533{
534public:
536 block_search_flags block_index,
537 domain_enum domain,
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)
542 {}
543
545 search_domain search, uint32_t namei,
546 dwarf2_per_objfile *per_objfile,
547 domain_enum domain = UNDEF_DOMAIN)
548 : m_map (map),
549 m_domain (domain),
550 m_search (search),
551 m_addr (find_vec_in_debug_names (map, namei, per_objfile)),
552 m_per_objfile (per_objfile)
553 {}
554
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)
561 {}
562
563 /* Return the next matching CU or NULL if there are no more. */
565
566private:
567 static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map,
568 const char *name,
569 dwarf2_per_objfile *per_objfile);
570 static const gdb_byte *find_vec_in_debug_names (const mapped_debug_names &map,
571 uint32_t namei,
572 dwarf2_per_objfile *per_objfile);
573
574 /* The internalized form of .debug_names. */
576
577 /* Restrict the search to these blocks. */
578 block_search_flags m_block_index = (SEARCH_GLOBAL_BLOCK
580
581 /* The kind of symbol we're looking for. */
584
585 /* The list of CUs from the index entry of the symbol, or NULL if
586 not found. */
587 const gdb_byte *m_addr;
588
590};
591
592const char *
594 (uint32_t namei, dwarf2_per_objfile *per_objfile) const
595{
596 const ULONGEST namei_string_offs
598 + namei * offset_size),
601 return read_indirect_string_at_offset (per_objfile, namei_string_offs);
602}
603
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,
606 return NULL. */
607
608const gdb_byte *
610 (const mapped_debug_names &map, const char *name,
611 dwarf2_per_objfile *per_objfile)
612{
613 int (*cmp) (const char *, const char *);
614
615 gdb::unique_xmalloc_ptr<char> without_params;
619 {
620 /* NAME is already canonical. Drop any qualifiers as
621 .debug_names does not contain any. */
622
623 if (strchr (name, '(') != NULL)
624 {
625 without_params = cp_remove_params (name);
626 if (without_params != NULL)
627 name = without_params.get ();
628 }
629 }
630
631 cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp);
632
633 const uint32_t full_hash = dwarf5_djb_hash (name);
634 uint32_t namei
635 = extract_unsigned_integer (reinterpret_cast<const gdb_byte *>
637 + (full_hash % map.bucket_count)), 4,
639 if (namei == 0)
640 return NULL;
641 --namei;
642 if (namei >= map.name_count)
643 {
644 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
645 "[in module %s]"),
646 namei, map.name_count,
647 objfile_name (per_objfile->objfile));
648 return NULL;
649 }
650
651 for (;;)
652 {
653 const uint32_t namei_full_hash
654 = extract_unsigned_integer (reinterpret_cast<const gdb_byte *>
655 (map.hash_table_reordered + namei), 4,
657 if (full_hash % map.bucket_count != namei_full_hash % map.bucket_count)
658 return NULL;
659
660 if (full_hash == namei_full_hash)
661 {
662 const char *const namei_string = map.namei_to_name (namei, per_objfile);
663
664#if 0 /* An expensive sanity check. */
665 if (namei_full_hash != dwarf5_djb_hash (namei_string))
666 {
667 complaint (_("Wrong .debug_names hash for string at index %u "
668 "[in module %s]"),
670 return NULL;
671 }
672#endif
673
674 if (cmp (namei_string, name) == 0)
675 {
676 const ULONGEST namei_entry_offs
678 + namei * map.offset_size),
680 return map.entry_pool + namei_entry_offs;
681 }
682 }
683
684 ++namei;
685 if (namei >= map.name_count)
686 return NULL;
687 }
688}
689
690const gdb_byte *
692 (const mapped_debug_names &map, uint32_t namei, dwarf2_per_objfile *per_objfile)
693{
694 if (namei >= map.name_count)
695 {
696 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
697 "[in module %s]"),
698 namei, map.name_count,
699 objfile_name (per_objfile->objfile));
700 return NULL;
701 }
702
703 const ULONGEST namei_entry_offs
705 + namei * map.offset_size),
707 return map.entry_pool + namei_entry_offs;
708}
709
710/* See dw2_debug_names_iterator. */
711
714{
715 if (m_addr == NULL)
716 return NULL;
717
720 bfd *const abfd = objfile->obfd.get ();
721
722 again:
723
724 unsigned int bytes_read;
725 const ULONGEST abbrev = read_unsigned_leb128 (abfd, m_addr, &bytes_read);
726 m_addr += bytes_read;
727 if (abbrev == 0)
728 return NULL;
729
730 const auto indexval_it = m_map.abbrev_map.find (abbrev);
731 if (indexval_it == m_map.abbrev_map.cend ())
732 {
733 complaint (_("Wrong .debug_names undefined abbrev code %s "
734 "[in module %s]"),
735 pulongest (abbrev), objfile_name (objfile));
736 return NULL;
737 }
738 const mapped_debug_names::index_val &indexval = indexval_it->second;
739 enum class symbol_linkage {
740 unknown,
741 static_,
742 extern_,
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)
746 {
747 ULONGEST ull;
748 switch (attr.form)
749 {
750 case DW_FORM_implicit_const:
751 ull = attr.implicit_const;
752 break;
753 case DW_FORM_flag_present:
754 ull = 1;
755 break;
756 case DW_FORM_udata:
757 ull = read_unsigned_leb128 (abfd, m_addr, &bytes_read);
758 m_addr += bytes_read;
759 break;
760 case DW_FORM_ref4:
761 ull = read_4_bytes (abfd, m_addr);
762 m_addr += 4;
763 break;
764 case DW_FORM_ref8:
765 ull = read_8_bytes (abfd, m_addr);
766 m_addr += 8;
767 break;
768 case DW_FORM_ref_sig8:
769 ull = read_8_bytes (abfd, m_addr);
770 m_addr += 8;
771 break;
772 default:
773 complaint (_("Unsupported .debug_names form %s [in module %s]"),
774 dwarf_form_name (attr.form),
776 return NULL;
777 }
778 switch (attr.dw_idx)
779 {
780 case DW_IDX_compile_unit:
781 {
782 /* Don't crash on bad data. */
783 if (ull >= per_bfd->all_comp_units.size ())
784 {
785 complaint (_(".debug_names entry has bad CU index %s"
786 " [in module %s]"),
787 pulongest (ull),
789 continue;
790 }
791 }
792 per_cu = per_bfd->get_cu (ull);
793 break;
794 case DW_IDX_type_unit:
795 /* Don't crash on bad data. */
796 if (ull >= per_bfd->all_type_units.size ())
797 {
798 complaint (_(".debug_names entry has bad TU index %s"
799 " [in module %s]"),
800 pulongest (ull),
802 continue;
803 }
804 {
805 int nr_cus = per_bfd->all_comp_units.size ();
806 per_cu = per_bfd->get_cu (nr_cus + ull);
807 }
808 break;
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. */
812 if (per_cu == NULL)
813 per_cu = per_bfd->get_cu (0);
814 break;
815 case DW_IDX_GNU_internal:
817 break;
818 symbol_linkage_ = symbol_linkage::static_;
819 break;
820 case DW_IDX_GNU_external:
822 break;
823 symbol_linkage_ = symbol_linkage::extern_;
824 break;
825 }
826 }
827
828 /* Skip if we couldn't find a valid CU/TU index. */
829 if (per_cu == nullptr)
830 goto again;
831
832 /* Skip if already read in. */
833 if (m_per_objfile->symtab_set_p (per_cu))
834 goto again;
835
836 /* Check static vs global. */
837 if (symbol_linkage_ != symbol_linkage::unknown)
838 {
839 if (symbol_linkage_ == symbol_linkage::static_)
840 {
842 goto again;
843 }
844 else
845 {
847 goto again;
848 }
849 }
850
851 /* Match dw2_symtab_iter_next, symbol_kind
852 and debug_names::psymbol_tag. */
853 switch (m_domain)
854 {
855 case VAR_DOMAIN:
856 switch (indexval.dwarf_tag)
857 {
858 case DW_TAG_variable:
859 case DW_TAG_subprogram:
860 /* Some types are also in VAR_DOMAIN. */
861 case DW_TAG_typedef:
862 case DW_TAG_structure_type:
863 break;
864 default:
865 goto again;
866 }
867 break;
868 case STRUCT_DOMAIN:
869 switch (indexval.dwarf_tag)
870 {
871 case DW_TAG_typedef:
872 case DW_TAG_structure_type:
873 break;
874 default:
875 goto again;
876 }
877 break;
878 case LABEL_DOMAIN:
879 switch (indexval.dwarf_tag)
880 {
881 case 0:
882 case DW_TAG_variable:
883 break;
884 default:
885 goto again;
886 }
887 break;
888 case MODULE_DOMAIN:
889 switch (indexval.dwarf_tag)
890 {
891 case DW_TAG_module:
892 break;
893 default:
894 goto again;
895 }
896 break;
897 default:
898 break;
899 }
900
901 /* Match dw2_expand_symtabs_matching, symbol_kind and
902 debug_names::psymbol_tag. */
903 switch (m_search)
904 {
905 case VARIABLES_DOMAIN:
906 switch (indexval.dwarf_tag)
907 {
908 case DW_TAG_variable:
909 break;
910 default:
911 goto again;
912 }
913 break;
914 case FUNCTIONS_DOMAIN:
915 switch (indexval.dwarf_tag)
916 {
917 case DW_TAG_subprogram:
918 break;
919 default:
920 goto again;
921 }
922 break;
923 case TYPES_DOMAIN:
924 switch (indexval.dwarf_tag)
925 {
926 case DW_TAG_typedef:
927 case DW_TAG_structure_type:
928 break;
929 default:
930 goto again;
931 }
932 break;
933 case MODULES_DOMAIN:
934 switch (indexval.dwarf_tag)
935 {
936 case DW_TAG_module:
937 break;
938 default:
939 goto again;
940 }
941 default:
942 break;
943 }
944
945 return per_cu;
946}
947
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. */
951
952void
954{
955 gdb_printf (".debug_names: exists\n");
956}
957
958void
960 (struct objfile *objfile,
961 const lookup_name_info &name, domain_enum domain,
962 int global,
963 symbol_compare_ftype *ordered_compare)
964{
966
968 = *(gdb::checked_static_cast<mapped_debug_names *>
969 (per_objfile->per_bfd->index_table.get ()));
970 const block_search_flags block_flags
972
973 const char *match_name = name.ada ().lookup_name ().c_str ();
974 auto matcher = [&] (const char *symname)
975 {
976 if (ordered_compare == nullptr)
977 return true;
978 return ordered_compare (symname, match_name) == 0;
979 };
980
982 [&] (offset_type namei)
983 {
984 /* The name was matched, now expand corresponding CUs that were
985 marked. */
986 dw2_debug_names_iterator iter (map, block_flags, domain, namei,
987 per_objfile);
988
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,
992 nullptr);
993 return true;
994 }, per_objfile);
995}
996
997bool
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,
1005 domain_enum domain,
1006 enum search_domain kind)
1007{
1009
1010 dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
1011
1012 /* This invariant is documented in quick-functions.h. */
1013 gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr);
1014 if (lookup_name == nullptr)
1015 {
1016 for (dwarf2_per_cu_data *per_cu
1017 : all_units_range (per_objfile->per_bfd))
1018 {
1019 QUIT;
1020
1021 if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
1022 file_matcher,
1023 expansion_notify))
1024 return false;
1025 }
1026 return true;
1027 }
1028
1030 = *(gdb::checked_static_cast<mapped_debug_names *>
1031 (per_objfile->per_bfd->index_table.get ()));
1032
1033 bool result
1034 = dw2_expand_symtabs_matching_symbol (map, *lookup_name,
1035 symbol_matcher,
1036 [&] (offset_type namei)
1037 {
1038 /* The name was matched, now expand corresponding CUs that were
1039 marked. */
1040 dw2_debug_names_iterator iter (map, kind, namei, per_objfile, domain);
1041
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,
1045 file_matcher,
1046 expansion_notify))
1047 return false;
1048 return true;
1049 }, per_objfile);
1050
1051 return result;
1052}
const char *const name
static const gdb_byte * find_vec_in_debug_names(const mapped_debug_names &map, const char *name, dwarf2_per_objfile *per_objfile)
dw2_debug_names_iterator(const mapped_debug_names &map, block_search_flags block_index, domain_enum domain, const char *name, dwarf2_per_objfile *per_objfile)
dwarf2_per_cu_data * next()
const search_domain m_search
block_search_flags m_block_index
dw2_debug_names_iterator(const mapped_debug_names &map, block_search_flags block_index, domain_enum domain, uint32_t namei, dwarf2_per_objfile *per_objfile)
const mapped_debug_names & m_map
dwarf2_per_objfile * m_per_objfile
dw2_debug_names_iterator(const mapped_debug_names &map, search_domain search, uint32_t namei, dwarf2_per_objfile *per_objfile, domain_enum domain=UNDEF_DOMAIN)
const gdb_byte * read_and_check_comp_unit_head(dwarf2_per_objfile *per_objfile, struct comp_unit_head *header, struct dwarf2_section_info *section, struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr, rcuh_kind section_kind)
#define complaint(FMT,...)
Definition complaints.h:47
gdb::unique_xmalloc_ptr< char > cp_remove_params(const char *demangled_name)
Definition cp-support.c:959
@ language_cplus
Definition defs.h:216
@ language_fortran
Definition defs.h:219
@ language_d
Definition defs.h:217
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
#define QUIT
Definition defs.h:187
struct dwz_file * dwarf2_get_dwz_file(dwarf2_per_bfd *per_bfd, bool require)
Definition dwz.c:193
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
uint32_t dwarf5_djb_hash(const char *str_)
uint32_t offset_type
const struct language_defn * current_language
Definition language.c:82
case_sensitivity
Definition language.h:72
@ case_sensitive_on
Definition language.h:73
LONGEST read_signed_leb128(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
Definition leb.c:59
LONGEST read_initial_length(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read, bool handle_nonstd)
Definition leb.c:90
ULONGEST read_unsigned_leb128(bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read_ptr)
Definition leb.c:31
static unsigned int read_4_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:64
static unsigned int read_2_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:45
static ULONGEST read_8_bytes(bfd *abfd, const gdb_byte *buf)
Definition leb.h:76
const char * objfile_name(const struct objfile *objfile)
Definition objfiles.c:1259
int symbol_compare_ftype(const char *string1, const char *string2)
@ SEARCH_GLOBAL_BLOCK
@ SEARCH_STATIC_BLOCK
std::unique_ptr< quick_symbol_functions > quick_symbol_functions_up
static void create_signatured_type_table_from_debug_names(dwarf2_per_objfile *per_objfile, const mapped_debug_names &map, struct dwarf2_section_info *section, struct dwarf2_section_info *abbrev_section)
static bool create_cus_from_debug_names_list(dwarf2_per_bfd *per_bfd, const mapped_debug_names &map, dwarf2_section_info &section, bool is_dwz)
static bool read_debug_names_from_section(struct objfile *objfile, const char *filename, struct dwarf2_section_info *section, mapped_debug_names &map)
bool dwarf2_read_debug_names(dwarf2_per_objfile *per_objfile)
static bool create_cus_from_debug_names(dwarf2_per_bfd *per_bfd, const mapped_debug_names &map, const mapped_debug_names &dwz_map)
static void create_addrmap_from_aranges(dwarf2_per_objfile *per_objfile, struct dwarf2_section_info *section)
static const gdb_byte dwarf5_augmentation[]
htab_up create_quick_file_names_table(unsigned int nr_initial_entries)
Definition read.c:1710
bool dw2_expand_symtabs_matching_symbol(mapped_index_base &index, const lookup_name_info &lookup_name_in, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< bool(offset_type)> match_callback, dwarf2_per_objfile *per_objfile)
Definition read.c:2477
dwarf2_per_cu_data_up create_cu_from_index_list(dwarf2_per_bfd *per_bfd, struct dwarf2_section_info *section, int is_dwz, sect_offset sect_off, ULONGEST length)
Definition read.c:1826
const char * read_indirect_string_at_offset(dwarf2_per_objfile *per_objfile, LONGEST str_offset)
Definition read.c:17514
void finalize_all_units(dwarf2_per_bfd *per_bfd)
Definition read.c:5271
void dw_expand_symtabs_matching_file_matcher(dwarf2_per_objfile *per_objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher)
Definition read.c:3055
bool read_addrmap_from_aranges(dwarf2_per_objfile *per_objfile, dwarf2_section_info *section, addrmap *mutable_map)
Definition read.c:1842
bool dw2_expand_symtabs_matching_one(dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify)
Definition read.c:3032
htab_up allocate_signatured_type_table()
Definition read.c:3561
dwarf2_per_objfile * get_dwarf2_per_objfile(struct objfile *objfile)
Definition read.c:165
std::unique_ptr< signatured_type > signatured_type_up
Definition read.h:411
std::unique_ptr< dwarf2_per_cu_data, dwarf2_per_cu_data_deleter > dwarf2_per_cu_data_up
Definition read.h:94
const char * dwarf_form_name(unsigned form)
Definition stringify.c:82
cu_offset type_cu_offset_in_tu
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
void dump(struct objfile *objfile) override
htab_up signatured_types
Definition read.h:505
gdb::array_view< dwarf2_per_cu_data_up > all_comp_units
Definition read.h:496
dwarf2_per_cu_data * get_cu(int index) const
Definition read.h:434
std::unique_ptr< dwarf_scanner_base > index_table
Definition read.h:533
gdb::array_view< dwarf2_per_cu_data_up > all_type_units
Definition read.h:497
signatured_type_up allocate_signatured_type(ULONGEST signature)
Definition read.c:1813
std::vector< dwarf2_per_cu_data_up > all_units
Definition read.h:492
struct objfile * objfile
Definition read.h:724
struct dwarf2_per_bfd * per_bfd
Definition read.h:728
bool symtab_set_p(const dwarf2_per_cu_data *per_cu) const
Definition read.c:1323
void read(struct objfile *objfile)
Definition section.c:119
bool empty() const
Definition section.c:111
const gdb_byte * buffer
Definition section.h:115
bfd_size_type size
Definition section.h:117
struct bfd * get_bfd_owner() const
Definition section.c:49
int get_flags() const
Definition section.c:102
Definition dwz.h:32
gdb_bfd_ref_ptr dwz_bfd
Definition dwz.h:54
enum language la_language
Definition language.h:275
const char * namei_to_name(uint32_t namei, dwarf2_per_objfile *per_objfile) const
const gdb_byte * tu_table_reordered
quick_symbol_functions_up make_quick_functions() const override
const gdb_byte * name_table_string_offs_reordered
bfd_endian dwarf5_byte_order
const gdb_byte * entry_pool
const uint32_t * hash_table_reordered
const gdb_byte * cu_table_reordered
size_t symbol_name_count() const override
const uint32_t * bucket_table_reordered
std::unordered_map< ULONGEST, index_val > abbrev_map
const char * symbol_name_at(offset_type idx, dwarf2_per_objfile *per_objfile) const override
const gdb_byte * name_table_entry_offs_reordered
struct gdbarch * arch() const
Definition objfiles.h:507
struct objfile_per_bfd_storage * per_bfd
Definition objfiles.h:744
gdb_bfd_ref_ptr obfd
Definition objfiles.h:740
search_domain
Definition symtab.h:945
@ VARIABLES_DOMAIN
Definition symtab.h:948
@ FUNCTIONS_DOMAIN
Definition symtab.h:951
@ TYPES_DOMAIN
Definition symtab.h:954
@ MODULES_DOMAIN
Definition symtab.h:957
@ ALL_DOMAIN
Definition symtab.h:960
domain_enum
Definition symtab.h:900
@ VAR_DOMAIN
Definition symtab.h:910
@ STRUCT_DOMAIN
Definition symtab.h:916
@ LABEL_DOMAIN
Definition symtab.h:924
@ UNDEF_DOMAIN
Definition symtab.h:905
@ MODULE_DOMAIN
Definition symtab.h:920
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
const char version[]
Definition version.c:2