From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 655A83858018; Wed, 21 Sep 2022 15:05:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 655A83858018 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663772746; bh=TaAuUoNQRLwf454gXewk1rQsVUVhXhAnWZpsjcbCwNc=; h=From:To:Subject:Date:From; b=hw6bqAHUAhGWfIujfyk26LiQ7hc1aDbCf+R9AjXhcE5ZKgpqSldYgKu9D7nangTPt 5tX0CM7c854l1oKheB2sYGo2pFPzDAp38Uij2YNz5rJbpzOOtbI9FMt8l4YTpF6K1x fXaWGjupgWujhEaLorbHOI5VoUL0MRK3S5aaRqFA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: add type::length / type::set_length X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 27710edb4e588d0360620df424dd7ee7e8cfafee X-Git-Newrev: b6cdbc9a8173b9e6cc8cfc284caa0efa8129ca02 Message-Id: <20220921150546.655A83858018@sourceware.org> Date: Wed, 21 Sep 2022 15:05:46 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db6cdbc9a8173= b9e6cc8cfc284caa0efa8129ca02 commit b6cdbc9a8173b9e6cc8cfc284caa0efa8129ca02 Author: Simon Marchi Date: Sat Jul 30 12:01:12 2022 -0400 gdb: add type::length / type::set_length =20 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. =20 Change-Id: Id1090244f15c9856969b9be5006aefe8d8897ca4 Diff: --- gdb/ada-lang.c | 47 ++++++++++++++++--------------- gdb/coffread.c | 14 +++++----- gdb/cp-valprint.c | 2 +- gdb/ctfread.c | 10 +++---- gdb/dwarf2/read.c | 44 ++++++++++++----------------- gdb/eval.c | 2 +- gdb/f-valprint.c | 6 ++-- gdb/gdbtypes.c | 71 ++++++++++++++++++++++++-------------------= ---- gdb/gdbtypes.h | 16 +++++++++-- gdb/mdebugread.c | 4 +-- gdb/opencl-lang.c | 2 +- gdb/rust-lang.c | 5 ++-- gdb/stabsread.c | 10 +++---- gdb/target-descriptions.c | 2 +- 14 files changed, 119 insertions(+), 116 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 95fb37b49f4..93425660053 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 =3D (hi - lo + 1) * TYPE_FIELD_BITSIZE (elt_type, 0); =20 - TYPE_LENGTH (array_type) =3D (array_bitsize + 7) / 8; + array_type->set_length ((array_bitsize + 7) / 8); } } } @@ -2392,12 +2392,14 @@ constrained_packed_array_type (struct type *type, l= ong *elt_bits) || !get_discrete_bounds (index_type, &low_bound, &high_bound)) low_bound =3D high_bound =3D 0; if (high_bound < low_bound) - *elt_bits =3D TYPE_LENGTH (new_type) =3D 0; + { + *elt_bits =3D 0; + new_type->set_length (0); + } else { *elt_bits *=3D (high_bound - low_bound + 1); - TYPE_LENGTH (new_type) =3D - (*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; + new_type->set_length ((*elt_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BI= T); } =20 new_type->set_is_fixed_instance (true); @@ -2471,8 +2473,8 @@ recursively_update_array_bitsize (struct type *type) LONGEST elt_bitsize =3D elt_len * TYPE_FIELD_BITSIZE (elt_type, 0); TYPE_FIELD_BITSIZE (type, 0) =3D elt_bitsize; =20 - TYPE_LENGTH (type) =3D ((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)); } =20 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 (""); - TYPE_LENGTH (type) =3D 0; + type->set_length (0); return type; } =20 @@ -7996,8 +7998,7 @@ ada_template_to_fixed_record_type_1 (struct type *typ= e, if (off + fld_bit_len > bit_len) bit_len =3D off + fld_bit_len; off +=3D fld_bit_len; - TYPE_LENGTH (rtype) =3D - align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT; + rtype->set_length (align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR= _BIT); } =20 /* 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 *typ= e, TARGET_CHAR_BIT; if (off + fld_bit_len > bit_len) bit_len =3D off + fld_bit_len; - TYPE_LENGTH (rtype) =3D - align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT; + + rtype->set_length + (align_up (bit_len, TARGET_CHAR_BIT) / TARGET_CHAR_BIT); } } =20 @@ -8063,10 +8065,7 @@ ada_template_to_fixed_record_type_1 (struct type *ty= pe, pulongest (TYPE_LENGTH (type))); } else - { - TYPE_LENGTH (rtype) =3D align_up (TYPE_LENGTH (rtype), - TYPE_LENGTH (type)); - } + rtype->set_length (align_up (TYPE_LENGTH (rtype), TYPE_LENGTH (type))); =20 value_free_to_mark (mark); return rtype; @@ -8148,7 +8147,7 @@ template_to_static_fixed_type (struct type *type0) =20 type->set_name (ada_type_name (type0)); type->set_is_fixed_instance (true); - TYPE_LENGTH (type) =3D 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, =20 rtype->set_name (ada_type_name (type)); rtype->set_is_fixed_instance (true); - TYPE_LENGTH (rtype) =3D TYPE_LENGTH (type); + rtype->set_length (TYPE_LENGTH (type)); =20 branch_type =3D 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) =3D 0; - TYPE_LENGTH (rtype) +=3D TYPE_LENGTH (branch_type); + rtype->set_length (TYPE_LENGTH (rtype) + TYPE_LENGTH (branch_type)); } - TYPE_LENGTH (rtype) -=3D TYPE_LENGTH (type->field (variant_field).type (= )); + + rtype->set_length (TYPE_LENGTH (rtype) + - TYPE_LENGTH (type->field (variant_field).type ())); =20 value_free_to_mark (mark); return rtype; @@ -8532,9 +8533,9 @@ to_fixed_array_type (struct type *type0, struct value= *dval, int elt_bitsize =3D TYPE_FIELD_BITSIZE (type0, 0); =20 TYPE_FIELD_BITSIZE (result, 0) =3D TYPE_FIELD_BITSIZE (type0, 0); - TYPE_LENGTH (result) =3D 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); } =20 result->set_is_fixed_instance (true); @@ -8630,7 +8631,7 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byt= e *valaddr, if (xvz_found && TYPE_LENGTH (fixed_record_type) !=3D size) { fixed_record_type =3D copy_type (fixed_record_type); - TYPE_LENGTH (fixed_record_type) =3D size; + fixed_record_type->set_length (size); =20 /* 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) =3D 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 27afa11738d..801978978e9 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 =3D real_type->target_type (); int field_size =3D real_target->num_fields () * sizeof (struct field); =20 - TYPE_LENGTH (target) =3D TYPE_LENGTH (real_target); + target->set_length (real_target->length ()); target->set_num_fields (real_target->num_fields ()); =20 field *fields =3D (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) =3D 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 =3D coff_alloc_type (cs->c_symnum); type->set_name (NULL); INIT_CPLUS_SPECIFIC (type); - TYPE_LENGTH (type) =3D 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 =3D coff_alloc_type (cs->c_symnum); type->set_code (TYPE_CODE_ENUM); type->set_name (NULL); - TYPE_LENGTH (type) =3D 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 las= tsym, type =3D coff_alloc_type (index); type->set_code (TYPE_CODE_STRUCT); INIT_CPLUS_SPECIFIC (type); - TYPE_LENGTH (type) =3D length; + type->set_length (length); =20 while (!done && symnum < lastsym && symnum < nlist_nsyms_global) { @@ -2124,9 +2124,9 @@ coff_read_enum_type (int index, int length, int lasts= ym, /* Now fill in the fields of the type-structure. */ =20 if (length > 0) - TYPE_LENGTH (type) =3D length; + type->set_length (length); else /* Assume ints. */ - TYPE_LENGTH (type) =3D 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 07bbb9b262e..86bc57b5353 100644 --- a/gdb/cp-valprint.c +++ b/gdb/cp-valprint.c @@ -729,7 +729,7 @@ test_print_fields (gdbarch *arch) type *uint8_type =3D builtin_type (arch)->builtin_uint8; type *bool_type =3D builtin_type (arch)->builtin_bool; type *the_struct =3D arch_composite_type (arch, NULL, TYPE_CODE_STRUCT); - TYPE_LENGTH (the_struct) =3D 4; + the_struct->set_length (4); =20 /* Value: 1110 1001 Fields: C-BB B-A- */ diff --git a/gdb/ctfread.c b/gdb/ctfread.c index 561534f9ebe..890cb91aca7 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); =20 - TYPE_LENGTH (type) =3D ctf_type_size (fp, tid); + type->set_length (ctf_type_size (fp, tid)); set_type_align (type, ctf_type_align (fp, tid)); =20 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); =20 type->set_code (TYPE_CODE_ENUM); - TYPE_LENGTH (type) =3D 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 ti= d) if (ar.ctr_nelems <=3D 1) /* Check if undefined upper bound. */ { range_type->bounds ()->high.set_undefined (); - TYPE_LENGTH (type) =3D 0; + type->set_length (0); type->set_target_is_stub (true); } else - TYPE_LENGTH (type) =3D ctf_type_size (fp, tid); + type->set_length (ctf_type_size (fp, tid)); =20 set_type_align (type, ctf_type_align (fp, tid)); =20 @@ -988,7 +988,7 @@ read_forward_type (struct ctf_context *ccp, ctf_id_t ti= d) else type->set_code (TYPE_CODE_STRUCT); =20 - TYPE_LENGTH (type) =3D 0; + type->set_length (0); type->set_is_stub (true); =20 return set_tid_type (of, tid, type); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index d358297acef..ef988d7d14c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -8191,7 +8191,7 @@ quirk_rust_enum (struct type *type, struct objfile *o= bjfile) =20 /* In Rust, each element should have the size of the enclosing enum. */ - TYPE_LENGTH (type->field (i).type ()) =3D TYPE_LENGTH (type); + type->field (i).type ()->set_length (TYPE_LENGTH (type)); =20 /* Remove the discriminant field, if it exists. */ struct type *sub_type =3D type->field (i).type (); @@ -14640,19 +14640,18 @@ read_structure_type (struct die_info *die, struct= dwarf2_cu *cu) if (attr !=3D nullptr) { if (attr->form_is_constant ()) - TYPE_LENGTH (type) =3D 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) =3D 0; + + type->set_length (0); } } else - { - TYPE_LENGTH (type) =3D 0; - } + type->set_length (0); =20 maybe_set_alignment (cu, die, type); =20 @@ -15200,13 +15199,9 @@ read_enumeration_type (struct die_info *die, struc= t dwarf2_cu *cu) =20 attr =3D dwarf2_attr (die, DW_AT_byte_size, cu); if (attr !=3D nullptr) - { - TYPE_LENGTH (type) =3D attr->constant_value (0); - } + type->set_length (attr->constant_value (0)); else - { - TYPE_LENGTH (type) =3D 0; - } + type->set_length (0); =20 maybe_set_alignment (cu, die, type); =20 @@ -15233,7 +15228,7 @@ read_enumeration_type (struct die_info *die, struct= dwarf2_cu *cu) type->set_is_unsigned (underlying_type->is_unsigned ()); =20 if (TYPE_LENGTH (type) =3D=3D 0) - TYPE_LENGTH (type) =3D TYPE_LENGTH (underlying_type); + type->set_length (TYPE_LENGTH (underlying_type)); =20 if (TYPE_RAW_ALIGN (type) =3D=3D 0 && TYPE_RAW_ALIGN (underlying_type) !=3D 0) @@ -15530,7 +15525,7 @@ quirk_ada_thick_pointer (struct die_info *die, stru= ct dwarf2_cu *cu, int last_fieldno =3D range_fields.size () - 1; int bounds_size =3D (bounds->field (last_fieldno).loc_bitpos () / 8 + TYPE_LENGTH (bounds->field (last_fieldno).type ())); - TYPE_LENGTH (bounds) =3D align_up (bounds_size, max_align); + bounds->set_length (align_up (bounds_size, max_align)); =20 /* 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, stru= ct dwarf2_cu *cu, result->field (1).set_loc_bitpos (8 * bounds_offset); =20 result->set_name (type->name ()); - TYPE_LENGTH (result) =3D (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 ())); =20 return result; } @@ -15706,7 +15701,7 @@ read_array_type (struct die_info *die, struct dwarf= 2_cu *cu) if (attr !=3D nullptr && attr->form_is_unsigned ()) { if (attr->as_unsigned () >=3D TYPE_LENGTH (type)) - TYPE_LENGTH (type) =3D 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) =20 attr =3D dwarf2_attr (die, DW_AT_byte_size, cu); if (attr !=3D nullptr && attr->form_is_unsigned ()) - TYPE_LENGTH (set_type) =3D attr->as_unsigned (); + set_type->set_length (attr->as_unsigned ()); =20 maybe_set_alignment (cu, die, set_type); =20 @@ -16194,7 +16189,7 @@ read_tag_pointer_type (struct die_info *die, struct= dwarf2_cu *cu) } } =20 - TYPE_LENGTH (type) =3D 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, st= ruct dwarf2_cu *cu, type =3D lookup_reference_type (target_type, refcode); attr =3D dwarf2_attr (die, DW_AT_byte_size, cu); if (attr !=3D nullptr) - { - TYPE_LENGTH (type) =3D attr->constant_value (cu_header->addr_size); - } + type->set_length (attr->constant_value (cu_header->addr_size)); else - { - TYPE_LENGTH (type) =3D 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 dw= arf2_cu *cu) =20 attr =3D dwarf2_attr (die, DW_AT_byte_size, cu); if (attr !=3D nullptr) - TYPE_LENGTH (range_type) =3D attr->constant_value (0); + range_type->set_length (attr->constant_value (0)); =20 maybe_set_alignment (cu, die, range_type); =20 diff --git a/gdb/eval.c b/gdb/eval.c index ddbdd95b39c..a6e295d78cd 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -482,7 +482,7 @@ fake_method::fake_method (type_instance_flags flags, struct type *type =3D &m_type; =20 TYPE_MAIN_TYPE (type) =3D &m_main_type; - TYPE_LENGTH (type) =3D 1; + type->set_length (1); type->set_code (TYPE_CODE_METHOD); TYPE_CHAIN (type) =3D type; type->set_instance_flags (flags); diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c index 544657d5850..2dda1b8c67c 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 =3D f77_get_upperbound (type); =20 /* Patch in a valid length value. */ - - TYPE_LENGTH (type) =3D - (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 ()))); } =20 /* Per-dimension statistics. */ diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 71a8bd193b6..a306c1a4e84 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -376,7 +376,7 @@ make_pointer_type (struct type *type, struct type **typ= eptr) =20 /* FIXME! Assumes the machine has only one representation for pointers!= */ =20 - TYPE_LENGTH (ntype) =3D gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BI= T; + ntype->set_length (gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT); ntype->set_code (TYPE_CODE_PTR); =20 /* Mark pointers as unsigned. The target converts between pointers @@ -388,7 +388,7 @@ make_pointer_type (struct type *type, struct type **typ= eptr) chain =3D TYPE_CHAIN (ntype); while (chain !=3D ntype) { - TYPE_LENGTH (chain) =3D TYPE_LENGTH (ntype); + chain->set_length (TYPE_LENGTH (ntype)); chain =3D TYPE_CHAIN (chain); } =20 @@ -459,7 +459,7 @@ make_reference_type (struct type *type, struct type **t= ypeptr, references, and that it matches the (only) representation for pointers! */ =20 - TYPE_LENGTH (ntype) =3D gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BI= T; + ntype->set_length (gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT); ntype->set_code (refcode); =20 *reftype =3D ntype; @@ -468,7 +468,7 @@ make_reference_type (struct type *type, struct type **t= ypeptr, chain =3D TYPE_CHAIN (ntype); while (chain !=3D ntype) { - TYPE_LENGTH (chain) =3D TYPE_LENGTH (ntype); + chain->set_length (TYPE_LENGTH (ntype)); chain =3D TYPE_CHAIN (chain); } =20 @@ -524,7 +524,7 @@ make_function_type (struct type *type, struct type **ty= peptr) =20 ntype->set_target_type (type); =20 - TYPE_LENGTH (ntype) =3D 1; + ntype->set_length (1); ntype->set_code (TYPE_CODE_FUNC); =20 INIT_FUNC_SPECIFIC (ntype); @@ -671,7 +671,7 @@ make_qualified_type (struct type *type, type_instance_f= lags new_flags, ntype->set_instance_flags (new_flags); =20 /* Set length of new type to that of the original type. */ - TYPE_LENGTH (ntype) =3D TYPE_LENGTH (type); + ntype->set_length (TYPE_LENGTH (type)); =20 return ntype; } @@ -824,7 +824,7 @@ replace_type (struct type *ntype, struct type *type) call replace_type(). */ gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) =3D=3D 0); =20 - TYPE_LENGTH (chain) =3D TYPE_LENGTH (type); + chain->set_length (TYPE_LENGTH (type)); chain =3D TYPE_CHAIN (chain); } while (ntype !=3D chain); @@ -874,7 +874,7 @@ allocate_stub_method (struct type *type) =20 mtype =3D alloc_type_copy (type); mtype->set_code (TYPE_CODE_METHOD); - TYPE_LENGTH (mtype) =3D 1; + mtype->set_length (1); mtype->set_is_stub (true); mtype->set_target_type (type); /* TYPE_SELF_TYPE (mtype) =3D unknown yet */ @@ -945,7 +945,7 @@ create_range_type (struct type *result_type, struct typ= e *index_type, if (index_type->is_stub ()) result_type->set_target_is_stub (true); else - TYPE_LENGTH (result_type) =3D TYPE_LENGTH (check_typedef (index_type)); + result_type->set_length (TYPE_LENGTH (check_typedef (index_type))); =20 range_bounds *bounds =3D (struct range_bounds *) TYPE_ZALLOC (result_type, sizeof (range_bo= unds)); @@ -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) =3D 0; + type->set_length (0); else if (stride !=3D 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 =3D std::abs (high_bound - low_bound + 1); - TYPE_LENGTH (type) - =3D ((std::abs (stride) * element_count) + 7) / 8; + type->set_length (((std::abs (stride) * element_count) + 7) / 8); } else - TYPE_LENGTH (type) =3D - TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); + type->set_length (TYPE_LENGTH (element_type) + * (high_bound - low_bound + 1)); =20 /* 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_ty= pe, 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) =3D 0; + result_type->set_length (0); } =20 /* TYPE_TARGET_STUB will take care of zero length arrays. */ @@ -1492,8 +1491,8 @@ create_set_type (struct type *result_type, struct typ= e *domain_type) low_bound =3D high_bound =3D 0; =20 bit_length =3D high_bound - low_bound + 1; - TYPE_LENGTH (result_type) - =3D (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 >=3D 0) result_type->set_is_unsigned (true); } @@ -1614,7 +1613,7 @@ smash_to_memberptr_type (struct type *type, struct ty= pe *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) =3D gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_= BIT; + type->set_length (gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_BIT); } =20 /* 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 ty= pe *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) =3D cplus_method_ptr_size (to_type); + type->set_length (cplus_method_ptr_size (to_type)); } =20 /* 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) =3D 1; /* In practice, this is never needed. */ + + /* In practice, this is never needed. */ + type->set_length (1); } =20 /* 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 =3D TYPE_LENGTH (real_type); } =20 - TYPE_LENGTH (resolved_type) =3D max_len; + resolved_type->set_length (max_len); return resolved_type; } =20 @@ -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 !=3D language_fortran) - TYPE_LENGTH (resolved_type) - =3D (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_B= IT; + resolved_type->set_length ((resolved_type_bit_length + TARGET_CHAR_BIT= - 1) + / TARGET_CHAR_BIT); =20 /* The Ada language uses this field as a cache for static fixed types: r= eset it as RESOLVED_TYPE must have its own static fixed type. */ @@ -2873,7 +2875,7 @@ resolve_dynamic_type_internal (struct type *type, =20 if (type_length.has_value ()) { - TYPE_LENGTH (resolved_type) =3D *type_length; + resolved_type->set_length (*type_length); resolved_type->remove_dyn_prop (DYN_PROP_BYTE_SIZE); } =20 @@ -3146,7 +3148,7 @@ check_typedef (struct type *type) } else if (type->code () =3D=3D TYPE_CODE_RANGE) { - TYPE_LENGTH (type) =3D TYPE_LENGTH (target_type); + type->set_length (TYPE_LENGTH (target_type)); type->set_target_is_stub (false); } else if (type->code () =3D=3D TYPE_CODE_ARRAY @@ -3157,7 +3159,7 @@ check_typedef (struct type *type) type =3D make_qualified_type (type, instance_flags, NULL); =20 /* Cache TYPE_LENGTH for future use. */ - TYPE_LENGTH (orig_type) =3D TYPE_LENGTH (type); + orig_type->set_length (TYPE_LENGTH (type)); =20 return type; } @@ -3430,7 +3432,7 @@ init_type (struct objfile *objfile, enum type_code co= de, int bit, type =3D alloc_type (objfile); set_type_code (type, code); gdb_assert ((bit % TARGET_CHAR_BIT) =3D=3D 0); - TYPE_LENGTH (type) =3D bit / TARGET_CHAR_BIT; + type->set_length (bit / TARGET_CHAR_BIT); type->set_name (name); =20 return type; @@ -3579,7 +3581,7 @@ init_complex_type (const char *name, struct type *tar= get_type) =20 t =3D alloc_type_copy (target_type); set_type_code (t, TYPE_CODE_COMPLEX); - TYPE_LENGTH (t) =3D 2 * TYPE_LENGTH (target_type); + t->set_length (2 * TYPE_LENGTH (target_type)); t->set_name (name); =20 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 ())); =20 new_type->set_instance_flags (type->instance_flags ()); - TYPE_LENGTH (new_type) =3D TYPE_LENGTH (type); + new_type->set_length (TYPE_LENGTH (type)); =20 /* Copy the fields. */ if (type->num_fields ()) @@ -5787,7 +5789,7 @@ copy_type (const struct type *type) { struct type *new_type =3D alloc_type_copy (type); new_type->set_instance_flags (type->instance_flags ()); - TYPE_LENGTH (new_type) =3D 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 !=3D NULL) @@ -5816,7 +5818,7 @@ arch_type (struct gdbarch *gdbarch, type =3D alloc_type_arch (gdbarch); set_type_code (type, code); gdb_assert ((bit % TARGET_CHAR_BIT) =3D=3D 0); - TYPE_LENGTH (type) =3D bit / TARGET_CHAR_BIT; + type->set_length (bit / TARGET_CHAR_BIT); =20 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 () =3D=3D TYPE_CODE_UNION) { if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) - TYPE_LENGTH (t) =3D TYPE_LENGTH (field); + t->set_length (TYPE_LENGTH (field)); } else if (t->code () =3D=3D TYPE_CODE_STRUCT) { - TYPE_LENGTH (t) =3D 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) +=3D (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 6f4b2d61ca8..6d12a489b15 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1045,6 +1045,16 @@ struct type this->main_type->name =3D name; } =20 + ULONGEST length () const + { + return this->m_length; + } + + void set_length (ULONGEST length) + { + this->m_length =3D 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 =3D=3D TYPE_SPECIFIC_INT - && main_type->type_specific.int_stuff.bit_size !=3D 8 * length); + && main_type->type_specific.int_stuff.bit_size !=3D 8 * length ()); } =20 /* * 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. */ =20 - ULONGEST length; + ULONGEST m_length; =20 /* * Core type, shared by a group of qualified types. */ =20 @@ -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 ()) =20 /* * 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 673c370e120..56710cf6041 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)); =20 t->set_code (type_code); - TYPE_LENGTH (t) =3D sh->value; + t->set_length (sh->value); t->set_num_fields (nfields); f =3D ((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) =3D=3D t->num_fields () || TYPE_LENGTH (t) =3D=3D 0) - TYPE_LENGTH (t) =3D gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT; + t->set_length (gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT); for (ext_tsym =3D ext_sh + external_sym_size; ; ext_tsym +=3D external_sym_size) diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 32aa58c7211..5bd3edb4adc 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -899,7 +899,7 @@ public: tmp->set_name (OCL_STRING(TYPE ## 2)); \ tmp =3D add (init_vector_type (ELEMENT_TYPE, 3)); \ tmp->set_name (OCL_STRING(TYPE ## 3)); \ - TYPE_LENGTH (tmp) =3D 4 * TYPE_LENGTH (ELEMENT_TYPE); \ + tmp->set_length (4 * TYPE_LENGTH (ELEMENT_TYPE)); \ tmp =3D add (init_vector_type (ELEMENT_TYPE, 4)); \ tmp->set_name (OCL_STRING(TYPE ## 4)); \ tmp =3D add (init_vector_type (ELEMENT_TYPE, 8)); \ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 36f77907a70..a48996e1b2e 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -989,9 +989,8 @@ rust_composite_type (struct type *original, } =20 if (i > 0) - TYPE_LENGTH (result) - =3D (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; } =20 diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 3c484cee87b..af34353903b 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) =3D 1; + type->set_length (1); } else if (type_size >=3D 0 || is_string) { @@ -2008,7 +2008,7 @@ again: =20 /* Size specified in a type attribute overrides any other size. */ if (type_size !=3D -1) - TYPE_LENGTH (type) =3D (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR= _BIT; + type->set_length ((type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT); =20 return type; } @@ -3385,7 +3385,7 @@ set_length_in_type_chain (struct type *type) while (ntype !=3D type) { if (TYPE_LENGTH(ntype) =3D=3D 0) - TYPE_LENGTH (ntype) =3D TYPE_LENGTH (type); + ntype->set_length (TYPE_LENGTH (type)); else complain_about_struct_wipeout (ntype); ntype =3D TYPE_CHAIN (ntype); @@ -3441,7 +3441,7 @@ read_struct_type (const char **pp, struct type *type,= enum type_code type_code, { int nbits; =20 - TYPE_LENGTH (type) =3D read_huge_number (pp, 0, &nbits, 0); + type->set_length (read_huge_number (pp, 0, &nbits, 0)); if (nbits !=3D 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, =20 /* Now fill in the fields of the type-structure. */ =20 - TYPE_LENGTH (type) =3D 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 044b171ecd2..20a79d5d458 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -246,7 +246,7 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_ty= pe *ttype) } =20 if (e->size !=3D 0) - TYPE_LENGTH (m_type) =3D e->size; + m_type->set_length (e->size); } =20 void make_gdb_type_union (const tdesc_type_with_fields *e)