diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2023-01-19 21:15:56 +0000 |
---|---|---|
committer | Maciej W. Rozycki <macro@embecosm.com> | 2023-01-19 21:15:56 +0000 |
commit | 76b58849c5fc433f71ad7ec18f9f47f782643bc6 (patch) | |
tree | 3e50cc9b530290e4a0180ff98bd9730150cf19a4 /gdb/valprint.h | |
parent | 7aeb03e2d4186d1184050d2ec048301f48255644 (diff) | |
download | fsf-binutils-gdb-76b58849c5fc433f71ad7ec18f9f47f782643bc6.zip fsf-binutils-gdb-76b58849c5fc433f71ad7ec18f9f47f782643bc6.tar.gz fsf-binutils-gdb-76b58849c5fc433f71ad7ec18f9f47f782643bc6.tar.bz2 |
GDB: Add a character string limiting option
This commit splits the `set/show print elements' option into two. We
retain `set/show print elements' for controlling how many elements of an
array we print, but a new `set/show print characters' setting is added
which is used for controlling how many characters of a string are
printed.
The motivation behind this change is to allow users a finer level of
control over how data is printed, reflecting that, although strings can
be thought of as arrays of characters, users often want to treat these
two things differently.
For compatibility reasons by default the `set/show print characters'
option is set to `elements', which makes the limit for character strings
follow the setting of the `set/show print elements' option, as it used
to. Using `set print characters' with any other value makes the limit
independent from the `set/show print elements' setting, however it can
be restored to the default with the `set print characters elements'
command at any time.
A corresponding `-characters' option for the `print' command is added,
with the same semantics, i.e. one can use `elements' to make a given
`print' invocation follow the limit of elements, be it set with the
`-elements' option also given with the same invocation or taken from the
`set/show print elements' setting, for characters as well regardless of
the current setting of the `set/show print characters' option.
The GDB changes are all pretty straightforward, just changing references
to the old 'print_max' to use a new `get_print_max_chars' helper which
figures out which of the two of `print_max' and `print_max_chars' values
to use.
Likewise, the documentation is just updated to reference the new setting
where appropriate.
To make people's life easier the message shown by `show print elements'
now indicates if the setting also applies to character strings:
(gdb) set print characters elements
(gdb) show print elements
Limit on string chars or array elements to print is 200.
(gdb) set print characters unlimited
(gdb) show print elements
Limit on array elements to print is 200.
(gdb)
and the help text shows the dependency as well:
(gdb) help set print elements
Set limit on array elements to print.
"unlimited" causes there to be no limit.
This setting also applies to string chars when "print characters"
is set to "elements".
(gdb)
In the testsuite there are two minor updates, one to add `-characters'
to the list of completions now shown for the `print' command, and a bare
minimum pair of checks for the right handling of `set print characters'
and `show print characters', copied from the corresponding checks for
`set print elements' and `show print elements' respectively.
Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/valprint.h')
-rw-r--r-- | gdb/valprint.h | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/gdb/valprint.h b/gdb/valprint.h index 68382a1..cf5e2f2 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -51,12 +51,15 @@ struct value_print_options in its vtables. */ bool objectprint; - /* Maximum number of chars to print for a string pointer value or vector - contents, or UINT_MAX for no limit. Note that "set print elements 0" - stores UINT_MAX in print_max, which displays in a show command as - "unlimited". */ + /* Maximum number of elements to print for vector contents, or UINT_MAX + for no limit. Note that "set print elements 0" stores UINT_MAX in + print_max, which displays in a show command as "unlimited". */ unsigned int print_max; + /* Maximum number of string chars to print for a string pointer value, + zero if to follow the value of print_max, or UINT_MAX for no limit. */ + unsigned int print_max_chars; + /* Print repeat counts if there are more than this many repetitions of an element in an array. */ unsigned int repeat_count_threshold; @@ -105,6 +108,21 @@ struct value_print_options int max_depth; }; +/* The value to use for `print_max_chars' to follow `print_max'. */ +#define PRINT_MAX_CHARS_ELEMENTS 0 + +/* The value to use for `print_max_chars' for no limit. */ +#define PRINT_MAX_CHARS_UNLIMITED UINT_MAX + +/* Return the character count limit for printing strings. */ + +static inline unsigned int +get_print_max_chars (const struct value_print_options *options) +{ + return (options->print_max_chars != PRINT_MAX_CHARS_ELEMENTS + ? options->print_max_chars : options->print_max); +} + /* Create an option_def_group for the value_print options, with OPTS as context. */ extern gdb::option::option_def_group make_value_print_options_def_group |