aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/index-write.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2025-03-10 14:55:12 -0400
committerSimon Marchi <simon.marchi@efficios.com>2025-03-10 16:09:02 -0400
commitae2a50a9ae15c6a7fdb1f6255bb9bf45ad2a67d4 (patch)
tree79e687a3561e856f901a21c99ec9d68ec387819f /gdb/dwarf2/index-write.c
parente9386435c94f10c3d047142fdb9b85f1486e2f14 (diff)
downloadbinutils-ae2a50a9ae15c6a7fdb1f6255bb9bf45ad2a67d4.zip
binutils-ae2a50a9ae15c6a7fdb1f6255bb9bf45ad2a67d4.tar.gz
binutils-ae2a50a9ae15c6a7fdb1f6255bb9bf45ad2a67d4.tar.bz2
attempt to revamp to the CU/TU list
Change-Id: I1c8214413583d540c10c9a2322ef2a21f8bb54e7
Diffstat (limited to 'gdb/dwarf2/index-write.c')
-rw-r--r--gdb/dwarf2/index-write.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 8fb5931..ddb8517 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1313,13 +1313,28 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
/* Store out the .debug_type CUs, if any. */
data_buf types_cu_list;
- /* The CU list is already sorted, so we don't need to do additional
- work here. */
+ /* dwarf_per_bfd::all_units is not necessarily sorted as needed in .gdb_index,
+ so sort it here. */
+ std::vector<dwarf2_per_cu *> units;
+
+ for (const auto &per_cu : per_bfd->all_units)
+ units.emplace_back (per_cu.get ());
+
+ std::sort (units.begin (), units.end (),
+ [] (const dwarf2_per_cu *a, const dwarf2_per_cu *b)
+ {
+ /* Comp units go before type units. */
+ if (a->is_debug_types != b->is_debug_types)
+ return a->is_debug_types < b->is_debug_types;
+
+ /* Then, sort by section offset. */
+ return a->sect_off < b->sect_off;
+ });
int counter = 0;
- for (const dwarf2_per_cu_up &per_cu : per_bfd->all_units)
+ for (const dwarf2_per_cu *per_cu : units)
{
- const auto insertpair = cu_index_htab.emplace (per_cu.get (), counter);
+ const auto insertpair = cu_index_htab.emplace (per_cu, counter);
gdb_assert (insertpair.second);
/* See enhancement PR symtab/30838. */
@@ -1335,7 +1350,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table,
to_underlying (per_cu->sect_off));
if (per_cu->is_debug_types)
{
- signatured_type *sig_type = (signatured_type *) per_cu.get ();
+ const signatured_type *sig_type = (const signatured_type *) per_cu;
cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
to_underlying (sig_type->type_offset_in_tu));
cu_list.append_uint (8, BFD_ENDIAN_LITTLE,
@@ -1411,8 +1426,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);