shortcuts.append_offset (main_name_offset);
}
+/* Lists of units, split by kind. Each list is sorted by section offset. */
+
+struct unit_lists
+{
+ /* Compilation units. */
+ std::vector<const dwarf2_per_cu *> comp;
+
+ /* Type units. */
+ 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 (); };
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.
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);
/* 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);
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 (),
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 (),