[RFC] Make init_type/arch_type take a size in bits

Simon Marchi simon.marchi@polymtl.ca
Wed Sep 20 14:40:00 GMT 2017


On 2017-09-20 15:51, Ulrich Weigand wrote:
> Simon Marchi wrote:
> 
>> Since this is where we do the division by
>> TARGET_CHAR_BIT, and therefore assume (implicitly) that bit is a
>> multiple of TARGET_CHAR_BIT, I think this is where the assert should 
>> be
>> added.  To avoid adding them everywhere, we could make
>> arch_type/init_type take a size in bits, and do the division and 
>> assert
>> there.
> 
> As discussed, this changes the interfaces to init_type and arch_type
> to take the type length in bits as input (instead of as bytes).  The
> routine asserts that the length is a multiple of TARGET_CHAR_BIT.
> 
> For consistency, arch_flags_type is changed likewise, so that now
> all type creation interfaces always use length in bits.
> 
> All callers are updated in the straightforward manner.
> 
> The assert actually found a bug in stabsread.c:read_range_type, where
> the init_integer_type routine was called with a wrong argument 
> (probably
> a bug introduced with the conversion to use init_integer_type).

I took a quick look, it looks good to me.  Just one comment below.

> Index: binutils-gdb/gdb/gnu-v3-abi.c
> ===================================================================
> --- binutils-gdb.orig/gdb/gnu-v3-abi.c
> +++ binutils-gdb/gdb/gnu-v3-abi.c
> @@ -1024,7 +1024,7 @@ build_std_type_info_type (struct gdbarch
> 
>    gdb_assert (field == (field_list + 2));
> 
> -  t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);
> +  t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, 
> NULL);
>    TYPE_NFIELDS (t) = field - field_list;
>    TYPE_FIELDS (t) = field_list;
>    TYPE_TAG_NAME (t) = "gdb_gnu_v3_type_info";

In gnu-v3-abi.c, there seems to be another call to arch_type that needs 
adjusting in build_gdb_vtable_type:

   t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL);

Simon



More information about the Gdb-patches mailing list