]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: use enumerate in index-write.c
authorSimon Marchi <simon.marchi@polymtl.ca>
Sat, 21 Feb 2026 01:18:59 +0000 (20:18 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 16 Apr 2026 19:43:55 +0000 (15:43 -0400)
Use the new enumerate util to get rid of some manual counters.

Change-Id: I0573f0890e9b775a5181d8c0d435bb7ba661cae4

gdb/dwarf2/index-write.c

index 82c4645a26549de0653c51910e510fb734dd8351..0f940920862f8425cfef57f17526b8e4997b5431 100644 (file)
@@ -24,6 +24,7 @@
 #include "cli/cli-decode.h"
 #include "exceptions.h"
 #include "gdbsupport/byte-vector.h"
+#include "gdbsupport/enumerate.h"
 #include "gdbsupport/filestuff.h"
 #include "gdbsupport/gdb_unlinker.h"
 #include "gdbsupport/pathstuff.h"
@@ -1496,32 +1497,28 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table,
   unit_lists units = get_unit_lists (*per_bfd);
   debug_names nametable (per_bfd, dwarf5_is_dwarf64, dwarf5_byte_order);
   data_buf comp_unit_list;
-  int comp_unit_counter = 0;
 
-  for (const auto per_cu : units.comp)
+  for (auto [i, per_cu] : gdb::ranges::views::enumerate (units.comp))
     {
-      nametable.add_cu (per_cu, comp_unit_counter);
+      nametable.add_cu (per_cu, i);
       comp_unit_list.append_uint (nametable.dwarf5_offset_size (),
                                  dwarf5_byte_order,
                                  to_underlying (per_cu->sect_off ()));
-      comp_unit_counter++;
     }
 
   data_buf type_unit_list;
-  int type_unit_counter = 0;
 
-  for (const auto per_cu : units.type)
+  for (auto [i, per_cu] : gdb::ranges::views::enumerate (units.type))
     {
-      nametable.add_cu (per_cu, type_unit_counter);
+      nametable.add_cu (per_cu, i);
       type_unit_list.append_uint (nametable.dwarf5_offset_size (),
                                  dwarf5_byte_order,
                                  to_underlying (per_cu->sect_off ()));
-      type_unit_counter++;
     }
 
-   /* Verify that all units are represented.  */
-  gdb_assert (comp_unit_counter == per_bfd->num_comp_units);
-  gdb_assert (type_unit_counter == per_bfd->num_type_units);
+  /* Verify that all units are represented.  */
+  gdb_assert (units.comp.size () == per_bfd->num_comp_units);
+  gdb_assert (units.type.size () == per_bfd->num_type_units);
 
   for (const cooked_index_entry *entry : table->all_entries ())
     nametable.insert (entry);
@@ -1560,11 +1557,11 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table,
   header.append_uint (2, dwarf5_byte_order, 0);
 
   /* comp_unit_count - The number of CUs in the CU list.  */
-  header.append_uint (4, dwarf5_byte_order, comp_unit_counter);
+  header.append_uint (4, dwarf5_byte_order, units.comp.size ());
 
   /* local_type_unit_count - The number of TUs in the local TU
      list.  */
-  header.append_uint (4, dwarf5_byte_order, type_unit_counter);
+  header.append_uint (4, dwarf5_byte_order, units.type.size ());
 
   /* foreign_type_unit_count - The number of TUs in the foreign TU
      list.  */