From 3e27b49025ff4cc62a8d028f7de6aa1a53a31df1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 9 Jul 2025 11:35:09 -0400 Subject: [PATCH] gdb/dwarf: remove all_{comp,type}_units views In DWARF 5, type units appear in the .debug_info section, interleaved with comp units, and the order in all_units reflects that. The all_comp_units and all_type_units views are wrong in that case (all_comp_units contains some type units, and vice-versa). It would be possible to manually sort all_units to ensure that type units follow comp units, but this series takes the approach of sorting the units by section and section offset. Remove those views, and replace their uses with num_comp_units and num_type_units. It appears that the views were only used to know the number of each kind. The finalize_all_units function is now empty, but I am keeping it because a subsequent patch adds a call to std::sort in there to sort the all_units vector. Change-Id: I42a65b6f1b6192957b55cea0e2eaff097e13a33b Approved-By: Tom Tromey --- gdb/dwarf2/index-write.c | 4 ++-- gdb/dwarf2/read-debug-names.c | 10 +++++----- gdb/dwarf2/read.c | 8 ++------ gdb/dwarf2/read.h | 5 ----- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 0a3b9d01b5e..0efd6a20e5e 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1409,8 +1409,8 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table, } /* Verify that all units are represented. */ - gdb_assert (counter == per_bfd->all_comp_units.size ()); - gdb_assert (types_counter == per_bfd->all_type_units.size ()); + gdb_assert (counter == per_bfd->num_comp_units); + gdb_assert (types_counter == per_bfd->num_type_units); for (const cooked_index_entry *entry : table->all_entries ()) nametable.insert (entry); diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c index 4b3f385a950..fe09705eb35 100644 --- a/gdb/dwarf2/read-debug-names.c +++ b/gdb/dwarf2/read-debug-names.c @@ -232,7 +232,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->all_comp_units.size ()) + if (ull >= per_objfile->per_bfd->num_comp_units) { complaint (_(".debug_names entry has bad CU index %s" " [in module %s]"), @@ -245,7 +245,7 @@ mapped_debug_names_reader::scan_one_entry (const char *name, break; case DW_IDX_type_unit: /* Don't crash on bad data. */ - if (ull >= per_objfile->per_bfd->all_type_units.size ()) + if (ull >= per_objfile->per_bfd->num_type_units) { complaint (_(".debug_names entry has bad TU index %s" " [in module %s]"), @@ -254,7 +254,7 @@ mapped_debug_names_reader::scan_one_entry (const char *name, continue; } { - int nr_cus = per_objfile->per_bfd->all_comp_units.size (); + int nr_cus = per_objfile->per_bfd->num_comp_units; per_cu = per_objfile->per_bfd->get_unit (nr_cus + ull); } break; @@ -450,7 +450,7 @@ check_signatured_type_table_from_debug_names { struct objfile *objfile = per_objfile->objfile; dwarf2_per_bfd *per_bfd = per_objfile->per_bfd; - int nr_cus = per_bfd->all_comp_units.size (); + int nr_cus = per_bfd->num_comp_units; int nr_cus_tus = per_bfd->all_units.size (); section->read (objfile); @@ -705,7 +705,7 @@ check_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd, dwarf2_section_info §ion, bool is_dwz) { - int nr_cus = per_bfd->all_comp_units.size (); + int nr_cus = per_bfd->num_comp_units; if (!map.augmentation_is_gdb) { diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 80f630faeb7..430246c8007 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3367,7 +3367,7 @@ cooked_index_worker_debug_info::process_type_units abbrev_table_up abbrev_table; sect_offset abbrev_offset; - if (per_objfile->per_bfd->all_type_units.size () == 0) + if (per_objfile->per_bfd->num_type_units == 0) return; /* TUs typically share abbrev tables, and there can be way more TUs than @@ -3394,7 +3394,7 @@ cooked_index_worker_debug_info::process_type_units /* Sort in a separate table to maintain the order of all_units for .gdb_index: TU indices directly index all_type_units. */ std::vector sorted_by_abbrev; - sorted_by_abbrev.reserve (per_objfile->per_bfd->all_type_units.size ()); + sorted_by_abbrev.reserve (per_objfile->per_bfd->num_type_units); for (const auto &cu : per_objfile->per_bfd->all_units) if (cu->is_debug_types) @@ -3651,10 +3651,6 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile, void finalize_all_units (dwarf2_per_bfd *per_bfd) { - gdb::array_view tmp = per_bfd->all_units; - per_bfd->all_comp_units = tmp.slice (0, per_bfd->num_comp_units); - per_bfd->all_type_units - = tmp.slice (per_bfd->num_comp_units, per_bfd->num_type_units); } /* See read.h. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 3e1ec7baea4..85a042a645a 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -618,11 +618,6 @@ public: the target compilation unit of a particular reference. */ std::vector all_units; - /* The all_units vector contains both CUs and TUs. Provide views on the - vector that are limited to either the CU part or the TU part. */ - gdb::array_view all_comp_units; - gdb::array_view all_type_units; - /* Number of compilation and type units in the ALL_UNITS vector. */ unsigned int num_comp_units = 0; unsigned int num_type_units = 0; -- 2.47.2