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/maint-test-options.c | |
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/maint-test-options.c')
-rw-r--r-- | gdb/maint-test-options.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/gdb/maint-test-options.c b/gdb/maint-test-options.c index 5f0007a..9e2e211 100644 --- a/gdb/maint-test-options.c +++ b/gdb/maint-test-options.c @@ -61,13 +61,15 @@ available kinds of commands (boolean, enum, flag, string, uinteger): (gdb) maint test-options require-delimiter -[TAB] - -bool -enum -flag -string -uinteger -xx1 -xx2 + -bool -pinteger-unlimited -xx1 + -enum -string -xx2 + -flag -uinteger-unlimited (gdb) maint test-options require-delimiter -bool o[TAB] off on (gdb) maint test-options require-delimiter -enum [TAB] xxx yyy zzz - (gdb) maint test-options require-delimiter -uinteger [TAB] + (gdb) maint test-options require-delimiter -uinteger-unlimited [TAB] NUMBER unlimited '-xx1' and '-xx2' are flag options too. They exist in order to @@ -76,14 +78,14 @@ Invoking the commands makes them print out the options parsed: (gdb) maint test-options unknown-is-error -flag -enum yyy cmdarg - -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint 0 -zuint-unl 0 -- cmdarg + -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint-unl 0 -pint-unl 0 -string '' -- cmdarg (gdb) maint test-options require-delimiter -flag -enum yyy cmdarg - -flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint 0 -zuint-unl 0 -- -flag -enum yyy cmdarg + -flag 0 -xx1 0 -xx2 0 -bool 0 -enum xxx -uint-unl 0 -pint-unl 0 -string '' -- -flag -enum yyy cmdarg (gdb) maint test-options require-delimiter -flag -enum yyy cmdarg -- Unrecognized option at: cmdarg -- (gdb) maint test-options require-delimiter -flag -enum yyy -- cmdarg - -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint 0 -zuint-unl 0 -- cmdarg + -flag 1 -xx1 0 -xx2 0 -bool 0 -enum yyy -uint-unl 0 -pint-unl 0 -string '' -- cmdarg The "maint show test-options-completion-result" command exists in order to do something similar for completion: @@ -131,8 +133,8 @@ struct test_options_opts bool xx2_opt = false; bool boolean_opt = false; const char *enum_opt = test_options_enum_values_xxx; - unsigned int uint_opt = 0; - int zuint_unl_opt = 0; + unsigned int uint_unl_opt = 0; + int pint_unl_opt = 0; std::string string_opt; test_options_opts () = default; @@ -145,18 +147,18 @@ struct test_options_opts { gdb_printf (file, _("-flag %d -xx1 %d -xx2 %d -bool %d " - "-enum %s -uint %s -zuint-unl %s -string '%s' -- %s\n"), + "-enum %s -uint-unl %s -pint-unl %s -string '%s' -- %s\n"), flag_opt, xx1_opt, xx2_opt, boolean_opt, enum_opt, - (uint_opt == UINT_MAX + (uint_unl_opt == UINT_MAX ? "unlimited" - : pulongest (uint_opt)), - (zuint_unl_opt == -1 + : pulongest (uint_unl_opt)), + (pint_unl_opt == -1 ? "unlimited" - : plongest (zuint_unl_opt)), + : plongest (pint_unl_opt)), string_opt.c_str (), args); } @@ -203,22 +205,24 @@ static const gdb::option::option_def test_options_option_defs[] = { N_("An enum option."), }, - /* A uinteger option. */ + /* A uinteger + "unlimited" option. */ gdb::option::uinteger_option_def<test_options_opts> { - "uinteger", - [] (test_options_opts *opts) { return &opts->uint_opt; }, + "uinteger-unlimited", + [] (test_options_opts *opts) { return &opts->uint_unl_opt; }, + uinteger_unlimited_literals, nullptr, /* show_cmd_cb */ N_("A uinteger option."), nullptr, /* show_doc */ N_("A help doc that spawns\nmultiple lines."), }, - /* A zuinteger_unlimited option. */ - gdb::option::zuinteger_unlimited_option_def<test_options_opts> { - "zuinteger-unlimited", - [] (test_options_opts *opts) { return &opts->zuint_unl_opt; }, + /* A pinteger + "unlimited" option. */ + gdb::option::pinteger_option_def<test_options_opts> { + "pinteger-unlimited", + [] (test_options_opts *opts) { return &opts->pint_unl_opt; }, + pinteger_unlimited_literals, nullptr, /* show_cmd_cb */ - N_("A zuinteger-unlimited option."), + N_("A pinteger-unlimited option."), nullptr, /* show_doc */ nullptr, /* help_doc */ }, |