#include "dwarf2/line-header.h"
#include "dwarf2/dwz.h"
#include "dwarf2/macro.h"
+#include "dwarf2/die.h"
#include "bfd.h"
#include "elf-bfd.h"
#include "symtab.h"
struct comp_unit_head header {};
/* Base address of this compilation unit. */
- CORE_ADDR base_address = 0;
-
- /* Non-zero if base_address has been set. */
- int base_known = 0;
+ gdb::optional<CORE_ADDR> base_address;
/* The language we are debugging. */
enum language language = language_unknown;
}
};
-/* This data structure holds a complete die structure. */
-struct die_info
- {
- /* DWARF-2 tag for this DIE. */
- ENUM_BITFIELD(dwarf_tag) tag : 16;
-
- /* Number of attributes */
- unsigned char num_attrs;
-
- /* True if we're presently building the full type name for the
- type derived from this DIE. */
- unsigned char building_fullname : 1;
-
- /* True if this die is in process. PR 16581. */
- unsigned char in_process : 1;
-
- /* True if this DIE has children. */
- unsigned char has_children : 1;
-
- /* Abbrev number */
- unsigned int abbrev;
-
- /* Offset in .debug_info or .debug_types section. */
- sect_offset sect_off;
-
- /* The dies in a compilation unit form an n-ary tree. PARENT
- points to this die's parent; CHILD points to the first child of
- this node; and all the children of a given node are chained
- together via their SIBLING fields. */
- struct die_info *child; /* Its first child, if any. */
- struct die_info *sibling; /* Its next sibling, if any. */
- struct die_info *parent; /* Its parent, if any. */
-
- /* An array of attributes, with NUM_ATTRS elements. There may be
- zero, but it's not common and zero-sized arrays are not
- sufficiently portable C. */
- struct attribute attrs[1];
- };
-
/* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
but this would require a corresponding change in unpack_field_as_long
and friends. */
static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
struct dwarf2_cu *);
-static struct attribute *dwarf2_attr_no_follow (struct die_info *,
- unsigned int);
-
static const char *dwarf2_string_attr (struct die_info *die, unsigned int name,
struct dwarf2_cu *cu);
static const char *dwarf_type_encoding_name (unsigned int);
-static struct die_info *sibling_die (struct die_info *);
-
static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
static void dump_die_for_error (struct die_info *);
{
struct attribute *attr;
- cu->base_known = 0;
- cu->base_address = 0;
+ cu->base_address.reset ();
attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
if (attr != nullptr)
- {
- cu->base_address = attr->value_as_address ();
- cu->base_known = 1;
- }
+ cu->base_address = attr->value_as_address ();
else
{
attr = dwarf2_attr (die, DW_AT_low_pc, cu);
if (attr != nullptr)
- {
- cu->base_address = attr->value_as_address ();
- cu->base_known = 1;
- }
+ cu->base_address = attr->value_as_address ();
}
}
}
}
-/* Return the address base of the compile unit, which, if exists, is stored
- either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
-static gdb::optional<ULONGEST>
-lookup_addr_base (struct die_info *comp_unit_die)
-{
- struct attribute *attr;
- attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_addr_base);
- if (attr == nullptr)
- attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_GNU_addr_base);
- if (attr == nullptr)
- return gdb::optional<ULONGEST> ();
- return DW_UNSND (attr);
-}
-
-/* Return range lists base of the compile unit, which, if exists, is stored
- either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
-static ULONGEST
-lookup_ranges_base (struct die_info *comp_unit_die)
-{
- struct attribute *attr;
- attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_rnglists_base);
- if (attr == nullptr)
- attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_GNU_ranges_base);
- if (attr == nullptr)
- return 0;
- return DW_UNSND (attr);
-}
-
/* Low level DIE reading support. */
/* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
ranges = dwarf2_attr (stub_comp_unit_die, DW_AT_ranges, cu);
comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu);
- cu->addr_base = lookup_addr_base (stub_comp_unit_die);
+ cu->addr_base = stub_comp_unit_die->addr_base ();
/* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
here (if needed). We need the value before we can process
DW_AT_ranges. */
- cu->ranges_base = lookup_ranges_base (stub_comp_unit_die);
+ cu->ranges_base = stub_comp_unit_die->ranges_base ();
}
else if (stub_comp_dir != NULL)
{
if (! type_unit_die->has_children)
return;
- attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
+ attr = type_unit_die->attr (DW_AT_stmt_list);
tu_group = get_type_unit_group (cu, attr);
if (tu_group->tus == nullptr)
if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
for (child_die = die->child; child_die && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
{
/* DWARF-4: A Fortran use statement with a “rename list” may be
represented by an imported module entry with an import attribute
while (child_die && child_die->tag)
{
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
while (child_die && child_die->tag)
{
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
}
for (child_die = die->child;
child_die && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
{
struct die_info *child_origin_die;
struct dwarf2_cu *child_origin_cu;
if (!origin_child_die->in_process)
process_die (origin_child_die, origin_cu);
}
- origin_child_die = sibling_die (origin_child_die);
+ origin_child_die = origin_child_die->sibling;
}
origin_cu->list_in_scope = origin_previous_list_in_scope;
/* If we have any template arguments, then we must allocate a
different sort of symbol. */
- for (child_die = die->child; child_die; child_die = sibling_die (child_die))
+ for (child_die = die->child; child_die; child_die = child_die->sibling)
{
if (child_die->tag == DW_TAG_template_type_param
|| child_die->tag == DW_TAG_template_value_param)
}
else
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
{
if (child_die->tag == DW_TAG_imported_module)
process_die (child_die, spec_cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
/* In some cases, GCC generates specification DIEs that
GCC does no longer produces such DWARF since GCC r224161. */
for (child_die = die->child;
child_die != NULL && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
process_die (child_die, cu);
return;
case PC_BOUNDS_INVALID:
while (child_die && child_die->tag)
{
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
inherit_abstract_dies (die, cu);
nparams = 0;
for (child_die = die->child; child_die && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
{
if (child_die->tag != DW_TAG_call_site_parameter
&& child_die->tag != DW_TAG_GNU_call_site_parameter)
for (child_die = die->child;
child_die && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
{
struct call_site_parameter *parameter;
struct attribute *loc, *origin;
struct objfile *objfile = dwarf2_per_objfile->objfile;
bfd *obfd = objfile->obfd;
/* Base address selection entry. */
- CORE_ADDR base;
- int found_base;
+ gdb::optional<CORE_ADDR> base;
const gdb_byte *buffer;
CORE_ADDR baseaddr;
bool overflow = false;
- found_base = cu->base_known;
base = cu->base_address;
dwarf2_per_objfile->rnglists.read (objfile);
break;
}
base = cu->header.read_address (obfd, buffer, &bytes_read);
- found_base = 1;
buffer += bytes_read;
break;
case DW_RLE_start_length:
if (rlet == DW_RLE_base_address)
continue;
- if (!found_base)
+ if (!base.has_value ())
{
/* We have no valid base address for the ranges
data. */
if (range_beginning == range_end)
continue;
- range_beginning += base;
- range_end += base;
+ range_beginning += *base;
+ range_end += *base;
/* A not-uncommon case of bad debug info.
Don't pollute the addrmap with bad data. */
unsigned int addr_size = cu_header->addr_size;
CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
/* Base address selection entry. */
- CORE_ADDR base;
- int found_base;
+ gdb::optional<CORE_ADDR> base;
unsigned int dummy;
const gdb_byte *buffer;
CORE_ADDR baseaddr;
if (cu_header->version >= 5)
return dwarf2_rnglists_process (offset, cu, callback);
- found_base = cu->base_known;
base = cu->base_address;
dwarf2_per_objfile->ranges.read (objfile);
/* If we found the largest possible address, then we already
have the base address in range_end. */
base = range_end;
- found_base = 1;
continue;
}
- if (!found_base)
+ if (!base.has_value ())
{
/* We have no valid base address for the ranges
data. */
if (range_beginning == range_end)
continue;
- range_beginning += base;
- range_end += base;
+ range_beginning += *base;
+ range_end += *base;
/* A not-uncommon case of bad debug info.
Don't pollute the addrmap with bad data. */
if (child->tag == DW_TAG_subprogram
|| child->tag == DW_TAG_lexical_block)
dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
- child = sibling_die (child);
+ child = child->sibling;
}
}
break;
}
- child = sibling_die (child);
+ child = child->sibling;
}
}
/* If the definition of this type lives in .debug_types, read that type.
Don't follow DW_AT_specification though, that will take us back up
the chain and we want to go down. */
- attr = dwarf2_attr_no_follow (die, DW_AT_signature);
+ attr = die->attr (DW_AT_signature);
if (attr != nullptr)
{
type = get_DW_AT_signature_type (die, attr, cu);
for (die_info *variant_child = child_die->child;
variant_child != NULL;
- variant_child = sibling_die (variant_child))
+ variant_child = variant_child->sibling)
{
if (variant_child->tag == DW_TAG_member)
{
if (is_variant_part && discr_offset == child_die->sect_off)
fi.fields.back ().variant.is_discriminant = true;
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
/* Attach template arguments to type. */
else
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
/* Do not consider external references. According to the DWARF standard,
for (child_die = die->child;
child_die != NULL && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
{
struct attribute *attr;
LONGEST value;
/* If the definition of this type lives in .debug_types, read that type.
Don't follow DW_AT_specification though, that will take us back up
the chain and we want to go down. */
- attr = dwarf2_attr_no_follow (die, DW_AT_signature);
+ attr = die->attr (DW_AT_signature);
if (attr != nullptr)
{
type = get_DW_AT_signature_type (die, attr, cu);
}
}
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
if (!fields.empty ())
range_types.push_back (child_type);
}
}
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
/* Dwarf2 dimensions are output from left to right, create the
for (child_die = die->child;
child_die && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
++n_entries;
size = (sizeof (struct common_block)
for (child_die = die->child;
child_die && child_die->tag;
- child_die = sibling_die (child_die))
+ child_die = child_die->sibling)
{
/* Create the symbol in the DW_TAG_common_block block in the current
symbol scope. */
while (child_die && child_die->tag)
{
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
}
while (child_die && child_die->tag)
{
process_die (child_die, cu);
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
nparams++;
else if (child_die->tag == DW_TAG_unspecified_parameters)
TYPE_VARARGS (ftype) = 1;
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
/* Allocate storage for parameters and fill them in. */
TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
iparams++;
}
- child_die = sibling_die (child_die);
+ child_die = child_die->sibling;
}
}
indexes_that_need_reprocess.push_back (i);
}
- struct attribute *attr = dwarf2_attr_no_follow (die, DW_AT_str_offsets_base);
+ struct attribute *attr = die->attr (DW_AT_str_offsets_base);
if (attr != nullptr)
cu->str_offsets_base = DW_UNSND (attr);
- auto maybe_addr_base = lookup_addr_base(die);
+ auto maybe_addr_base = die->addr_base ();
if (maybe_addr_base.has_value ())
cu->addr_base = *maybe_addr_base;
for (int index : indexes_that_need_reprocess)
return NULL;
}
-/* Return the named attribute or NULL if not there,
- but do not follow DW_AT_specification, etc.
- This is for use in contexts where we're reading .debug_types dies.
- Following DW_AT_specification, DW_AT_abstract_origin will take us
- back up the chain, and we want to go down. */
-
-static struct attribute *
-dwarf2_attr_no_follow (struct die_info *die, unsigned int name)
-{
- unsigned int i;
-
- for (i = 0; i < die->num_attrs; ++i)
- if (die->attrs[i].name == name)
- return &die->attrs[i];
-
- return NULL;
-}
-
/* Return the string associated with a string-typed attribute, or NULL if it
is either not found or is of an incorrect type. */
}
}
-/* Return sibling of die, NULL if no sibling. */
-
-static struct die_info *
-sibling_die (struct die_info *die)
-{
- return die->sibling;
-}
-
/* Get name of a die, return NULL if not found. */
static const char *
don't run off the edge of the section. */
baton->size = section->size - DW_UNSND (attr);
baton->data = section->buffer + DW_UNSND (attr);
- baton->base_address = cu->base_address;
+ if (cu->base_address.has_value ())
+ baton->base_address = *cu->base_address;
+ else
+ baton->base_address = 0;
baton->from_dwo = cu->dwo_unit != NULL;
}
fill_in_loclist_baton (cu, baton, attr);
- if (cu->base_known == 0)
+ if (!cu->base_address.has_value ())
complaint (_("Location list used without "
"specifying the CU base address."));