[PATCH v2 1/4] gdb: Add typesafe getter/setter for cmd_list_element.var

Simon Marchi simon.marchi@polymtl.ca
Tue Aug 10 12:22:31 GMT 2021


I'm forwarding some comments from Tony Tye, from AMD, who looked at the
patch, and had some minor comments.

> @@ -230,7 +226,7 @@ struct cmd_list_element
>  
>    /* Pointer to variable affected by "set" and "show".  Doesn't
>       matter if type is not_set.  */
> -  void *var = nullptr;
> +  setting var;

The comment should probably be updated, this is no longer a pointer.
Well, for now it contains a pointer, but later in the series it can
become a getter/setter too.  So maybe just say "Setting affected by
...".

> diff --git a/gdb/command.h b/gdb/command.h
> index baf34401a07..644812c4d46 100644
> --- a/gdb/command.h
> +++ b/gdb/command.h
> @@ -125,6 +125,164 @@ typedef enum var_types
>    }
>  var_types;
>  
> +/* Return true if a setting of type VAR_TYPE is backed with type T.
> +
> +   This  function is left without definition intentionally.  This template
> +   is specialized for all valid types that are used to back var_types.
> +   Therefore if one tries to instantiate this un-specialized template it
> +   means the T parameter is not a type used to back a var_type and it is most
> +   likely a programming error.  */
> +template<typename T>
> +inline bool var_type_uses (var_types t);

So what will happen if you try to use var_type_uses with an invalid
template type, link error?  Tony suggested using a static_assert to have
a compile-time error instead, with an explanation.  I suppose you would
define a body for this function and put a static_assert (false) in
there?

Simon


More information about the Gdb-patches mailing list