From ae2a50a9ae15c6a7fdb1f6255bb9bf45ad2a67d4 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 10 Mar 2025 14:55:12 -0400 Subject: attempt to revamp to the CU/TU list Change-Id: I1c8214413583d540c10c9a2322ef2a21f8bb54e7 --- gdb/dwarf2/index-write.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'gdb/dwarf2/index-write.c') 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 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); -- cgit v1.1