This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] (for VLA) Prepare for 3-fields TYPE_CODE_RANGE (TYPE_HIGH_BOUND)


> Questionable is whether ada_array_bound_from_type() can get something besides
> TYPE_CODE_RANGE or TYPE_CODE_ENUM which gets internal_error()ed now.  I did
> not find such case but the TYPE_CODE_ENUM case could be changed to `default:'
> if it can happen.

Initially, I was thinking that maybe we could get a range type that's
a TYPE_CODE_INT. But that's not possible either with stabs nor DWARF.
But I think the code is fine as it is.

> 2008-12-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
> 
> 	Fix TYPE_HIGH_BOUND for TYPE_CODE_RANGE using arbitrary TYPE_NFIELDS.

Perhaps you could mention that this is in preparation for supporting
DW_AT_byte_stride.

> 	* ada-lang.c (packed_array_type, ada_index_type): Use TYPE_INDEX_TYPE.
> 	(ada_array_bound_from_type): Move `index_type' declaration to the
> 	function start.  Return the bounds for TYPE_CODE_RANGE using
> 	TYPE_LOW_BOUND and TYPE_HIGH_BOUND.  Abort on invalid index type codes.
> 	* ada-typeprint.c (print_range): Set `upper_bound' for TYPE_CODE_RANGE
> 	now using TYPE_HIGH_BOUND.
> 	* ada-valprint.c (val_print_packed_array_elements): Use `index_type'.
> 	* eval.c (evaluate_subexp_standard): Use TYPE_INDEX_TYPE.
> 	* gdbtypes.c (create_range_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
> 	refer to the number of fields only through TYPE_NFIELDS.
> 	(create_array_type): Use TYPE_INDEX_TYPE.
> 	(check_typedef): Use TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND.
> 	* gdbtypes.h (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED)
> 	(TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED): Use TYPE_INDEX_TYPE.
> 	(TYPE_ARRAY_UPPER_BOUND_VALUE, TYPE_ARRAY_LOWER_BOUND_VALUE): Use
> 	TYPE_INDEX_TYPE, TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
> 	* hppa-tdep.c (hppa_alignof <TYPE_CODE_ARRAY>): Use TYPE_INDEX_TYPE.
> 	* mdebugread.c (parse_type): Use TYPE_LOW_BOUND, TYPE_HIGH_BOUND,
> 	* valarith.c (value_bit_index): Use TYPE_INDEX_TYPE.

OK.  Please just make a tiny change before checking in.


(in ada_array_bound_from_type):

> +  if (typep != NULL)
> +    *typep = index_type;
>  
> -      return
> -        (LONGEST) (which == 0
> -                   ? TYPE_LOW_BOUND (index_type)
> -                   : TYPE_HIGH_BOUND (index_type));
> +  switch (TYPE_CODE (index_type))
> +    {
> +    case TYPE_CODE_RANGE:
> +      return which == 0 ? TYPE_LOW_BOUND (index_type)
> +			: TYPE_HIGH_BOUND (index_type);
> +    case TYPE_CODE_ENUM:
> +      return which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
> +			: TYPE_FIELD_BITPOS (index_type,
> +					     TYPE_NFIELDS (index_type) - 1);
> +    default:
> +      internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
>      }

If we raise the internal_error, I'd rather we do no assign *typep.
Can you instead compute the bound value first, and then, if we haven't
detected the internal error, assign *typep before returning the bound?

Thanks,
-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]