forked from Imagelibrary/binutils-gdb
GDB: Introduce limited array lengths while printing values
This commit introduces the idea of loading only part of an array in
order to print it, what I call "limited length" arrays.
The motivation behind this work is to make it possible to print slices
of very large arrays, where very large means bigger than
`max-value-size'.
Consider this GDB session with the current GDB:
(gdb) set max-value-size 100
(gdb) p large_1d_array
value requires 400 bytes, which is more than max-value-size
(gdb) p -elements 10 -- large_1d_array
value requires 400 bytes, which is more than max-value-size
notice that the request to print 10 elements still fails, even though 10
elements should be less than the max-value-size. With a patched version
of GDB:
(gdb) p -elements 10 -- large_1d_array
$1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
So now the print has succeeded. It also has loaded `max-value-size'
worth of data into value history, so the recorded value can be accessed
consistently:
(gdb) p -elements 10 -- $1
$2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9...}
(gdb) p $1
$3 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, <unavailable> <repeats 75 times>}
(gdb)
Accesses with other languages work similarly, although for Ada only
C-style [] array element/dimension accesses use history. For both Ada
and Fortran () array element/dimension accesses go straight to the
inferior, bypassing the value history just as with C pointers.
Co-Authored-By: Maciej W. Rozycki <macro@embecosm.com>
This commit is contained in:
committed by
Maciej W. Rozycki
parent
a2fb245a4b
commit
a0c0791577
@@ -1242,6 +1242,11 @@ print_command_parse_format (const char **expp, const char *cmdname,
|
||||
void
|
||||
print_value (value *val, const value_print_options &opts)
|
||||
{
|
||||
/* This setting allows large arrays to be printed by limiting the
|
||||
number of elements that are loaded into GDB's memory; we only
|
||||
need to load as many array elements as we plan to print. */
|
||||
scoped_array_length_limiting limit_large_arrays (opts.print_max);
|
||||
|
||||
int histindex = record_latest_value (val);
|
||||
|
||||
annotate_value_history_begin (histindex, value_type (val));
|
||||
@@ -1301,6 +1306,11 @@ process_print_command_args (const char *args, value_print_options *print_opts,
|
||||
|
||||
if (exp != nullptr && *exp)
|
||||
{
|
||||
/* This setting allows large arrays to be printed by limiting the
|
||||
number of elements that are loaded into GDB's memory; we only
|
||||
need to load as many array elements as we plan to print. */
|
||||
scoped_array_length_limiting limit_large_arrays (print_opts->print_max);
|
||||
|
||||
/* VOIDPRINT is true to indicate that we do want to print a void
|
||||
value, so invert it for parse_expression. */
|
||||
expression_up expr = parse_expression (exp, nullptr, !voidprint);
|
||||
@@ -1489,6 +1499,12 @@ output_command (const char *exp, int from_tty)
|
||||
|
||||
get_formatted_print_options (&opts, format);
|
||||
opts.raw = fmt.raw;
|
||||
|
||||
/* This setting allows large arrays to be printed by limiting the
|
||||
number of elements that are loaded into GDB's memory; we only
|
||||
need to load as many array elements as we plan to print. */
|
||||
scoped_array_length_limiting limit_large_arrays (opts.print_max);
|
||||
|
||||
print_formatted (val, fmt.size, &opts, gdb_stdout);
|
||||
|
||||
annotate_value_end ();
|
||||
|
||||
Reference in New Issue
Block a user