aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-07-30 12:01:12 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2022-09-21 10:59:51 -0400
commitb6cdbc9a8173b9e6cc8cfc284caa0efa8129ca02 (patch)
tree4b7956463a020307fcfa270fdb15f744adcf5c18 /gdb
parent27710edb4e588d0360620df424dd7ee7e8cfafee (diff)
downloadgdb-b6cdbc9a8173b9e6cc8cfc284caa0efa8129ca02.zip
gdb-b6cdbc9a8173b9e6cc8cfc284caa0efa8129ca02.tar.gz
gdb-b6cdbc9a8173b9e6cc8cfc284caa0efa8129ca02.tar.bz2
gdb: add type::length / type::set_length
Add the `length` and `set_length` methods on `struct type`, in order to remove the `TYPE_LENGTH` macro. In this patch, the macro is changed to use the getter, so all the call sites of the macro that are used as a setter are changed to use the setter method directly. The next patch will remove the macro completely. Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ada-lang.c47
-rw-r--r--gdb/coffread.c14
-rw-r--r--gdb/cp-valprint.c2
-rw-r--r--gdb/ctfread.c10
-rw-r--r--gdb/dwarf2/read.c44
-rw-r--r--gdb/eval.c2
-rw-r--r--gdb/f-valprint.c6
-rw-r--r--gdb/gdbtypes.c71
-rw-r--r--gdb/gdbtypes.h16
-rw-r--r--gdb/mdebugread.c4
-rw-r--r--gdb/opencl-lang.c2
-rw-r--r--gdb/rust-lang.c5
-rw-r--r--gdb/stabsread.c10
-rw-r--r--gdb/target-descriptions.c2
14 files changed, 119 insertions, 116 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 95fb37b..9342566 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2165,7 +2165,7 @@ ada_type_of_array (struct value *arr, int bounds)
int array_bitsize =
(hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0);
- TYPE_LENGTH (array_type) = (array_bitsize + 7) / 8;
+ array_type->set_length ((array_bitsize + 7) / 8);
}
}
}
@@ -2392,12 +2392,14 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
|| !get_discrete_bounds (index_type, &low_bound, &high_bound))
low_bound = high_bound = 0;
if (high_bound < low_bound)
- *elt_bits = TYPE_LENGTH (new_type) = 0;
+ {
+ *elt_bits = 0;
+ new_type->set_length (0);
+ }
else
{
*elt_bits *= (high_bound - low_bound + 1);
- TYPE_LENGTH (new_type) =
- (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
+ new_type->set_length ((*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT);
}
new_type->set_is_fixed_instance (true);
@@ -2471,8 +2473,8 @@ recursively_update_array_bitsize (struct type *type)
LONGEST elt_bitsize = elt_len * TYPE_FIELD_BITSIZE (elt_type, 0);
TYPE_FIELD_BITSIZE (type, 0) = elt_bitsize;
- TYPE_LENGTH (type) = ((our_len * elt_bitsize + HOST_CHAR_BIT - 1)
- / HOST_CHAR_BIT);
+ type->set_length (((our_len * elt_bitsize + HOST_CHAR_BIT - 1)
+ / HOST_CHAR_BIT));
}
return our_len;
@@ -7826,7 +7828,7 @@ empty_record (struct type *templ)
type->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (type);
type->set_name ("<empty>");
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
return type;
}
@@ -7996,8 +7998,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
if (off + fld_bit_len > bit_len)
bit_len = off + fld_bit_len;
off += fld_bit_len;
- TYPE_LENGTH (rtype) =
- align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
+ rtype->set_length (align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT);
}
/* We handle the variant part, if any, at the end because of certain
@@ -8042,8 +8043,9 @@ ada_template_to_fixed_record_type_1 (struct type *type,
TARGET_CHAR_BIT;
if (off + fld_bit_len > bit_len)
bit_len = off + fld_bit_len;
- TYPE_LENGTH (rtype) =
- align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT;
+
+ rtype->set_length
+ (align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT);
}
}
@@ -8063,10 +8065,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
pulongest (TYPE_LENGTH (type)));
}
else
- {
- TYPE_LENGTH (rtype) = align_up (TYPE_LENGTH (rtype),
- TYPE_LENGTH (type));
- }
+ rtype->set_length (align_up (TYPE_LENGTH (rtype), TYPE_LENGTH (type)));
value_free_to_mark (mark);
return rtype;
@@ -8148,7 +8147,7 @@ template_to_static_fixed_type (struct type *type0)
type->set_name (ada_type_name (type0));
type->set_is_fixed_instance (true);
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
}
type->field (f).set_type (new_type);
type->field (f).set_name (type0->field (f).name ());
@@ -8199,7 +8198,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
rtype->set_name (ada_type_name (type));
rtype->set_is_fixed_instance (true);
- TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
+ rtype->set_length (TYPE_LENGTH (type));
branch_type = to_fixed_variant_branch_type
(type->field (variant_field).type (),
@@ -8222,9 +8221,11 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
rtype->field (variant_field).set_type (branch_type);
rtype->field (variant_field).set_name ("S");
TYPE_FIELD_BITSIZE (rtype, variant_field) = 0;
- TYPE_LENGTH (rtype) += TYPE_LENGTH (branch_type);
+ rtype->set_length (TYPE_LENGTH (rtype) + TYPE_LENGTH (branch_type));
}
- TYPE_LENGTH (rtype) -= TYPE_LENGTH (type->field (variant_field).type ());
+
+ rtype->set_length (TYPE_LENGTH (rtype)
+ - TYPE_LENGTH (type->field (variant_field).type ()));
value_free_to_mark (mark);
return rtype;
@@ -8532,9 +8533,9 @@ to_fixed_array_type (struct type *type0, struct value *dval,
int elt_bitsize = TYPE_FIELD_BITSIZE (type0, 0);
TYPE_FIELD_BITSIZE (result, 0) = TYPE_FIELD_BITSIZE (type0, 0);
- TYPE_LENGTH (result) = len * elt_bitsize / HOST_CHAR_BIT;
+ result->set_length (len * elt_bitsize / HOST_CHAR_BIT);
if (TYPE_LENGTH (result) * HOST_CHAR_BIT < len * elt_bitsize)
- TYPE_LENGTH (result)++;
+ result->set_length (TYPE_LENGTH (result) + 1);
}
result->set_is_fixed_instance (true);
@@ -8630,7 +8631,7 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
{
fixed_record_type = copy_type (fixed_record_type);
- TYPE_LENGTH (fixed_record_type) = size;
+ fixed_record_type->set_length (size);
/* The FIXED_RECORD_TYPE may have be a stub. We have
observed this when the debugging info is STABS, and
@@ -11528,7 +11529,7 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
/* create_static_range_type alters the resulting type's length
to match the size of the base_type, which is not what we want.
Set it back to the original range type's length. */
- TYPE_LENGTH (type) = TYPE_LENGTH (raw_type);
+ type->set_length (TYPE_LENGTH (raw_type));
type->set_name (name);
return type;
}
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 27afa11..8019789 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1472,7 +1472,7 @@ patch_type (struct type *type, struct type *real_type)
struct type *real_target = real_type->target_type ();
int field_size = real_target->num_fields () * sizeof (struct field);
- TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
+ target->set_length (real_target->length ());
target->set_num_fields (real_target->num_fields ());
field *fields = (struct field *) TYPE_ALLOC (target, field_size);
@@ -1887,7 +1887,7 @@ decode_base_type (struct coff_symbol *cs,
type->set_code (TYPE_CODE_STRUCT);
type->set_name (NULL);
INIT_CPLUS_SPECIFIC (type);
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_fields (nullptr);
type->set_num_fields (0);
}
@@ -1907,7 +1907,7 @@ decode_base_type (struct coff_symbol *cs,
type = coff_alloc_type (cs->c_symnum);
type->set_name (NULL);
INIT_CPLUS_SPECIFIC (type);
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_fields (nullptr);
type->set_num_fields (0);
}
@@ -1928,7 +1928,7 @@ decode_base_type (struct coff_symbol *cs,
type = coff_alloc_type (cs->c_symnum);
type->set_code (TYPE_CODE_ENUM);
type->set_name (NULL);
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_fields (nullptr);
type->set_num_fields (0);
}
@@ -1996,7 +1996,7 @@ coff_read_struct_type (int index, int length, int lastsym,
type = coff_alloc_type (index);
type->set_code (TYPE_CODE_STRUCT);
INIT_CPLUS_SPECIFIC (type);
- TYPE_LENGTH (type) = length;
+ type->set_length (length);
while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
{
@@ -2124,9 +2124,9 @@ coff_read_enum_type (int index, int length, int lastsym,
/* Now fill in the fields of the type-structure. */
if (length > 0)
- TYPE_LENGTH (type) = length;
+ type->set_length (length);
else /* Assume ints. */
- TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
+ type->set_length (gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT);
type->set_code (TYPE_CODE_ENUM);
type->set_num_fields (nsyms);
type->set_fields
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 07bbb9b..86bc57b 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -729,7 +729,7 @@ test_print_fields (gdbarch *arch)
type *uint8_type = builtin_type (arch)->builtin_uint8;
type *bool_type = builtin_type (arch)->builtin_bool;
type *the_struct = arch_composite_type (arch, NULL, TYPE_CODE_STRUCT);
- TYPE_LENGTH (the_struct) = 4;
+ the_struct->set_length (4);
/* Value: 1110 1001
Fields: C-BB B-A- */
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 561534f..890cb91 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -641,7 +641,7 @@ read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
else
type->set_code (TYPE_CODE_STRUCT);
- TYPE_LENGTH (type) = ctf_type_size (fp, tid);
+ type->set_length (ctf_type_size (fp, tid));
set_type_align (type, ctf_type_align (fp, tid));
return set_tid_type (ccp->of, tid, type);
@@ -747,7 +747,7 @@ read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
type->set_name (name);
type->set_code (TYPE_CODE_ENUM);
- TYPE_LENGTH (type) = ctf_type_size (fp, tid);
+ type->set_length (ctf_type_size (fp, tid));
/* Set the underlying type based on its ctf_type_size bits. */
type->set_target_type (objfile_int_type (of, TYPE_LENGTH (type), false));
set_type_align (type, ctf_type_align (fp, tid));
@@ -834,11 +834,11 @@ read_array_type (struct ctf_context *ccp, ctf_id_t tid)
if (ar.ctr_nelems <= 1) /* Check if undefined upper bound. */
{
range_type->bounds ()->high.set_undefined ();
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_target_is_stub (true);
}
else
- TYPE_LENGTH (type) = ctf_type_size (fp, tid);
+ type->set_length (ctf_type_size (fp, tid));
set_type_align (type, ctf_type_align (fp, tid));
@@ -988,7 +988,7 @@ read_forward_type (struct ctf_context *ccp, ctf_id_t tid)
else
type->set_code (TYPE_CODE_STRUCT);
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
type->set_is_stub (true);
return set_tid_type (of, tid, type);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d358297..ef988d7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -8191,7 +8191,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
/* In Rust, each element should have the size of the
enclosing enum. */
- TYPE_LENGTH (type->field (i).type ()) = TYPE_LENGTH (type);
+ type->field (i).type ()->set_length (TYPE_LENGTH (type));
/* Remove the discriminant field, if it exists. */
struct type *sub_type = type->field (i).type ();
@@ -14640,19 +14640,18 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
if (attr != nullptr)
{
if (attr->form_is_constant ())
- TYPE_LENGTH (type) = attr->constant_value (0);
+ type->set_length (attr->constant_value (0));
else
{
struct dynamic_prop prop;
if (attr_to_dynamic_prop (attr, die, cu, &prop, cu->addr_type ()))
type->add_dyn_prop (DYN_PROP_BYTE_SIZE, prop);
- TYPE_LENGTH (type) = 0;
+
+ type->set_length (0);
}
}
else
- {
- TYPE_LENGTH (type) = 0;
- }
+ type->set_length (0);
maybe_set_alignment (cu, die, type);
@@ -15200,13 +15199,9 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- {
- TYPE_LENGTH (type) = attr->constant_value (0);
- }
+ type->set_length (attr->constant_value (0));
else
- {
- TYPE_LENGTH (type) = 0;
- }
+ type->set_length (0);
maybe_set_alignment (cu, die, type);
@@ -15233,7 +15228,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
type->set_is_unsigned (underlying_type->is_unsigned ());
if (TYPE_LENGTH (type) == 0)
- TYPE_LENGTH (type) = TYPE_LENGTH (underlying_type);
+ type->set_length (TYPE_LENGTH (underlying_type));
if (TYPE_RAW_ALIGN (type) == 0
&& TYPE_RAW_ALIGN (underlying_type) != 0)
@@ -15530,7 +15525,7 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
int last_fieldno = range_fields.size () - 1;
int bounds_size = (bounds->field (last_fieldno).loc_bitpos () / 8
+ TYPE_LENGTH (bounds->field (last_fieldno).type ()));
- TYPE_LENGTH (bounds) = align_up (bounds_size, max_align);
+ bounds->set_length (align_up (bounds_size, max_align));
/* Rewrite the existing array type in place. Specifically, we
remove any dynamic properties we might have read, and we replace
@@ -15564,8 +15559,8 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
result->field (1).set_loc_bitpos (8 * bounds_offset);
result->set_name (type->name ());
- TYPE_LENGTH (result) = (TYPE_LENGTH (result->field (0).type ())
- + TYPE_LENGTH (result->field (1).type ()));
+ result->set_length (TYPE_LENGTH (result->field (0).type ())
+ + TYPE_LENGTH (result->field (1).type ()));
return result;
}
@@ -15706,7 +15701,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
if (attr != nullptr && attr->form_is_unsigned ())
{
if (attr->as_unsigned () >= TYPE_LENGTH (type))
- TYPE_LENGTH (type) = attr->as_unsigned ();
+ type->set_length (attr->as_unsigned ());
else
complaint (_("DW_AT_byte_size for array type smaller "
"than the total size of elements"));
@@ -15792,7 +15787,7 @@ read_set_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr && attr->form_is_unsigned ())
- TYPE_LENGTH (set_type) = attr->as_unsigned ();
+ set_type->set_length (attr->as_unsigned ());
maybe_set_alignment (cu, die, set_type);
@@ -16194,7 +16189,7 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
}
}
- TYPE_LENGTH (type) = byte_size;
+ type->set_length (byte_size);
set_type_align (type, alignment);
return set_die_type (die, type, cu);
}
@@ -16257,13 +16252,10 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu,
type = lookup_reference_type (target_type, refcode);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- {
- TYPE_LENGTH (type) = attr->constant_value (cu_header->addr_size);
- }
+ type->set_length (attr->constant_value (cu_header->addr_size));
else
- {
- TYPE_LENGTH (type) = cu_header->addr_size;
- }
+ type->set_length (cu_header->addr_size);
+
maybe_set_alignment (cu, die, type);
return set_die_type (die, type, cu);
}
@@ -17692,7 +17684,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
if (attr != nullptr)
- TYPE_LENGTH (range_type) = attr->constant_value (0);
+ range_type->set_length (attr->constant_value (0));
maybe_set_alignment (cu, die, range_type);
diff --git a/gdb/eval.c b/gdb/eval.c
index ddbdd95..a6e295d 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -482,7 +482,7 @@ fake_method::fake_method (type_instance_flags flags,
struct type *type = &m_type;
TYPE_MAIN_TYPE (type) = &m_main_type;
- TYPE_LENGTH (type) = 1;
+ type->set_length (1);
type->set_code (TYPE_CODE_METHOD);
TYPE_CHAIN (type) = type;
type->set_instance_flags (flags);
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 544657d..2dda1b8 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -91,10 +91,8 @@ f77_get_dynamic_length_of_aggregate (struct type *type)
upper_bound = f77_get_upperbound (type);
/* Patch in a valid length value. */
-
- TYPE_LENGTH (type) =
- (upper_bound - lower_bound + 1)
- * TYPE_LENGTH (check_typedef (type->target_type ()));
+ type->set_length ((upper_bound - lower_bound + 1)
+ * TYPE_LENGTH (check_typedef (type->target_type ())));
}
/* Per-dimension statistics. */
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 71a8bd1..a306c1a 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -376,7 +376,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
/* FIXME! Assumes the machine has only one representation for pointers! */
- TYPE_LENGTH (ntype) = gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT;
+ ntype->set_length (gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT);
ntype->set_code (TYPE_CODE_PTR);
/* Mark pointers as unsigned. The target converts between pointers
@@ -388,7 +388,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
chain = TYPE_CHAIN (ntype);
while (chain != ntype)
{
- TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
+ chain->set_length (TYPE_LENGTH (ntype));
chain = TYPE_CHAIN (chain);
}
@@ -459,7 +459,7 @@ make_reference_type (struct type *type, struct type **typeptr,
references, and that it matches the (only) representation for
pointers! */
- TYPE_LENGTH (ntype) = gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT;
+ ntype->set_length (gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT);
ntype->set_code (refcode);
*reftype = ntype;
@@ -468,7 +468,7 @@ make_reference_type (struct type *type, struct type **typeptr,
chain = TYPE_CHAIN (ntype);
while (chain != ntype)
{
- TYPE_LENGTH (chain) = TYPE_LENGTH (ntype);
+ chain->set_length (TYPE_LENGTH (ntype));
chain = TYPE_CHAIN (chain);
}
@@ -524,7 +524,7 @@ make_function_type (struct type *type, struct type **typeptr)
ntype->set_target_type (type);
- TYPE_LENGTH (ntype) = 1;
+ ntype->set_length (1);
ntype->set_code (TYPE_CODE_FUNC);
INIT_FUNC_SPECIFIC (ntype);
@@ -671,7 +671,7 @@ make_qualified_type (struct type *type, type_instance_flags new_flags,
ntype->set_instance_flags (new_flags);
/* Set length of new type to that of the original type. */
- TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
+ ntype->set_length (TYPE_LENGTH (type));
return ntype;
}
@@ -824,7 +824,7 @@ replace_type (struct type *ntype, struct type *type)
call replace_type(). */
gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
- TYPE_LENGTH (chain) = TYPE_LENGTH (type);
+ chain->set_length (TYPE_LENGTH (type));
chain = TYPE_CHAIN (chain);
}
while (ntype != chain);
@@ -874,7 +874,7 @@ allocate_stub_method (struct type *type)
mtype = alloc_type_copy (type);
mtype->set_code (TYPE_CODE_METHOD);
- TYPE_LENGTH (mtype) = 1;
+ mtype->set_length (1);
mtype->set_is_stub (true);
mtype->set_target_type (type);
/* TYPE_SELF_TYPE (mtype) = unknown yet */
@@ -945,7 +945,7 @@ create_range_type (struct type *result_type, struct type *index_type,
if (index_type->is_stub ())
result_type->set_target_is_stub (true);
else
- TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
+ result_type->set_length (TYPE_LENGTH (check_typedef (index_type)));
range_bounds *bounds
= (struct range_bounds *) TYPE_ZALLOC (result_type, sizeof (range_bounds));
@@ -1297,7 +1297,7 @@ update_static_array_size (struct type *type)
empty arrays with the high_bound being smaller than the low_bound.
In such cases, the array length should be zero. */
if (high_bound < low_bound)
- TYPE_LENGTH (type) = 0;
+ type->set_length (0);
else if (stride != 0)
{
/* Ensure that the type length is always positive, even in the
@@ -1307,12 +1307,11 @@ update_static_array_size (struct type *type)
special, it's still just a single element array) so do
consider that case when touching this code. */
LONGEST element_count = std::abs (high_bound - low_bound + 1);
- TYPE_LENGTH (type)
- = ((std::abs (stride) * element_count) + 7) / 8;
+ type->set_length (((std::abs (stride) * element_count) + 7) / 8);
}
else
- TYPE_LENGTH (type) =
- TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
+ type->set_length (TYPE_LENGTH (element_type)
+ * (high_bound - low_bound + 1));
/* If this array's element is itself an array with a bit stride,
then we want to update this array's bit stride to reflect the
@@ -1397,7 +1396,7 @@ create_array_type_with_stride (struct type *result_type,
to trust TYPE_LENGTH in this case, setting the size to zero
allows us to avoid allocating objects of random sizes in case
we accidently do. */
- TYPE_LENGTH (result_type) = 0;
+ result_type->set_length (0);
}
/* TYPE_TARGET_STUB will take care of zero length arrays. */
@@ -1492,8 +1491,8 @@ create_set_type (struct type *result_type, struct type *domain_type)
low_bound = high_bound = 0;
bit_length = high_bound - low_bound + 1;
- TYPE_LENGTH (result_type)
- = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
+ result_type->set_length ((bit_length + TARGET_CHAR_BIT - 1)
+ / TARGET_CHAR_BIT);
if (low_bound >= 0)
result_type->set_is_unsigned (true);
}
@@ -1614,7 +1613,7 @@ smash_to_memberptr_type (struct type *type, struct type *self_type,
set_type_self_type (type, self_type);
/* Assume that a data member pointer is the same size as a normal
pointer. */
- TYPE_LENGTH (type) = gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_BIT;
+ type->set_length (gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_BIT);
}
/* Smash TYPE to be a type of pointer to methods type TO_TYPE.
@@ -1630,7 +1629,7 @@ smash_to_methodptr_type (struct type *type, struct type *to_type)
type->set_code (TYPE_CODE_METHODPTR);
type->set_target_type (to_type);
set_type_self_type (type, TYPE_SELF_TYPE (to_type));
- TYPE_LENGTH (type) = cplus_method_ptr_size (to_type);
+ type->set_length (cplus_method_ptr_size (to_type));
}
/* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE.
@@ -1651,9 +1650,12 @@ smash_to_method_type (struct type *type, struct type *self_type,
set_type_self_type (type, self_type);
type->set_fields (args);
type->set_num_fields (nargs);
+
if (varargs)
type->set_has_varargs (true);
- TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
+
+ /* In practice, this is never needed. */
+ type->set_length (1);
}
/* A wrapper of TYPE_NAME which calls error if the type is anonymous.
@@ -2503,7 +2505,7 @@ resolve_dynamic_union (struct type *type,
max_len = TYPE_LENGTH (real_type);
}
- TYPE_LENGTH (resolved_type) = max_len;
+ resolved_type->set_length (max_len);
return resolved_type;
}
@@ -2777,8 +2779,8 @@ resolve_dynamic_struct (struct type *type,
type length of the structure. If we adapt it, we run into problems
when calculating the element offset for arrays of structs. */
if (current_language->la_language != language_fortran)
- TYPE_LENGTH (resolved_type)
- = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
+ resolved_type->set_length ((resolved_type_bit_length + TARGET_CHAR_BIT - 1)
+ / TARGET_CHAR_BIT);
/* The Ada language uses this field as a cache for static fixed types: reset
it as RESOLVED_TYPE must have its own static fixed type. */
@@ -2873,7 +2875,7 @@ resolve_dynamic_type_internal (struct type *type,
if (type_length.has_value ())
{
- TYPE_LENGTH (resolved_type) = *type_length;
+ resolved_type->set_length (*type_length);
resolved_type->remove_dyn_prop (DYN_PROP_BYTE_SIZE);
}
@@ -3146,7 +3148,7 @@ check_typedef (struct type *type)
}
else if (type->code () == TYPE_CODE_RANGE)
{
- TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
+ type->set_length (TYPE_LENGTH (target_type));
type->set_target_is_stub (false);
}
else if (type->code () == TYPE_CODE_ARRAY
@@ -3157,7 +3159,7 @@ check_typedef (struct type *type)
type = make_qualified_type (type, instance_flags, NULL);
/* Cache TYPE_LENGTH for future use. */
- TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
+ orig_type->set_length (TYPE_LENGTH (type));
return type;
}
@@ -3430,7 +3432,7 @@ init_type (struct objfile *objfile, enum type_code code, int bit,
type = alloc_type (objfile);
set_type_code (type, code);
gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
- TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
+ type->set_length (bit / TARGET_CHAR_BIT);
type->set_name (name);
return type;
@@ -3579,7 +3581,7 @@ init_complex_type (const char *name, struct type *target_type)
t = alloc_type_copy (target_type);
set_type_code (t, TYPE_CODE_COMPLEX);
- TYPE_LENGTH (t) = 2 * TYPE_LENGTH (target_type);
+ t->set_length (2 * TYPE_LENGTH (target_type));
t->set_name (name);
t->set_target_type (target_type);
@@ -5658,7 +5660,7 @@ copy_type_recursive (struct type *type, htab_t copied_types)
new_type->set_name (xstrdup (type->name ()));
new_type->set_instance_flags (type->instance_flags ());
- TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
+ new_type->set_length (TYPE_LENGTH (type));
/* Copy the fields. */
if (type->num_fields ())
@@ -5787,7 +5789,7 @@ copy_type (const struct type *type)
{
struct type *new_type = alloc_type_copy (type);
new_type->set_instance_flags (type->instance_flags ());
- TYPE_LENGTH (new_type) = TYPE_LENGTH (type);
+ new_type->set_length (TYPE_LENGTH (type));
memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
sizeof (struct main_type));
if (type->main_type->dyn_prop_list != NULL)
@@ -5816,7 +5818,7 @@ arch_type (struct gdbarch *gdbarch,
type = alloc_type_arch (gdbarch);
set_type_code (type, code);
gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
- TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
+ type->set_length (bit / TARGET_CHAR_BIT);
if (name)
type->set_name (gdbarch_obstack_strdup (gdbarch, name));
@@ -6026,11 +6028,11 @@ append_composite_type_field_aligned (struct type *t, const char *name,
if (t->code () == TYPE_CODE_UNION)
{
if (TYPE_LENGTH (t) < TYPE_LENGTH (field))
- TYPE_LENGTH (t) = TYPE_LENGTH (field);
+ t->set_length (TYPE_LENGTH (field));
}
else if (t->code () == TYPE_CODE_STRUCT)
{
- TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
+ t->set_length (TYPE_LENGTH (t) + TYPE_LENGTH (field));
if (t->num_fields () > 1)
{
f->set_loc_bitpos
@@ -6046,7 +6048,8 @@ append_composite_type_field_aligned (struct type *t, const char *name,
if (left)
{
f->set_loc_bitpos (f[0].loc_bitpos () + (alignment - left));
- TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
+ t->set_length
+ (t->length () + (alignment - left) / TARGET_CHAR_BIT);
}
}
}
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 6f4b2d6..6d12a48 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1045,6 +1045,16 @@ struct type
this->main_type->name = name;
}
+ ULONGEST length () const
+ {
+ return this->m_length;
+ }
+
+ void set_length (ULONGEST length)
+ {
+ this->m_length = length;
+ }
+
/* Get the number of fields of this type. */
int num_fields () const
{
@@ -1443,7 +1453,7 @@ struct type
bool bit_size_differs_p () const
{
return (main_type->type_specific_field == TYPE_SPECIFIC_INT
- && main_type->type_specific.int_stuff.bit_size != 8 * length);
+ && main_type->type_specific.int_stuff.bit_size != 8 * length ());
}
/* * Return the logical (bit) size for this integer type. Only
@@ -1528,7 +1538,7 @@ struct type
type_length_units function should be used in order to get the length
expressed in target addressable memory units. */
- ULONGEST length;
+ ULONGEST m_length;
/* * Core type, shared by a group of qualified types. */
@@ -2105,7 +2115,7 @@ extern void allocate_gnat_aux_type (struct type *);
But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
so you only have to call check_typedef once. Since allocate_value
calls check_typedef, TYPE_LENGTH (VALUE_TYPE (X)) is safe. */
-#define TYPE_LENGTH(thistype) (thistype)->length
+#define TYPE_LENGTH(thistype) ((thistype)->length ())
/* * Return the alignment of the type in target addressable memory
units, or 0 if no alignment was specified. */
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 673c370..56710cf 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1022,7 +1022,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
name, (char *) NULL));
t->set_code (type_code);
- TYPE_LENGTH (t) = sh->value;
+ t->set_length (sh->value);
t->set_num_fields (nfields);
f = ((struct field *) TYPE_ALLOC (t, nfields * sizeof (struct field)));
t->set_fields (f);
@@ -1043,7 +1043,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
that too. */
if (TYPE_LENGTH (t) == t->num_fields ()
|| TYPE_LENGTH (t) == 0)
- TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
+ t->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT);
for (ext_tsym = ext_sh + external_sym_size;
;
ext_tsym += external_sym_size)
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 32aa58c..5bd3edb 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -899,7 +899,7 @@ public:
tmp->set_name (OCL_STRING(TYPE ## 2)); \
tmp = add (init_vector_type (ELEMENT_TYPE, 3)); \
tmp->set_name (OCL_STRING(TYPE ## 3)); \
- TYPE_LENGTH (tmp) = 4 * TYPE_LENGTH (ELEMENT_TYPE); \
+ tmp->set_length (4 * TYPE_LENGTH (ELEMENT_TYPE)); \
tmp = add (init_vector_type (ELEMENT_TYPE, 4)); \
tmp->set_name (OCL_STRING(TYPE ## 4)); \
tmp = add (init_vector_type (ELEMENT_TYPE, 8)); \
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 36f7790..a48996e 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -989,9 +989,8 @@ rust_composite_type (struct type *original,
}
if (i > 0)
- TYPE_LENGTH (result)
- = (result->field (i - 1).loc_bitpos () / TARGET_CHAR_BIT +
- TYPE_LENGTH (result->field (i - 1).type ()));
+ result->set_length (result->field (i - 1).loc_bitpos () / TARGET_CHAR_BIT
+ + TYPE_LENGTH (result->field (i - 1).type ()));
return result;
}
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 3c484ce..af34353 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1684,7 +1684,7 @@ again:
{
/* It's being defined as itself. That means it is "void". */
type->set_code (TYPE_CODE_VOID);
- TYPE_LENGTH (type) = 1;
+ type->set_length (1);
}
else if (type_size >= 0 || is_string)
{
@@ -2008,7 +2008,7 @@ again:
/* Size specified in a type attribute overrides any other size. */
if (type_size != -1)
- TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
+ type->set_length ((type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT);
return type;
}
@@ -3385,7 +3385,7 @@ set_length_in_type_chain (struct type *type)
while (ntype != type)
{
if (TYPE_LENGTH(ntype) == 0)
- TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
+ ntype->set_length (TYPE_LENGTH (type));
else
complain_about_struct_wipeout (ntype);
ntype = TYPE_CHAIN (ntype);
@@ -3441,7 +3441,7 @@ read_struct_type (const char **pp, struct type *type, enum type_code type_code,
{
int nbits;
- TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits, 0);
+ type->set_length (read_huge_number (pp, 0, &nbits, 0));
if (nbits != 0)
return error_type (pp, objfile);
set_length_in_type_chain (type);
@@ -3606,7 +3606,7 @@ read_enum_type (const char **pp, struct type *type,
/* Now fill in the fields of the type-structure. */
- TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
+ type->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT);
set_length_in_type_chain (type);
type->set_code (TYPE_CODE_ENUM);
type->set_is_stub (false);
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 044b171..20a79d5 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -246,7 +246,7 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype)
}
if (e->size != 0)
- TYPE_LENGTH (m_type) = e->size;
+ m_type->set_length (e->size);
}
void make_gdb_type_union (const tdesc_type_with_fields *e)