From: Simon Marchi Date: Wed, 9 Jul 2025 15:35:10 +0000 (-0400) Subject: gdb/dwarf: move index unit vectors to .debug_names reader and use them X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5acdeb08eb52cb1dd893853376c380412d5706cb;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: move index unit vectors to .debug_names reader and use them The all_comp_units_index_cus and all_comp_units_index_tus vectors contain the CU and TU lists as found in the .debug_names list. It seems like they are meant to be used by the .debug_names reader when handling a DW_IDX_compile_unit or DW_IDX_type_unit attribute. The value of the attribute would translate directly into an index into one of these vectors. However, it looks like these vectors aren't actually used in practice. They are used in the dwarf2_per_bfd::get_index_{c,t}u methods, which in turn aren't used anywhere. The handlers of DW_IDX_compile_unit and DW_IDX_type_unit use the dwarf2_per_bfd::get_unit method, with the assumption that dwarf2_per_bfd::all_units has comp units before type units. This is not the case: the .debug_names reader creates the units in dwarf2_per_bfd::all_units using the create_all_units function, which creates the units in the order found in .debug_info, where type units can be interleaved with comp units. Since those vectors are specific to the .debug_names reader, move them to the mapped_debug_names_reader struct. Then, update the handlers of DW_IDX_compile_unit and DW_IDX_type_unit to actually use them. Change-Id: Ie7db81f4442f634ac6d02280a60c6c671bcd22a5 Approved-By: Tom Tromey --- diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c index fe09705eb35..e1a6a56646c 100644 --- a/gdb/dwarf2/read-debug-names.c +++ b/gdb/dwarf2/read-debug-names.c @@ -114,6 +114,14 @@ struct mapped_debug_names_reader gdb::unordered_map abbrev_map; + /* List of CUs in the same order as found in the index header (DWARF 5 section + 6.1.1.4.2). */ + std::vector comp_units; + + /* List of local TUs in the same order as found in the index (DWARF 5 section + 6.1.1.4.3). */ + std::vector type_units; + /* Even though the scanning of .debug_names and creation of the cooked index entries is done serially, we create multiple shards so that the finalization step can be parallelized. The shards @@ -232,7 +240,7 @@ mapped_debug_names_reader::scan_one_entry (const char *name, case DW_IDX_compile_unit: { /* Don't crash on bad data. */ - if (ull >= per_objfile->per_bfd->num_comp_units) + if (ull >= this->comp_units.size ()) { complaint (_(".debug_names entry has bad CU index %s" " [in module %s]"), @@ -240,30 +248,31 @@ mapped_debug_names_reader::scan_one_entry (const char *name, bfd_get_filename (abfd)); continue; } + + per_cu = this->comp_units[ull]; + break; } - per_cu = per_objfile->per_bfd->get_unit (ull); - break; case DW_IDX_type_unit: - /* Don't crash on bad data. */ - if (ull >= per_objfile->per_bfd->num_type_units) - { - complaint (_(".debug_names entry has bad TU index %s" - " [in module %s]"), - pulongest (ull), - bfd_get_filename (abfd)); - continue; - } { - int nr_cus = per_objfile->per_bfd->num_comp_units; - per_cu = per_objfile->per_bfd->get_unit (nr_cus + ull); + /* Don't crash on bad data. */ + if (ull >= this->type_units.size ()) + { + complaint (_(".debug_names entry has bad TU index %s" + " [in module %s]"), + pulongest (ull), + bfd_get_filename (abfd)); + continue; + } + + per_cu = this->type_units[ull]; + break; } - break; case DW_IDX_die_offset: die_offset = sect_offset (ull); /* In a per-CU index (as opposed to a per-module index), index entries without CU attribute implicitly refer to the single CU. */ - if (per_cu == NULL) - per_cu = per_objfile->per_bfd->get_unit (0); + if (per_cu == nullptr) + per_cu = this->comp_units[0]; break; case DW_IDX_parent: parent = ull; @@ -440,13 +449,16 @@ cooked_index_worker_debug_names::do_reading () bfd_thread_cleanup (); } -/* Check the signatured type hash table from .debug_names. */ +/* Build the list of TUs (mapped_debug_names_reader::type_units) from the index + header and verify that it matches the list of TUs read from the DIEs in + `.debug_info`. + + Return true if they match, false otherwise. */ static bool -check_signatured_type_table_from_debug_names - (dwarf2_per_objfile *per_objfile, - const mapped_debug_names_reader &map, - struct dwarf2_section_info *section) +build_and_check_tu_list_from_debug_names (dwarf2_per_objfile *per_objfile, + mapped_debug_names_reader &map, + dwarf2_section_info *section) { struct objfile *objfile = per_objfile->objfile; dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; @@ -477,7 +489,8 @@ check_signatured_type_table_from_debug_names " ignoring .debug_names.")); return false; } - per_bfd->all_comp_units_index_tus.push_back (per_bfd->get_unit (j)); + + map.type_units.emplace_back (per_bfd->get_unit (j)); } return true; } @@ -700,10 +713,10 @@ read_debug_names_from_section (dwarf2_per_objfile *per_objfile, list. */ static bool -check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, - const mapped_debug_names_reader &map, - dwarf2_section_info §ion, - bool is_dwz) +build_and_check_cu_list_from_debug_names (dwarf2_per_bfd *per_bfd, + mapped_debug_names_reader &map, + dwarf2_section_info §ion, + bool is_dwz) { int nr_cus = per_bfd->num_comp_units; @@ -730,7 +743,8 @@ check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, " ignoring .debug_names.")); return false; } - per_bfd->all_comp_units_index_cus.push_back (per_bfd->get_unit (j)); + + map.comp_units.emplace_back (per_bfd->get_unit (j)); } return true; } @@ -755,29 +769,35 @@ check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, " ignoring .debug_names.")); return false; } + + map.comp_units.emplace_back (per_bfd->get_unit (i)); } return true; } -/* Read the CU list from the mapped index, and use it to create all - the CU objects for this dwarf2_per_objfile. */ +/* Build the list of CUs (mapped_debug_names_reader::compile_units) from the + index header and verify that it matches the list of CUs read from the DIEs in + `.debug_info`. + + Return true if they match, false otherwise. */ static bool -check_cus_from_debug_names (dwarf2_per_bfd *per_bfd, - const mapped_debug_names_reader &map, - const mapped_debug_names_reader &dwz_map) +build_and_check_cu_lists_from_debug_names (dwarf2_per_bfd *per_bfd, + mapped_debug_names_reader &map, + mapped_debug_names_reader &dwz_map) { - if (!check_cus_from_debug_names_list (per_bfd, map, per_bfd->infos[0], - false /* is_dwz */)) + if (!build_and_check_cu_list_from_debug_names (per_bfd, map, + per_bfd->infos[0], + false /* is_dwz */)) return false; if (dwz_map.cu_count == 0) return true; dwz_file *dwz = per_bfd->get_dwz_file (); - return check_cus_from_debug_names_list (per_bfd, dwz_map, dwz->info, - true /* is_dwz */); + return build_and_check_cu_list_from_debug_names (per_bfd, dwz_map, dwz->info, + true /* is_dwz */); } /* This does all the work for dwarf2_read_debug_names, but putting it @@ -815,7 +835,7 @@ do_dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) } create_all_units (per_objfile); - if (!check_cus_from_debug_names (per_bfd, map, dwz_map)) + if (!build_and_check_cu_lists_from_debug_names (per_bfd, map, dwz_map)) return false; if (map.tu_count != 0) @@ -831,8 +851,8 @@ do_dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile) ? &per_bfd->types[0] : &per_bfd->infos[0]); - if (!check_signatured_type_table_from_debug_names (per_objfile, - map, section)) + if (!build_and_check_tu_list_from_debug_names (per_objfile, map, + section)) return false; } diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 85a042a645a..c718b9ff714 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -520,20 +520,6 @@ struct dwarf2_per_bfd return this->all_units[index].get (); } - /* Return the CU given its index in the CU table in the index. */ - dwarf2_per_cu *get_index_cu (int index) const - { - if (this->all_comp_units_index_cus.empty ()) - return get_unit (index); - - return this->all_comp_units_index_cus[index]; - } - - dwarf2_per_cu *get_index_tu (int index) const - { - return this->all_comp_units_index_tus[index]; - } - /* Return the separate '.dwz' debug file. If there is no .gnu_debugaltlink or .debug_sup section in the file, then the result depends on REQUIRE: if REQUIRE is true, error out; if @@ -622,9 +608,6 @@ public: unsigned int num_comp_units = 0; unsigned int num_type_units = 0; - std::vector all_comp_units_index_cus; - std::vector all_comp_units_index_tus; - /* Set of signatured_types, used to look up by signature. */ signatured_type_set signatured_types;