]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: remove all_{comp,type}_units views
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 9 Jul 2025 15:35:09 +0000 (11:35 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 1 Aug 2025 04:25:15 +0000 (00:25 -0400)
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>
gdb/dwarf2/index-write.c
gdb/dwarf2/read-debug-names.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 0a3b9d01b5ea789af77fc3718a2caf2869b622a7..0efd6a20e5e42b88c91a412c7ed734c17fdc4527 100644 (file)
@@ -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);
index 4b3f385a950fa1bcdf0976796ac3dc648bdb3d4a..fe09705eb35445254067d0f909c534628fb5d90b 100644 (file)
@@ -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)
     {
index 80f630faeb7dbe706452fc17d310fd04c78b9cce..430246c800792bd8c6edc8605580aabe38ebaf02 100644 (file)
@@ -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.  */
index 3e1ec7baea465b0a85b9bdbe4f67854ae0f3078d..85a042a645a9e71ee3307a0f6966f11399e21d4c 100644 (file)
@@ -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;