that can be shared across objfiles. The non-shareable parts are in
type_unit_group_unshareable. */
-struct type_unit_group
+struct type_unit_group : public dwarf2_per_cu_data
{
- /* dwarf2read.c's main "handle" on a TU symtab.
- To simplify things we create an artificial CU that "includes" all the
- type units using this stmt_list so that the rest of the code still has
- a "per_cu" handle on the symtab. */
- struct dwarf2_per_cu_data per_cu;
-
/* The TUs that share this DW_AT_stmt_list entry.
This is added to while parsing type units to build partial symtabs,
and is deleted afterwards and not used again. */
- std::vector<signatured_type *> *tus;
+ std::vector<signatured_type *> *tus = nullptr;
/* The data used to construct the hash key. */
- struct stmt_list_hash hash;
+ struct stmt_list_hash hash {};
};
/* These sections are what may appear in a (real or virtual) DWO file. */
dwarf2_per_bfd::~dwarf2_per_bfd ()
{
- for (dwarf2_per_cu_data *per_cu : all_comp_units)
+ for (auto &per_cu : all_comp_units)
per_cu->imported_symtabs_free ();
- for (signatured_type *sig_type : all_type_units)
- sig_type->per_cu.imported_symtabs_free ();
+ for (auto &sig_type : all_type_units)
+ sig_type->imported_symtabs_free ();
/* Everything else should be on this->obstack. */
}
{
index -= this->all_comp_units.size ();
gdb_assert (index < this->all_type_units.size ());
- return &this->all_type_units[index]->per_cu;
+ return this->all_type_units[index].get ();
}
- return this->all_comp_units[index];
+ return this->all_comp_units[index].get ();
}
/* See declaration. */
{
gdb_assert (index >= 0 && index < this->all_comp_units.size ());
- return this->all_comp_units[index];
+ return this->all_comp_units[index].get ();
}
/* See declaration. */
{
gdb_assert (index >= 0 && index < this->all_type_units.size ());
- return this->all_type_units[index];
+ return this->all_type_units[index].get ();
}
/* See read.h. */
-dwarf2_per_cu_data *
+std::unique_ptr<dwarf2_per_cu_data>
dwarf2_per_bfd::allocate_per_cu ()
{
- dwarf2_per_cu_data *result = OBSTACK_ZALLOC (&obstack, dwarf2_per_cu_data);
+ std::unique_ptr<dwarf2_per_cu_data> result (new dwarf2_per_cu_data);
result->per_bfd = this;
result->index = m_num_psymtabs++;
return result;
/* See read.h. */
-signatured_type *
+std::unique_ptr<signatured_type>
dwarf2_per_bfd::allocate_signatured_type ()
{
- signatured_type *result = OBSTACK_ZALLOC (&obstack, signatured_type);
- result->per_cu.per_bfd = this;
- result->per_cu.index = m_num_psymtabs++;
+ std::unique_ptr<signatured_type> result (new signatured_type);
+ result->per_bfd = this;
+ result->index = m_num_psymtabs++;
return result;
}
/* Return a new dwarf2_per_cu_data allocated on the per-bfd
obstack, and constructed with the specified field values. */
-static dwarf2_per_cu_data *
+static std::unique_ptr<dwarf2_per_cu_data>
create_cu_from_index_list (dwarf2_per_bfd *per_bfd,
struct dwarf2_section_info *section,
int is_dwz,
sect_offset sect_off, ULONGEST length)
{
- dwarf2_per_cu_data *the_cu = per_bfd->allocate_per_cu ();
+ std::unique_ptr<dwarf2_per_cu_data> the_cu = per_bfd->allocate_per_cu ();
the_cu->sect_off = sect_off;
the_cu->length = length;
the_cu->section = section;
ULONGEST length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE);
cu_list += 2 * 8;
- dwarf2_per_cu_data *per_cu
+ std::unique_ptr<dwarf2_per_cu_data> per_cu
= create_cu_from_index_list (per_bfd, section, is_dwz, sect_off,
length);
- per_bfd->all_comp_units.push_back (per_cu);
+ per_bfd->all_comp_units.push_back (std::move (per_cu));
}
}
for (offset_type i = 0; i < elements; i += 3)
{
- struct signatured_type *sig_type;
+ std::unique_ptr<signatured_type> sig_type;
ULONGEST signature;
void **slot;
cu_offset type_offset_in_tu;
sig_type = per_bfd->allocate_signatured_type ();
sig_type->signature = signature;
sig_type->type_offset_in_tu = type_offset_in_tu;
- sig_type->per_cu.is_debug_types = 1;
- sig_type->per_cu.section = section;
- sig_type->per_cu.sect_off = sect_off;
- sig_type->per_cu.v.quick
+ sig_type->is_debug_types = 1;
+ sig_type->section = section;
+ sig_type->sect_off = sect_off;
+ sig_type->v.quick
= OBSTACK_ZALLOC (&per_bfd->obstack,
struct dwarf2_per_cu_quick_data);
- slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT);
- *slot = sig_type;
+ slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
+ *slot = sig_type.get ();
- per_bfd->all_type_units.push_back (sig_type);
+ per_bfd->all_type_units.push_back (std::move (sig_type));
}
per_bfd->signatured_types = std::move (sig_types_hash);
for (uint32_t i = 0; i < map.tu_count; ++i)
{
- struct signatured_type *sig_type;
+ std::unique_ptr<signatured_type> sig_type;
void **slot;
sect_offset sect_off
sig_type = per_objfile->per_bfd->allocate_signatured_type ();
sig_type->signature = cu_header.signature;
sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
- sig_type->per_cu.is_debug_types = 1;
- sig_type->per_cu.section = section;
- sig_type->per_cu.sect_off = sect_off;
- sig_type->per_cu.v.quick
+ sig_type->is_debug_types = 1;
+ sig_type->section = section;
+ sig_type->sect_off = sect_off;
+ sig_type->v.quick
= OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack,
struct dwarf2_per_cu_quick_data);
- slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT);
- *slot = sig_type;
+ slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
+ *slot = sig_type.get ();
- per_objfile->per_bfd->all_type_units.push_back (sig_type);
+ per_objfile->per_bfd->all_type_units.push_back (std::move (sig_type));
}
per_objfile->per_bfd->signatured_types = std::move (sig_types_hash);
dwarf2_per_cu_data *,
gdb::hash_enum<sect_offset>>
debug_info_offset_to_per_cu;
- for (dwarf2_per_cu_data *per_cu : per_bfd->all_comp_units)
+ for (const auto &per_cu : per_bfd->all_comp_units)
{
const auto insertpair
- = debug_info_offset_to_per_cu.emplace (per_cu->sect_off, per_cu);
+ = debug_info_offset_to_per_cu.emplace (per_cu->sect_off,
+ per_cu.get ());
if (!insertpair.second)
{
warning (_("Section .debug_aranges in %s has duplicate "
dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- dwarf2_per_cu_data *dwarf_cu = per_objfile->per_bfd->all_comp_units.back ();
+ dwarf2_per_cu_data *dwarf_cu
+ = per_objfile->per_bfd->all_comp_units.back ().get ();
compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu, per_objfile, false);
if (cust == NULL)
/* The rule is CUs specify all the files, including those used by
any TU, so there's no need to scan TUs here. */
- for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+ for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
{
QUIT;
per_cu->v.quick->mark = 0;
/* We only need to look at symtabs not already expanded. */
- if (per_objfile->symtab_set_p (per_cu))
+ if (per_objfile->symtab_set_p (per_cu.get ()))
continue;
- quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
+ quick_file_names *file_data = dw2_get_file_names (per_cu.get (),
+ per_objfile);
if (file_data == NULL)
continue;
if (symbol_matcher == NULL && lookup_name == NULL)
{
- for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+ for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
{
QUIT;
- if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+ if (!dw2_expand_symtabs_matching_one (per_cu.get (), per_objfile,
file_matcher,
expansion_notify))
return false;
reuse the file names data from a currently unexpanded CU, in this
case we don't want to report the files from the unexpanded CU. */
- for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+ for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
{
- if (per_objfile->symtab_set_p (per_cu))
+ if (per_objfile->symtab_set_p (per_cu.get ()))
{
if (per_cu->v.quick->file_names != nullptr)
qfn_cache.insert (per_cu->v.quick->file_names);
}
}
- for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+ for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
{
/* We only need to look at symtabs not already expanded. */
- if (per_objfile->symtab_set_p (per_cu))
+ if (per_objfile->symtab_set_p (per_cu.get ()))
continue;
- quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile);
+ quick_file_names *file_data = dw2_get_file_names (per_cu.get (),
+ per_objfile);
if (file_data == nullptr
|| qfn_cache.find (file_data) != qfn_cache.end ())
continue;
of the next CU as end of this CU. We create the CUs here with
length 0, and in cutu_reader::cutu_reader we'll fill in the
actual length. */
- dwarf2_per_cu_data *per_cu
+ std::unique_ptr<dwarf2_per_cu_data> per_cu
= create_cu_from_index_list (per_bfd, §ion, is_dwz,
sect_off, 0);
- per_bfd->all_comp_units.push_back (per_cu);
+ per_bfd->all_comp_units.push_back (std::move (per_cu));
}
return;
}
if (i >= 1)
{
const ULONGEST length = sect_off_next - sect_off_prev;
- dwarf2_per_cu_data *per_cu
+ std::unique_ptr<dwarf2_per_cu_data> per_cu
= create_cu_from_index_list (per_bfd, §ion, is_dwz,
sect_off_prev, length);
- per_bfd->all_comp_units.push_back (per_cu);
+ per_bfd->all_comp_units.push_back (std::move (per_cu));
}
sect_off_prev = sect_off_next;
}
objfile_name (objfile));
continue;
}
- per_cu = &per_bfd->get_tu (ull)->per_cu;
+ per_cu = per_bfd->get_tu (ull);
break;
case DW_IDX_die_offset:
/* In a per-CU index (as opposed to a per-module index), index
if (symbol_matcher == NULL && lookup_name == NULL)
{
- for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+ for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
{
QUIT;
- if (!dw2_expand_symtabs_matching_one (per_cu, per_objfile,
+ if (!dw2_expand_symtabs_matching_one (per_cu.get (), per_objfile,
file_matcher,
expansion_notify))
return false;
add_signatured_type_cu_to_table (void **slot, void *datum)
{
struct signatured_type *sigt = (struct signatured_type *) *slot;
- std::vector<signatured_type *> *all_type_units
- = (std::vector<signatured_type *> *) datum;
+ std::vector<std::unique_ptr<signatured_type>> *all_type_units
+ = (std::vector<std::unique_ptr<signatured_type>> *) datum;
- all_type_units->push_back (sigt);
+ all_type_units->emplace_back (sigt);
return 1;
}
end_ptr = info_ptr + section->size;
while (info_ptr < end_ptr)
{
- struct signatured_type *sig_type;
+ std::unique_ptr<signatured_type> sig_type;
struct dwo_unit *dwo_tu;
void **slot;
const gdb_byte *ptr = info_ptr;
if (dwo_file)
{
- sig_type = NULL;
dwo_tu = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, dwo_unit);
dwo_tu->dwo_file = dwo_file;
dwo_tu->signature = header.signature;
sig_type = per_objfile->per_bfd->allocate_signatured_type ();
sig_type->signature = header.signature;
sig_type->type_offset_in_tu = header.type_cu_offset_in_tu;
- sig_type->per_cu.is_debug_types = 1;
- sig_type->per_cu.section = section;
- sig_type->per_cu.sect_off = sect_off;
- sig_type->per_cu.length = length;
+ sig_type->is_debug_types = 1;
+ sig_type->section = section;
+ sig_type->sect_off = sect_off;
+ sig_type->length = length;
}
slot = htab_find_slot (types_htab.get (),
- dwo_file ? (void*) dwo_tu : (void *) sig_type,
+ (dwo_file
+ ? (void *) dwo_tu
+ : (void *) sig_type.get ()),
INSERT);
gdb_assert (slot != NULL);
if (*slot != NULL)
const struct signatured_type *dup_tu
= (const struct signatured_type *) *slot;
- dup_sect_off = dup_tu->per_cu.sect_off;
+ dup_sect_off = dup_tu->sect_off;
}
complaint (_("debug type entry at offset %s is duplicate to"
sect_offset_str (sect_off), sect_offset_str (dup_sect_off),
hex_string (header.signature));
}
- *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type;
+ *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type.release ();
dwarf_read_debug_printf_v (" offset %s, signature %s",
sect_offset_str (sect_off),
== per_objfile->per_bfd->all_type_units.capacity ())
++per_objfile->per_bfd->tu_stats.nr_all_type_units_reallocs;
- signatured_type *sig_type = per_objfile->per_bfd->allocate_signatured_type ();
+ std::unique_ptr<signatured_type> sig_type_holder
+ = per_objfile->per_bfd->allocate_signatured_type ();
+ signatured_type *sig_type = sig_type_holder.get ();
per_objfile->resize_symtabs ();
- per_objfile->per_bfd->all_type_units.push_back (sig_type);
+ per_objfile->per_bfd->all_type_units.push_back (std::move (sig_type_holder));
sig_type->signature = sig;
- sig_type->per_cu.is_debug_types = 1;
+ sig_type->is_debug_types = 1;
if (per_objfile->per_bfd->using_index)
{
- sig_type->per_cu.v.quick =
+ sig_type->v.quick =
OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack,
struct dwarf2_per_cu_quick_data);
}
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
/* Make sure we're not clobbering something we don't expect to. */
- gdb_assert (! sig_entry->per_cu.queued);
- gdb_assert (per_objfile->get_cu (&sig_entry->per_cu) == NULL);
+ gdb_assert (! sig_entry->queued);
+ gdb_assert (per_objfile->get_cu (sig_entry) == NULL);
if (per_bfd->using_index)
{
- gdb_assert (sig_entry->per_cu.v.quick != NULL);
- gdb_assert (!per_objfile->symtab_set_p (&sig_entry->per_cu));
+ gdb_assert (sig_entry->v.quick != NULL);
+ gdb_assert (!per_objfile->symtab_set_p (sig_entry));
}
else
- gdb_assert (sig_entry->per_cu.v.psymtab == NULL);
+ gdb_assert (sig_entry->v.psymtab == NULL);
gdb_assert (sig_entry->signature == dwo_entry->signature);
gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0);
gdb_assert (sig_entry->type_unit_group == NULL);
gdb_assert (sig_entry->dwo_unit == NULL);
- sig_entry->per_cu.section = dwo_entry->section;
- sig_entry->per_cu.sect_off = dwo_entry->sect_off;
- sig_entry->per_cu.length = dwo_entry->length;
- sig_entry->per_cu.reading_dwo_directly = 1;
- sig_entry->per_cu.per_bfd = per_bfd;
+ sig_entry->section = dwo_entry->section;
+ sig_entry->sect_off = dwo_entry->sect_off;
+ sig_entry->length = dwo_entry->length;
+ sig_entry->reading_dwo_directly = 1;
+ sig_entry->per_bfd = per_bfd;
sig_entry->type_offset_in_tu = dwo_entry->type_offset_in_tu;
sig_entry->dwo_unit = dwo_entry;
}
/* Have we already tried to read this TU?
Note: sig_entry can be NULL if the skeleton TU was removed (thus it
needn't exist in the global table yet). */
- if (sig_entry != NULL && sig_entry->per_cu.tu_read)
+ if (sig_entry != NULL && sig_entry->tu_read)
return sig_entry;
/* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
sig_entry = add_type_unit (per_objfile, sig, slot);
fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry);
- sig_entry->per_cu.tu_read = 1;
+ sig_entry->tu_read = 1;
return sig_entry;
}
return htab_up (htab_create_alloc (3,
hash_type_unit_group,
eq_type_unit_group,
- NULL, xcalloc, xfree));
+ [] (void *arg)
+ {
+ type_unit_group *grp
+ = (type_unit_group *) arg;
+ delete grp;
+ },
+ xcalloc, xfree));
}
/* Type units that don't have DW_AT_stmt_list are grouped into their own
/* Helper routine for get_type_unit_group.
Create the type_unit_group object used to hold one or more TUs. */
-static struct type_unit_group *
+static std::unique_ptr<type_unit_group>
create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
- struct dwarf2_per_cu_data *per_cu;
- struct type_unit_group *tu_group;
- tu_group = OBSTACK_ZALLOC (&per_bfd->obstack, type_unit_group);
- per_cu = &tu_group->per_cu;
- per_cu->per_bfd = per_bfd;
+ std::unique_ptr<type_unit_group> tu_group (new type_unit_group);
+ tu_group->per_bfd = per_bfd;
if (per_bfd->using_index)
{
- per_cu->v.quick = OBSTACK_ZALLOC (&per_bfd->obstack,
- struct dwarf2_per_cu_quick_data);
+ tu_group->v.quick = OBSTACK_ZALLOC (&per_bfd->obstack,
+ struct dwarf2_per_cu_quick_data);
}
else
{
else
name = string_printf ("<type_units_at_0x%x>", line_offset);
- pst = create_partial_symtab (per_cu, per_objfile, name.c_str ());
+ pst = create_partial_symtab (tu_group.get (), per_objfile,
+ name.c_str ());
pst->anonymous = true;
}
type_unit_group_for_lookup.hash.line_sect_off = (sect_offset) line_offset;
slot = htab_find_slot (per_objfile->per_bfd->type_unit_groups.get (),
&type_unit_group_for_lookup, INSERT);
- if (*slot != NULL)
- {
- tu_group = (struct type_unit_group *) *slot;
- gdb_assert (tu_group != NULL);
- }
- else
+ if (*slot == nullptr)
{
sect_offset line_offset_struct = (sect_offset) line_offset;
- tu_group = create_type_unit_group (cu, line_offset_struct);
- *slot = tu_group;
+ std::unique_ptr<type_unit_group> grp
+ = create_type_unit_group (cu, line_offset_struct);
+ *slot = grp.release ();
++tu_stats->nr_symtabs;
}
+ tu_group = (struct type_unit_group *) *slot;
+ gdb_assert (tu_group != nullptr);
return tu_group;
}
\f
std::vector<tu_abbrev_offset> sorted_by_abbrev;
sorted_by_abbrev.reserve (per_objfile->per_bfd->all_type_units.size ());
- for (signatured_type *sig_type : per_objfile->per_bfd->all_type_units)
+ for (const auto &sig_type : per_objfile->per_bfd->all_type_units)
sorted_by_abbrev.emplace_back
- (sig_type, read_abbrev_offset (per_objfile, sig_type->per_cu.section,
- sig_type->per_cu.sect_off));
+ (sig_type.get (), read_abbrev_offset (per_objfile, sig_type->section,
+ sig_type->sect_off));
std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end (),
sort_tu_by_abbrev_offset);
++tu_stats->nr_uniq_abbrev_tables;
}
- cutu_reader reader (&tu.sig_type->per_cu, per_objfile,
+ cutu_reader reader (tu.sig_type, per_objfile,
abbrev_table.get (), nullptr, false);
if (!reader.dummy_p)
build_type_psymtabs_reader (&reader, reader.info_ptr,
dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) info;
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
struct type_unit_group *tu_group = (struct type_unit_group *) *slot;
- struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu;
- dwarf2_psymtab *pst = per_cu->v.psymtab;
+ dwarf2_psymtab *pst = tu_group->v.psymtab;
int len = (tu_group->tus == nullptr) ? 0 : tu_group->tus->size ();
int i;
gdb_assert (len > 0);
- gdb_assert (per_cu->type_unit_group_p ());
+ gdb_assert (tu_group->type_unit_group_p ());
pst->number_of_dependencies = len;
pst->dependencies = per_bfd->partial_symtabs->allocate_dependencies (len);
for (i = 0; i < len; ++i)
{
struct signatured_type *iter = tu_group->tus->at (i);
- gdb_assert (iter->per_cu.is_debug_types);
- pst->dependencies[i] = iter->per_cu.v.psymtab;
+ gdb_assert (iter->is_debug_types);
+ pst->dependencies[i] = iter->v.psymtab;
iter->type_unit_group = tu_group;
}
*slot = entry;
/* This does the job that build_type_psymtabs_1 would have done. */
- cutu_reader reader (&entry->per_cu, per_objfile, nullptr, nullptr, false);
+ cutu_reader reader (entry, per_objfile, nullptr, nullptr, false);
if (!reader.dummy_p)
build_type_psymtabs_reader (&reader, reader.info_ptr,
reader.comp_unit_die);
static void
set_partial_user (dwarf2_per_objfile *per_objfile)
{
- for (dwarf2_per_cu_data *per_cu : per_objfile->per_bfd->all_comp_units)
+ for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
{
dwarf2_psymtab *pst = per_cu->v.psymtab;
= make_scoped_restore (&per_bfd->partial_symtabs->psymtabs_addrmap,
addrmap_create_mutable (&temp_obstack));
- for (dwarf2_per_cu_data *per_cu : per_bfd->all_comp_units)
+ for (const auto &per_cu : per_bfd->all_comp_units)
{
if (per_cu->v.psymtab != NULL)
/* In case a forward DW_TAG_imported_unit has read the CU already. */
continue;
- process_psymtab_comp_unit (per_cu, per_objfile, false,
+ process_psymtab_comp_unit (per_cu.get (), per_objfile, false,
language_minimal);
}
while (info_ptr < section->buffer + section->size)
{
- struct dwarf2_per_cu_data *this_cu;
+ std::unique_ptr<dwarf2_per_cu_data> this_cu;
sect_offset sect_off = (sect_offset) (info_ptr - section->buffer);
auto sig_type = per_objfile->per_bfd->allocate_signatured_type ();
sig_type->signature = cu_header.signature;
sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
- this_cu = &sig_type->per_cu;
+ this_cu = std::move (sig_type);
}
this_cu->is_debug_types = (cu_header.unit_type == DW_UT_type);
this_cu->sect_off = sect_off;
this_cu->is_dwz = is_dwz;
this_cu->section = section;
- per_objfile->per_bfd->all_comp_units.push_back (this_cu);
-
info_ptr = info_ptr + this_cu->length;
+ per_objfile->per_bfd->all_comp_units.push_back (std::move (this_cu));
}
}
void **slot;
sect_offset sect_off = (sect_offset) (info_ptr - section.buffer);
- memset (&per_cu, 0, sizeof (per_cu));
per_cu.per_bfd = per_bfd;
per_cu.is_debug_types = 0;
per_cu.sect_off = sect_offset (info_ptr - section.buffer);
if (sig_type != NULL)
{
- struct dwarf2_per_cu_data *sig_cu = &sig_type->per_cu;
-
/* We pass NULL for DEPENDENT_CU because we don't yet know if there's
a real dependency of PER_CU on SIG_TYPE. That is detected later
while processing PER_CU. */
- if (maybe_queue_comp_unit (NULL, sig_cu, cu->per_objfile, cu->language))
- load_full_type_unit (sig_cu, cu->per_objfile);
- cu->per_cu->imported_symtabs_push (sig_cu);
+ if (maybe_queue_comp_unit (NULL, sig_type, cu->per_objfile,
+ cu->language))
+ load_full_type_unit (sig_type, cu->per_objfile);
+ cu->per_cu->imported_symtabs_push (sig_type);
}
return 1;
Even if maybe_queue_comp_unit doesn't require us to load the CU's DIEs,
it doesn't mean they are currently loaded. Since we require them
to be loaded, we must check for ourselves. */
- if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, per_objfile,
+ if (maybe_queue_comp_unit (*ref_cu, sig_type, per_objfile,
language_minimal)
- || per_objfile->get_cu (&sig_type->per_cu) == nullptr)
+ || per_objfile->get_cu (sig_type) == nullptr)
read_signatured_type (sig_type, per_objfile);
- sig_cu = per_objfile->get_cu (&sig_type->per_cu);
+ sig_cu = per_objfile->get_cu (sig_type);
gdb_assert (sig_cu != NULL);
gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
temp_die.sect_off = sig_type->type_offset_in_section;
read_signatured_type (signatured_type *sig_type,
dwarf2_per_objfile *per_objfile)
{
- struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu;
-
- gdb_assert (per_cu->is_debug_types);
- gdb_assert (per_objfile->get_cu (per_cu) == nullptr);
+ gdb_assert (sig_type->is_debug_types);
+ gdb_assert (per_objfile->get_cu (sig_type) == nullptr);
- cutu_reader reader (per_cu, per_objfile, nullptr, nullptr, false);
+ cutu_reader reader (sig_type, per_objfile, nullptr, nullptr, false);
if (!reader.dummy_p)
{
reader.keep ();
}
- sig_type->per_cu.tu_read = 1;
+ sig_type->tu_read = 1;
}
/* Decode simple location descriptions.
dwarf2_find_containing_comp_unit
(sect_offset sect_off,
unsigned int offset_in_dwz,
- const std::vector<dwarf2_per_cu_data *> &all_comp_units)
+ const std::vector<std::unique_ptr<dwarf2_per_cu_data>> &all_comp_units)
{
int low, high;
struct dwarf2_per_cu_data *mid_cu;
int mid = low + (high - low) / 2;
- mid_cu = all_comp_units[mid];
+ mid_cu = all_comp_units[mid].get ();
if (mid_cu->is_dwz > offset_in_dwz
|| (mid_cu->is_dwz == offset_in_dwz
&& mid_cu->sect_off + mid_cu->length > sect_off))
{
int low = dwarf2_find_containing_comp_unit
(sect_off, offset_in_dwz, per_objfile->per_bfd->all_comp_units);
- dwarf2_per_cu_data *this_cu = per_objfile->per_bfd->all_comp_units[low];
+ dwarf2_per_cu_data *this_cu
+ = per_objfile->per_bfd->all_comp_units[low].get ();
if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
{
gdb_assert (per_objfile->per_bfd->all_comp_units[low-1]->sect_off
<= sect_off);
- return per_objfile->per_bfd->all_comp_units[low-1];
+ return per_objfile->per_bfd->all_comp_units[low - 1].get ();
}
else
{
static void
run_test ()
{
- struct dwarf2_per_cu_data one {};
- struct dwarf2_per_cu_data two {};
- struct dwarf2_per_cu_data three {};
- struct dwarf2_per_cu_data four {};
-
- one.length = 5;
- two.sect_off = sect_offset (one.length);
- two.length = 7;
-
- three.length = 5;
- three.is_dwz = 1;
- four.sect_off = sect_offset (three.length);
- four.length = 7;
- four.is_dwz = 1;
-
- std::vector<dwarf2_per_cu_data *> units;
- units.push_back (&one);
- units.push_back (&two);
- units.push_back (&three);
- units.push_back (&four);
+ std::unique_ptr<dwarf2_per_cu_data> one (new dwarf2_per_cu_data);
+ dwarf2_per_cu_data *one_ptr = one.get ();
+ std::unique_ptr<dwarf2_per_cu_data> two (new dwarf2_per_cu_data);
+ dwarf2_per_cu_data *two_ptr = two.get ();
+ std::unique_ptr<dwarf2_per_cu_data> three (new dwarf2_per_cu_data);
+ dwarf2_per_cu_data *three_ptr = three.get ();
+ std::unique_ptr<dwarf2_per_cu_data> four (new dwarf2_per_cu_data);
+ dwarf2_per_cu_data *four_ptr = four.get ();
+
+ one->length = 5;
+ two->sect_off = sect_offset (one->length);
+ two->length = 7;
+
+ three->length = 5;
+ three->is_dwz = 1;
+ four->sect_off = sect_offset (three->length);
+ four->length = 7;
+ four->is_dwz = 1;
+
+ std::vector<std::unique_ptr<dwarf2_per_cu_data>> units;
+ units.push_back (std::move (one));
+ units.push_back (std::move (two));
+ units.push_back (std::move (three));
+ units.push_back (std::move (four));
int result;
result = dwarf2_find_containing_comp_unit (sect_offset (0), 0, units);
- SELF_CHECK (units[result] == &one);
+ SELF_CHECK (units[result].get () == one_ptr);
result = dwarf2_find_containing_comp_unit (sect_offset (3), 0, units);
- SELF_CHECK (units[result] == &one);
+ SELF_CHECK (units[result].get () == one_ptr);
result = dwarf2_find_containing_comp_unit (sect_offset (5), 0, units);
- SELF_CHECK (units[result] == &two);
+ SELF_CHECK (units[result].get () == two_ptr);
result = dwarf2_find_containing_comp_unit (sect_offset (0), 1, units);
- SELF_CHECK (units[result] == &three);
+ SELF_CHECK (units[result].get () == three_ptr);
result = dwarf2_find_containing_comp_unit (sect_offset (3), 1, units);
- SELF_CHECK (units[result] == &three);
+ SELF_CHECK (units[result].get () == three_ptr);
result = dwarf2_find_containing_comp_unit (sect_offset (5), 1, units);
- SELF_CHECK (units[result] == &four);
+ SELF_CHECK (units[result].get () == four_ptr);
}
}