aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2025-07-09 11:35:09 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2025-08-01 00:25:15 -0400
commit3e27b49025ff4cc62a8d028f7de6aa1a53a31df1 (patch)
treee8f475a5fa75d7ca5ed48b1a4af53de50d6a3cea
parentbedd6a7a44f0d02f087595888a6cba44e2f6d1ce (diff)
downloadbinutils-3e27b49025ff4cc62a8d028f7de6aa1a53a31df1.zip
binutils-3e27b49025ff4cc62a8d028f7de6aa1a53a31df1.tar.gz
binutils-3e27b49025ff4cc62a8d028f7de6aa1a53a31df1.tar.bz2
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 <tom@tromey.com>
-rw-r--r--gdb/dwarf2/index-write.c4
-rw-r--r--gdb/dwarf2/read-debug-names.c10
-rw-r--r--gdb/dwarf2/read.c8
-rw-r--r--gdb/dwarf2/read.h5
4 files changed, 9 insertions, 18 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 0a3b9d0..0efd6a2 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 4b3f385..fe09705 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 &section,
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 80f630f..430246c 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<tu_abbrev_offset> 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<dwarf2_per_cu_up> 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 3e1ec7b..85a042a 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<dwarf2_per_cu_up> 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<dwarf2_per_cu_up> all_comp_units;
- gdb::array_view<dwarf2_per_cu_up> 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;