dwarf2_per_cu_up per_cu = per_bfd->allocate_per_cu (section, sect_off,
length, is_dwz);
units.emplace_back (per_cu.get ());
- per_bfd->all_units.emplace_back (std::move (per_cu));
+ per_bfd->add_unit (std::move (per_cu));
}
}
sig_types_hash.emplace (sig_type.get ());
units.emplace_back (sig_type.get ());
- per_bfd->all_units.emplace_back (std::move (sig_type));
+ per_bfd->add_unit (std::move (sig_type));
}
per_bfd->signatured_types = std::move (sig_types_hash);
false /* is_dwz */, sig);
auto emplace_ret = per_bfd->signatured_types.emplace (sig_type.get ());
- per_bfd->all_units.emplace_back (std::move (sig_type));
+ per_bfd->add_unit (std::move (sig_type));
/* Assert that an insertion took place - that there wasn't a type unit with
that signature already. */
}
info_ptr = info_ptr + this_cu->length ();
- per_bfd->all_units.push_back (std::move (this_cu));
+ per_bfd->add_unit (std::move (this_cu));
}
}
return all_units_less_than (*a, { b->section (),
b->sect_off () });
});
+ this->all_units_sorted = true;
}
/* See read.h. */
/* See read.h. */
+void
+dwarf2_per_cu::set_section (dwarf2_section_info *section)
+{
+ gdb_assert (section != nullptr);
+ gdb_assert (m_section == nullptr);
+ m_section = section;
+ m_per_bfd->all_units_sorted = false;
+}
+
+/* See read.h. */
+
+void
+dwarf2_per_cu::set_sect_off (sect_offset sect_off)
+{
+ gdb_assert (m_sect_off == invalid_sect_offset);
+ m_sect_off = sect_off;
+ m_per_bfd->all_units_sorted = false;
+}
+
+/* See read.h. */
+
void
dwarf2_per_cu::set_lang (enum language lang, dwarf_source_language dw_lang)
{
dwarf2_per_cu *
dwarf2_find_unit (const section_and_offset &start, dwarf2_per_bfd *per_bfd)
{
+ gdb_assert (per_bfd->all_units_sorted);
+
auto it = std::lower_bound (per_bfd->all_units.begin (),
per_bfd->all_units.end (), start,
[] (const dwarf2_per_cu_up &per_cu,
{ return m_section; }
/* Set the section of this unit. */
- void set_section (dwarf2_section_info *section)
- {
- gdb_assert (section != nullptr);
- gdb_assert (m_section == nullptr);
- m_section = section;
- }
+ void set_section (dwarf2_section_info *section);
sect_offset sect_off () const
{ return m_sect_off; }
/* Set the section offset of this unit. */
- void set_sect_off (sect_offset sect_off)
- {
- gdb_assert (m_sect_off == invalid_sect_offset);
- m_sect_off = sect_off;
- }
+ void set_sect_off (sect_offset sect_off);
bool is_dwz () const
{ return m_is_dwz; }
dwarf2_find_containing_unit to be able to perform a binary search. */
void sort_all_units ();
+ /* Clear the all_units vector. */
+ void clear_all_units ()
+ {
+ this->all_units.clear ();
+ this->all_units_sorted = true;
+ }
+
/* Return the separate '.dwz' debug file. If there is no
.gnu_debugaltlink or .debug_sup section in the file, then the
result depends on REQUIRE: if REQUIRE is true, error out; if
This one is used when only the signature is known at creation time. */
signatured_type_up allocate_signatured_type (ULONGEST signature);
+ /* Append UNIT to ALL_UNITS. */
+ void add_unit (dwarf2_per_cu_up unit)
+ {
+ this->all_units_sorted = false;
+ this->all_units.emplace_back (std::move (unit));
+ }
+
/* Map all the DWARF section data needed when scanning
.debug_info. */
void map_info_sections (struct objfile *objfile);
DW_FORM_ref_addr attributes (reference by section offset). */
std::vector<dwarf2_per_cu_up> all_units;
+ /* True if ALL_UNITS is currently sorted according to all_units_less_than.
+ Set by sort_all_units, cleared whenever a unit is added to ALL_UNITS or
+ a unit's sort key (section / sect_off) is modified. */
+ bool all_units_sorted = false;
+
/* Number of compilation and type units in the ALL_UNITS vector. */
unsigned int num_comp_units = 0;
unsigned int num_type_units = 0;
if (m_per_bfd == nullptr)
return;
- m_per_bfd->all_units.clear ();
+ m_per_bfd->clear_all_units ();
m_per_bfd->num_comp_units = 0;
m_per_bfd->num_type_units = 0;
}