+2020-07-12 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * gdbtypes.h (struct dynamic_prop) <kind, set_undefined,
+ const_val, set_const_val, baton, set_locexpr, set_loclist,
+ set_addr_offset, variant_parts, set_variant_parts,
+ original_type, set_original_type>: New methods.
+ <kind>: Rename to...
+ <m_kind>: ... this. Update all users to use the new methods
+ instead.
+ <data>: Rename to...
+ <m_data>: ... this. Update all users to use the new methods
+ instead.
+
2020-07-12 Simon Marchi <simon.marchi@efficios.com>
* gdbtypes.c (get_discrete_bounds): Return failure if
struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
if (prop != nullptr)
{
- if (prop->kind == PROP_TYPE)
+ if (prop->kind () == PROP_TYPE)
{
- type = prop->data.original_type;
+ type = prop->original_type ();
prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
}
- gdb_assert (prop->kind == PROP_VARIANT_PARTS);
- print_record_field_types_dynamic (*prop->data.variant_parts,
+ gdb_assert (prop->kind () == PROP_VARIANT_PARTS);
+ print_record_field_types_dynamic (*prop->variant_parts (),
0, type->num_fields (),
type, stream, show, level, flags);
return type->num_fields ();
type = create_array_type (NULL, element_type, range_type);
if (ar.ctr_nelems <= 1) /* Check if undefined upper bound. */
{
- TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+ range_type->bounds ()->high.set_undefined ();
TYPE_LENGTH (type) = 0;
TYPE_TARGET_STUB (type) = 1;
}
if (frame == NULL && has_stack_frames ())
frame = get_selected_frame (NULL);
- switch (prop->kind)
+ switch (prop->kind ())
{
case PROP_LOCEXPR:
{
const struct dwarf2_property_baton *baton
- = (const struct dwarf2_property_baton *) prop->data.baton;
+ = (const struct dwarf2_property_baton *) prop->baton ();
gdb_assert (baton->property_type != NULL);
if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack,
case PROP_LOCLIST:
{
struct dwarf2_property_baton *baton
- = (struct dwarf2_property_baton *) prop->data.baton;
+ = (struct dwarf2_property_baton *) prop->baton ();
CORE_ADDR pc;
const gdb_byte *data;
struct value *val;
break;
case PROP_CONST:
- *value = prop->data.const_val;
+ *value = prop->const_val ();
return true;
case PROP_ADDR_OFFSET:
{
struct dwarf2_property_baton *baton
- = (struct dwarf2_property_baton *) prop->data.baton;
+ = (struct dwarf2_property_baton *) prop->baton ();
const struct property_addr_info *pinfo;
struct value *val;
struct symbol *sym)
{
struct dwarf2_property_baton *baton
- = (struct dwarf2_property_baton *) prop->data.baton;
+ = (struct dwarf2_property_baton *) prop->baton ();
const gdb_byte *data;
size_t size;
dwarf2_per_cu_data *per_cu;
dwarf2_per_objfile *per_objfile;
- if (prop->kind == PROP_LOCEXPR)
+ if (prop->kind () == PROP_LOCEXPR)
{
data = baton->locexpr.data;
size = baton->locexpr.size;
}
else
{
- gdb_assert (prop->kind == PROP_LOCLIST);
+ gdb_assert (prop->kind () == PROP_LOCLIST);
data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
per_cu = baton->loclist.per_cu;
= new (storage) gdb::array_view<variant_part> (part, 1);
struct dynamic_prop prop;
- prop.kind = PROP_VARIANT_PARTS;
- prop.data.variant_parts = prop_value;
+ prop.set_variant_parts (prop_value);
type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
}
fip->variant_parts);
struct dynamic_prop prop;
- prop.kind = PROP_VARIANT_PARTS;
- prop.data.variant_parts
- = ((gdb::array_view<variant_part> *)
- obstack_copy (&objfile->objfile_obstack, &parts, sizeof (parts)));
+ prop.set_variant_parts ((gdb::array_view<variant_part> *)
+ obstack_copy (&objfile->objfile_obstack, &parts,
+ sizeof (parts)));
type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
}
{
struct dynamic_prop low_bound;
- low_bound.kind = PROP_CONST;
- low_bound.data.const_val = 1;
+ low_bound.set_const_val (1);
range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
}
char_type = language_string_char_type (cu->language_defn, gdbarch);
baton->locexpr.is_reference = false;
break;
}
- prop->data.baton = baton;
- prop->kind = PROP_LOCEXPR;
- gdb_assert (prop->data.baton != NULL);
+
+ prop->set_locexpr (baton);
+ gdb_assert (prop->baton () != NULL);
}
else if (attr->form_is_ref ())
{
baton = XOBNEW (obstack, struct dwarf2_property_baton);
baton->property_type = die_type (target_die, target_cu);
fill_in_loclist_baton (cu, &baton->loclist, target_attr);
- prop->data.baton = baton;
- prop->kind = PROP_LOCLIST;
- gdb_assert (prop->data.baton != NULL);
+ prop->set_loclist (baton);
+ gdb_assert (prop->baton () != NULL);
}
else if (target_attr->form_is_block ())
{
baton->locexpr.size = DW_BLOCK (target_attr)->size;
baton->locexpr.data = DW_BLOCK (target_attr)->data;
baton->locexpr.is_reference = true;
- prop->data.baton = baton;
- prop->kind = PROP_LOCEXPR;
- gdb_assert (prop->data.baton != NULL);
+ prop->set_locexpr (baton);
+ gdb_assert (prop->baton () != NULL);
}
else
{
target_cu);
baton->offset_info.offset = offset;
baton->offset_info.type = die_type (target_die, target_cu);
- prop->data.baton = baton;
- prop->kind = PROP_ADDR_OFFSET;
+ prop->set_addr_offset (baton);
break;
}
}
}
else if (attr->form_is_constant ())
- {
- prop->data.const_val = attr->constant_value (0);
- prop->kind = PROP_CONST;
- }
+ prop->set_const_val (attr->constant_value (0));
else
{
dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form),
if (range_type)
return range_type;
- low.kind = PROP_CONST;
- high.kind = PROP_CONST;
- high.data.const_val = 0;
+ high.set_const_val (0);
/* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
omitting DW_AT_lower_bound. */
{
case language_c:
case language_cplus:
- low.data.const_val = 0;
+ low.set_const_val (0);
low_default_is_valid = 1;
break;
case language_fortran:
- low.data.const_val = 1;
+ low.set_const_val (1);
low_default_is_valid = 1;
break;
case language_d:
case language_objc:
case language_rust:
- low.data.const_val = 0;
+ low.set_const_val (0);
low_default_is_valid = (cu->header.version >= 4);
break;
case language_ada:
case language_m2:
case language_pascal:
- low.data.const_val = 1;
+ low.set_const_val (1);
low_default_is_valid = (cu->header.version >= 4);
break;
default:
- low.data.const_val = 0;
+ low.set_const_val (0);
low_default_is_valid = 0;
break;
}
if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
{
/* If bounds are constant do the final calculation here. */
- if (low.kind == PROP_CONST && high.kind == PROP_CONST)
- high.data.const_val = low.data.const_val + high.data.const_val - 1;
+ if (low.kind () == PROP_CONST && high.kind () == PROP_CONST)
+ high.set_const_val (low.const_val () + high.const_val () - 1);
else
high_bound_is_count = 1;
}
the base type is signed. */
negative_mask =
-((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
- if (low.kind == PROP_CONST
- && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
- low.data.const_val |= negative_mask;
- if (high.kind == PROP_CONST
- && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
- high.data.const_val |= negative_mask;
+ if (low.kind () == PROP_CONST
+ && !TYPE_UNSIGNED (base_type) && (low.const_val () & negative_mask))
+ low.set_const_val (low.const_val () | negative_mask);
+ if (high.kind () == PROP_CONST
+ && !TYPE_UNSIGNED (base_type) && (high.const_val () & negative_mask))
+ high.set_const_val (high.const_val () | negative_mask);
/* Check for bit and byte strides. */
struct dynamic_prop byte_stride_prop;
/* Ada expects an empty array on no boundary attributes. */
if (attr == NULL && cu->language != language_ada)
- TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+ range_type->bounds ()->high.set_undefined ();
name = dwarf2_name (die, cu);
if (name)
bool
operator== (const dynamic_prop &l, const dynamic_prop &r)
{
- if (l.kind != r.kind)
+ if (l.kind () != r.kind ())
return false;
- switch (l.kind)
+ switch (l.kind ())
{
case PROP_UNDEFINED:
return true;
case PROP_CONST:
- return l.data.const_val == r.data.const_val;
+ return l.const_val () == r.const_val ();
case PROP_ADDR_OFFSET:
case PROP_LOCEXPR:
case PROP_LOCLIST:
- return l.data.baton == r.data.baton;
+ return l.baton () == r.baton ();
case PROP_VARIANT_PARTS:
- return l.data.variant_parts == r.data.variant_parts;
+ return l.variant_parts () == r.variant_parts ();
case PROP_TYPE:
- return l.data.original_type == r.data.original_type;
+ return l.original_type () == r.original_type ();
}
gdb_assert_not_reached ("unhandled dynamic_prop kind");
bounds->low = *low_bound;
bounds->high = *high_bound;
bounds->bias = bias;
-
- /* Initialize the stride to be a constant, the value will already be zero
- thanks to the use of TYPE_ZALLOC above. */
- bounds->stride.kind = PROP_CONST;
+ bounds->stride.set_const_val (0);
result_type->set_bounds (bounds);
- if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
+ if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0)
TYPE_UNSIGNED (result_type) = 1;
/* Ada allows the declaration of range types whose upper bound is
less than the lower bound, so checking the lower bound is not
enough. Make sure we do not mark a range type whose upper bound
is negative as unsigned. */
- if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
+ if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0)
TYPE_UNSIGNED (result_type) = 0;
TYPE_ENDIANITY_NOT_DEFAULT (result_type)
{
struct dynamic_prop low, high;
- low.kind = PROP_CONST;
- low.data.const_val = low_bound;
-
- high.kind = PROP_CONST;
- high.data.const_val = high_bound;
+ low.set_const_val (low_bound);
+ high.set_const_val (high_bound);
result_type = create_range_type (result_type, index_type, &low, &high, 0);
{
/* If the range doesn't have a defined stride then its stride field will
be initialized to the constant 0. */
- return (bounds->low.kind == PROP_CONST
- && bounds->high.kind == PROP_CONST
- && bounds->stride.kind == PROP_CONST);
+ return (bounds->low.kind () == PROP_CONST
+ && bounds->high.kind () == PROP_CONST
+ && bounds->stride.kind () == PROP_CONST);
}
unsigned int bit_stride)
{
if (byte_stride_prop != NULL
- && byte_stride_prop->kind == PROP_CONST)
+ && byte_stride_prop->kind () == PROP_CONST)
{
/* The byte stride is actually not dynamic. Pretend we were
called with bit_stride set instead of byte_stride_prop.
This will give us the same result type, while avoiding
the need to handle this as a special case. */
- bit_stride = byte_stride_prop->data.const_val * 8;
+ bit_stride = byte_stride_prop->const_val () * 8;
byte_stride_prop = NULL;
}
{
struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_BYTE_STRIDE);
- return (prop != NULL && prop->kind != PROP_CONST);
+ return (prop != NULL && prop->kind () != PROP_CONST);
}
/* Worker for is_dynamic_type. */
return 1;
struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
- if (prop != nullptr && prop->kind != PROP_TYPE)
+ if (prop != nullptr && prop->kind () != PROP_TYPE)
return 1;
if (TYPE_HAS_DYNAMIC_LENGTH (type))
const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low;
if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
- {
- low_bound.kind = PROP_CONST;
- low_bound.data.const_val = value;
- }
+ low_bound.set_const_val (value);
else
- {
- low_bound.kind = PROP_UNDEFINED;
- low_bound.data.const_val = 0;
- }
+ low_bound.set_undefined ();
prop = &dyn_range_type->bounds ()->high;
if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
{
- high_bound.kind = PROP_CONST;
- high_bound.data.const_val = value;
+ high_bound.set_const_val (value);
if (dyn_range_type->bounds ()->flag_upper_bound_is_count)
- high_bound.data.const_val
- = low_bound.data.const_val + high_bound.data.const_val - 1;
+ high_bound.set_const_val
+ (low_bound.const_val () + high_bound.const_val () - 1);
}
else
- {
- high_bound.kind = PROP_UNDEFINED;
- high_bound.data.const_val = 0;
- }
+ high_bound.set_undefined ();
bool byte_stride_p = dyn_range_type->bounds ()->flag_is_byte_stride;
prop = &dyn_range_type->bounds ()->stride;
if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
{
- stride.kind = PROP_CONST;
- stride.data.const_val = value;
+ stride.set_const_val (value);
/* If we have a bit stride that is not an exact number of bytes then
I really don't think this is going to work with current GDB, the
}
else
{
- stride.kind = PROP_UNDEFINED;
- stride.data.const_val = 0;
+ stride.set_undefined ();
byte_stride_p = true;
}
will update the length of the array accordingly. */
prop = TYPE_ALLOCATED_PROP (type);
if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
- {
- TYPE_DYN_PROP_ADDR (prop) = value;
- TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
- }
+ prop->set_const_val (value);
+
prop = TYPE_ASSOCIATED_PROP (type);
if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
- {
- TYPE_DYN_PROP_ADDR (prop) = value;
- TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
- }
+ prop->set_const_val (value);
ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
resolved_type = copy_type (type);
dynamic_prop *variant_prop = resolved_type->dyn_prop (DYN_PROP_VARIANT_PARTS);
- if (variant_prop != nullptr && variant_prop->kind == PROP_VARIANT_PARTS)
+ if (variant_prop != nullptr && variant_prop->kind () == PROP_VARIANT_PARTS)
{
compute_variant_fields (type, resolved_type, addr_stack,
- *variant_prop->data.variant_parts);
+ *variant_prop->variant_parts ());
/* We want to leave the property attached, so that the Rust code
can tell whether the type was originally an enum. */
- variant_prop->kind = PROP_TYPE;
- variant_prop->data.original_type = type;
+ variant_prop->set_original_type (type);
}
else
{
baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (resolved_type, i);
struct dynamic_prop prop;
- prop.kind = PROP_LOCEXPR;
- prop.data.baton = &baton;
+ prop.set_locexpr (&baton);
CORE_ADDR addr;
if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr,
prop = TYPE_DATA_LOCATION (resolved_type);
if (prop != NULL
&& dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
- {
- TYPE_DYN_PROP_ADDR (prop) = value;
- TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
- }
+ prop->set_const_val (value);
return resolved_type;
}
struct dynamic_prop
{
+ dynamic_prop_kind kind () const
+ {
+ return m_kind;
+ }
+
+ void set_undefined ()
+ {
+ m_kind = PROP_UNDEFINED;
+ }
+
+ LONGEST const_val () const
+ {
+ gdb_assert (m_kind == PROP_CONST);
+
+ return m_data.const_val;
+ }
+
+ void set_const_val (LONGEST const_val)
+ {
+ m_kind = PROP_CONST;
+ m_data.const_val = const_val;
+ }
+
+ void *baton () const
+ {
+ gdb_assert (m_kind == PROP_LOCEXPR
+ || m_kind == PROP_LOCLIST
+ || m_kind == PROP_ADDR_OFFSET);
+
+ return m_data.baton;
+ }
+
+ void set_locexpr (void *baton)
+ {
+ m_kind = PROP_LOCEXPR;
+ m_data.baton = baton;
+ }
+
+ void set_loclist (void *baton)
+ {
+ m_kind = PROP_LOCLIST;
+ m_data.baton = baton;
+ }
+
+ void set_addr_offset (void *baton)
+ {
+ m_kind = PROP_ADDR_OFFSET;
+ m_data.baton = baton;
+ }
+
+ const gdb::array_view<variant_part> *variant_parts () const
+ {
+ gdb_assert (m_kind == PROP_VARIANT_PARTS);
+
+ return m_data.variant_parts;
+ }
+
+ void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
+ {
+ m_kind = PROP_VARIANT_PARTS;
+ m_data.variant_parts = variant_parts;
+ }
+
+ struct type *original_type () const
+ {
+ gdb_assert (m_kind == PROP_TYPE);
+
+ return m_data.original_type;
+ }
+
+ void set_original_type (struct type *original_type)
+ {
+ m_kind = PROP_TYPE;
+ m_data.original_type = original_type;
+ }
+
/* Determine which field of the union dynamic_prop.data is used. */
- enum dynamic_prop_kind kind;
+ enum dynamic_prop_kind m_kind;
/* Storage for dynamic or static value. */
- union dynamic_prop_data data;
+ union dynamic_prop_data m_data;
};
/* Compare two dynamic_prop objects for equality. dynamic_prop
extern bool set_type_align (struct type *, ULONGEST);
#define TYPE_LOW_BOUND(range_type) \
- ((range_type)->bounds ()->low.data.const_val)
+ ((range_type)->bounds ()->low.const_val ())
#define TYPE_HIGH_BOUND(range_type) \
- ((range_type)->bounds ()->high.data.const_val)
+ ((range_type)->bounds ()->high.const_val ())
#define TYPE_LOW_BOUND_UNDEFINED(range_type) \
(TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
#define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
(TYPE_HIGH_BOUND_KIND(range_type) == PROP_UNDEFINED)
#define TYPE_HIGH_BOUND_KIND(range_type) \
- ((range_type)->bounds ()->high.kind)
+ ((range_type)->bounds ()->high.kind ())
#define TYPE_LOW_BOUND_KIND(range_type) \
- ((range_type)->bounds ()->low.kind)
+ ((range_type)->bounds ()->low.kind ())
#define TYPE_BIT_STRIDE(range_type) \
- ((range_type)->bounds ()->stride.data.const_val \
+ ((range_type)->bounds ()->stride.const_val () \
* ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
/* Property accessors for the type data location. */
#define TYPE_DATA_LOCATION_BATON(thistype) \
TYPE_DATA_LOCATION (thistype)->data.baton
#define TYPE_DATA_LOCATION_ADDR(thistype) \
- TYPE_DATA_LOCATION (thistype)->data.const_val
+ (TYPE_DATA_LOCATION (thistype)->const_val ())
#define TYPE_DATA_LOCATION_KIND(thistype) \
- TYPE_DATA_LOCATION (thistype)->kind
+ (TYPE_DATA_LOCATION (thistype)->kind ())
#define TYPE_DYNAMIC_LENGTH(thistype) \
((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))
#define TYPE_DYN_PROP_BATON(dynprop) \
dynprop->data.baton
#define TYPE_DYN_PROP_ADDR(dynprop) \
- dynprop->data.const_val
+ (dynprop->const_val ())
#define TYPE_DYN_PROP_KIND(dynprop) \
- dynprop->kind
+ (dynprop->kind ())
/* Accessors for struct range_bounds data attached to an array type's
baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (type, index);
struct dynamic_prop prop;
- prop.kind = PROP_LOCEXPR;
- prop.data.baton = &baton;
+ prop.set_locexpr (&baton);
struct property_addr_info addr_stack;
addr_stack.type = type;
tp->set_num_fields (0);
tp->set_bounds (((struct range_bounds *)
TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
- TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
+ tp->bounds ()->low.set_const_val (AUX_GET_DNLOW (bigend, ax));
ax++;
- TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
+ tp->bounds ()->high.set_const_val (AUX_GET_DNHIGH (bigend, ax));
ax++;
}
maximum value. */
bound_info = 0;
high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
- TYPE_HIGH_BOUND (range) = high_bound;
+ range->bounds ()->high.set_const_val (high_bound);
}
maybe_bad_bstring:
if (bound_info < 0)
{
fputs_filtered ("enum ", stream);
dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
- if (prop != nullptr && prop->kind == PROP_TYPE)
- type = prop->data.original_type;
+ if (prop != nullptr && prop->kind () == PROP_TYPE)
+ type = prop->original_type ();
}
else if (type->code () == TYPE_CODE_STRUCT)
fputs_filtered ("struct ", stream);
lookup_array_range_type (follow_type,
0, array_size >= 0 ? array_size - 1 : 0);
if (array_size < 0)
- TYPE_HIGH_BOUND_KIND (follow_type->index_type ())
- = PROP_UNDEFINED;
+ follow_type->index_type ()->bounds ()->high.set_undefined ();
break;
case tp_function:
/* FIXME-type-allocation: need a way to free this type when we are