diff options
author | Gareth Rees <grees@undo.io> | 2023-03-11 11:49:34 +0000 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-05-04 08:58:18 -0600 |
commit | 51f8dafba8175a8d59716f220a46de4e626e5073 (patch) | |
tree | abf342f8f989dbaf7c737b0ca2cf5d75d2918e0b /gdb/python | |
parent | 3539414584be0094b0a4fe56dfd64ea79d802edc (diff) | |
download | gdb-51f8dafba8175a8d59716f220a46de4e626e5073.zip gdb-51f8dafba8175a8d59716f220a46de4e626e5073.tar.gz gdb-51f8dafba8175a8d59716f220a46de4e626e5073.tar.bz2 |
Don't treat references to compound values as "simple".
SUMMARY
The '--simple-values' argument to '-stack-list-arguments' and similar
GDB/MI commands does not take reference types into account, so that
references to arbitrarily large structures are considered "simple" and
printed. This means that the '--simple-values' argument cannot be used
by IDEs when tracing the stack due to the time taken to print large
structures passed by reference.
DETAILS
Various GDB/MI commands ('-stack-list-arguments', '-stack-list-locals',
'-stack-list-variables' and so on) take a PRINT-VALUES argument which
may be '--no-values' (0), '--all-values' (1) or '--simple-values' (2).
In the '--simple-values' case, the command is supposed to print the
name, type, and value of variables with simple types, and print only the
name and type of variables with compound types.
The '--simple-values' argument ought to be suitable for IDEs that need
to update their user interface with the program's call stack every time
the program stops. However, it does not take C++ reference types into
account, and this makes the argument unsuitable for this purpose.
For example, consider the following C++ program:
struct s {
int v[10];
};
int
sum(const struct s &s)
{
int total = 0;
for (int i = 0; i < 10; ++i) total += s.v[i];
return total;
}
int
main(void)
{
struct s s = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };
return sum(s);
}
If we start GDB in MI mode and continue to 'sum', the behaviour of
'-stack-list-arguments' is as follows:
(gdb)
-stack-list-arguments --simple-values
^done,stack-args=[frame={level="0",args=[{name="s",type="const s &",value="@0x7fffffffe310: {v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}"}]},frame={level="1",args=[]}]
Note that the value of the argument 's' was printed, even though 's' is
a reference to a structure, which is not a simple value.
See https://github.com/microsoft/MIEngine/pull/673 for a case where this
behaviour caused Microsoft to avoid the use of '--simple-values' in
their MIEngine debug adapter, because it caused Visual Studio Code to
take too long to refresh the call stack in the user interface.
SOLUTIONS
There are two ways we could fix this problem, depending on whether we
consider the current behaviour to be a bug.
1. If the current behaviour is a bug, then we can update the behaviour
of '--simple-values' so that it takes reference types into account:
that is, a value is simple if it is neither an array, struct, or
union, nor a reference to an array, struct or union.
In this case we must add a feature to the '-list-features' command so
that IDEs can detect that it is safe to use the '--simple-values'
argument when refreshing the call stack.
2. If the current behaviour is not a bug, then we can add a new option
for the PRINT-VALUES argument, for example, '--scalar-values' (3),
that would be suitable for use by IDEs.
In this case we must add a feature to the '-list-features' command
so that IDEs can detect that the '--scalar-values' argument is
available for use when refreshing the call stack.
PATCH
This patch implements solution (1) as I think the current behaviour of
not printing structures, but printing references to structures, is
contrary to reasonable expectation.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-framefilter.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c index 0e8b240..e555dc3 100644 --- a/gdb/python/py-framefilter.c +++ b/gdb/python/py-framefilter.c @@ -235,14 +235,10 @@ py_print_value (struct ui_out *out, struct value *val, if (args_type == MI_PRINT_SIMPLE_VALUES || args_type == MI_PRINT_ALL_VALUES) { - struct type *type = check_typedef (val->type ()); - if (args_type == MI_PRINT_ALL_VALUES) should_print = 1; else if (args_type == MI_PRINT_SIMPLE_VALUES - && type->code () != TYPE_CODE_ARRAY - && type->code () != TYPE_CODE_STRUCT - && type->code () != TYPE_CODE_UNION) + && mi_simple_type_p (val->type ())) should_print = 1; } else if (args_type != NO_VALUES) |