Whether to style the source and assembly code highlighted by the
TUI's current position indicator. The default is off.
+set print characters LIMIT
+show print characters
+ This new setting is like 'set print elements', but controls how many
+ characters of a string are printed. This functionality used to be
+ covered by 'set print elements', but it can be controlled separately
+ now. LIMIT can be set to a numerical value to request that particular
+ character count, to 'unlimited' to print all characters of a string,
+ or to 'elements', which is also the default, to follow the setting of
+ 'set print elements' as it used to be.
+
+print -characters LIMIT
+ This new option to the 'print' command has the same effect as a temporary
+ use of 'set print characters'.
+
* Changed commands
document user-defined
return;
}
- for (i = 0; i < length && things_printed < options->print_max; i += 1)
+ unsigned int print_max_chars = get_print_max_chars (options);
+ for (i = 0; i < length && things_printed < print_max_chars; i += 1)
{
/* Position of the character we are examining
to see whether it is repeated. */
elements up to it. */
if (options->stop_print_at_null)
{
+ unsigned int print_max_chars = get_print_max_chars (options);
int temp_len;
/* Look for a NULL char. */
for (temp_len = 0;
(temp_len < len
- && temp_len < options->print_max
+ && temp_len < print_max_chars
&& char_at (valaddr + offset_aligned,
temp_len, eltlen, byte_order) != 0);
temp_len += 1);
/* Print the character string STRING, printing at most LENGTH
characters. LENGTH is -1 if the string is nul terminated. Each
character is WIDTH bytes long. Printing stops early if the number
- hits print_max; repeat counts are printed as appropriate. Print
- ellipses at the end if we had to stop before printing LENGTH
+ hits print_max_chars; repeat counts are printed as appropriate.
+ Print ellipses at the end if we had to stop before printing LENGTH
characters, or if FORCE_ELLIPSES. */
void
print elements up to it. */
if (options->stop_print_at_null)
{
+ unsigned int print_max_chars = get_print_max_chars (options);
unsigned int temp_len;
for (temp_len = 0;
(temp_len < len
- && temp_len < options->print_max
+ && temp_len < print_max_chars
&& extract_unsigned_integer (valaddr + temp_len * eltlen,
eltlen, byte_order) != 0);
++temp_len)
/* Force printstr to print ellipses if
we've printed the maximum characters and
the next character is not \000. */
- if (temp_len == options->print_max && temp_len < len)
+ if (temp_len == print_max_chars && temp_len < len)
{
ULONGEST ival
= extract_unsigned_integer (valaddr + temp_len * eltlen,
Set printing of array indexes.
Related setting: @ref{set print array-indexes}.
-@item -elements @var{number-of-elements}|@code{unlimited}
-Set limit on string chars or array elements to print. The value
+@item -characters @var{number-of-characters}|@code{elements}|@code{unlimited}
+Set limit on string characters to print. The value @code{elements}
+causes the limit on array elements to print to be used. The value
@code{unlimited} causes there to be no limit. Related setting:
-@ref{set print elements}.
+@ref{set print characters}.
+
+@item -elements @var{number-of-elements}|@code{unlimited}
+Set limit on array elements and optionally string characters to print.
+See @ref{set print characters}, and the @code{-characters} option above
+for when this option applies to strings. The value @code{unlimited}
+causes there to be no limit. @xref{set print elements}, for a related
+CLI command.
@item -max-depth @var{depth}|@code{unlimited}
Set the threshold after which nested structures are replaced with
@item show print nibbles
Show whether to print binary values in groups of four bits.
+@anchor{set print characters}
+@item set print characters @var{number-of-characters}
+@itemx set print characters elements
+@itemx set print characters unlimited
+@cindex number of string characters to print
+@cindex limit on number of printed string characters
+Set a limit on how many characters of a string @value{GDBN} will print.
+If @value{GDBN} is printing a large string, it stops printing after it
+has printed the number of characters set by the @code{set print
+characters} command. This equally applies to multi-byte and wide
+character strings, that is for strings whose character type is
+@code{wchar_t}, @code{char16_t}, or @code{char32_t} it is the number of
+actual characters rather than underlying bytes the encoding uses that
+this setting controls.
+Setting @var{number-of-characters} to @code{elements} means that the
+limit on the number of characters to print follows one for array
+elements; see @ref{set print elements}.
+Setting @var{number-of-characters} to @code{unlimited} means that the
+number of characters to print is unlimited.
+When @value{GDBN} starts, this limit is set to @code{elements}.
+
+@item show print characters
+Display the number of characters of a large string that @value{GDBN}
+will print.
+
@anchor{set print elements}
@item set print elements @var{number-of-elements}
@itemx set print elements unlimited
Set a limit on how many elements of an array @value{GDBN} will print.
If @value{GDBN} is printing a large array, it stops printing after it has
printed the number of elements set by the @code{set print elements} command.
-This limit also applies to the display of strings.
+By default this limit also applies to the display of strings; see
+@ref{set print characters}.
When @value{GDBN} starts, this limit is set to 200.
Setting @var{number-of-elements} to @code{unlimited} or zero means
that the number of elements to print is unlimited.
@code{s} requests that pointers to chars be handled as strings, in
particular collecting the contents of the memory being pointed at, up
to the first zero. The upper bound is by default the value of the
-@code{print elements} variable; if @code{s} is followed by a decimal
+@code{print characters} variable; if @code{s} is followed by a decimal
number, that is the upper bound instead. So for instance
@samp{collect/s25 mystr} collects as many as 25 characters at
@samp{mystr}.
representation of a C@t{++} object, @code{False} if they shouldn't (see
@code{set print static-members} in @ref{Print Settings}).
+@item max_characters
+Number of string characters to print, @code{0} to follow
+@code{max_elements}, or @code{UINT_MAX} to print an unlimited number
+of characters (see @code{set print characters} in @ref{Print Settings}).
+
@item max_elements
Number of array elements to print, or @code{0} to print an unlimited
number of elements (see @code{set print elements} in @ref{Print
struct ui_file * stream) const;
/* Print the character string STRING, printing at most LENGTH characters.
- Printing stops early if the number hits print_max; repeat counts
+ Printing stops early if the number hits print_max_chars; repeat counts
are printed as appropriate. Print ellipses at the end if we
had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
return;
}
- for (i = 0; i < length && things_printed < options->print_max; ++i)
+ unsigned int print_max_chars = get_print_max_chars (options);
+ for (i = 0; i < length && things_printed < print_max_chars; ++i)
{
/* Position of the character we are examining
to see whether it is repeated. */
elements up to it. */
if (options->stop_print_at_null)
{
+ unsigned int print_max_chars = get_print_max_chars (options);
unsigned int temp_len;
/* Look for a NULL char. */
for (temp_len = 0;
(valaddr[temp_len]
- && temp_len < len && temp_len < options->print_max);
+ && temp_len < len
+ && temp_len < print_max_chars);
temp_len++);
len = temp_len;
}
return;
}
- for (i = 0; i < length && things_printed < options->print_max; ++i)
+ unsigned int print_max_chars = get_print_max_chars (options);
+ for (i = 0; i < length && things_printed < print_max_chars; ++i)
{
/* Position of the character we are examining
to see whether it is repeated. */
elements up to it. */
if (options->stop_print_at_null)
{
+ unsigned int print_max_chars
+ = get_print_max_chars (options);
unsigned int temp_len;
/* Look for a NULL char. */
for (temp_len = 0;
- extract_unsigned_integer (valaddr + temp_len * eltlen,
- eltlen, byte_order)
- && temp_len < len && temp_len < options->print_max;
+ (extract_unsigned_integer
+ (valaddr + temp_len * eltlen, eltlen, byte_order)
+ && temp_len < len
+ && temp_len < print_max_chars);
temp_len++);
len = temp_len;
}
chars_to_read * char_size);
chars_read /= char_size;
read_error = (chars_read == chars_to_read) ? 0 : 1;
+ unsigned int print_max_chars = get_print_max_chars (options);
/* Searching for '\0' from the end of buffer in backward direction. */
for (i = 0; i < chars_read && count > 0 ; ++i, ++chars_counted)
{
int offset = (chars_to_read - i - 1) * char_size;
if (integer_is_zero (&buffer[offset], char_size)
- || chars_counted == options->print_max)
+ || chars_counted == print_max_chars)
{
- /* Found '\0' or reached print_max. As OFFSET is the offset to
- '\0', we add CHAR_SIZE to return the start address of
- a string. */
+ /* Found '\0' or reached `print_max_chars'. As OFFSET
+ is the offset to '\0', we add CHAR_SIZE to return
+ the start address of a string. */
--count;
string_start_addr = addr + offset + char_size;
chars_counted = 0;
"actual_objects", /* See set print object on|off. */
"static_members", /* See set print static-members on|off. */
/* C non-bool options. */
+ "max_characters", /* See set print characters N. */
"max_elements", /* See set print elements N. */
"max_depth", /* See set print max-depth N. */
"repeat_threshold", /* See set print repeats. */
char *format = NULL;
if (!gdb_PyArg_ParseTupleAndKeywords (args,
kw,
- "|O!O!O!O!O!O!O!O!O!O!O!O!O!IIIs",
+ "|O!O!O!O!O!O!O!O!O!O!O!O!O!IIIIs",
keywords,
&PyBool_Type, &raw_obj,
&PyBool_Type, &pretty_arrays_obj,
&PyBool_Type, &deref_refs_obj,
&PyBool_Type, &actual_objects_obj,
&PyBool_Type, &static_members_obj,
+ &opts.print_max_chars,
&opts.print_max,
&opts.max_depth,
&opts.repeat_count_threshold,
gdb_test_no_output "set print array" "set print array"
#test set print asm-demangle
gdb_test_no_output "set print asm-demangle" "set print asm-demangle"
+#test set print characters
+gdb_test "set print characters" \
+ "Argument required \\(integer to set it to, or one of:\
+ \"elements\", \"unlimited\"\\)\\."
#test set print demangle
gdb_test_no_output "set print demangle" "set print demangle"
#test set print elements
gdb_test "show print array" "Pretty formatting of arrays is on."
#test show print asm-demangle
gdb_test "show print asm-demangle" "Demangling of C\[+\]+/ObjC names in disassembly listings is on."
+#test show print characters
+gdb_test "show print characters" \
+ "Limit on string characters to print is elements\\."
#test show print demangle
gdb_test "show print demangle" "Demangling of encoded C\[+\]+/ObjC names when displaying symbols is on."
#test show print elements
"-address"
"-array"
"-array-indexes"
+ "-characters"
"-elements"
"-max-depth"
"-memory-tag-violations"
if (target_supports_string_tracing ())
{
/* Allow an optional decimal number giving an explicit maximum
- string length, defaulting it to the "print elements" value;
+ string length, defaulting it to the "print characters" value;
so "collect/s80 mystr" gets at most 80 bytes of string. */
- *trace_string = opts.print_max;
+ *trace_string = get_print_max_chars (&opts);
exp++;
if (*exp >= '0' && *exp <= '9')
*trace_string = atoi (exp);
int embedded_offset,
struct ui_file *stream);
-#define PRINT_MAX_DEFAULT 200 /* Start print_max off at this value. */
-#define PRINT_MAX_DEPTH_DEFAULT 20 /* Start print_max_depth off at this value. */
+/* Start print_max at this value. */
+#define PRINT_MAX_DEFAULT 200
+
+/* Start print_max_chars at this value (meaning follow print_max). */
+#define PRINT_MAX_CHARS_DEFAULT PRINT_MAX_CHARS_ELEMENTS
+
+/* Start print_max_depth at this value. */
+#define PRINT_MAX_DEPTH_DEFAULT 20
struct value_print_options user_print_options =
{
false, /* nibblesprint */
false, /* objectprint */
PRINT_MAX_DEFAULT, /* print_max */
+ PRINT_MAX_CHARS_DEFAULT, /* print_max_chars */
10, /* repeat_count_threshold */
0, /* output_format */
0, /* format */
opts->format = format;
}
+/* Implement 'show print elements'. */
+
static void
show_print_max (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
+{
+ gdb_printf
+ (file,
+ (user_print_options.print_max_chars != PRINT_MAX_CHARS_ELEMENTS
+ ? _("Limit on array elements to print is %s.\n")
+ : _("Limit on string chars or array elements to print is %s.\n")),
+ value);
+}
+
+/* Implement 'show print characters'. */
+
+static void
+show_print_max_chars (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
{
gdb_printf (file,
- _("Limit on string chars or array "
- "elements to print is %s.\n"),
+ _("Limit on string characters to print is %s.\n"),
value);
}
-
/* Default input and output radixes, and output format letter. */
unsigned input_radix = 10;
/* Print the character string STRING, printing at most LENGTH
characters. LENGTH is -1 if the string is nul terminated. TYPE is
the type of each character. OPTIONS holds the printing options;
- printing stops early if the number hits print_max; repeat counts
- are printed as appropriate. Print ellipses at the end if we had to
- stop before printing LENGTH characters, or if FORCE_ELLIPSES.
+ printing stops early if the number hits print_max_chars; repeat
+ counts are printed as appropriate. Print ellipses at the end if we
+ had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
QUOTE_CHAR is the character to print at each end of the string. If
C_STYLE_TERMINATOR is true, and the last character is 0, then it is
omitted. */
/* Convert characters until the string is over or the maximum
number of printed characters has been reached. */
i = 0;
- while (i < options->print_max)
+ unsigned int print_max_chars = get_print_max_chars (options);
+ while (i < print_max_chars)
{
int r;
/* Print a string from the inferior, starting at ADDR and printing up to LEN
characters, of WIDTH bytes a piece, to STREAM. If LEN is -1, printing
stops at the first null byte, otherwise printing proceeds (including null
- bytes) until either print_max or LEN characters have been printed,
+ bytes) until either print_max_chars or LEN characters have been printed,
whichever is smaller. ENCODING is the name of the string's
encoding. It can be NULL, in which case the target encoding is
assumed. */
int width = elttype->length ();
/* First we need to figure out the limit on the number of characters we are
- going to attempt to fetch and print. This is actually pretty simple. If
- LEN >= zero, then the limit is the minimum of LEN and print_max. If
- LEN is -1, then the limit is print_max. This is true regardless of
- whether print_max is zero, UINT_MAX (unlimited), or something in between,
- because finding the null byte (or available memory) is what actually
- limits the fetch. */
-
- fetchlimit = (len == -1 ? options->print_max : std::min ((unsigned) len,
- options->print_max));
+ going to attempt to fetch and print. This is actually pretty simple.
+ If LEN >= zero, then the limit is the minimum of LEN and print_max_chars.
+ If LEN is -1, then the limit is print_max_chars. This is true regardless
+ of whether print_max_chars is zero, UINT_MAX (unlimited), or something in
+ between, because finding the null byte (or available memory) is what
+ actually limits the fetch. */
+
+ unsigned int print_max_chars = get_print_max_chars (options);
+ fetchlimit = (len == -1
+ ? print_max_chars
+ : std::min ((unsigned) len, print_max_chars));
err = target_read_string (addr, len, width, fetchlimit,
&buffer, &bytes_read);
using pinteger_option_def
= gdb::option::pinteger_option_def<value_print_options>;
+/* Extra literals supported with the `set print characters' and
+ `print -characters' commands. */
+static const literal_def print_characters_literals[] =
+ {
+ { "elements", PRINT_MAX_CHARS_ELEMENTS },
+ { "unlimited", PRINT_MAX_CHARS_UNLIMITED, 0 },
+ { nullptr }
+ };
+
/* Definitions of options for the "print" and "compile print"
commands. */
static const gdb::option::option_def value_print_option_defs[] = {
NULL, /* help_doc */
},
+ uinteger_option_def {
+ "characters",
+ [] (value_print_options *opt) { return &opt->print_max_chars; },
+ print_characters_literals,
+ show_print_max_chars, /* show_cmd_cb */
+ N_("Set limit on string chars to print."),
+ N_("Show limit on string chars to print."),
+ N_("\"elements\" causes the array element limit to be used.\n"
+ "\"unlimited\" causes there to be no limit."),
+ },
+
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."),
+ N_("Set limit on array elements to print."),
+ N_("Show limit on array elements to print."),
+ N_("\"unlimited\" causes there to be no limit.\n"
+ "This setting also applies to string chars when \"print characters\"\n"
+ "is set to \"elements\"."),
},
pinteger_option_def {
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;
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