[PATCH v2] [gdb/mi] Don't treat references to compound values as "simple".

Gareth Rees grees@undo.io
Thu Sep 8 13:58:22 GMT 2022


Eli Zaretskii <eliz@gnu.org> wrote:
> > +* MI changes
> > +
> > +  ** The '--simple-values' argument to the '-stack-list-arguments',
> > +     '-stack-list-locals', '-stack-list-variables', and
> > +     '-var-list-children' commands takes reference types into account:
> > +     that is, a value is now considered simple if it is neither an
> > +     array, structure, or union, nor a reference to an array, structure,
> > +     or union.
>
> Isn't it easier to say "only if the value is a scalar"?

I deliberately echoed the wording used in the documentation for
'-stack-list-arguments' and similar commands, which uses the formula
"if it is 2 or --simple-values, print the name, type and value for
simple data types, and the name and type for arrays, structures and
unions."

But you are right that this concept corresponds to the 'scalars'
arguments to 'set print frame-arguments'. But then should I update the
documentation for '-stack-list-arguments' to match?

> Thanks.  FWIW, I think we should implement 2, not 1.

I note that 'set print frame-arguments scalars' already takes
reference types into account: see the function
'val_print_scalar_type_p' in gdb/valprint.c, which is implemented like
this:

    int
    val_print_scalar_type_p (struct type *type)
    {
      type = check_typedef (type);
      while (TYPE_IS_REFERENCE (type))
        {
          type = TYPE_TARGET_TYPE (type);
          type = check_typedef (type);
        }
      switch (type->code ())
        {
        case TYPE_CODE_ARRAY:
        case TYPE_CODE_STRUCT:
        case TYPE_CODE_UNION:
        case TYPE_CODE_SET:
        case TYPE_CODE_STRING:
          return 0;
        default:
          return 1;
        }
    }

Updating '--simple-values' to call 'val_print_scalar_type_p' is
probably a step too far because of the exclusion of strings, so if we
want the 'scalars' behaviour then we need solution (2) in which we
would add a PRINT-VALUES option '--scalar-values' which behaves the
same way as 'set print frame-arguments scalars'.


More information about the Gdb-patches mailing list