for (dwarf2_per_cu_data *per_cu : all_comp_units)
VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs);
- for (int ix = 0; ix < n_type_units; ++ix)
- VEC_free (dwarf2_per_cu_ptr,
- all_type_units[ix]->per_cu.imported_symtabs);
- xfree (all_type_units);
+ for (signatured_type *sig_type : all_type_units)
+ VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs);
VEC_free (dwarf2_section_info_def, types);
if (index >= this->all_comp_units.size ())
{
index -= this->all_comp_units.size ();
- gdb_assert (index < this->n_type_units);
+ gdb_assert (index < this->all_type_units.size ());
return &this->all_type_units[index]->per_cu;
}
signatured_type *
dwarf2_per_objfile::get_tu (int index)
{
- gdb_assert (index >= 0 && index < this->n_type_units);
+ gdb_assert (index >= 0 && index < this->all_type_units.size ());
return this->all_type_units[index];
}
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
- dwarf2_per_objfile->n_type_units
- = dwarf2_per_objfile->n_allocated_type_units
- = elements / 3;
- dwarf2_per_objfile->all_type_units =
- XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
+ gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
+ dwarf2_per_objfile->all_type_units.reserve (elements / 3);
htab_t sig_types_hash = allocate_signatured_type_table (objfile);
slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
*slot = sig_type;
- dwarf2_per_objfile->all_type_units[i / 3] = sig_type;
+ dwarf2_per_objfile->all_type_units.push_back (sig_type);
}
dwarf2_per_objfile->signatured_types = sig_types_hash;
dwarf2_read_section (objfile, section);
dwarf2_read_section (objfile, abbrev_section);
- dwarf2_per_objfile->n_type_units
- = dwarf2_per_objfile->n_allocated_type_units
- = map.tu_count;
- dwarf2_per_objfile->all_type_units
- = XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
+ gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
+ dwarf2_per_objfile->all_type_units.reserve (map.tu_count);
htab_t sig_types_hash = allocate_signatured_type_table (objfile);
slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
*slot = sig_type;
- dwarf2_per_objfile->all_type_units[i] = sig_type;
+ dwarf2_per_objfile->all_type_units.push_back (sig_type);
}
dwarf2_per_objfile->signatured_types = sig_types_hash;
/* A helper function that reads the .gdb_index from SECTION and fills
in MAP. FILENAME is the name of the file containing the section;
- it is used for error reporting. DEPRECATED_OK is nonzero if it is
+ it is used for error reporting. DEPRECATED_OK is true if it is
ok to use deprecated sections.
CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
Returns 1 if all went well, 0 otherwise. */
-static int
+static bool
read_index_from_section (struct objfile *objfile,
const char *filename,
- int deprecated_ok,
+ bool deprecated_ok,
struct dwarf2_section_info *section,
struct mapped_index *map,
const gdb_byte **cu_list,
/* Don't crash on bad data. */
if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units))
+ + dwarf2_per_objfile->all_type_units.size ()))
{
complaint (&symfile_complaints,
_(".gdb_index entry has bad CU index"
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
int total = (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units);
+ + dwarf2_per_objfile->all_type_units.size ());
int count = 0;
for (int i = 0; i < total; ++i)
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);
int total_units = (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units);
+ + dwarf2_per_objfile->all_type_units.size ());
for (int i = 0; i < total_units; ++i)
{
DISABLE_COPY_AND_ASSIGN (mock_mapped_index);
/* Return the number of names in the symbol table. */
- virtual size_t symbol_name_count () const
+ size_t symbol_name_count () const override
{
return m_symbol_table.size ();
}
/* Get the name of the symbol at IDX in the symbol table. */
- virtual const char *symbol_name_at (offset_type idx) const
+ const char *symbol_name_at (offset_type idx) const override
{
return m_symbol_table[idx];
}
/* Don't crash on bad data. */
if (cu_index >= (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units))
+ + dwarf2_per_objfile->all_type_units.size ()))
{
complaint (&symfile_complaints,
_(".gdb_index entry has bad CU index"
break;
case DW_IDX_type_unit:
/* Don't crash on bad data. */
- if (ull >= dwarf2_per_objfile->n_type_units)
+ if (ull >= dwarf2_per_objfile->all_type_units.size ())
{
complaint (&symfile_complaints,
_(".debug_names entry has bad TU index %s"
(dwarf2_per_objfile->all_comp_units.size ());
for (int i = 0; i < (dwarf2_per_objfile->all_comp_units.size ()
- + dwarf2_per_objfile->n_type_units); ++i)
+ + dwarf2_per_objfile->all_type_units.size ()); ++i)
{
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
add_signatured_type_cu_to_table (void **slot, void *datum)
{
struct signatured_type *sigt = (struct signatured_type *) *slot;
- struct signatured_type ***datap = (struct signatured_type ***) datum;
+ std::vector<signatured_type *> *all_type_units
+ = (std::vector<signatured_type *> *) datum;
- **datap = sigt;
- ++*datap;
+ all_type_units->push_back (sigt);
return 1;
}
create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
htab_t types_htab = NULL;
- struct signatured_type **iter;
create_debug_type_hash_table (dwarf2_per_objfile, NULL,
&dwarf2_per_objfile->info, types_htab,
dwarf2_per_objfile->signatured_types = types_htab;
- dwarf2_per_objfile->n_type_units
- = dwarf2_per_objfile->n_allocated_type_units
- = htab_elements (types_htab);
- dwarf2_per_objfile->all_type_units =
- XNEWVEC (struct signatured_type *, dwarf2_per_objfile->n_type_units);
- iter = &dwarf2_per_objfile->all_type_units[0];
- htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter);
- gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0]
- == dwarf2_per_objfile->n_type_units);
+ gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
+ dwarf2_per_objfile->all_type_units.reserve (htab_elements (types_htab));
+
+ htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table,
+ &dwarf2_per_objfile->all_type_units);
return 1;
}
void **slot)
{
struct objfile *objfile = dwarf2_per_objfile->objfile;
- int n_type_units = dwarf2_per_objfile->n_type_units;
- struct signatured_type *sig_type;
- gdb_assert (n_type_units <= dwarf2_per_objfile->n_allocated_type_units);
- ++n_type_units;
- if (n_type_units > dwarf2_per_objfile->n_allocated_type_units)
- {
- if (dwarf2_per_objfile->n_allocated_type_units == 0)
- dwarf2_per_objfile->n_allocated_type_units = 1;
- dwarf2_per_objfile->n_allocated_type_units *= 2;
- dwarf2_per_objfile->all_type_units
- = XRESIZEVEC (struct signatured_type *,
- dwarf2_per_objfile->all_type_units,
- dwarf2_per_objfile->n_allocated_type_units);
- ++dwarf2_per_objfile->tu_stats.nr_all_type_units_reallocs;
- }
- dwarf2_per_objfile->n_type_units = n_type_units;
+ if (dwarf2_per_objfile->all_type_units.size ()
+ == dwarf2_per_objfile->all_type_units.capacity ())
+ ++dwarf2_per_objfile->tu_stats.nr_all_type_units_reallocs;
- sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
- struct signatured_type);
- dwarf2_per_objfile->all_type_units[n_type_units - 1] = sig_type;
+ signatured_type *sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+ struct signatured_type);
+
+ dwarf2_per_objfile->all_type_units.push_back (sig_type);
sig_type->signature = sig;
sig_type->per_cu.is_debug_types = 1;
if (dwarf2_per_objfile->using_index)
struct tu_abbrev_offset
{
- struct signatured_type *sig_type;
+ tu_abbrev_offset (signatured_type *sig_type_, sect_offset abbrev_offset_)
+ : sig_type (sig_type_), abbrev_offset (abbrev_offset_)
+ {}
+
+ signatured_type *sig_type;
sect_offset abbrev_offset;
};
struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
abbrev_table_up abbrev_table;
sect_offset abbrev_offset;
- int i;
/* It's up to the caller to not call us multiple times. */
gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL);
- if (dwarf2_per_objfile->n_type_units == 0)
+ if (dwarf2_per_objfile->all_type_units.empty ())
return;
/* TUs typically share abbrev tables, and there can be way more TUs than
/* Sort in a separate table to maintain the order of all_type_units
for .gdb_index: TU indices directly index all_type_units. */
- std::vector<struct tu_abbrev_offset> sorted_by_abbrev
- (dwarf2_per_objfile->n_type_units);
- for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
- {
- struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i];
+ std::vector<tu_abbrev_offset> sorted_by_abbrev;
+ sorted_by_abbrev.reserve (dwarf2_per_objfile->all_type_units.size ());
+
+ for (signatured_type *sig_type : dwarf2_per_objfile->all_type_units)
+ sorted_by_abbrev.emplace_back
+ (sig_type, read_abbrev_offset (dwarf2_per_objfile,
+ sig_type->per_cu.section,
+ sig_type->per_cu.sect_off));
- sorted_by_abbrev[i].sig_type = sig_type;
- sorted_by_abbrev[i].abbrev_offset =
- read_abbrev_offset (dwarf2_per_objfile,
- sig_type->per_cu.section,
- sig_type->per_cu.sect_off);
- }
std::sort (sorted_by_abbrev.begin (), sorted_by_abbrev.end (),
sort_tu_by_abbrev_offset);
abbrev_offset = (sect_offset) ~(unsigned) 0;
- for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i)
+ for (const tu_abbrev_offset &tu : sorted_by_abbrev)
{
- const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i];
-
/* Switch to the next abbrev table if necessary. */
if (abbrev_table == NULL
- || tu->abbrev_offset != abbrev_offset)
+ || tu.abbrev_offset != abbrev_offset)
{
- abbrev_offset = tu->abbrev_offset;
+ abbrev_offset = tu.abbrev_offset;
abbrev_table =
abbrev_table_read_table (dwarf2_per_objfile,
&dwarf2_per_objfile->abbrev,
++tu_stats->nr_uniq_abbrev_tables;
}
- init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table.get (),
+ init_cutu_and_read_dies (&tu.sig_type->per_cu, abbrev_table.get (),
0, 0, build_type_psymtabs_reader, NULL);
}
}
struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats;
fprintf_unfiltered (gdb_stdlog, "Type unit statistics:\n");
- fprintf_unfiltered (gdb_stdlog, " %d TUs\n",
- dwarf2_per_objfile->n_type_units);
+ fprintf_unfiltered (gdb_stdlog, " %zu TUs\n",
+ dwarf2_per_objfile->all_type_units.size ());
fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n",
tu_stats->nr_uniq_abbrev_tables);
fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n",
TYPE_FIELDS (union_type)
= (struct field *) TYPE_ZALLOC (type, 3 * sizeof (struct field));
TYPE_LENGTH (union_type) = TYPE_LENGTH (type);
+ set_type_align (union_type, TYPE_RAW_ALIGN (type));
/* Put the discriminant must at index 0. */
TYPE_FIELD_TYPE (union_type, 0) = field_type;
TYPE_CODE (union_type) = TYPE_CODE_UNION;
TYPE_NFIELDS (union_type) = TYPE_NFIELDS (type);
TYPE_LENGTH (union_type) = TYPE_LENGTH (type);
+ set_type_align (union_type, TYPE_RAW_ALIGN (type));
TYPE_FIELDS (union_type) = TYPE_FIELDS (type);
struct type *field_type = TYPE_FIELD_TYPE (union_type, 0);
{
disr_type = TYPE_FIELD_TYPE (type, i);
- if (TYPE_NFIELDS (disr_type) == 0)
+ if (TYPE_CODE (disr_type) != TYPE_CODE_STRUCT)
+ {
+ /* All fields of a true enum will be structs. */
+ return;
+ }
+ else if (TYPE_NFIELDS (disr_type) == 0)
{
/* Could be data-less variant, so keep going. */
+ disr_type = nullptr;
}
else if (strcmp (TYPE_FIELD_NAME (disr_type, 0),
"RUST$ENUM$DISR") != 0)
TYPE_CODE (union_type) = TYPE_CODE_UNION;
TYPE_NFIELDS (union_type) = 1 + TYPE_NFIELDS (type);
TYPE_LENGTH (union_type) = TYPE_LENGTH (type);
+ set_type_align (union_type, TYPE_RAW_ALIGN (type));
TYPE_FIELDS (union_type)
= (struct field *) TYPE_ZALLOC (union_type,
(TYPE_NFIELDS (union_type)
if (iter != discriminant_map.end ())
disc->discriminants[i] = iter->second;
- /* Remove the discriminant field. */
+ /* Remove the discriminant field, if it exists. */
struct type *sub_type = TYPE_FIELD_TYPE (union_type, i);
- --TYPE_NFIELDS (sub_type);
- ++TYPE_FIELDS (sub_type);
+ if (TYPE_NFIELDS (sub_type) > 0)
+ {
+ --TYPE_NFIELDS (sub_type);
+ ++TYPE_FIELDS (sub_type);
+ }
TYPE_FIELD_NAME (union_type, i) = variant_name;
TYPE_NAME (sub_type)
= rust_fully_qualify (&objfile->objfile_obstack,
cu->processing_has_namespace_info = 1;
if (read_namespace_alias (die, cu))
break;
- /* The declaration is not a global namespace alias: fall through. */
+ /* The declaration is not a global namespace alias. */
+ /* Fall through. */
case DW_TAG_imported_module:
cu->processing_has_namespace_info = 1;
if (die->child != NULL && (die->tag == DW_TAG_imported_declaration
smash_to_methodptr_type (type, new_type);
}
+/* If the DIE has a DW_AT_alignment attribute, return its value, doing
+ appropriate error checking and issuing complaints if there is a
+ problem. */
+
+static ULONGEST
+get_alignment (struct dwarf2_cu *cu, struct die_info *die)
+{
+ struct attribute *attr = dwarf2_attr (die, DW_AT_alignment, cu);
+
+ if (attr == nullptr)
+ return 0;
+
+ if (!attr_form_is_constant (attr))
+ {
+ complaint (&symfile_complaints,
+ _("DW_AT_alignment must have constant form"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+
+ ULONGEST align;
+ if (attr->form == DW_FORM_sdata)
+ {
+ LONGEST val = DW_SND (attr);
+ if (val < 0)
+ {
+ complaint (&symfile_complaints,
+ _("DW_AT_alignment value must not be negative"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+ align = val;
+ }
+ else
+ align = DW_UNSND (attr);
+
+ if (align == 0)
+ {
+ complaint (&symfile_complaints,
+ _("DW_AT_alignment value must not be zero"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+ if ((align & (align - 1)) != 0)
+ {
+ complaint (&symfile_complaints,
+ _("DW_AT_alignment value must be a power of 2"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ return 0;
+ }
+
+ return align;
+}
+
+/* If the DIE has a DW_AT_alignment attribute, use its value to set
+ the alignment for TYPE. */
+
+static void
+maybe_set_alignment (struct dwarf2_cu *cu, struct die_info *die,
+ struct type *type)
+{
+ if (!set_type_align (type, get_alignment (cu, die)))
+ complaint (&symfile_complaints,
+ _("DW_AT_alignment value too large"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+}
/* Called when we find the DIE that starts a structure or union scope
(definition) to create a type for the structure or union. Fill in
TYPE_LENGTH (type) = 0;
}
+ maybe_set_alignment (cu, die, type);
+
if (producer_is_icc_lt_14 (cu) && (TYPE_LENGTH (type) == 0))
{
/* ICC<14 does not output the required DW_AT_declaration on
TYPE_LENGTH (type) = 0;
}
+ maybe_set_alignment (cu, die, type);
+
/* The enumeration DIE can be incomplete. In Ada, any type can be
declared as private in the package spec, and then defined only
inside the package body. Such types are known as Taft Amendment
TYPE_UNSIGNED (type) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type));
if (TYPE_LENGTH (type) == 0)
TYPE_LENGTH (type) = TYPE_LENGTH (TYPE_TARGET_TYPE (type));
+ if (TYPE_RAW_ALIGN (type) == 0
+ && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type)) != 0)
+ set_type_align (type, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type)));
}
TYPE_DECLARED_CLASS (type) = dwarf2_flag_true_p (die, DW_AT_enum_class, cu);
if (name)
TYPE_NAME (type) = name;
+ maybe_set_alignment (cu, die, type);
+
/* Install the type in the die. */
set_die_type (die, type, cu);
if (attr)
TYPE_LENGTH (set_type) = DW_UNSND (attr);
+ maybe_set_alignment (cu, die, set_type);
+
return set_die_type (die, set_type, cu);
}
else
addr_class = DW_ADDR_none;
- /* If the pointer size or address class is different than the
- default, create a type variant marked as such and set the
- length accordingly. */
- if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
+ ULONGEST alignment = get_alignment (cu, die);
+
+ /* If the pointer size, alignment, or address class is different
+ than the default, create a type variant marked as such and set
+ the length accordingly. */
+ if (TYPE_LENGTH (type) != byte_size
+ || (alignment != 0 && TYPE_RAW_ALIGN (type) != 0
+ && alignment != TYPE_RAW_ALIGN (type))
+ || addr_class != DW_ADDR_none)
{
if (gdbarch_address_class_type_flags_p (gdbarch))
{
complaint (&symfile_complaints,
_("invalid pointer size %d"), byte_size);
}
+ else if (TYPE_RAW_ALIGN (type) != alignment)
+ {
+ complaint (&symfile_complaints,
+ _("Invalid DW_AT_alignment"
+ " - DIE at %s [in module %s]"),
+ sect_offset_str (die->sect_off),
+ objfile_name (cu->per_cu->dwarf2_per_objfile->objfile));
+ }
else
{
/* Should we also complain about unhandled address classes? */
}
TYPE_LENGTH (type) = byte_size;
+ set_type_align (type, alignment);
return set_die_type (die, type, cu);
}
{
TYPE_LENGTH (type) = cu_header->addr_size;
}
+ maybe_set_alignment (cu, die, type);
return set_die_type (die, type, cu);
}
if (name && strcmp (name, "char") == 0)
TYPE_NOSIGN (type) = 1;
+ maybe_set_alignment (cu, die, type);
+
return set_die_type (die, type, cu);
}
if (attr)
TYPE_LENGTH (range_type) = DW_UNSND (attr);
+ maybe_set_alignment (cu, die, range_type);
+
set_die_type (die, range_type, cu);
/* set_die_type should be already done. */