summaryrefslogtreecommitdiff
path: root/gdb/valprint.c
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@embecosm.com>2023-01-19 21:15:56 +0000
committerMaciej W. Rozycki <macro@embecosm.com>2023-01-19 21:15:56 +0000
commit7aeb03e2d4186d1184050d2ec048301f48255644 (patch)
tree3d2f57b0f5fa23d6f977c7fbaee809c284e7bc5c /gdb/valprint.c
parent0fcd58d843ce1b07c8516c51f9120714673003a3 (diff)
downloadbinutils-gdb-7aeb03e2d4186d1184050d2ec048301f48255644.tar.gz
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/valprint.c')
-rw-r--r--gdb/valprint.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 1fed8287d0e..77d1f1348eb 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -2861,8 +2861,8 @@ using boolean_option_def
= gdb::option::boolean_option_def<value_print_options>;
using uinteger_option_def
= gdb::option::uinteger_option_def<value_print_options>;
-using zuinteger_unlimited_option_def
- = gdb::option::zuinteger_unlimited_option_def<value_print_options>;
+using pinteger_option_def
+ = gdb::option::pinteger_option_def<value_print_options>;
/* Definitions of options for the "print" and "compile print"
commands. */
@@ -2907,15 +2907,17 @@ static const gdb::option::option_def value_print_option_defs[] = {
uinteger_option_def {
"elements",
[] (value_print_options *opt) { return &opt->print_max; },
+ uinteger_unlimited_literals,
show_print_max, /* show_cmd_cb */
N_("Set limit on string chars or array elements to print."),
N_("Show limit on string chars or array elements to print."),
N_("\"unlimited\" causes there to be no limit."),
},
- zuinteger_unlimited_option_def {
+ pinteger_option_def {
"max-depth",
[] (value_print_options *opt) { return &opt->max_depth; },
+ pinteger_unlimited_literals,
show_print_max_depth, /* show_cmd_cb */
N_("Set maximum print depth for nested structures, unions and arrays."),
N_("Show maximum print depth for nested structures, unions, and arrays."),
@@ -2975,6 +2977,7 @@ pretty-printers for that value.")
uinteger_option_def {
"repeats",
[] (value_print_options *opt) { return &opt->repeat_count_threshold; },
+ uinteger_unlimited_literals,
show_repeat_count_threshold, /* show_cmd_cb */
N_("Set threshold for repeated print elements."),
N_("Show threshold for repeated print elements."),