diff options
author | Maciej W. Rozycki <macro@embecosm.com> | 2023-01-19 21:15:56 +0000 |
---|---|---|
committer | Maciej W. Rozycki <macro@embecosm.com> | 2023-01-19 21:15:56 +0000 |
commit | 7aeb03e2d4186d1184050d2ec048301f48255644 (patch) | |
tree | 3d2f57b0f5fa23d6f977c7fbaee809c284e7bc5c /gdb/command.h | |
parent | 0fcd58d843ce1b07c8516c51f9120714673003a3 (diff) | |
download | gdb-7aeb03e2d4186d1184050d2ec048301f48255644.zip gdb-7aeb03e2d4186d1184050d2ec048301f48255644.tar.gz gdb-7aeb03e2d4186d1184050d2ec048301f48255644.tar.bz2 |
GDB: Allow arbitrary keywords in integer set commands
Rather than just `unlimited' allow the integer set commands (or command
options) to define arbitrary keywords for the user to use, removing
hardcoded arrangements for the `unlimited' keyword.
Remove the confusingly named `var_zinteger', `var_zuinteger' and
`var_zuinteger_unlimited' `set'/`show' command variable types redefining
them in terms of `var_uinteger', `var_integer' and `var_pinteger', which
have the range of [0;UINT_MAX], [INT_MIN;INT_MAX], and [0;INT_MAX] each.
Following existing practice `var_pinteger' allows extra negative values
to be used, however unlike `var_zuinteger_unlimited' any number of such
values can be defined rather than just `-1'.
The "p" in `var_pinteger' stands for "positive", for the lack of a more
appropriate unambiguous letter, even though 0 obviously is not positive;
"n" would be confusing as to whether it stands for "non-negative" or
"negative".
Add a new structure, `literal_def', the entries of which define extra
keywords allowed for a command and numerical values they correspond to.
Those values are not verified against the basic range supported by the
underlying variable type, allowing extra values to be allowed outside
that range, which may or may not be individually made visible to the
user. An optional value translation is possible with the structure to
follow the existing practice for some commands where user-entered 0 is
internally translated to UINT_MAX or INT_MAX. Such translation can now
be arbitrary. Literals defined by this structure are automatically used
for completion as necessary.
So for example:
const literal_def integer_unlimited_literals[] =
{
{ "unlimited", INT_MAX, 0 },
{ nullptr }
};
defines an extra `unlimited' keyword and a user-visible 0 value, both of
which get translated to INT_MAX for the setting to be used with.
Similarly:
const literal_def zuinteger_unlimited_literals[] =
{
{ "unlimited", -1, -1 },
{ nullptr }
};
defines the same keyword and a corresponding user-visible -1 value that
is used for the requested setting. If the last member were omitted (or
set to `{}') here, then only the keyword would be allowed for the user
to enter and while -1 would still be used internally trying to enter it
as a part of a command would result in an "integer -1 out of range"
error.
Use said error message in all cases (citing the invalid value requested)
replacing "only -1 is allowed to set as unlimited" previously used for
`var_zuinteger_unlimited' settings only rather than propagating it to
`var_pinteger' type. It could only be used for the specific case where
a single extra `unlimited' keyword was defined standing for -1 and the
use of numeric equivalents is discouraged anyway as it is for historical
reasons only that they expose GDB internals, confusingly different
across variable types. Similarly update the "must be >= -1" Guile error
message.
Redefine Guile and Python parameter types in terms of the new variable
types and interpret extra keywords as Scheme keywords and Python strings
used to communicate corresponding parameter values. Do not add a new
PARAM_INTEGER Guile parameter type, however do handle the `var_integer'
variable type now, permitting existing parameters defined by GDB proper,
such as `listsize', to be accessed from Scheme code.
With these changes in place it should be trivial for a Scheme or Python
programmer to expand the syntax of the `make-parameter' command and the
`gdb.Parameter' class initializer to have arbitrary extra literals along
with their internal representation supplied.
Update the testsuite accordingly.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/command.h')
-rw-r--r-- | gdb/command.h | 113 |
1 files changed, 88 insertions, 25 deletions
diff --git a/gdb/command.h b/gdb/command.h index 7d6f9c7..e9c9f16 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -84,16 +84,18 @@ enum var_types value. */ var_auto_boolean, - /* Unsigned Integer. *VAR is an unsigned int. The user can type - 0 to mean "unlimited", which is stored in *VAR as UINT_MAX. */ + /* Unsigned Integer. *VAR is an unsigned int. In the Guile and Python + APIs 0 means unlimited, which is stored in *VAR as UINT_MAX. */ var_uinteger, - /* Like var_uinteger but signed. *VAR is an int. The user can - type 0 to mean "unlimited", which is stored in *VAR as - INT_MAX. The only remaining use of it is the Python API. - Don't use it elsewhere. */ + /* Like var_uinteger but signed. *VAR is an int. In the Guile and + Python APIs 0 means unlimited, which is stored in *VAR as INT_MAX. */ var_integer, + /* Like var_integer but negative numbers are not allowed, + except for special values. *VAR is an int. */ + var_pinteger, + /* String which the user enters with escapes (e.g. the user types \n and it is a real newline in the stored string). *VAR is a std::string, "" if the string is empty. */ @@ -106,22 +108,27 @@ enum var_types var_optional_filename, /* String which stores a filename. (*VAR) is a std::string. */ var_filename, - /* ZeroableInteger. *VAR is an int. Like var_integer except - that zero really means zero. */ - var_zinteger, - /* ZeroableUnsignedInteger. *VAR is an unsigned int. Zero really - means zero. */ - var_zuinteger, - /* ZeroableUnsignedInteger with unlimited value. *VAR is an int, - but its range is [0, INT_MAX]. -1 stands for unlimited and - other negative numbers are not allowed. */ - var_zuinteger_unlimited, /* Enumerated type. Can only have one of the specified values. *VAR is a char pointer to the name of the element that we find. */ var_enum }; +/* A structure describing an extra literal accepted and shown in place + of a number. */ +struct literal_def +{ + /* The literal to define, e.g. "unlimited". */ + const char *literal; + + /* The number to substitute internally for LITERAL or VAL; + the use of this number is not allowed (unless the same as VAL). */ + LONGEST use; + + /* An optional number accepted that stands for the literal. */ + gdb::optional<LONGEST> val; +}; + /* Return true if a setting of type VAR_TYPE is backed with type T. This function is left without definition intentionally. This template is @@ -152,15 +159,14 @@ inline bool var_type_uses<enum auto_boolean> (var_types t) template<> inline bool var_type_uses<unsigned int> (var_types t) { - return (t == var_uinteger || t == var_zinteger || t == var_zuinteger); + return t == var_uinteger; } /* Return true if a setting of type T is backed by an int variable. */ template<> inline bool var_type_uses<int> (var_types t) { - return (t == var_integer || t == var_zinteger - || t == var_zuinteger_unlimited); + return t == var_integer || t == var_pinteger; } /* Return true if a setting of type T is backed by a std::string variable. */ @@ -218,8 +224,9 @@ struct setting Type T must match the var type VAR_TYPE (see VAR_TYPE_USES). */ template<typename T> - setting (var_types var_type, T *var) - : m_var_type (var_type), m_var (var) + setting (var_types var_type, T *var, + const literal_def *extra_literals = nullptr) + : m_var_type (var_type), m_var (var), m_extra_literals (extra_literals) { gdb_assert (var != nullptr); gdb_assert (var_type_uses<T> (var_type)); @@ -258,12 +265,14 @@ struct setting }; } - /* Create a setting backed by pre-validated type-erased args. - ERASED_VAR's fields' real types must match the var type VAR_TYPE - (see VAR_TYPE_USES). */ - setting (var_types var_type, const erased_args &args) + /* Create a setting backed by pre-validated type-erased args and using + EXTRA_LITERALS. ERASED_VAR's fields' real types must match the var + type VAR_TYPE (see VAR_TYPE_USES). */ + setting (var_types var_type, const literal_def *extra_literals, + const erased_args &args) : m_var_type (var_type), m_var (args.var), + m_extra_literals (extra_literals), m_getter (args.getter), m_setter (args.setter) { @@ -294,6 +303,10 @@ struct setting var_types type () const { return m_var_type; } + /* Access any extra literals accepted. */ + const literal_def *extra_literals () const + { return m_extra_literals; } + /* Return the current value. The template parameter T is the type of the variable used to store the @@ -356,6 +369,9 @@ private: non-nullptr. */ void *m_var = nullptr; + /* Any extra literals accepted. */ + const literal_def *m_extra_literals = nullptr; + /* Pointer to a user provided getter. */ erased_func m_getter = nullptr; @@ -651,6 +667,11 @@ typedef void (show_value_ftype) (struct ui_file *file, instead print the value out directly. */ extern show_value_ftype deprecated_show_value_hack; +/* Various sets of extra literals accepted. */ +extern const literal_def integer_unlimited_literals[]; +extern const literal_def uinteger_unlimited_literals[]; +extern const literal_def pinteger_unlimited_literals[]; + extern set_show_commands add_setshow_enum_cmd (const char *name, command_class theclass, const char *const *enumlist, const char **var, const char *set_doc, const char *show_doc, @@ -747,6 +768,20 @@ extern set_show_commands add_setshow_optional_filename_cmd cmd_list_element **show_list); extern set_show_commands add_setshow_integer_cmd + (const char *name, command_class theclass, int *var, + const literal_def *extra_literals, const char *set_doc, + const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, + show_value_ftype *show_func, cmd_list_element **set_list, + cmd_list_element **show_list); + +extern set_show_commands add_setshow_integer_cmd + (const char *name, command_class theclass, const literal_def *extra_literals, + const char *set_doc, const char *show_doc, const char *help_doc, + setting_func_types<int>::set set_func, + setting_func_types<int>::get get_func, show_value_ftype *show_func, + cmd_list_element **set_list, cmd_list_element **show_list); + +extern set_show_commands add_setshow_integer_cmd (const char *name, command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, cmd_list_element **set_list, @@ -759,6 +794,34 @@ extern set_show_commands add_setshow_integer_cmd setting_func_types<int>::get get_func, show_value_ftype *show_func, cmd_list_element **set_list, cmd_list_element **show_list); +extern set_show_commands add_setshow_pinteger_cmd + (const char *name, command_class theclass, int *var, + const literal_def *extra_literals, const char *set_doc, + const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, + show_value_ftype *show_func, cmd_list_element **set_list, + cmd_list_element **show_list); + +extern set_show_commands add_setshow_pinteger_cmd + (const char *name, command_class theclass, const literal_def *extra_literals, + const char *set_doc, const char *show_doc, const char *help_doc, + setting_func_types<int>::set set_func, + setting_func_types<int>::get get_func, show_value_ftype *show_func, + cmd_list_element **set_list, cmd_list_element **show_list); + +extern set_show_commands add_setshow_uinteger_cmd + (const char *name, command_class theclass, unsigned int *var, + const literal_def *extra_literals, + const char *set_doc, const char *show_doc, const char *help_doc, + cmd_func_ftype *set_func, show_value_ftype *show_func, + cmd_list_element **set_list, cmd_list_element **show_list); + +extern set_show_commands add_setshow_uinteger_cmd + (const char *name, command_class theclass, const literal_def *extra_literals, + const char *set_doc, const char *show_doc, const char *help_doc, + setting_func_types<unsigned int>::set set_func, + setting_func_types<unsigned int>::get get_func, show_value_ftype *show_func, + cmd_list_element **set_list, cmd_list_element **show_list); + extern set_show_commands add_setshow_uinteger_cmd (const char *name, command_class theclass, unsigned int *var, const char *set_doc, const char *show_doc, const char *help_doc, |