From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 5/5] gdb/dwarf: add unit_lists structure to index writer
Date: Sat, 17 Jan 2026 01:02:35 -0500 [thread overview]
Message-ID: <20260117060335.691691-6-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260117060335.691691-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@polymtl.ca>
I think it makes the code more readable than the pair of vector. Also,
I'm considering adding a third list (foreigh type units), which will be
easier with the structure.
Change-Id: I38ec4ddf8f786a2ba10c5b371cfe04c2baaa7da9
---
gdb/dwarf2/index-write.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index c4bd424d4340..ffbd3777b4c7 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1314,21 +1314,25 @@ write_shortcuts_table (cooked_index *table, data_buf &shortcuts,
shortcuts.append_offset (main_name_offset);
}
+struct unit_lists
+{
+ std::vector<const dwarf2_per_cu *> comp;
+ std::vector<const signatured_type *> type;
+};
+
/* Get sorted (by section offset) lists of comp units and type units. */
-static std::pair<std::vector<const dwarf2_per_cu *>,
- std::vector<const signatured_type *>>
+static unit_lists
get_unit_lists (const dwarf2_per_bfd &per_bfd)
{
- std::vector<const dwarf2_per_cu *> comp_units;
- std::vector<const signatured_type *> type_units;
+ unit_lists lists;
for (const auto &unit : per_bfd.all_units)
if (const signatured_type *sig_type = unit->as_signatured_type ();
sig_type != nullptr)
- type_units.emplace_back (sig_type);
+ lists.type.emplace_back (sig_type);
else
- comp_units.emplace_back (unit.get ());
+ lists.comp.emplace_back (unit.get ());
auto by_sect_off = [] (const dwarf2_per_cu *lhs, const dwarf2_per_cu *rhs)
{ return lhs->sect_off () < rhs->sect_off (); };
@@ -1342,10 +1346,10 @@ get_unit_lists (const dwarf2_per_bfd &per_bfd)
However, it helps make sure that GDB produce a stable and predictable
output, which is nice. */
- std::sort (comp_units.begin (), comp_units.end (), by_sect_off);
- std::sort (type_units.begin (), type_units.end (), by_sect_off);
+ std::sort (lists.comp.begin (), lists.comp.end (), by_sect_off);
+ std::sort (lists.type.begin (), lists.type.end (), by_sect_off);
- return {std::move (comp_units), std::move (type_units)};
+ return lists;
}
/* Write contents of a .gdb_index section for OBJFILE into OUT_FILE.
@@ -1365,14 +1369,14 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
cu_index_map cu_index_htab;
cu_index_htab.reserve (per_bfd->all_units.size ());
- auto [comp_units, type_units] = get_unit_lists (*per_bfd);
+ unit_lists units = get_unit_lists (*per_bfd);
int counter = 0;
/* Write comp units. */
data_buf objfile_cu_list;
data_buf dwz_cu_list;
- for (const dwarf2_per_cu *per_cu : comp_units)
+ for (const dwarf2_per_cu *per_cu : units.comp)
{
const auto insertpair = cu_index_htab.emplace (per_cu, counter);
gdb_assert (insertpair.second);
@@ -1390,7 +1394,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
/* Write type units. */
data_buf types_cu_list;
- for (const signatured_type *sig_type : type_units)
+ for (const signatured_type *sig_type : units.type)
{
const auto insertpair = cu_index_htab.emplace (sig_type, counter);
gdb_assert (insertpair.second);
@@ -1449,12 +1453,12 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table,
const enum bfd_endian dwarf5_byte_order
= bfd_big_endian (per_bfd->obfd) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
- auto [comp_units, type_units] = get_unit_lists (*per_bfd);
+ 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 : comp_units)
+ for (const auto per_cu : units.comp)
{
nametable.add_cu (per_cu, comp_unit_counter);
comp_unit_list.append_uint (nametable.dwarf5_offset_size (),
@@ -1466,7 +1470,7 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table,
data_buf type_unit_list;
int type_unit_counter = 0;
- for (const auto per_cu : type_units)
+ for (const auto per_cu : units.type)
{
nametable.add_cu (per_cu, type_unit_counter);
type_unit_list.append_uint (nametable.dwarf5_offset_size (),
--
2.52.0
next prev parent reply other threads:[~2026-01-17 6:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-17 6:02 [PATCH 0/5] Some semi-random DWARF cleanups simon.marchi
2026-01-17 6:02 ` [PATCH 1/5] gdb/dwarf: merge one CU/TU code path simon.marchi
2026-01-17 6:02 ` [PATCH 2/5] gdb/dwarf: move DWP htab nullptr check to lookup_dwo_unit_in_dwp simon.marchi
2026-01-17 6:02 ` [PATCH 3/5] gdb/dwarf: add comments to debug_names::build simon.marchi
2026-01-17 6:02 ` [PATCH 4/5] gdb/dwarf: rename some abbrev-related things in debug_names writer simon.marchi
2026-01-17 6:02 ` simon.marchi [this message]
2026-01-20 17:00 ` [PATCH 5/5] gdb/dwarf: add unit_lists structure to index writer Tom Tromey
2026-01-20 17:33 ` Simon Marchi
2026-01-20 20:42 ` Tom Tromey
2026-01-20 21:12 ` Simon Marchi
2026-01-20 17:00 ` [PATCH 0/5] Some semi-random DWARF cleanups Tom Tromey
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=20260117060335.691691-6-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/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