[PATCHv2 2/2] gdb/fortran: Access elements of a structure with dynamic type

Andrew Burgess andrew.burgess@embecosm.com
Thu Jul 23 10:28:45 GMT 2020


* Tom Tromey <tom@tromey.com> [2020-07-22 13:19:12 -0600]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew>      case STRUCTOP_STRUCT:
> Andrew>        tem = longest_to_int (exp->elts[pc + 1].longconst);
> Andrew>        (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
> Andrew> +      oldpos = *pos;
> Andrew>        arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
> Andrew>        if (noside == EVAL_SKIP)
> Andrew>  	return eval_skip_value (exp);
> Andrew> +      if (noside == EVAL_AVOID_SIDE_EFFECTS)
> Andrew> +	{
> Andrew> +	  /* If the element of the structure has a dynamic type then we
> Andrew> +	     need to get the real value representing the containing
> Andrew> +	     structure so that we can correctly evaluate the type of the
> Andrew> +	     element.  If we're not already avoiding side effects then we
> Andrew> +	     already have the real value of the containing structure, so
> Andrew> +	     this is not needed.  */
> Andrew> +	  type = lookup_struct_elt_type (value_type (arg1),
> Andrew> +					 &exp->elts[pc + 2].string, 1);
> Andrew> +	  if (type != nullptr && is_dynamic_type (type))
> Andrew> +	    {
> Andrew> +	      *pos = oldpos;
> Andrew> +	      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
> 
> Re-evaluating a subexpression like this can lead to problems; see for
> example commit 6830f270e ("Avoid exponential behavior in rust_evaluate_subexp").
> 
> I don't know if there's another way to do this, though.

Thanks for your feedback.

Personally, I'd like to rip out EVAL_AVOID_SIDE_EFFECTS completely.  I
don't know the history here, but I suspect this was a poor-man's lazy
value system.

The behaviour of this flag seems like it should be don't access the
target unless it's required to correctly do the task we're trying to
do.  But it seems like a working lazy value system should give the
same result.....

.... but I'm probably missing something.

Thanks,
Andrew


More information about the Gdb-patches mailing list