Change two functions to be methods on struct attribute
This changes dwarf2_get_ref_die_offset and dwarf2_get_attr_constant_value to be methods on struct attribute. gdb/ChangeLog 2020-03-26 Tom Tromey <tom@tromey.com> * dwarf2/read.c (handle_data_member_location, dwarf2_add_field) (mark_common_block_symbol_computed, read_tag_string_type) (attr_to_dynamic_prop, read_subrange_type): Update. (dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move to be methods on struct attribute. (skip_one_die, process_imported_unit_die, read_namespace_alias) (read_call_site_scope, partial_die_info::read) (partial_die_info::read, lookup_die_type, follow_die_ref): Update. * dwarf2/attribute.c (attribute::get_ref_die_offset): New method, from dwarf2_get_ref_die_offset. (attribute::constant_value): New method, from dwarf2_get_attr_constant_value. * dwarf2/attribute.h (struct attribute) <get_ref_die_offset>: Declare method. <constant_value>: New method.
This commit is contained in:
parent
2b2558bfac
commit
0826b30a9f
|
@ -1,3 +1,22 @@
|
|||
2020-03-26 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* dwarf2/read.c (handle_data_member_location, dwarf2_add_field)
|
||||
(mark_common_block_symbol_computed, read_tag_string_type)
|
||||
(attr_to_dynamic_prop, read_subrange_type): Update.
|
||||
(dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move
|
||||
to be methods on struct attribute.
|
||||
(skip_one_die, process_imported_unit_die, read_namespace_alias)
|
||||
(read_call_site_scope, partial_die_info::read)
|
||||
(partial_die_info::read, lookup_die_type, follow_die_ref):
|
||||
Update.
|
||||
* dwarf2/attribute.c (attribute::get_ref_die_offset): New method,
|
||||
from dwarf2_get_ref_die_offset.
|
||||
(attribute::constant_value): New method, from
|
||||
dwarf2_get_attr_constant_value.
|
||||
* dwarf2/attribute.h (struct attribute) <get_ref_die_offset>:
|
||||
Declare method.
|
||||
<constant_value>: New method.
|
||||
|
||||
2020-03-26 Tom Tromey <tom@tromey.com>
|
||||
|
||||
* dwarf2/read.c (dwarf_unit_type_name, dwarf_tag_name)
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include "defs.h"
|
||||
#include "dwarf2/attribute.h"
|
||||
#include "dwarf2/stringify.h"
|
||||
#include "complaints.h"
|
||||
|
||||
/* See attribute.h. */
|
||||
|
||||
|
@ -119,3 +121,38 @@ attribute::form_is_ref () const
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* See attribute.h. */
|
||||
|
||||
sect_offset
|
||||
attribute::get_ref_die_offset () const
|
||||
{
|
||||
if (form_is_ref ())
|
||||
return (sect_offset) DW_UNSND (this);
|
||||
|
||||
complaint (_("unsupported die ref attribute form: '%s'"),
|
||||
dwarf_form_name (form));
|
||||
return {};
|
||||
}
|
||||
|
||||
/* See attribute.h. */
|
||||
|
||||
LONGEST
|
||||
attribute::constant_value (int default_value) const
|
||||
{
|
||||
if (form == DW_FORM_sdata || form == DW_FORM_implicit_const)
|
||||
return DW_SND (this);
|
||||
else if (form == DW_FORM_udata
|
||||
|| form == DW_FORM_data1
|
||||
|| form == DW_FORM_data2
|
||||
|| form == DW_FORM_data4
|
||||
|| form == DW_FORM_data8)
|
||||
return DW_UNSND (this);
|
||||
else
|
||||
{
|
||||
/* For DW_FORM_data16 see attribute::form_is_constant. */
|
||||
complaint (_("Attribute value is not a constant (%s)"),
|
||||
dwarf_form_name (form));
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define GDB_DWARF2_ATTRIBUTE_H
|
||||
|
||||
#include "dwarf2.h"
|
||||
#include "gdbtypes.h"
|
||||
|
||||
/* Blocks are a bunch of untyped bytes. */
|
||||
struct dwarf_block
|
||||
|
@ -84,6 +85,17 @@ struct attribute
|
|||
|
||||
bool form_is_block () const;
|
||||
|
||||
/* Return DIE offset of this attribute. Return 0 with complaint if
|
||||
the attribute is not of the required kind. */
|
||||
|
||||
sect_offset get_ref_die_offset () const;
|
||||
|
||||
/* Return the constant value held by this attribute. Return
|
||||
DEFAULT_VALUE if the value held by the attribute is not
|
||||
constant. */
|
||||
|
||||
LONGEST constant_value (int default_value) const;
|
||||
|
||||
|
||||
ENUM_BITFIELD(dwarf_attribute) name : 16;
|
||||
ENUM_BITFIELD(dwarf_form) form : 15;
|
||||
|
|
|
@ -1419,10 +1419,6 @@ static void dump_die_1 (struct ui_file *, int level, int max_level,
|
|||
static void store_in_ref_table (struct die_info *,
|
||||
struct dwarf2_cu *);
|
||||
|
||||
static sect_offset dwarf2_get_ref_die_offset (const struct attribute *);
|
||||
|
||||
static LONGEST dwarf2_get_attr_constant_value (const struct attribute *, int);
|
||||
|
||||
static struct die_info *follow_die_ref_or_sig (struct die_info *,
|
||||
const struct attribute *,
|
||||
struct dwarf2_cu **);
|
||||
|
@ -8476,7 +8472,7 @@ skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
|
|||
complaint (_("ignoring absolute DW_AT_sibling"));
|
||||
else
|
||||
{
|
||||
sect_offset off = dwarf2_get_ref_die_offset (&attr);
|
||||
sect_offset off = attr.get_ref_die_offset ();
|
||||
const gdb_byte *sibling_ptr = buffer + to_underlying (off);
|
||||
|
||||
if (sibling_ptr < info_ptr)
|
||||
|
@ -9643,7 +9639,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
|
|||
attr = dwarf2_attr (die, DW_AT_import, cu);
|
||||
if (attr != NULL)
|
||||
{
|
||||
sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
|
||||
sect_offset sect_off = attr->get_ref_die_offset ();
|
||||
bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
|
||||
dwarf2_per_cu_data *per_cu
|
||||
= dwarf2_find_containing_comp_unit (sect_off, is_dwz,
|
||||
|
@ -10296,7 +10292,7 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
|
|||
if (attr != NULL)
|
||||
{
|
||||
struct type *type;
|
||||
sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
|
||||
sect_offset sect_off = attr->get_ref_die_offset ();
|
||||
|
||||
type = get_die_type_at_offset (sect_off, cu->per_cu);
|
||||
if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
|
||||
|
@ -13224,8 +13220,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
|
|||
{
|
||||
parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
|
||||
|
||||
sect_offset sect_off
|
||||
= (sect_offset) dwarf2_get_ref_die_offset (origin);
|
||||
sect_offset sect_off = origin->get_ref_die_offset ();
|
||||
if (!cu->header.offset_in_cu_p (sect_off))
|
||||
{
|
||||
/* As DW_OP_GNU_parameter_ref uses CU-relative offset this
|
||||
|
@ -14059,7 +14054,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
|
|||
so if we see it, we can assume that a constant form is really
|
||||
a constant and not a section offset. */
|
||||
if (attr->form_is_constant ())
|
||||
*offset = dwarf2_get_attr_constant_value (attr, 0);
|
||||
*offset = attr->constant_value (0);
|
||||
else if (attr->form_is_section_offset ())
|
||||
dwarf2_complex_location_expr_complaint ();
|
||||
else if (attr->form_is_block ())
|
||||
|
@ -14186,7 +14181,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
|
|||
attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
|
||||
if (attr != NULL)
|
||||
SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
|
||||
+ dwarf2_get_attr_constant_value (attr, 0)));
|
||||
+ attr->constant_value (0)));
|
||||
|
||||
/* Get name of field. */
|
||||
fieldname = dwarf2_name (die, cu);
|
||||
|
@ -15860,7 +15855,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
|
|||
|
||||
if (member_loc->form_is_constant ())
|
||||
{
|
||||
offset = dwarf2_get_attr_constant_value (member_loc, 0);
|
||||
offset = member_loc->constant_value (0);
|
||||
baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
|
||||
}
|
||||
else
|
||||
|
@ -16452,7 +16447,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
|
|||
{
|
||||
/* Pass 0 as the default as we know this attribute is constant
|
||||
and the default value will not be returned. */
|
||||
LONGEST sz = dwarf2_get_attr_constant_value (len, 0);
|
||||
LONGEST sz = len->constant_value (0);
|
||||
prop_type = cu->per_cu->int_type (sz, true);
|
||||
}
|
||||
else
|
||||
|
@ -16474,12 +16469,12 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
|
|||
indirection. There's no need to create a dynamic property in this
|
||||
case. Pass 0 for the default value as we know it will not be
|
||||
returned in this case. */
|
||||
length = dwarf2_get_attr_constant_value (attr, 0);
|
||||
length = attr->constant_value (0);
|
||||
}
|
||||
else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
|
||||
{
|
||||
/* We don't currently support non-constant byte sizes for strings. */
|
||||
length = dwarf2_get_attr_constant_value (attr, 1);
|
||||
length = attr->constant_value (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -17058,7 +17053,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
|
|||
}
|
||||
else if (attr->form_is_constant ())
|
||||
{
|
||||
prop->data.const_val = dwarf2_get_attr_constant_value (attr, 0);
|
||||
prop->data.const_val = attr->constant_value (0);
|
||||
prop->kind = PROP_CONST;
|
||||
}
|
||||
else
|
||||
|
@ -17236,7 +17231,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
|
|||
LONGEST bias = 0;
|
||||
struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
|
||||
if (bias_attr != nullptr && bias_attr->form_is_constant ())
|
||||
bias = dwarf2_get_attr_constant_value (bias_attr, 0);
|
||||
bias = bias_attr->constant_value (0);
|
||||
|
||||
/* Normally, the DWARF producers are expected to use a signed
|
||||
constant form (Eg. DW_FORM_sdata) to express negative bounds.
|
||||
|
@ -17942,7 +17937,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
|
|||
case DW_AT_specification:
|
||||
case DW_AT_extension:
|
||||
has_specification = 1;
|
||||
spec_offset = dwarf2_get_ref_die_offset (&attr);
|
||||
spec_offset = attr.get_ref_die_offset ();
|
||||
spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
|
||||
|| cu->per_cu->is_dwz);
|
||||
break;
|
||||
|
@ -17954,7 +17949,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
|
|||
else
|
||||
{
|
||||
const gdb_byte *buffer = reader->buffer;
|
||||
sect_offset off = dwarf2_get_ref_die_offset (&attr);
|
||||
sect_offset off = attr.get_ref_die_offset ();
|
||||
const gdb_byte *sibling_ptr = buffer + to_underlying (off);
|
||||
|
||||
if (sibling_ptr < info_ptr)
|
||||
|
@ -17999,7 +17994,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
|
|||
case DW_AT_import:
|
||||
if (tag == DW_TAG_imported_unit)
|
||||
{
|
||||
d.sect_off = dwarf2_get_ref_die_offset (&attr);
|
||||
d.sect_off = attr.get_ref_die_offset ();
|
||||
is_dwz = (attr.form == DW_FORM_GNU_ref_alt
|
||||
|| cu->per_cu->is_dwz);
|
||||
}
|
||||
|
@ -20701,7 +20696,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
|
|||
if (attr->form == DW_FORM_GNU_ref_alt)
|
||||
{
|
||||
struct dwarf2_per_cu_data *per_cu;
|
||||
sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
|
||||
sect_offset sect_off = attr->get_ref_die_offset ();
|
||||
|
||||
per_cu = dwarf2_find_containing_comp_unit (sect_off, 1,
|
||||
dwarf2_per_objfile);
|
||||
|
@ -20709,7 +20704,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
|
|||
}
|
||||
else if (attr->form_is_ref ())
|
||||
{
|
||||
sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
|
||||
sect_offset sect_off = attr->get_ref_die_offset ();
|
||||
|
||||
this_type = get_die_type_at_offset (sect_off, cu->per_cu);
|
||||
}
|
||||
|
@ -21511,43 +21506,6 @@ store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
|
|||
*slot = die;
|
||||
}
|
||||
|
||||
/* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
|
||||
required kind. */
|
||||
|
||||
static sect_offset
|
||||
dwarf2_get_ref_die_offset (const struct attribute *attr)
|
||||
{
|
||||
if (attr->form_is_ref ())
|
||||
return (sect_offset) DW_UNSND (attr);
|
||||
|
||||
complaint (_("unsupported die ref attribute form: '%s'"),
|
||||
dwarf_form_name (attr->form));
|
||||
return {};
|
||||
}
|
||||
|
||||
/* Return the constant value held by ATTR. Return DEFAULT_VALUE if
|
||||
* the value held by the attribute is not constant. */
|
||||
|
||||
static LONGEST
|
||||
dwarf2_get_attr_constant_value (const struct attribute *attr, int default_value)
|
||||
{
|
||||
if (attr->form == DW_FORM_sdata || attr->form == DW_FORM_implicit_const)
|
||||
return DW_SND (attr);
|
||||
else if (attr->form == DW_FORM_udata
|
||||
|| attr->form == DW_FORM_data1
|
||||
|| attr->form == DW_FORM_data2
|
||||
|| attr->form == DW_FORM_data4
|
||||
|| attr->form == DW_FORM_data8)
|
||||
return DW_UNSND (attr);
|
||||
else
|
||||
{
|
||||
/* For DW_FORM_data16 see attribute::form_is_constant. */
|
||||
complaint (_("Attribute value is not a constant (%s)"),
|
||||
dwarf_form_name (attr->form));
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
/* Follow reference or signature attribute ATTR of SRC_DIE.
|
||||
On entry *REF_CU is the CU of SRC_DIE.
|
||||
On exit *REF_CU is the CU of the result. */
|
||||
|
@ -21638,7 +21596,7 @@ static struct die_info *
|
|||
follow_die_ref (struct die_info *src_die, const struct attribute *attr,
|
||||
struct dwarf2_cu **ref_cu)
|
||||
{
|
||||
sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
|
||||
sect_offset sect_off = attr->get_ref_die_offset ();
|
||||
struct dwarf2_cu *cu = *ref_cu;
|
||||
struct die_info *die;
|
||||
|
||||
|
|
Loading…
Reference in New Issue