From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/3] gdb/dwarf: use enumerate in index-write.c
Date: Fri, 20 Feb 2026 15:19:42 -0500 [thread overview]
Message-ID: <20260220202002.860008-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260220202002.860008-1-simon.marchi@efficios.com>
From: Simon Marchi <simon.marchi@polymtl.ca>
Use the new enumerate util to get rid of some manual counters.
Change-Id: I0573f0890e9b775a5181d8c0d435bb7ba661cae4
---
gdb/dwarf2/index-write.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index c4e75898f4c0..66beff663072 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -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"
@@ -1461,32 +1462,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::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::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);
@@ -1525,11 +1522,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. */
--
2.53.0
next prev parent reply other threads:[~2026-02-20 20:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-20 20:19 [PATCH 1/3] gdbsupport: add gdb::enumerate util Simon Marchi
2026-02-20 20:19 ` Simon Marchi [this message]
2026-02-20 20:19 ` [PATCH 3/3] gdb: use enumerate in gdbtypes.c Simon Marchi
2026-02-20 20:47 ` [PATCH 1/3] gdbsupport: add gdb::enumerate util Tom Tromey
2026-02-21 0:58 ` Simon Marchi
2026-02-21 1:18 ` [PATCH v2 1/3] gdbsupport: add gdb::ranges::views::enumerate util simon.marchi
2026-02-21 1:18 ` [PATCH v2 2/3] gdb/dwarf: use enumerate in index-write.c simon.marchi
2026-02-21 1:19 ` [PATCH v2 3/3] gdb: use enumerate in gdbtypes.c simon.marchi
2026-03-14 17:32 ` [PATCH v2 1/3] gdbsupport: add gdb::ranges::views::enumerate util Simon Marchi
2026-04-16 19:52 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260220202002.860008-2-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox