* [PATCH] [gdb/mi] Don't treat references to compound values as "simple".
@ 2022-09-08 7:18 Gareth Rees
2022-09-08 10:27 ` Andrew Burgess
0 siblings, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2022-09-08 7:18 UTC (permalink / raw)
To: gdb-patches
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, '--simplest-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 '--simplest-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
surprising. However, if you prefer solution (2) I would be happy to
implement that instead.
---
gdb/NEWS | 12 ++++++
gdb/doc/gdb.texinfo | 7 ++++
gdb/mi/mi-cmd-stack.c | 6 +--
gdb/mi/mi-cmd-var.c | 22 ++++++----
gdb/mi/mi-cmds.h | 5 +++
gdb/mi/mi-main.c | 7 +---
gdb/python/py-framefilter.c | 6 +--
gdb/testsuite/gdb.mi/print-simple-values.cc | 44 ++++++++++++++++++++
gdb/testsuite/gdb.mi/print-simple-values.exp | 40 ++++++++++++++++++
9 files changed, 126 insertions(+), 23 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index dee0ac2ecd8..855f42a9549 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -114,6 +114,18 @@ maintenance info line-table
entry corresponds to an address where a breakpoint should be placed
to be at the first instruction past a function's prologue.
+* MI changes
+
+ ** The '--simple-values' argument to the '-stack-list-arguments',
+ '-stack-list-locals', '-stack-list-variables', and
+ '-var-list-children' commands takes reference types into account:
+ that is, a value is now considered simple if it is neither an
+ array, structure, or union, nor a reference to an array, structure,
+ or union. (Previously all references were considered simple.)
+ Support for this feature can be verified by using the
+ '-list-features' command, which should contain
+ "simple-values-ref-types".
+
* New targets
GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 238a49b027d..5ccf6609709 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -37295,6 +37295,13 @@ option (@pxref{GDB/MI Program Execution}).
@item data-disassemble-a-option
Indicates that the @code{-data-disassemble} command supports the @option{-a}
option (@pxref{GDB/MI Data Manipulation}).
+@item simple-values-ref-types
+Indicates that the @code{--simple-values} argument to the
+@code{-stack-list-arguments}, @code{-stack-list-locals},
+@code{-stack-list-variables}, and @code{-var-list-children} commands
+takes reference types into account: that is, a value is considered
+simple if it neither an array, structure, or union, nor a reference to
+an array, structure, or union.
@end ftable
@subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 0fe204dbc66..f8f4ad266d0 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -571,7 +571,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
const struct block *block;
struct symbol *sym;
struct block_iterator iter;
- struct type *type;
const char *name_of_result;
struct ui_out *uiout = current_uiout;
@@ -650,10 +649,7 @@ list_args_or_locals (const frame_print_options &fp_opts,
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (sym2->type ());
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
+ if (mi_simple_values_type_p (sym2->type ()))
{
case PRINT_ALL_VALUES:
if (sym->is_argument ())
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 3db09cf7815..f9d332d13a4 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -335,15 +335,21 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
if (type == NULL)
return 1;
else
- {
- type = check_typedef (type);
+ return mi_simple_values_type_p (type);
+}
- /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
- and that type is not a compound type. */
- return (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION);
- }
+int
+mi_simple_values_type_p (struct type *type)
+{
+ type = check_typedef (type);
+
+ if (type->code () == TYPE_CODE_REF || type->code () == TYPE_CODE_RVALUE_REF)
+ type = TYPE_TARGET_TYPE (type);
+
+ return (type
+ && type->code () != TYPE_CODE_ARRAY
+ && type->code () != TYPE_CODE_STRUCT
+ && type->code () != TYPE_CODE_UNION);
}
void
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 9ffb11bf997..81a5578ca1c 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
= gdb::function_view<bool (mi_command *)>;
extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
+/* Return 1 if type is suitable for printing with PRINT_SIMPLE_VALUES, that is,
+ if type is neither a compound type nor a reference to a compound type. */
+
+extern int mi_simple_values_type_p (struct type *type);
+
#endif /* MI_MI_CMDS_H */
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b758f398e2a..dd1962fd0e2 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
uiout->field_string (NULL, "undefined-command-error-code");
uiout->field_string (NULL, "exec-run-start-option");
uiout->field_string (NULL, "data-disassemble-a-option");
+ uiout->field_string (NULL, "simple-values-ref-types");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
@@ -2462,7 +2463,6 @@ static void
print_variable_or_computed (const char *expression, enum print_values values)
{
struct value *val;
- struct type *type;
struct ui_out *uiout = current_uiout;
string_file stb;
@@ -2482,12 +2482,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (value_type (val));
type_print (value_type (val), "", &stb, -1);
uiout->field_stream ("type", stb);
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
+ if (mi_simple_values_type_p (value_type (val)))
{
struct value_print_options opts;
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 366f3745b9d..227a9ecb4f1 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 (value_type (val));
-
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_values_type_p (value_type (val)))
should_print = 1;
}
else if (args_type != NO_VALUES)
diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
new file mode 100644
index 00000000000..15567c740a0
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
@@ -0,0 +1,44 @@
+/* This test case is part of GDB, the GNU debugger.
+
+ Copyright 2022 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* PRINT_SIMPLE_VALUES test program.
+
+ Test that PRINT_SIMPLE_VALUES handles C++ reference types correctly.
+
+ In the function f(), arguments a, b, and c are either ints or references to
+ int, and their values should be printed by PRINT_SIMPLE_VALUES, but arguments
+ s, t, and u are structures or references to structures, and their values
+ should not be printed by PRINT_SIMPLE_VALUES. */
+
+struct s
+{
+ int v;
+};
+
+int
+f(int a, int &b, int &&c, struct s s, struct s &t, struct s &&u)
+{
+ return a + b + c + s.v + t.v + u.v;
+}
+
+int
+main(void)
+{
+ int a = 1, b = 2;
+ struct s s = { 4 }, t = { 5 };
+ return f(a, b, 3, s, t, (struct s){ 6 });
+}
diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
new file mode 100644
index 00000000000..c1b5a54ad3b
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
@@ -0,0 +1,40 @@
+# Copyright 2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+standard_testfile .cc
+
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
+ untested "failed to compile"
+ return -1
+}
+
+mi_clean_restart $binfile
+
+mi_runto_main
+
+mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
+
+mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
+
+mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} "run until breakpoint on f"
+
+mi_gdb_test "-stack-list-arguments 2" \
+ "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"a\",type=\"int\",value=\"1\"\},\{name=\"b\",type=\"int &\",value=\"@0x\[0-9a-f\]+: 2\"\},\{name=\"c\",type=\"int &&\",value=\"@0x\[0-9a-f\]+: 3\"\},\{name=\"s\",type=\"s\"\},\{name=\"t\",type=\"s &\"\},\{name=\"u\",type=\"s &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
+ "stack list arguments, simple types: names, types and values, compound types: names and types"
+
+mi_gdb_exit
--
2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 7:18 [PATCH] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
@ 2022-09-08 10:27 ` Andrew Burgess
2022-09-08 11:02 ` [PATCH v2] " Gareth Rees
2022-09-08 11:09 ` [PATCH] " Gareth Rees
0 siblings, 2 replies; 49+ messages in thread
From: Andrew Burgess @ 2022-09-08 10:27 UTC (permalink / raw)
To: Gareth Rees, gdb-patches
Thanks for this patch. I have a few notes, in line below.
Gareth Rees via Gdb-patches <gdb-patches@sourceware.org> writes:
> 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, '--simplest-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 '--simplest-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
> surprising. However, if you prefer solution (2) I would be happy to
> implement that instead.
I'm agree that this feels like a bug, and that solution #1 seems like
the way to go.
> ---
> gdb/NEWS | 12 ++++++
> gdb/doc/gdb.texinfo | 7 ++++
> gdb/mi/mi-cmd-stack.c | 6 +--
> gdb/mi/mi-cmd-var.c | 22 ++++++----
> gdb/mi/mi-cmds.h | 5 +++
> gdb/mi/mi-main.c | 7 +---
> gdb/python/py-framefilter.c | 6 +--
> gdb/testsuite/gdb.mi/print-simple-values.cc | 44 ++++++++++++++++++++
> gdb/testsuite/gdb.mi/print-simple-values.exp | 40 ++++++++++++++++++
> 9 files changed, 126 insertions(+), 23 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..855f42a9549 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,18 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '--simple-values' argument to the '-stack-list-arguments',
> + '-stack-list-locals', '-stack-list-variables', and
> + '-var-list-children' commands takes reference types into account:
> + that is, a value is now considered simple if it is neither an
> + array, structure, or union, nor a reference to an array, structure,
> + or union. (Previously all references were considered simple.)
> + Support for this feature can be verified by using the
> + '-list-features' command, which should contain
> + "simple-values-ref-types".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..5ccf6609709 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -37295,6 +37295,13 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item simple-values-ref-types
> +Indicates that the @code{--simple-values} argument to the
> +@code{-stack-list-arguments}, @code{-stack-list-locals},
> +@code{-stack-list-variables}, and @code{-var-list-children} commands
> +takes reference types into account: that is, a value is considered
> +simple if it neither an array, structure, or union, nor a reference to
> +an array, structure, or union.
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..f8f4ad266d0 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -571,7 +571,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -650,10 +649,7 @@ list_args_or_locals (const frame_print_options &fp_opts,
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> + if (mi_simple_values_type_p (sym2->type ()))
> {
> case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..f9d332d13a4 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -335,15 +335,21 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> if (type == NULL)
> return 1;
> else
> - {
> - type = check_typedef (type);
> + return mi_simple_values_type_p (type);
> +}
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> - }
> +int
> +mi_simple_values_type_p (struct type *type)
This new function should have a comment like:
/* See mi-cmds.h. */
And also, should be returning `bool`.
> +{
> + type = check_typedef (type);
> +
> + if (type->code () == TYPE_CODE_REF || type->code () == TYPE_CODE_RVALUE_REF)
> + type = TYPE_TARGET_TYPE (type);
> +
> + return (type
Checks for nullptr should be written as:
type != nullptr
but, can you ever get nullptr here? Certainly, if type is nullptr on
entry then an assert in check_typedef will trigger, I'd expect that
after calling check_typedef and TYPE_TARGET_TYPE you should still have a
valid type pointer ... but maybe there's some case you've seen where
this is not true?
Unless you know a case where type could be nullptr I would rather the
type check be moved into a separate:
gdb_assert (type != nullptr);
before the return.
> + && type->code () != TYPE_CODE_ARRAY
> + && type->code () != TYPE_CODE_STRUCT
> + && type->code () != TYPE_CODE_UNION);
> }
>
> void
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..81a5578ca1c 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return 1 if type is suitable for printing with PRINT_SIMPLE_VALUES, that is,
> + if type is neither a compound type nor a reference to a compound type. */
> +
> +extern int mi_simple_values_type_p (struct type *type);
Update the comment to reflect an update of the return type to bool.
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..dd1962fd0e2 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "simple-values-ref-types");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2462,7 +2463,6 @@ static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
> @@ -2482,12 +2482,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> + if (mi_simple_values_type_p (value_type (val)))
> {
> struct value_print_options opts;
>
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..227a9ecb4f1 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 (value_type (val));
> -
> 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_values_type_p (value_type (val)))
> should_print = 1;
> }
> else if (args_type != NO_VALUES)
> diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
> new file mode 100644
> index 00000000000..15567c740a0
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
> @@ -0,0 +1,44 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* PRINT_SIMPLE_VALUES test program.
> +
> + Test that PRINT_SIMPLE_VALUES handles C++ reference types correctly.
> +
> + In the function f(), arguments a, b, and c are either ints or references to
> + int, and their values should be printed by PRINT_SIMPLE_VALUES, but arguments
> + s, t, and u are structures or references to structures, and their values
> + should not be printed by PRINT_SIMPLE_VALUES. */
Two spaces before '*/' to close this comment.
Test programs should follow GNU style unless specifically required not
to for some test reason.
> +
> +struct s
> +{
> + int v;
It seems like everything is over indented in the test, 4 spaces instead
of 2.
> +};
> +
> +int
> +f(int a, int &b, int &&c, struct s s, struct s &t, struct s &&u)
Space after 'f'.
> +{
> + return a + b + c + s.v + t.v + u.v;
Indentation.
> +}
> +
> +int
> +main(void)
Space after 'main'.
> +{
> + int a = 1, b = 2;
> + struct s s = { 4 }, t = { 5 };
> + return f(a, b, 3, s, t, (struct s){ 6 });
Space after 'f' and after '(struct s)' (I think).
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
> new file mode 100644
> index 00000000000..c1b5a54ad3b
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
> @@ -0,0 +1,40 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
Test scripts should have a brief summary here of what the test is
checking. This will be similar to the comment you have in the source
file, so maybe you just want to move that here, but you can keep the
source comment and add an extra description here, whatever works.
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} "run until breakpoint on f"
We still try to wrap lines to under 80 characters when possible, so
here, and maybe the previous line too should be wrapped.
> +
> +mi_gdb_test "-stack-list-arguments 2" \
> + "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"a\",type=\"int\",value=\"1\"\},\{name=\"b\",type=\"int &\",value=\"@0x\[0-9a-f\]+: 2\"\},\{name=\"c\",type=\"int &&\",value=\"@0x\[0-9a-f\]+: 3\"\},\{name=\"s\",type=\"s\"\},\{name=\"t\",type=\"s &\"\},\{name=\"u\",type=\"s &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
> + "stack list arguments, simple types: names, types and values, compound types: names and types"
But lines like these can't easily be wrapped, so its fine for these to exist.
Thanks,
Andrew
> +
> +mi_gdb_exit
> --
> 2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 10:27 ` Andrew Burgess
@ 2022-09-08 11:02 ` Gareth Rees
2022-09-08 13:30 ` Eli Zaretskii
2022-09-08 11:09 ` [PATCH] " Gareth Rees
1 sibling, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2022-09-08 11:02 UTC (permalink / raw)
To: gdb-patches
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, '--simplest-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 '--simplest-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.
---
gdb/NEWS | 12 +++++
gdb/doc/gdb.texinfo | 7 +++
gdb/mi/mi-cmd-stack.c | 6 +--
gdb/mi/mi-cmd-var.c | 24 +++++++---
gdb/mi/mi-cmds.h | 6 +++
gdb/mi/mi-main.c | 7 +--
gdb/python/py-framefilter.c | 6 +--
gdb/testsuite/gdb.mi/print-simple-values.cc | 44 +++++++++++++++++
gdb/testsuite/gdb.mi/print-simple-values.exp | 50 ++++++++++++++++++++
9 files changed, 140 insertions(+), 22 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index dee0ac2ecd8..855f42a9549 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -114,6 +114,18 @@ maintenance info line-table
entry corresponds to an address where a breakpoint should be placed
to be at the first instruction past a function's prologue.
+* MI changes
+
+ ** The '--simple-values' argument to the '-stack-list-arguments',
+ '-stack-list-locals', '-stack-list-variables', and
+ '-var-list-children' commands takes reference types into account:
+ that is, a value is now considered simple if it is neither an
+ array, structure, or union, nor a reference to an array, structure,
+ or union. (Previously all references were considered simple.)
+ Support for this feature can be verified by using the
+ '-list-features' command, which should contain
+ "simple-values-ref-types".
+
* New targets
GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 238a49b027d..5ccf6609709 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -37295,6 +37295,13 @@ option (@pxref{GDB/MI Program Execution}).
@item data-disassemble-a-option
Indicates that the @code{-data-disassemble} command supports the @option{-a}
option (@pxref{GDB/MI Data Manipulation}).
+@item simple-values-ref-types
+Indicates that the @code{--simple-values} argument to the
+@code{-stack-list-arguments}, @code{-stack-list-locals},
+@code{-stack-list-variables}, and @code{-var-list-children} commands
+takes reference types into account: that is, a value is considered
+simple if it neither an array, structure, or union, nor a reference to
+an array, structure, or union.
@end ftable
@subheading The @code{-list-target-features} Command
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 0fe204dbc66..f8f4ad266d0 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -571,7 +571,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
const struct block *block;
struct symbol *sym;
struct block_iterator iter;
- struct type *type;
const char *name_of_result;
struct ui_out *uiout = current_uiout;
@@ -650,10 +649,7 @@ list_args_or_locals (const frame_print_options &fp_opts,
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (sym2->type ());
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
+ if (mi_simple_values_type_p (sym2->type ()))
{
case PRINT_ALL_VALUES:
if (sym->is_argument ())
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 3db09cf7815..a1c93f3a167 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -335,15 +335,25 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
if (type == NULL)
return 1;
else
- {
- type = check_typedef (type);
+ return mi_simple_values_type_p (type);
+}
- /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
- and that type is not a compound type. */
- return (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION);
+/* See mi-cmds.h. */
+
+bool
+mi_simple_values_type_p (struct type *type)
+{
+ type = check_typedef (type);
+
+ if (type->code () == TYPE_CODE_REF || type->code () == TYPE_CODE_RVALUE_REF)
+ {
+ type = TYPE_TARGET_TYPE (type);
+ gdb_assert (type != nullptr);
}
+
+ return (type->code () != TYPE_CODE_ARRAY
+ && type->code () != TYPE_CODE_STRUCT
+ && type->code () != TYPE_CODE_UNION);
}
void
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 9ffb11bf997..de39c7758d7 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -226,4 +226,10 @@ using remove_mi_cmd_entries_ftype
= gdb::function_view<bool (mi_command *)>;
extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
+/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
+ is, if type is neither a compound type, nor a reference to a compound
+ type. */
+
+extern bool mi_simple_values_type_p (struct type *type);
+
#endif /* MI_MI_CMDS_H */
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b758f398e2a..dd1962fd0e2 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
uiout->field_string (NULL, "undefined-command-error-code");
uiout->field_string (NULL, "exec-run-start-option");
uiout->field_string (NULL, "data-disassemble-a-option");
+ uiout->field_string (NULL, "simple-values-ref-types");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
@@ -2462,7 +2463,6 @@ static void
print_variable_or_computed (const char *expression, enum print_values values)
{
struct value *val;
- struct type *type;
struct ui_out *uiout = current_uiout;
string_file stb;
@@ -2482,12 +2482,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (value_type (val));
type_print (value_type (val), "", &stb, -1);
uiout->field_stream ("type", stb);
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
+ if (mi_simple_values_type_p (value_type (val)))
{
struct value_print_options opts;
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 366f3745b9d..227a9ecb4f1 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 (value_type (val));
-
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_values_type_p (value_type (val)))
should_print = 1;
}
else if (args_type != NO_VALUES)
diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
new file mode 100644
index 00000000000..3761b87f4cc
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
@@ -0,0 +1,44 @@
+/* This test case is part of GDB, the GNU debugger.
+
+ Copyright 2022 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* PRINT_SIMPLE_VALUES test program.
+
+ Test that PRINT_SIMPLE_VALUES handles C++ reference types correctly.
+
+ In the function f(), arguments a, b, and c are either ints or references to
+ int, and their values should be printed by PRINT_SIMPLE_VALUES, but arguments
+ s, t, and u are structures or references to structures, and their values
+ should not be printed by PRINT_SIMPLE_VALUES. */
+
+struct s
+{
+ int v;
+};
+
+int
+f (int a, int &b, int &&c, struct s s, struct s &t, struct s &&u)
+{
+ return a + b + c + s.v + t.v + u.v;
+}
+
+int
+main (void)
+{
+ int a = 1, b = 2;
+ struct s s = { 4 }, t = { 5 };
+ return f (a, b, 3, s, t, (struct s) { 6 });
+}
diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
new file mode 100644
index 00000000000..021ceb31ace
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
@@ -0,0 +1,50 @@
+# Copyright 2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# PRINT_SIMPLE_VALUES test.
+#
+# Test that PRINT_SIMPLE_VALUES handles C++ reference types correctly.
+#
+# In the function f() in the test program, arguments a, b, and c are either ints
+# or references to int, and their values should be printed by
+# PRINT_SIMPLE_VALUES, but arguments s, t, and u are structures or references to
+# structures, and their values should not be printed by PRINT_SIMPLE_VALUES. */
+
+if { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+standard_testfile .cc
+
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
+ untested "failed to compile"
+ return -1
+}
+
+mi_clean_restart $binfile
+
+mi_runto_main
+
+mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
+
+mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
+
+mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
+ "run until breakpoint on f"
+
+mi_gdb_test "-stack-list-arguments --simple-values" \
+ "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"a\",type=\"int\",value=\"1\"\},\{name=\"b\",type=\"int &\",value=\"@0x\[0-9a-f\]+: 2\"\},\{name=\"c\",type=\"int &&\",value=\"@0x\[0-9a-f\]+: 3\"\},\{name=\"s\",type=\"s\"\},\{name=\"t\",type=\"s &\"\},\{name=\"u\",type=\"s &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
+ "stack list arguments, simple types: names, types and values, compound types: names and types"
+
+mi_gdb_exit
--
2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 10:27 ` Andrew Burgess
2022-09-08 11:02 ` [PATCH v2] " Gareth Rees
@ 2022-09-08 11:09 ` Gareth Rees
1 sibling, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-08 11:09 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
Andrew Burgess <aburgess@redhat.com> wrote:
> Thanks for this patch. I have a few notes, in line below.
Thank you for the detailed review. I believe I've addressed all your
comments in version 2 of the patch but let me know if there's anything
else I need to do.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 11:02 ` [PATCH v2] " Gareth Rees
@ 2022-09-08 13:30 ` Eli Zaretskii
2022-09-08 13:58 ` Gareth Rees
` (2 more replies)
0 siblings, 3 replies; 49+ messages in thread
From: Eli Zaretskii @ 2022-09-08 13:30 UTC (permalink / raw)
To: Gareth Rees; +Cc: gdb-patches
> Date: Thu, 8 Sep 2022 12:02:48 +0100
> From: Gareth Rees via Gdb-patches <gdb-patches@sourceware.org>
>
> 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, '--simplest-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 '--simplest-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.
Thanks. FWIW, I think we should implement 2, not 1.
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,18 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '--simple-values' argument to the '-stack-list-arguments',
> + '-stack-list-locals', '-stack-list-variables', and
> + '-var-list-children' commands takes reference types into account:
> + that is, a value is now considered simple if it is neither an
> + array, structure, or union, nor a reference to an array, structure,
> + or union.
Isn't it easier to say "only if the value is a scalar"?
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..5ccf6609709 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -37295,6 +37295,13 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item simple-values-ref-types
> +Indicates that the @code{--simple-values} argument to the
> +@code{-stack-list-arguments}, @code{-stack-list-locals},
> +@code{-stack-list-variables}, and @code{-var-list-children} commands
> +takes reference types into account: that is, a value is considered
> +simple if it neither an array, structure, or union, nor a reference to
> +an array, structure, or union.
> @end ftable
Same here.
Other than that, the documentation parts are OK.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 13:30 ` Eli Zaretskii
@ 2022-09-08 13:58 ` Gareth Rees
2022-09-08 14:07 ` Eli Zaretskii
2022-09-09 8:01 ` [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
2022-09-09 8:04 ` [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
2 siblings, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2022-09-08 13:58 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Eli Zaretskii <eliz@gnu.org> wrote:
> > +* MI changes
> > +
> > + ** The '--simple-values' argument to the '-stack-list-arguments',
> > + '-stack-list-locals', '-stack-list-variables', and
> > + '-var-list-children' commands takes reference types into account:
> > + that is, a value is now considered simple if it is neither an
> > + array, structure, or union, nor a reference to an array, structure,
> > + or union.
>
> Isn't it easier to say "only if the value is a scalar"?
I deliberately echoed the wording used in the documentation for
'-stack-list-arguments' and similar commands, which uses the formula
"if it is 2 or --simple-values, print the name, type and value for
simple data types, and the name and type for arrays, structures and
unions."
But you are right that this concept corresponds to the 'scalars'
arguments to 'set print frame-arguments'. But then should I update the
documentation for '-stack-list-arguments' to match?
> Thanks. FWIW, I think we should implement 2, not 1.
I note that 'set print frame-arguments scalars' already takes
reference types into account: see the function
'val_print_scalar_type_p' in gdb/valprint.c, which is implemented like
this:
int
val_print_scalar_type_p (struct type *type)
{
type = check_typedef (type);
while (TYPE_IS_REFERENCE (type))
{
type = TYPE_TARGET_TYPE (type);
type = check_typedef (type);
}
switch (type->code ())
{
case TYPE_CODE_ARRAY:
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
case TYPE_CODE_SET:
case TYPE_CODE_STRING:
return 0;
default:
return 1;
}
}
Updating '--simple-values' to call 'val_print_scalar_type_p' is
probably a step too far because of the exclusion of strings, so if we
want the 'scalars' behaviour then we need solution (2) in which we
would add a PRINT-VALUES option '--scalar-values' which behaves the
same way as 'set print frame-arguments scalars'.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 13:58 ` Gareth Rees
@ 2022-09-08 14:07 ` Eli Zaretskii
0 siblings, 0 replies; 49+ messages in thread
From: Eli Zaretskii @ 2022-09-08 14:07 UTC (permalink / raw)
To: Gareth Rees; +Cc: gdb-patches
> From: Gareth Rees <grees@undo.io>
> Date: Thu, 8 Sep 2022 14:58:22 +0100
> Cc: gdb-patches@sourceware.org
>
> > Isn't it easier to say "only if the value is a scalar"?
>
> I deliberately echoed the wording used in the documentation for
> '-stack-list-arguments' and similar commands, which uses the formula
> "if it is 2 or --simple-values, print the name, type and value for
> simple data types, and the name and type for arrays, structures and
> unions."
>
> But you are right that this concept corresponds to the 'scalars'
> arguments to 'set print frame-arguments'. But then should I update the
> documentation for '-stack-list-arguments' to match?
It would be nice, yes. But you don't have to, it could be left for a
separate changeset.
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-08 13:30 ` Eli Zaretskii
2022-09-08 13:58 ` Gareth Rees
@ 2022-09-09 8:01 ` Gareth Rees
2022-09-15 9:06 ` [PING] " Gareth Rees
` (2 more replies)
2022-09-09 8:04 ` [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
2 siblings, 3 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-09 8:01 UTC (permalink / raw)
To: gdb-patches
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 that can be fixed.
1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
for the PRINT-VALUES argument to '-stack-list-arguments' and similar
commands. This option prints the value only for scalars and so matches
the behaviour of the 'scalars' argument to the 'set print
frame-arguments' command. References to structures are not scalars,
and so the option is suitable for use by IDEs.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
---
gdb/NEWS | 9 +++
gdb/doc/gdb.texinfo | 59 ++++++++++++--------
gdb/extension.h | 3 +
gdb/mi/mi-cmd-stack.c | 35 ++++++++----
gdb/mi/mi-cmd-var.c | 26 ++++++---
gdb/mi/mi-cmds.h | 8 ++-
gdb/mi/mi-main.c | 54 ++++++++++--------
gdb/mi/mi-parse.c | 8 ++-
gdb/python/py-framefilter.c | 23 ++++----
gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
12 files changed, 272 insertions(+), 79 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index dee0ac2ecd8..57061f19719 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -114,6 +114,15 @@ maintenance info line-table
entry corresponds to an address where a breakpoint should be placed
to be at the first instruction past a function's prologue.
+* MI changes
+
+ ** The '-stack-list-arguments', '-stack-list-locals',
+ '-stack-list-variables', and '-var-list-children' commands
+ support the '--scalar-values' option, which requests the command
+ to print values only for scalar types. Support for this feature
+ can be verified by using the '-list-features' command, which
+ should contain "scalar-values".
+
* New targets
GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 238a49b027d..b2b53de1022 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
@var{high-frame} may be larger than the actual number of frames, in
which case only existing frames will be returned.
-If @var{print-values} is 0 or @code{--no-values}, print only the names of
-the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. If the option @code{--no-frame-filters} is
-supplied, then Python frame filters will not be executed.
+If @var{print-values} is 0 or @code{--no-values}, print only the names
+of the variables; if it is 1 or @code{--all-values}, print also their
+values; if it is 2 or @code{--simple-values}, print the name, type and
+value for simple data types, and the name and type for arrays,
+structures and unions; and if it is 3 or @code{--scalar-values}, print
+the name, type and value for scalar data types, and the name and type
+otherwise. If the option @code{--no-frame-filters} is supplied, then
+Python frame filters will not be executed.
If the @code{--skip-unavailable} option is specified, arguments that
are not available are not listed. Partially available arguments
@@ -33549,13 +33551,15 @@ Show a single frame:
Display the local variable names for the selected frame. If
@var{print-values} is 0 or @code{--no-values}, print only the names of
the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. In this last case, a frontend can immediately
-display the value of simple data types and create variable objects for
-other data types when the user wishes to explore their values in
-more detail. If the option @code{--no-frame-filters} is supplied, then
-Python frame filters will not be executed.
+values; if it is 2 or @code{--simple-values}, print the name, type and
+value for simple data types, and the name and type for arrays,
+structures and unions; and if it is 3 or @code{--scalar-values}, print
+the name, type and value for scalar data types, and the name and type
+otherwise. In the last two cases, a frontend can immediately display
+the value of simple or scalar data types and create variable objects
+for other data types when the user wishes to explore their values in
+more detail. If the option @code{--no-frame-filters} is supplied,
+then Python frame filters will not be executed.
If the @code{--skip-unavailable} option is specified, local variables
that are not available are not listed. Partially available local
@@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
-stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
@end smallexample
-Display the names of local variables and function arguments for the selected frame. If
-@var{print-values} is 0 or @code{--no-values}, print only the names of
-the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. If the option @code{--no-frame-filters} is
-supplied, then Python frame filters will not be executed.
+Display the names of local variables and function arguments for the
+selected frame. If @var{print-values} is 0 or @code{--no-values},
+print only the names of the variables; if it is 1 or
+@code{--all-values}, print also their values; if it is 2 or
+@code{--simple-values}, print the name, type and value for simple data
+types, and the name and type for arrays, structures and unions; and if
+it is 3 or @code{--scalar-values}, print the name, type and value for
+scalar data types, and the name and type otherwise. If the option
+@code{--no-frame-filters} is supplied, then Python frame filters will
+not be executed.
If the @code{--skip-unavailable} option is specified, local variables
and arguments that are not available are not listed. Partially
@@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
a single argument or if @var{print-values} has a value of 0 or
@code{--no-values}, print only the names of the variables; if
@var{print-values} is 1 or @code{--all-values}, also print their
-values; and if it is 2 or @code{--simple-values} print the name and
-value for simple data types and just the name for arrays, structures
-and unions.
+values; if it is 2 or @code{--simple-values} print the name and value
+for simple data types and just the name for arrays, structures and
+unions; and if it is 3 or @code{--scalar-values}, print the name and
+value for scalar data types, and just the name otherwise.
@var{from} and @var{to}, if specified, indicate the range of children
to report. If @var{from} or @var{to} is less than zero, the range is
@@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
@item data-disassemble-a-option
Indicates that the @code{-data-disassemble} command supports the @option{-a}
option (@pxref{GDB/MI Data Manipulation}).
+@item scalar-values
+Indicates that the @code{-stack-list-arguments},
+@code{-stack-list-locals}, @code{-stack-list-variables}, and
+@code{-var-list-children} commands support the
+@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
@end ftable
@subheading The @code{-list-target-features} Command
diff --git a/gdb/extension.h b/gdb/extension.h
index 47839ea50be..16d12f00f41 100644
--- a/gdb/extension.h
+++ b/gdb/extension.h
@@ -121,6 +121,9 @@ enum ext_lang_frame_args
arguments when invoked from the MI. */
MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
+ /* Print only scalar values for arguments when invoked from the MI. */
+ MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
+
/* Print only scalar values for arguments when invoked from the CLI. */
CLI_SCALAR_VALUES,
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 0fe204dbc66..d3ae350f166 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
&& arg->error == NULL)
|| values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES
|| (values == PRINT_ALL_VALUES
&& (arg->val != NULL || arg->error != NULL)));
gdb_assert (arg->entry_kind == print_entry_values_no
@@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
if (what == all && arg->sym->is_argument ())
uiout->field_signed ("arg", 1);
- if (values == PRINT_SIMPLE_VALUES)
+ if (values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES)
{
check_typedef (arg->sym->type ());
type_print (arg->sym->type (), "", &stb, -1);
@@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
}
}
+/* Print SYM according to VALUES? */
+
+static bool
+print_symbol_p (struct symbol *sym, enum print_values values)
+{
+ switch (values)
+ {
+ default:
+ case PRINT_NO_VALUES:
+ return false;
+ case PRINT_ALL_VALUES:
+ return true;
+ case PRINT_SIMPLE_VALUES:
+ return mi_simple_values_type_p (sym->type ());
+ case PRINT_SCALAR_VALUES:
+ return val_print_scalar_type_p (sym->type ());
+ }
+}
+
/* Print a list of the objects for the frame FI in a certain form,
which is determined by VALUES. The objects can be locals,
arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
@@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
const struct block *block;
struct symbol *sym;
struct block_iterator iter;
- struct type *type;
const char *name_of_result;
struct ui_out *uiout = current_uiout;
@@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
entryarg.sym = sym2;
entryarg.entry_kind = print_entry_values_no;
- switch (values)
+ if (print_symbol_p (sym, values))
{
- case PRINT_SIMPLE_VALUES:
- type = check_typedef (sym2->type ());
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
- {
- case PRINT_ALL_VALUES:
if (sym->is_argument ())
read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
else
read_frame_local (sym2, fi, &arg);
- }
- break;
}
if (arg.entry_kind != print_entry_values_only)
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 3db09cf7815..064d13a3729 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -32,6 +32,7 @@
#include "mi-parse.h"
#include "gdbsupport/gdb_optional.h"
#include "inferior.h"
+#include "valprint.h"
static void varobj_update_one (struct varobj *var,
enum print_values print_values,
@@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
type = varobj_get_gdb_type (var);
if (type == NULL)
return 1;
+ else if (print_values == PRINT_SCALAR_VALUES)
+ return val_print_scalar_type_p (type);
else
- {
- type = check_typedef (type);
+ return mi_simple_values_type_p (type);
+}
+
+/* See mi-cmds.h. */
- /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
- and that type is not a compound type. */
- return (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION);
+bool
+mi_simple_values_type_p (struct type *type)
+{
+ type = check_typedef (type);
+ switch (type->code ())
+ {
+ case TYPE_CODE_ARRAY:
+ case TYPE_CODE_STRUCT:
+ case TYPE_CODE_UNION:
+ return false;
+ default:
+ return true;
}
}
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 9ffb11bf997..56c3ccb8b8a 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -29,7 +29,8 @@
enum print_values {
PRINT_NO_VALUES,
PRINT_ALL_VALUES,
- PRINT_SIMPLE_VALUES
+ PRINT_SIMPLE_VALUES,
+ PRINT_SCALAR_VALUES
};
typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
@@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
= gdb::function_view<bool (mi_command *)>;
extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
+/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
+ is, if type is not an array, structure or union. */
+
+extern bool mi_simple_values_type_p (struct type *type);
+
#endif /* MI_MI_CMDS_H */
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b758f398e2a..2e70bcde2da 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
uiout->field_string (NULL, "undefined-command-error-code");
uiout->field_string (NULL, "exec-run-start-option");
uiout->field_string (NULL, "data-disassemble-a-option");
+ uiout->field_string (NULL, "scalar-values");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
@@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char **argv, int argc)
print_ada_task_info (current_uiout, argv[0], current_inferior ());
}
+/* Print VAL according to VALUES? */
+
+static bool
+print_value_p (struct value *val, enum print_values values)
+{
+ switch (values)
+ {
+ default:
+ case PRINT_NO_VALUES:
+ return false;
+ case PRINT_ALL_VALUES:
+ return true;
+ case PRINT_SIMPLE_VALUES:
+ return mi_simple_values_type_p (value_type (val));
+ case PRINT_SCALAR_VALUES:
+ return val_print_scalar_type_p (value_type (val));
+ }
+}
+
/* Print EXPRESSION according to VALUES. */
static void
print_variable_or_computed (const char *expression, enum print_values values)
{
struct value *val;
- struct type *type;
struct ui_out *uiout = current_uiout;
string_file stb;
expression_up expr = parse_expression (expression);
- if (values == PRINT_SIMPLE_VALUES)
+ if (values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES)
val = evaluate_type (expr.get ());
else
val = evaluate_expression (expr.get ());
@@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (value_type (val));
+ case PRINT_SCALAR_VALUES:
type_print (value_type (val), "", &stb, -1);
uiout->field_stream ("type", stb);
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
- {
- struct value_print_options opts;
-
- get_no_prettyformat_print_options (&opts);
- opts.deref_ref = 1;
- common_val_print (val, &stb, 0, &opts, current_language);
- uiout->field_stream ("value", stb);
- }
break;
- case PRINT_ALL_VALUES:
- {
- struct value_print_options opts;
+ }
- get_no_prettyformat_print_options (&opts);
- opts.deref_ref = 1;
- common_val_print (val, &stb, 0, &opts, current_language);
- uiout->field_stream ("value", stb);
- }
- break;
+ if (print_value_p (val, values))
+ {
+ struct value_print_options opts;
+ get_no_prettyformat_print_options (&opts);
+ opts.deref_ref = 1;
+ common_val_print (val, &stb, 0, &opts, current_language);
+ uiout->field_stream ("value", stb);
}
}
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index dfa7b462714..dd70e4648a1 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -29,6 +29,7 @@
#include "language.h"
static const char mi_no_values[] = "--no-values";
+static const char mi_scalar_values[] = "--scalar-values";
static const char mi_simple_values[] = "--simple-values";
static const char mi_all_values[] = "--all-values";
@@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
else if (strcmp (name, "2") == 0
|| strcmp (name, mi_simple_values) == 0)
return PRINT_SIMPLE_VALUES;
+ else if (strcmp (name, "3") == 0
+ || strcmp (name, mi_scalar_values) == 0)
+ return PRINT_SCALAR_VALUES;
else
error (_("Unknown value for PRINT_VALUES: must be: \
-0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
- mi_no_values, mi_all_values, mi_simple_values);
+0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
+ mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
}
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 366f3745b9d..a746f309187 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *val,
/* MI does not print certain values, differentiated by type,
depending on what ARGS_TYPE indicates. Test type against option.
For CLI print all values. */
- if (args_type == MI_PRINT_SIMPLE_VALUES
+ if (args_type == MI_PRINT_SCALAR_VALUES
+ || args_type == MI_PRINT_SIMPLE_VALUES
|| args_type == MI_PRINT_ALL_VALUES)
{
- struct type *type = check_typedef (value_type (val));
-
if (args_type == MI_PRINT_ALL_VALUES)
should_print = 1;
+ else if (args_type == MI_PRINT_SCALAR_VALUES
+ && val_print_scalar_type_p (value_type (val)))
+ 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_values_type_p (value_type (val)))
should_print = 1;
}
else if (args_type != NO_VALUES)
@@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
if (print_args_field)
out->field_signed ("arg", 1);
- /* For MI print the type, but only for simple values. This seems
- weird, but this is how MI choose to format the various output
+ /* For MI print the type, but only for scalar and simple values. This
+ seems weird, but this is how MI chooses to format the various output
types. */
- if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
+ if ((args_type == MI_PRINT_SCALAR_VALUES
+ || args_type == MI_PRINT_SIMPLE_VALUES)
+ && val != NULL)
py_print_type (out, val);
if (val != NULL)
@@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
out->field_string ("name", sym_name.get ());
out->text (" = ");
- if (args_type == MI_PRINT_SIMPLE_VALUES)
+ if (args_type == MI_PRINT_SCALAR_VALUES
+ || args_type == MI_PRINT_SIMPLE_VALUES)
py_print_type (out, val);
/* CLI always prints values for locals. MI uses the
diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
index d04c8153c65..8aa4e2234ff 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.exp
+++ b/gdb/testsuite/gdb.mi/mi-stack.exp
@@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
# -stack-list-arguments 1 1 1
# -stack-list-arguments 1 1 3
# -stack-list-arguments
+ # -stack-list-arguments 1 1 300
+ # -stack-list-arguments 2 1 1
+ # -stack-list-arguments 3 1 1
mi_gdb_test "231-stack-list-arguments 0" \
"231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
@@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
mi_gdb_test "235-stack-list-arguments 1 1 300" \
"235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
"stack args listing 1 1 300"
+
+ mi_gdb_test "236-stack-list-arguments 2 1 1" \
+ "236\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
+ "stack args listing --simple-values 1 1"
+
+ mi_gdb_test "237-stack-list-arguments 3 1 1" \
+ "237\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
+ "stack args listing --scalar-values 1 1"
}
proc test_stack_info_depth {} {
@@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
# -stack-list-locals 0 (--no-values)
# -stack-list-locals 1 (--all-values)
# -stack-list-locals 2 (--simple-values)
- # -stack-list-arguments
+ # -stack-list-locals 3 (--scalar-values)
mi_gdb_test "232-stack-list-locals 0" \
"232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
@@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
"232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
"stack locals listing, simple types: names and values, complex type: names and types"
+ mi_gdb_test "233-stack-list-locals --scalar-values" \
+ "233\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
+ "stack locals listing, scalar types: names and values, otherwise: names and types"
+
mi_gdb_test "234-stack-list-locals" \
"234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
"stack locals listing wrong"
diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/gdb.mi/print-scalar-values.cc
new file mode 100644
index 00000000000..fd9daf1d962
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
@@ -0,0 +1,58 @@
+/* This test case is part of GDB, the GNU debugger.
+
+ Copyright 2022 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* PRINT_SCALAR_VALUES test program.
+
+ Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
+ types, including C++ reference and rvalue reference types.
+
+ In the function f(), arguments i, ir, and irr are ints or references
+ to ints, and their values should be printed by PRINT_SCALAR_VALUES;
+ but the other arguments are non-scalar, and so their values should
+ not be printed by PRINT_SCALAR_VALUES. */
+
+struct s
+{
+ int v;
+};
+
+union u
+{
+ int v;
+};
+
+int
+f (int i, int &ir, int &&irr,
+ int a[1], int (&ar)[1], int (&&arr)[1],
+ struct s s, struct s &sr, struct s &&srr,
+ union u u, union u &ur, union u &&urr)
+{
+ return (i + ir + irr
+ + a[0] + ar[0] + arr[0]
+ + s.v + sr.v + srr.v
+ + u.v + ur.v + urr.v);
+}
+
+int
+main (void)
+{
+ int i = 1, j = 2;
+ int a[1] = { 4 }, b[1] = { 5 };
+ struct s s = { 7 }, t = { 8 };
+ union u u = { 10 }, v = { 11 };
+ return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
+}
diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite/gdb.mi/print-scalar-values.exp
new file mode 100644
index 00000000000..3398218c063
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
@@ -0,0 +1,51 @@
+# Copyright 2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# PRINT_SCALAR_VALUES test.
+#
+# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
+# types, including C++ reference and rvalue reference types.
+#
+# In the function f(), arguments i, ir, and irr are ints or references
+# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
+# but the other arguments are non-scalar, and so their values should not
+# be printed by PRINT_SCALAR_VALUES.
+
+if { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+standard_testfile .cc
+
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
+ untested "failed to compile"
+ return -1
+}
+
+mi_clean_restart $binfile
+
+mi_runto_main
+
+mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
+
+mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
+
+mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
+ "run until breakpoint on f"
+
+mi_gdb_test "-stack-list-arguments --scalar-values" \
+ "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"i\",type=\"int\",value=\"1\"\},\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\},\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\},\{name=\"a\",type=\"int \\*\",value=\"$hex\"\},\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\},\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\},\{name=\"s\",type=\"s\"\},\{name=\"sr\",type=\"s &\"\},\{name=\"srr\",type=\"s &&\"\},\{name=\"u\",type=\"u\"\},\{name=\"ur\",type=\"u &\"\},\{name=\"urr\",type=\"u &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
+ "stack list arguments, scalar types: names, types and values, compound types: names and types"
+
+mi_gdb_exit
--
2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v2] [gdb/mi] Don't treat references to compound values as "simple".
2022-09-08 13:30 ` Eli Zaretskii
2022-09-08 13:58 ` Gareth Rees
2022-09-09 8:01 ` [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
@ 2022-09-09 8:04 ` Gareth Rees
2 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-09 8:04 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Eli Zaretskii <eliz@gnu.org> wrote:
> > 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, '--simplest-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 '--simplest-values' argument is
> > available for use when refreshing the call stack.
>
> Thanks. FWIW, I think we should implement 2, not 1.
I have prepared a new patch that implements solution (2), adding a
'--scalar-values' option for the PRINT-VALUES argument to
'-stack-list-arguments' and similar commands. This option prints the
value only for scalars and so matches the behaviour of the 'scalars'
argument to the 'set print frame-arguments' command. References to
structures are not scalars, and so the option is suitable for use by
IDEs.
See my e-mail with subject: "[PATCH v3] [PR mi/29554] New PRINT-VALUES
option '--scalar-values'."
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-09 8:01 ` [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
@ 2022-09-15 9:06 ` Gareth Rees
2022-09-25 8:15 ` Gareth Rees
2022-09-26 12:46 ` [PATCH v4] " Gareth Rees
2 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-15 9:06 UTC (permalink / raw)
To: gdb-patches
Reminder to review. This patch adds a new '--scalar-values' option to
'-stack-list-arguments' and similar MI commands, making these commands
suitable for use by IDEs that need to refresh their stack trace
display each time the program stops.
(Note that in v1 and v2 of the patch I implemented a different
solution, modifying the behaviour of the existing '--simple-values'
option instead of adding a new option, but Eli Zaretskii requested
that I implement the solution given in v3.)
On Fri, 9 Sept 2022 at 09:01, Gareth Rees <grees@undo.io> wrote:
>
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++++--------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 35 ++++++++----
> gdb/mi/mi-cmd-var.c | 26 ++++++---
> gdb/mi/mi-cmds.h | 8 ++-
> gdb/mi/mi-main.c | 54 ++++++++++--------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 23 ++++----
> gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
> gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
> 12 files changed, 272 insertions(+), 79 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..57061f19719 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + should contain "scalar-values".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the selected frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. */
> + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI. */
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..d3ae350f166 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> && arg->error == NULL)
> || values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES
> || (values == PRINT_ALL_VALUES
> && (arg->val != NULL || arg->error != NULL)));
> gdb_assert (arg->entry_kind == print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> if (what == all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> }
> }
>
> +/* Print SYM according to VALUES? */
> +
> +static bool
> +print_symbol_p (struct symbol *sym, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (sym->type ());
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (sym->type ());
> + }
> +}
> +
> /* Print a list of the objects for the frame FI in a certain form,
> which is determined by VALUES. The objects can be locals,
> arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
> @@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> entryarg.sym = sym2;
> entryarg.entry_kind = print_entry_values_no;
>
> - switch (values)
> + if (print_symbol_p (sym, values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind != print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..064d13a3729 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> type = varobj_get_gdb_type (var);
> if (type == NULL)
> return 1;
> + else if (print_values == PRINT_SCALAR_VALUES)
> + return val_print_scalar_type_p (type);
> else
> - {
> - type = check_typedef (type);
> + return mi_simple_values_type_p (type);
> +}
> +
> +/* See mi-cmds.h. */
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> +bool
> +mi_simple_values_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> }
> }
>
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..56c3ccb8b8a 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> @@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
> + is, if type is not an array, structure or union. */
> +
> +extern bool mi_simple_values_type_p (struct type *type);
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..2e70bcde2da 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char **argv, int argc)
> print_ada_task_info (current_uiout, argv[0], current_inferior ());
> }
>
> +/* Print VAL according to VALUES? */
> +
> +static bool
> +print_value_p (struct value *val, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (value_type (val));
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (value_type (val));
> + }
> +}
> +
> /* Print EXPRESSION according to VALUES. */
>
> static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
>
> expression_up expr = parse_expression (expression);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> val = evaluate_type (expr.get ());
> else
> val = evaluate_expression (expr.get ());
> @@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (print_value_p (val, values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref = 1;
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] = "--no-values";
> +static const char mi_scalar_values[] = "--scalar-values";
> static const char mi_simple_values[] = "--simple-values";
> static const char mi_all_values[] = "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") == 0
> || strcmp (name, mi_simple_values) == 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") == 0
> + || strcmp (name, mi_scalar_values) == 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..a746f309187 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *val,
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES
> || args_type == MI_PRINT_ALL_VALUES)
> {
> - struct type *type = check_typedef (value_type (val));
> -
> if (args_type == MI_PRINT_ALL_VALUES)
> should_print = 1;
> + else if (args_type == MI_PRINT_SCALAR_VALUES
> + && val_print_scalar_type_p (value_type (val)))
> + 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_values_type_p (value_type (val)))
> should_print = 1;
> }
> else if (args_type != NO_VALUES)
> @@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for scalar and simple values. This
> + seems weird, but this is how MI chooses to format the various output
> types. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> + if ((args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> + && val != NULL)
> py_print_type (out, val);
>
> if (val != NULL)
> @@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" = ");
>
> - if (args_type == MI_PRINT_SIMPLE_VALUES)
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index d04c8153c65..8aa4e2234ff 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments 3 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments 3 1 1" \
> + "237\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --scalar-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
>
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise: names and types"
> +
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> new file mode 100644
> index 00000000000..fd9daf1d962
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> @@ -0,0 +1,58 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* PRINT_SCALAR_VALUES test program.
> +
> + Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> + types, including C++ reference and rvalue reference types.
> +
> + In the function f(), arguments i, ir, and irr are ints or references
> + to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> + but the other arguments are non-scalar, and so their values should
> + not be printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> new file mode 100644
> index 00000000000..3398218c063
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# PRINT_SCALAR_VALUES test.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +#
> +# In the function f(), arguments i, ir, and irr are ints or references
> +# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> +# but the other arguments are non-scalar, and so their values should not
> +# be printed by PRINT_SCALAR_VALUES.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"i\",type=\"int\",value=\"1\"\},\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\},\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\},\{name=\"a\",type=\"int \\*\",value=\"$hex\"\},\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\},\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\},\{name=\"s\",type=\"s\"\},\{name=\"sr\",type=\"s &\"\},\{name=\"srr\",type=\"s &&\"\},\{name=\"u\",type=\"u\"\},\{name=\"ur\",type=\"u &\"\},\{name=\"urr\",type=\"u &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> +
> +mi_gdb_exit
> --
> 2.26.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-09 8:01 ` [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
2022-09-15 9:06 ` [PING] " Gareth Rees
@ 2022-09-25 8:15 ` Gareth Rees
2022-09-25 8:25 ` Eli Zaretskii
2022-09-25 10:16 ` Eli Zaretskii
2022-09-26 12:46 ` [PATCH v4] " Gareth Rees
2 siblings, 2 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-25 8:15 UTC (permalink / raw)
To: gdb-patches
Reminder to review.
On Fri, 9 Sept 2022 at 09:01, Gareth Rees <grees@undo.io> wrote:
>
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++++--------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 35 ++++++++----
> gdb/mi/mi-cmd-var.c | 26 ++++++---
> gdb/mi/mi-cmds.h | 8 ++-
> gdb/mi/mi-main.c | 54 ++++++++++--------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 23 ++++----
> gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
> gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
> 12 files changed, 272 insertions(+), 79 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..57061f19719 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + should contain "scalar-values".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the selected frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. */
> + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI. */
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..d3ae350f166 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> && arg->error == NULL)
> || values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES
> || (values == PRINT_ALL_VALUES
> && (arg->val != NULL || arg->error != NULL)));
> gdb_assert (arg->entry_kind == print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> if (what == all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> }
> }
>
> +/* Print SYM according to VALUES? */
> +
> +static bool
> +print_symbol_p (struct symbol *sym, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (sym->type ());
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (sym->type ());
> + }
> +}
> +
> /* Print a list of the objects for the frame FI in a certain form,
> which is determined by VALUES. The objects can be locals,
> arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
> @@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> entryarg.sym = sym2;
> entryarg.entry_kind = print_entry_values_no;
>
> - switch (values)
> + if (print_symbol_p (sym, values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind != print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..064d13a3729 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> type = varobj_get_gdb_type (var);
> if (type == NULL)
> return 1;
> + else if (print_values == PRINT_SCALAR_VALUES)
> + return val_print_scalar_type_p (type);
> else
> - {
> - type = check_typedef (type);
> + return mi_simple_values_type_p (type);
> +}
> +
> +/* See mi-cmds.h. */
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> +bool
> +mi_simple_values_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> }
> }
>
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..56c3ccb8b8a 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> @@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
> + is, if type is not an array, structure or union. */
> +
> +extern bool mi_simple_values_type_p (struct type *type);
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..2e70bcde2da 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char **argv, int argc)
> print_ada_task_info (current_uiout, argv[0], current_inferior ());
> }
>
> +/* Print VAL according to VALUES? */
> +
> +static bool
> +print_value_p (struct value *val, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (value_type (val));
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (value_type (val));
> + }
> +}
> +
> /* Print EXPRESSION according to VALUES. */
>
> static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
>
> expression_up expr = parse_expression (expression);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> val = evaluate_type (expr.get ());
> else
> val = evaluate_expression (expr.get ());
> @@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (print_value_p (val, values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref = 1;
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] = "--no-values";
> +static const char mi_scalar_values[] = "--scalar-values";
> static const char mi_simple_values[] = "--simple-values";
> static const char mi_all_values[] = "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") == 0
> || strcmp (name, mi_simple_values) == 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") == 0
> + || strcmp (name, mi_scalar_values) == 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..a746f309187 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *val,
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES
> || args_type == MI_PRINT_ALL_VALUES)
> {
> - struct type *type = check_typedef (value_type (val));
> -
> if (args_type == MI_PRINT_ALL_VALUES)
> should_print = 1;
> + else if (args_type == MI_PRINT_SCALAR_VALUES
> + && val_print_scalar_type_p (value_type (val)))
> + 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_values_type_p (value_type (val)))
> should_print = 1;
> }
> else if (args_type != NO_VALUES)
> @@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for scalar and simple values. This
> + seems weird, but this is how MI chooses to format the various output
> types. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> + if ((args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> + && val != NULL)
> py_print_type (out, val);
>
> if (val != NULL)
> @@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" = ");
>
> - if (args_type == MI_PRINT_SIMPLE_VALUES)
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index d04c8153c65..8aa4e2234ff 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments 3 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments 3 1 1" \
> + "237\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --scalar-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
>
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise: names and types"
> +
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> new file mode 100644
> index 00000000000..fd9daf1d962
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> @@ -0,0 +1,58 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* PRINT_SCALAR_VALUES test program.
> +
> + Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> + types, including C++ reference and rvalue reference types.
> +
> + In the function f(), arguments i, ir, and irr are ints or references
> + to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> + but the other arguments are non-scalar, and so their values should
> + not be printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> new file mode 100644
> index 00000000000..3398218c063
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# PRINT_SCALAR_VALUES test.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +#
> +# In the function f(), arguments i, ir, and irr are ints or references
> +# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> +# but the other arguments are non-scalar, and so their values should not
> +# be printed by PRINT_SCALAR_VALUES.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"i\",type=\"int\",value=\"1\"\},\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\},\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\},\{name=\"a\",type=\"int \\*\",value=\"$hex\"\},\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\},\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\},\{name=\"s\",type=\"s\"\},\{name=\"sr\",type=\"s &\"\},\{name=\"srr\",type=\"s &&\"\},\{name=\"u\",type=\"u\"\},\{name=\"ur\",type=\"u &\"\},\{name=\"urr\",type=\"u &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> +
> +mi_gdb_exit
> --
> 2.26.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-25 8:15 ` Gareth Rees
@ 2022-09-25 8:25 ` Eli Zaretskii
2022-09-25 9:00 ` Gareth Rees
2022-09-25 10:16 ` Eli Zaretskii
1 sibling, 1 reply; 49+ messages in thread
From: Eli Zaretskii @ 2022-09-25 8:25 UTC (permalink / raw)
To: Gareth Rees; +Cc: gdb-patches
> Date: Sun, 25 Sep 2022 09:15:49 +0100
> From: Gareth Rees via Gdb-patches <gdb-patches@sourceware.org>
>
> Reminder to review.
I already reviewed the documentation parts, didn't I?
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-25 8:25 ` Eli Zaretskii
@ 2022-09-25 9:00 ` Gareth Rees
2022-09-25 10:16 ` Eli Zaretskii
0 siblings, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2022-09-25 9:00 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Eli Zaretskii <eliz@gnu.org> wrote:
> I already reviewed the documentation parts, didn't I?
You reviewed version 2 of the patch on 2022-09-08 (thanks!) requesting
that I add a new PRINT-VALUES option instead of modifying the
behaviour of the '--simple-values' option.
Accordingly, I made version 3 of the patch, which leaves the
'--simple-values' option unchanged and adds a new '--scalar-values'
option. This version of the patch still needs review.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-25 8:15 ` Gareth Rees
2022-09-25 8:25 ` Eli Zaretskii
@ 2022-09-25 10:16 ` Eli Zaretskii
1 sibling, 0 replies; 49+ messages in thread
From: Eli Zaretskii @ 2022-09-25 10:16 UTC (permalink / raw)
To: Gareth Rees; +Cc: gdb-patches
> Date: Sun, 25 Sep 2022 09:15:49 +0100
> From: Gareth Rees via Gdb-patches <gdb-patches@sourceware.org>
>
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
^^
Two spaces between sentences.
Otherwise, the documentation parts are OK, thanks.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-25 9:00 ` Gareth Rees
@ 2022-09-25 10:16 ` Eli Zaretskii
2022-09-26 12:48 ` Gareth Rees
0 siblings, 1 reply; 49+ messages in thread
From: Eli Zaretskii @ 2022-09-25 10:16 UTC (permalink / raw)
To: Gareth Rees; +Cc: gdb-patches
> From: Gareth Rees <grees@undo.io>
> Date: Sun, 25 Sep 2022 10:00:35 +0100
> Cc: gdb-patches@sourceware.org
>
> Eli Zaretskii <eliz@gnu.org> wrote:
> > I already reviewed the documentation parts, didn't I?
>
> You reviewed version 2 of the patch on 2022-09-08 (thanks!) requesting
> that I add a new PRINT-VALUES option instead of modifying the
> behaviour of the '--simple-values' option.
>
> Accordingly, I made version 3 of the patch, which leaves the
> '--simple-values' option unchanged and adds a new '--scalar-values'
> option. This version of the patch still needs review.
Sorry for missing the original post. I've reviewed it now.
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-09 8:01 ` [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
2022-09-15 9:06 ` [PING] " Gareth Rees
2022-09-25 8:15 ` Gareth Rees
@ 2022-09-26 12:46 ` Gareth Rees
2022-10-04 9:08 ` [PING] " Gareth Rees
2022-10-12 16:38 ` Andrew Burgess
2 siblings, 2 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-26 12:46 UTC (permalink / raw)
To: gdb-patches
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 that can be fixed.
1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
for the PRINT-VALUES argument to '-stack-list-arguments' and similar
commands. This option prints the value only for scalars and so matches
the behaviour of the 'scalars' argument to the 'set print
frame-arguments' command. References to structures are not scalars,
and so the option is suitable for use by IDEs.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
---
gdb/NEWS | 9 +++
gdb/doc/gdb.texinfo | 59 ++++++++++++--------
gdb/extension.h | 3 +
gdb/mi/mi-cmd-stack.c | 35 ++++++++----
gdb/mi/mi-cmd-var.c | 26 ++++++---
gdb/mi/mi-cmds.h | 8 ++-
gdb/mi/mi-main.c | 54 ++++++++++--------
gdb/mi/mi-parse.c | 8 ++-
gdb/python/py-framefilter.c | 23 ++++----
gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
12 files changed, 272 insertions(+), 79 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index dee0ac2ecd8..62b15094dee 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -114,6 +114,15 @@ maintenance info line-table
entry corresponds to an address where a breakpoint should be placed
to be at the first instruction past a function's prologue.
+* MI changes
+
+ ** The '-stack-list-arguments', '-stack-list-locals',
+ '-stack-list-variables', and '-var-list-children' commands
+ support the '--scalar-values' option, which requests the command
+ to print values only for scalar types. Support for this feature
+ can be verified by using the '-list-features' command, which
+ should contain "scalar-values".
+
* New targets
GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 238a49b027d..b2b53de1022 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
@var{high-frame} may be larger than the actual number of frames, in
which case only existing frames will be returned.
-If @var{print-values} is 0 or @code{--no-values}, print only the names of
-the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. If the option @code{--no-frame-filters} is
-supplied, then Python frame filters will not be executed.
+If @var{print-values} is 0 or @code{--no-values}, print only the names
+of the variables; if it is 1 or @code{--all-values}, print also their
+values; if it is 2 or @code{--simple-values}, print the name, type and
+value for simple data types, and the name and type for arrays,
+structures and unions; and if it is 3 or @code{--scalar-values}, print
+the name, type and value for scalar data types, and the name and type
+otherwise. If the option @code{--no-frame-filters} is supplied, then
+Python frame filters will not be executed.
If the @code{--skip-unavailable} option is specified, arguments that
are not available are not listed. Partially available arguments
@@ -33549,13 +33551,15 @@ Show a single frame:
Display the local variable names for the selected frame. If
@var{print-values} is 0 or @code{--no-values}, print only the names of
the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. In this last case, a frontend can immediately
-display the value of simple data types and create variable objects for
-other data types when the user wishes to explore their values in
-more detail. If the option @code{--no-frame-filters} is supplied, then
-Python frame filters will not be executed.
+values; if it is 2 or @code{--simple-values}, print the name, type and
+value for simple data types, and the name and type for arrays,
+structures and unions; and if it is 3 or @code{--scalar-values}, print
+the name, type and value for scalar data types, and the name and type
+otherwise. In the last two cases, a frontend can immediately display
+the value of simple or scalar data types and create variable objects
+for other data types when the user wishes to explore their values in
+more detail. If the option @code{--no-frame-filters} is supplied,
+then Python frame filters will not be executed.
If the @code{--skip-unavailable} option is specified, local variables
that are not available are not listed. Partially available local
@@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
-stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
@end smallexample
-Display the names of local variables and function arguments for the selected frame. If
-@var{print-values} is 0 or @code{--no-values}, print only the names of
-the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. If the option @code{--no-frame-filters} is
-supplied, then Python frame filters will not be executed.
+Display the names of local variables and function arguments for the
+selected frame. If @var{print-values} is 0 or @code{--no-values},
+print only the names of the variables; if it is 1 or
+@code{--all-values}, print also their values; if it is 2 or
+@code{--simple-values}, print the name, type and value for simple data
+types, and the name and type for arrays, structures and unions; and if
+it is 3 or @code{--scalar-values}, print the name, type and value for
+scalar data types, and the name and type otherwise. If the option
+@code{--no-frame-filters} is supplied, then Python frame filters will
+not be executed.
If the @code{--skip-unavailable} option is specified, local variables
and arguments that are not available are not listed. Partially
@@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
a single argument or if @var{print-values} has a value of 0 or
@code{--no-values}, print only the names of the variables; if
@var{print-values} is 1 or @code{--all-values}, also print their
-values; and if it is 2 or @code{--simple-values} print the name and
-value for simple data types and just the name for arrays, structures
-and unions.
+values; if it is 2 or @code{--simple-values} print the name and value
+for simple data types and just the name for arrays, structures and
+unions; and if it is 3 or @code{--scalar-values}, print the name and
+value for scalar data types, and just the name otherwise.
@var{from} and @var{to}, if specified, indicate the range of children
to report. If @var{from} or @var{to} is less than zero, the range is
@@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
@item data-disassemble-a-option
Indicates that the @code{-data-disassemble} command supports the @option{-a}
option (@pxref{GDB/MI Data Manipulation}).
+@item scalar-values
+Indicates that the @code{-stack-list-arguments},
+@code{-stack-list-locals}, @code{-stack-list-variables}, and
+@code{-var-list-children} commands support the
+@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
@end ftable
@subheading The @code{-list-target-features} Command
diff --git a/gdb/extension.h b/gdb/extension.h
index 47839ea50be..16d12f00f41 100644
--- a/gdb/extension.h
+++ b/gdb/extension.h
@@ -121,6 +121,9 @@ enum ext_lang_frame_args
arguments when invoked from the MI. */
MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
+ /* Print only scalar values for arguments when invoked from the MI. */
+ MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
+
/* Print only scalar values for arguments when invoked from the CLI. */
CLI_SCALAR_VALUES,
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 0fe204dbc66..d3ae350f166 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
&& arg->error == NULL)
|| values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES
|| (values == PRINT_ALL_VALUES
&& (arg->val != NULL || arg->error != NULL)));
gdb_assert (arg->entry_kind == print_entry_values_no
@@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
if (what == all && arg->sym->is_argument ())
uiout->field_signed ("arg", 1);
- if (values == PRINT_SIMPLE_VALUES)
+ if (values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES)
{
check_typedef (arg->sym->type ());
type_print (arg->sym->type (), "", &stb, -1);
@@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
}
}
+/* Print SYM according to VALUES? */
+
+static bool
+print_symbol_p (struct symbol *sym, enum print_values values)
+{
+ switch (values)
+ {
+ default:
+ case PRINT_NO_VALUES:
+ return false;
+ case PRINT_ALL_VALUES:
+ return true;
+ case PRINT_SIMPLE_VALUES:
+ return mi_simple_values_type_p (sym->type ());
+ case PRINT_SCALAR_VALUES:
+ return val_print_scalar_type_p (sym->type ());
+ }
+}
+
/* Print a list of the objects for the frame FI in a certain form,
which is determined by VALUES. The objects can be locals,
arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
@@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
const struct block *block;
struct symbol *sym;
struct block_iterator iter;
- struct type *type;
const char *name_of_result;
struct ui_out *uiout = current_uiout;
@@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
entryarg.sym = sym2;
entryarg.entry_kind = print_entry_values_no;
- switch (values)
+ if (print_symbol_p (sym, values))
{
- case PRINT_SIMPLE_VALUES:
- type = check_typedef (sym2->type ());
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
- {
- case PRINT_ALL_VALUES:
if (sym->is_argument ())
read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
else
read_frame_local (sym2, fi, &arg);
- }
- break;
}
if (arg.entry_kind != print_entry_values_only)
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 3db09cf7815..064d13a3729 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -32,6 +32,7 @@
#include "mi-parse.h"
#include "gdbsupport/gdb_optional.h"
#include "inferior.h"
+#include "valprint.h"
static void varobj_update_one (struct varobj *var,
enum print_values print_values,
@@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
type = varobj_get_gdb_type (var);
if (type == NULL)
return 1;
+ else if (print_values == PRINT_SCALAR_VALUES)
+ return val_print_scalar_type_p (type);
else
- {
- type = check_typedef (type);
+ return mi_simple_values_type_p (type);
+}
+
+/* See mi-cmds.h. */
- /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
- and that type is not a compound type. */
- return (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION);
+bool
+mi_simple_values_type_p (struct type *type)
+{
+ type = check_typedef (type);
+ switch (type->code ())
+ {
+ case TYPE_CODE_ARRAY:
+ case TYPE_CODE_STRUCT:
+ case TYPE_CODE_UNION:
+ return false;
+ default:
+ return true;
}
}
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 9ffb11bf997..56c3ccb8b8a 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -29,7 +29,8 @@
enum print_values {
PRINT_NO_VALUES,
PRINT_ALL_VALUES,
- PRINT_SIMPLE_VALUES
+ PRINT_SIMPLE_VALUES,
+ PRINT_SCALAR_VALUES
};
typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
@@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
= gdb::function_view<bool (mi_command *)>;
extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
+/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
+ is, if type is not an array, structure or union. */
+
+extern bool mi_simple_values_type_p (struct type *type);
+
#endif /* MI_MI_CMDS_H */
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b758f398e2a..2e70bcde2da 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
uiout->field_string (NULL, "undefined-command-error-code");
uiout->field_string (NULL, "exec-run-start-option");
uiout->field_string (NULL, "data-disassemble-a-option");
+ uiout->field_string (NULL, "scalar-values");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
@@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char **argv, int argc)
print_ada_task_info (current_uiout, argv[0], current_inferior ());
}
+/* Print VAL according to VALUES? */
+
+static bool
+print_value_p (struct value *val, enum print_values values)
+{
+ switch (values)
+ {
+ default:
+ case PRINT_NO_VALUES:
+ return false;
+ case PRINT_ALL_VALUES:
+ return true;
+ case PRINT_SIMPLE_VALUES:
+ return mi_simple_values_type_p (value_type (val));
+ case PRINT_SCALAR_VALUES:
+ return val_print_scalar_type_p (value_type (val));
+ }
+}
+
/* Print EXPRESSION according to VALUES. */
static void
print_variable_or_computed (const char *expression, enum print_values values)
{
struct value *val;
- struct type *type;
struct ui_out *uiout = current_uiout;
string_file stb;
expression_up expr = parse_expression (expression);
- if (values == PRINT_SIMPLE_VALUES)
+ if (values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES)
val = evaluate_type (expr.get ());
else
val = evaluate_expression (expr.get ());
@@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (value_type (val));
+ case PRINT_SCALAR_VALUES:
type_print (value_type (val), "", &stb, -1);
uiout->field_stream ("type", stb);
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
- {
- struct value_print_options opts;
-
- get_no_prettyformat_print_options (&opts);
- opts.deref_ref = 1;
- common_val_print (val, &stb, 0, &opts, current_language);
- uiout->field_stream ("value", stb);
- }
break;
- case PRINT_ALL_VALUES:
- {
- struct value_print_options opts;
+ }
- get_no_prettyformat_print_options (&opts);
- opts.deref_ref = 1;
- common_val_print (val, &stb, 0, &opts, current_language);
- uiout->field_stream ("value", stb);
- }
- break;
+ if (print_value_p (val, values))
+ {
+ struct value_print_options opts;
+ get_no_prettyformat_print_options (&opts);
+ opts.deref_ref = 1;
+ common_val_print (val, &stb, 0, &opts, current_language);
+ uiout->field_stream ("value", stb);
}
}
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index dfa7b462714..dd70e4648a1 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -29,6 +29,7 @@
#include "language.h"
static const char mi_no_values[] = "--no-values";
+static const char mi_scalar_values[] = "--scalar-values";
static const char mi_simple_values[] = "--simple-values";
static const char mi_all_values[] = "--all-values";
@@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
else if (strcmp (name, "2") == 0
|| strcmp (name, mi_simple_values) == 0)
return PRINT_SIMPLE_VALUES;
+ else if (strcmp (name, "3") == 0
+ || strcmp (name, mi_scalar_values) == 0)
+ return PRINT_SCALAR_VALUES;
else
error (_("Unknown value for PRINT_VALUES: must be: \
-0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
- mi_no_values, mi_all_values, mi_simple_values);
+0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
+ mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
}
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 366f3745b9d..a746f309187 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *val,
/* MI does not print certain values, differentiated by type,
depending on what ARGS_TYPE indicates. Test type against option.
For CLI print all values. */
- if (args_type == MI_PRINT_SIMPLE_VALUES
+ if (args_type == MI_PRINT_SCALAR_VALUES
+ || args_type == MI_PRINT_SIMPLE_VALUES
|| args_type == MI_PRINT_ALL_VALUES)
{
- struct type *type = check_typedef (value_type (val));
-
if (args_type == MI_PRINT_ALL_VALUES)
should_print = 1;
+ else if (args_type == MI_PRINT_SCALAR_VALUES
+ && val_print_scalar_type_p (value_type (val)))
+ 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_values_type_p (value_type (val)))
should_print = 1;
}
else if (args_type != NO_VALUES)
@@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
if (print_args_field)
out->field_signed ("arg", 1);
- /* For MI print the type, but only for simple values. This seems
- weird, but this is how MI choose to format the various output
+ /* For MI print the type, but only for scalar and simple values. This
+ seems weird, but this is how MI chooses to format the various output
types. */
- if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
+ if ((args_type == MI_PRINT_SCALAR_VALUES
+ || args_type == MI_PRINT_SIMPLE_VALUES)
+ && val != NULL)
py_print_type (out, val);
if (val != NULL)
@@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
out->field_string ("name", sym_name.get ());
out->text (" = ");
- if (args_type == MI_PRINT_SIMPLE_VALUES)
+ if (args_type == MI_PRINT_SCALAR_VALUES
+ || args_type == MI_PRINT_SIMPLE_VALUES)
py_print_type (out, val);
/* CLI always prints values for locals. MI uses the
diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
index d04c8153c65..8aa4e2234ff 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.exp
+++ b/gdb/testsuite/gdb.mi/mi-stack.exp
@@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
# -stack-list-arguments 1 1 1
# -stack-list-arguments 1 1 3
# -stack-list-arguments
+ # -stack-list-arguments 1 1 300
+ # -stack-list-arguments 2 1 1
+ # -stack-list-arguments 3 1 1
mi_gdb_test "231-stack-list-arguments 0" \
"231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
@@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
mi_gdb_test "235-stack-list-arguments 1 1 300" \
"235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
"stack args listing 1 1 300"
+
+ mi_gdb_test "236-stack-list-arguments 2 1 1" \
+ "236\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
+ "stack args listing --simple-values 1 1"
+
+ mi_gdb_test "237-stack-list-arguments 3 1 1" \
+ "237\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
+ "stack args listing --scalar-values 1 1"
}
proc test_stack_info_depth {} {
@@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
# -stack-list-locals 0 (--no-values)
# -stack-list-locals 1 (--all-values)
# -stack-list-locals 2 (--simple-values)
- # -stack-list-arguments
+ # -stack-list-locals 3 (--scalar-values)
mi_gdb_test "232-stack-list-locals 0" \
"232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
@@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
"232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
"stack locals listing, simple types: names and values, complex type: names and types"
+ mi_gdb_test "233-stack-list-locals --scalar-values" \
+ "233\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
+ "stack locals listing, scalar types: names and values, otherwise: names and types"
+
mi_gdb_test "234-stack-list-locals" \
"234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
"stack locals listing wrong"
diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/gdb.mi/print-scalar-values.cc
new file mode 100644
index 00000000000..fd9daf1d962
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
@@ -0,0 +1,58 @@
+/* This test case is part of GDB, the GNU debugger.
+
+ Copyright 2022 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* PRINT_SCALAR_VALUES test program.
+
+ Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
+ types, including C++ reference and rvalue reference types.
+
+ In the function f(), arguments i, ir, and irr are ints or references
+ to ints, and their values should be printed by PRINT_SCALAR_VALUES;
+ but the other arguments are non-scalar, and so their values should
+ not be printed by PRINT_SCALAR_VALUES. */
+
+struct s
+{
+ int v;
+};
+
+union u
+{
+ int v;
+};
+
+int
+f (int i, int &ir, int &&irr,
+ int a[1], int (&ar)[1], int (&&arr)[1],
+ struct s s, struct s &sr, struct s &&srr,
+ union u u, union u &ur, union u &&urr)
+{
+ return (i + ir + irr
+ + a[0] + ar[0] + arr[0]
+ + s.v + sr.v + srr.v
+ + u.v + ur.v + urr.v);
+}
+
+int
+main (void)
+{
+ int i = 1, j = 2;
+ int a[1] = { 4 }, b[1] = { 5 };
+ struct s s = { 7 }, t = { 8 };
+ union u u = { 10 }, v = { 11 };
+ return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
+}
diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite/gdb.mi/print-scalar-values.exp
new file mode 100644
index 00000000000..3398218c063
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
@@ -0,0 +1,51 @@
+# Copyright 2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# PRINT_SCALAR_VALUES test.
+#
+# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
+# types, including C++ reference and rvalue reference types.
+#
+# In the function f(), arguments i, ir, and irr are ints or references
+# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
+# but the other arguments are non-scalar, and so their values should not
+# be printed by PRINT_SCALAR_VALUES.
+
+if { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+standard_testfile .cc
+
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
+ untested "failed to compile"
+ return -1
+}
+
+mi_clean_restart $binfile
+
+mi_runto_main
+
+mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
+
+mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
+
+mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
+ "run until breakpoint on f"
+
+mi_gdb_test "-stack-list-arguments --scalar-values" \
+ "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"i\",type=\"int\",value=\"1\"\},\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\},\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\},\{name=\"a\",type=\"int \\*\",value=\"$hex\"\},\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\},\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\},\{name=\"s\",type=\"s\"\},\{name=\"sr\",type=\"s &\"\},\{name=\"srr\",type=\"s &&\"\},\{name=\"u\",type=\"u\"\},\{name=\"ur\",type=\"u &\"\},\{name=\"urr\",type=\"u &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
+ "stack list arguments, scalar types: names, types and values, compound types: names and types"
+
+mi_gdb_exit
--
2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v3] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-25 10:16 ` Eli Zaretskii
@ 2022-09-26 12:48 ` Gareth Rees
0 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-09-26 12:48 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Eli Zaretskii wrote:
> Sorry for missing the original post. I've reviewed it now.
Thanks for the review. I addressed your comment and posted v4 of the patch.
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PING] [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-26 12:46 ` [PATCH v4] " Gareth Rees
@ 2022-10-04 9:08 ` Gareth Rees
2022-10-18 11:59 ` Gareth Rees
2022-10-12 16:38 ` Andrew Burgess
1 sibling, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2022-10-04 9:08 UTC (permalink / raw)
To: gdb-patches
Thanks to Andrew Burgess and Eli Zaretskii for reviewing. I've
addressed all the comments, so let me know how I can help progress
this patch.
On Mon, 26 Sept 2022 at 13:46, Gareth Rees <grees@undo.io> wrote:
>
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++++--------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 35 ++++++++----
> gdb/mi/mi-cmd-var.c | 26 ++++++---
> gdb/mi/mi-cmds.h | 8 ++-
> gdb/mi/mi-main.c | 54 ++++++++++--------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 23 ++++----
> gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
> gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
> 12 files changed, 272 insertions(+), 79 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..62b15094dee 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + should contain "scalar-values".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the selected frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. */
> + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI. */
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..d3ae350f166 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> && arg->error == NULL)
> || values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES
> || (values == PRINT_ALL_VALUES
> && (arg->val != NULL || arg->error != NULL)));
> gdb_assert (arg->entry_kind == print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> if (what == all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> }
> }
>
> +/* Print SYM according to VALUES? */
> +
> +static bool
> +print_symbol_p (struct symbol *sym, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (sym->type ());
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (sym->type ());
> + }
> +}
> +
> /* Print a list of the objects for the frame FI in a certain form,
> which is determined by VALUES. The objects can be locals,
> arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
> @@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> entryarg.sym = sym2;
> entryarg.entry_kind = print_entry_values_no;
>
> - switch (values)
> + if (print_symbol_p (sym, values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind != print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..064d13a3729 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> type = varobj_get_gdb_type (var);
> if (type == NULL)
> return 1;
> + else if (print_values == PRINT_SCALAR_VALUES)
> + return val_print_scalar_type_p (type);
> else
> - {
> - type = check_typedef (type);
> + return mi_simple_values_type_p (type);
> +}
> +
> +/* See mi-cmds.h. */
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> +bool
> +mi_simple_values_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> }
> }
>
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..56c3ccb8b8a 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> @@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
> + is, if type is not an array, structure or union. */
> +
> +extern bool mi_simple_values_type_p (struct type *type);
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..2e70bcde2da 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char **argv, int argc)
> print_ada_task_info (current_uiout, argv[0], current_inferior ());
> }
>
> +/* Print VAL according to VALUES? */
> +
> +static bool
> +print_value_p (struct value *val, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (value_type (val));
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (value_type (val));
> + }
> +}
> +
> /* Print EXPRESSION according to VALUES. */
>
> static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
>
> expression_up expr = parse_expression (expression);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> val = evaluate_type (expr.get ());
> else
> val = evaluate_expression (expr.get ());
> @@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (print_value_p (val, values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref = 1;
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] = "--no-values";
> +static const char mi_scalar_values[] = "--scalar-values";
> static const char mi_simple_values[] = "--simple-values";
> static const char mi_all_values[] = "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") == 0
> || strcmp (name, mi_simple_values) == 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") == 0
> + || strcmp (name, mi_scalar_values) == 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..a746f309187 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *val,
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES
> || args_type == MI_PRINT_ALL_VALUES)
> {
> - struct type *type = check_typedef (value_type (val));
> -
> if (args_type == MI_PRINT_ALL_VALUES)
> should_print = 1;
> + else if (args_type == MI_PRINT_SCALAR_VALUES
> + && val_print_scalar_type_p (value_type (val)))
> + 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_values_type_p (value_type (val)))
> should_print = 1;
> }
> else if (args_type != NO_VALUES)
> @@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for scalar and simple values. This
> + seems weird, but this is how MI chooses to format the various output
> types. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> + if ((args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> + && val != NULL)
> py_print_type (out, val);
>
> if (val != NULL)
> @@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" = ");
>
> - if (args_type == MI_PRINT_SIMPLE_VALUES)
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index d04c8153c65..8aa4e2234ff 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments 3 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments 3 1 1" \
> + "237\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --scalar-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
>
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise: names and types"
> +
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> new file mode 100644
> index 00000000000..fd9daf1d962
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> @@ -0,0 +1,58 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* PRINT_SCALAR_VALUES test program.
> +
> + Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> + types, including C++ reference and rvalue reference types.
> +
> + In the function f(), arguments i, ir, and irr are ints or references
> + to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> + but the other arguments are non-scalar, and so their values should
> + not be printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> new file mode 100644
> index 00000000000..3398218c063
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# PRINT_SCALAR_VALUES test.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +#
> +# In the function f(), arguments i, ir, and irr are ints or references
> +# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> +# but the other arguments are non-scalar, and so their values should not
> +# be printed by PRINT_SCALAR_VALUES.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"i\",type=\"int\",value=\"1\"\},\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\},\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\},\{name=\"a\",type=\"int \\*\",value=\"$hex\"\},\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\},\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\},\{name=\"s\",type=\"s\"\},\{name=\"sr\",type=\"s &\"\},\{name=\"srr\",type=\"s &&\"\},\{name=\"u\",type=\"u\"\},\{name=\"ur\",type=\"u &\"\},\{name=\"urr\",type=\"u &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> +
> +mi_gdb_exit
> --
> 2.26.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-09-26 12:46 ` [PATCH v4] " Gareth Rees
2022-10-04 9:08 ` [PING] " Gareth Rees
@ 2022-10-12 16:38 ` Andrew Burgess
2022-10-20 17:47 ` [PATCH v5] " Gareth Rees
2022-10-20 17:58 ` [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
1 sibling, 2 replies; 49+ messages in thread
From: Andrew Burgess @ 2022-10-12 16:38 UTC (permalink / raw)
To: Gareth Rees, gdb-patches
Gareth Rees via Gdb-patches <gdb-patches@sourceware.org> writes:
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++++--------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 35 ++++++++----
> gdb/mi/mi-cmd-var.c | 26 ++++++---
> gdb/mi/mi-cmds.h | 8 ++-
> gdb/mi/mi-main.c | 54 ++++++++++--------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 23 ++++----
> gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
> gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
> 12 files changed, 272 insertions(+), 79 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..62b15094dee 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + should contain "scalar-values".
I think:
can be verified by using the '-list-features' command, which
now includes "scalar-values".
Using "should" seems to indicate some doubt as to whether the value is
there or not.
I prefer "includes" to "contains", for former is, I think, clearer that
"scalar-values" is just one of many values.
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the selected frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. */
> + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI. */
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..d3ae350f166 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> && arg->error == NULL)
> || values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES
> || (values == PRINT_ALL_VALUES
> && (arg->val != NULL || arg->error != NULL)));
> gdb_assert (arg->entry_kind == print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> if (what == all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> }
> }
>
> +/* Print SYM according to VALUES? */
> +
> +static bool
> +print_symbol_p (struct symbol *sym, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (sym->type ());
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (sym->type ());
> + }
> +}
> +
> /* Print a list of the objects for the frame FI in a certain form,
> which is determined by VALUES. The objects can be locals,
> arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
> @@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> entryarg.sym = sym2;
> entryarg.entry_kind = print_entry_values_no;
>
> - switch (values)
> + if (print_symbol_p (sym, values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind != print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..064d13a3729 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> type = varobj_get_gdb_type (var);
> if (type == NULL)
> return 1;
> + else if (print_values == PRINT_SCALAR_VALUES)
> + return val_print_scalar_type_p (type);
> else
> - {
> - type = check_typedef (type);
> + return mi_simple_values_type_p (type);
> +}
> +
> +/* See mi-cmds.h. */
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> +bool
> +mi_simple_values_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> }
> }
>
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..56c3ccb8b8a 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> @@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES: that
> + is, if type is not an array, structure or union. */
> +
> +extern bool mi_simple_values_type_p (struct type *type);
I think this should be renamed to just 'mi_simple_type_p', I don't think
the values part is useful.
Instances of 'type' in the comment should be upper case.
I also think it is worth drawing attention to the issues that triggered
this patch in the first place, that is, I think you should include some
text that says that references are always considered simple, even if the
type they refer to is not simple, and that this behaviour needs to be
maintained for backward compatibility.
This will prevent someone helpfully "fixing" the simple type mechanism
in the future.
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..2e70bcde2da 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char **argv, int argc)
> print_ada_task_info (current_uiout, argv[0], current_inferior ());
> }
>
> +/* Print VAL according to VALUES? */
> +
> +static bool
> +print_value_p (struct value *val, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (value_type (val));
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (value_type (val));
> + }
> +}
I think you should probably fold together this print_value_p and
print_symbol_p in mi-cmd-stack.c. Maybe create an mi_print_type_p
somewhere, which can contain the core switch table?
> +
> /* Print EXPRESSION according to VALUES. */
>
> static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
>
> expression_up expr = parse_expression (expression);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> val = evaluate_type (expr.get ());
> else
> val = evaluate_expression (expr.get ());
> @@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (print_value_p (val, values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref = 1;
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] = "--no-values";
> +static const char mi_scalar_values[] = "--scalar-values";
> static const char mi_simple_values[] = "--simple-values";
> static const char mi_all_values[] = "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") == 0
> || strcmp (name, mi_simple_values) == 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") == 0
> + || strcmp (name, mi_scalar_values) == 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..a746f309187 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *val,
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES
> || args_type == MI_PRINT_ALL_VALUES)
> {
> - struct type *type = check_typedef (value_type (val));
> -
> if (args_type == MI_PRINT_ALL_VALUES)
> should_print = 1;
> + else if (args_type == MI_PRINT_SCALAR_VALUES
> + && val_print_scalar_type_p (value_type (val)))
> + 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_values_type_p (value_type (val)))
> should_print = 1;
> }
> else if (args_type != NO_VALUES)
> @@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for scalar and simple values. This
> + seems weird, but this is how MI chooses to format the various output
> types. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> + if ((args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> + && val != NULL)
> py_print_type (out, val);
>
> if (val != NULL)
> @@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" = ");
>
> - if (args_type == MI_PRINT_SIMPLE_VALUES)
> + if (args_type == MI_PRINT_SCALAR_VALUES
> + || args_type == MI_PRINT_SIMPLE_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index d04c8153c65..8aa4e2234ff 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments 3 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments 3 1 1" \
> + "237\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --scalar-values 1 1"
I think these tests should be repeated using the string version of the
control parameter, i.e. --simple-values and --scalar-values.
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
>
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise: names and types"
> +
And this test should be repeated using the numerical version of the
control parameter, i.e. 3.
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> new file mode 100644
> index 00000000000..fd9daf1d962
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> @@ -0,0 +1,58 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* PRINT_SCALAR_VALUES test program.
> +
> + Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> + types, including C++ reference and rvalue reference types.
> +
> + In the function f(), arguments i, ir, and irr are ints or references
> + to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> + but the other arguments are non-scalar, and so their values should
> + not be printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> new file mode 100644
> index 00000000000..3398218c063
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# PRINT_SCALAR_VALUES test.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +#
> +# In the function f(), arguments i, ir, and irr are ints or references
> +# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> +# but the other arguments are non-scalar, and so their values should not
> +# be printed by PRINT_SCALAR_VALUES.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\{name=\"i\",type=\"int\",value=\"1\"\},\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\},\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\},\{name=\"a\",type=\"int \\*\",value=\"$hex\"\},\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\},\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\},\{name=\"s\",type=\"s\"\},\{name=\"sr\",type=\"s &\"\},\{name=\"srr\",type=\"s &&\"\},\{name=\"u\",type=\"u\"\},\{name=\"ur\",type=\"u &\"\},\{name=\"urr\",type=\"u &&\"\}\\\]\},frame=\{level=\"1\",args=\\\[\\\]\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> +
I think this test should be repeated using '3' as the control variable.
More importantly, I think this would be the perfect place to test
--simple-values too.
I'm pretty sure we don't have an existing test that checks that
--simple-values _does_ print the target of a reference, if we had ever
tried to write such a test then I think --simple-values would have been
"fixed" long ago.
So, given we have decided to preserve its current behaviour, which is
fine, we should be adding tests for that behaviour, and here seems like
the perfect place. I think it's probably only a couple of extra
mi_gdb_test calls.
Other than the above minor issues, I think the patch is looking pretty
good. Thanks for all your work so far.
Thanks,
Andrew
> +mi_gdb_exit
> --
> 2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PING] [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-10-04 9:08 ` [PING] " Gareth Rees
@ 2022-10-18 11:59 ` Gareth Rees
0 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-10-18 11:59 UTC (permalink / raw)
To: gdb-patches
Thanks to Andrew Burgess and Eli Zaretskii for reviewing. I've
addressed all the comments, so let me know how I can help progress
this patch.
On Mon, 26 Sept 2022 at 13:46, Gareth Rees <grees@undo.io> wrote:
>
> 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 =3D 0;
> for (int i =3D 0; i < 10; ++i) total +=3D s.v[i];
> return total;
> }
>
> int
> main(void)
> {
> struct s s =3D { { 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=3D[frame=3D{level=3D"0",args=3D[{name=3D"s",type=3D"=
const s &",value=3D"@0x7fffffffe310: {v =3D {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}=
}"}]},frame=3D{level=3D"1",args=3D[]}]
>
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++++--------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 35 ++++++++----
> gdb/mi/mi-cmd-var.c | 26 ++++++---
> gdb/mi/mi-cmds.h | 8 ++-
> gdb/mi/mi-main.c | 54 ++++++++++--------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 23 ++++----
> gdb/testsuite/gdb.mi/mi-stack.exp | 17 +++++-
> gdb/testsuite/gdb.mi/print-scalar-values.cc | 58 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-scalar-values.exp | 51 +++++++++++++++++
> 12 files changed, 272 insertions(+), 79 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-scalar-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..62b15094dee 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + should contain "scalar-values".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On th=
e other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names o=
f
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @va=
r{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the sele=
cted frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not=
already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option=
{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES =3D PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. =
*/
> + MI_PRINT_SCALAR_VALUES =3D PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI.=
*/
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..d3ae350f166 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum =
what_to_list what,
> gdb_assert ((values =3D=3D PRINT_NO_VALUES && arg->val =3D=3D NULL
> && arg->error =3D=3D NULL)
> || values =3D=3D PRINT_SIMPLE_VALUES
> + || values =3D=3D PRINT_SCALAR_VALUES
> || (values =3D=3D PRINT_ALL_VALUES
> && (arg->val !=3D NULL || arg->error !=3D NULL)));
> gdb_assert (arg->entry_kind =3D=3D print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum =
what_to_list what,
> if (what =3D=3D all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values =3D=3D PRINT_SIMPLE_VALUES)
> + if (values =3D=3D PRINT_SIMPLE_VALUES
> + || values =3D=3D PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -557,6 +559,25 @@ list_arg_or_local (const struct frame_arg *arg, enum=
what_to_list what,
> }
> }
>
> +/* Print SYM according to VALUES? */
> +
> +static bool
> +print_symbol_p (struct symbol *sym, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (sym->type ());
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (sym->type ());
> + }
> +}
> +
> /* Print a list of the objects for the frame FI in a certain form,
> which is determined by VALUES. The objects can be locals,
> arguments or both, which is determined by WHAT. If SKIP_UNAVAILABLE
> @@ -571,7 +592,6 @@ list_args_or_locals (const frame_print_options &fp_op=
ts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout =3D current_uiout;
>
> @@ -647,21 +667,12 @@ list_args_or_locals (const frame_print_options &fp_=
opts,
> entryarg.sym =3D sym2;
> entryarg.entry_kind =3D print_entry_values_no;
>
> - switch (values)
> + if (print_symbol_p (sym, values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type =3D check_typedef (sym2->type ());
> - if (type->code () !=3D TYPE_CODE_ARRAY
> - && type->code () !=3D TYPE_CODE_STRUCT
> - && type->code () !=3D TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind !=3D print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..064d13a3729 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -334,15 +335,26 @@ mi_print_value_p (struct varobj *var, enum print_va=
lues print_values)
> type =3D varobj_get_gdb_type (var);
> if (type =3D=3D NULL)
> return 1;
> + else if (print_values =3D=3D PRINT_SCALAR_VALUES)
> + return val_print_scalar_type_p (type);
> else
> - {
> - type =3D check_typedef (type);
> + return mi_simple_values_type_p (type);
> +}
> +
> +/* See mi-cmds.h. */
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () !=3D TYPE_CODE_ARRAY
> - && type->code () !=3D TYPE_CODE_STRUCT
> - && type->code () !=3D TYPE_CODE_UNION);
> +bool
> +mi_simple_values_type_p (struct type *type)
> +{
> + type =3D check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> }
> }
>
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..56c3ccb8b8a 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int =
argc);
> @@ -226,4 +227,9 @@ using remove_mi_cmd_entries_ftype
> =3D gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback)=
;
>
> +/* Return true if type is suitable for printing with PRINT_SIMPLE_VALUES=
: that
> + is, if type is not an array, structure or union. */
> +
> +extern bool mi_simple_values_type_p (struct type *type);
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..2e70bcde2da 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **a=
rgv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2456,20 +2457,39 @@ mi_cmd_ada_task_info (const char *command, char *=
*argv, int argc)
> print_ada_task_info (current_uiout, argv[0], current_inferior ());
> }
>
> +/* Print VAL according to VALUES? */
> +
> +static bool
> +print_value_p (struct value *val, enum print_values values)
> +{
> + switch (values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_values_type_p (value_type (val));
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (value_type (val));
> + }
> +}
> +
> /* Print EXPRESSION according to VALUES. */
>
> static void
> print_variable_or_computed (const char *expression, enum print_values va=
lues)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout =3D current_uiout;
>
> string_file stb;
>
> expression_up expr =3D parse_expression (expression);
>
> - if (values =3D=3D PRINT_SIMPLE_VALUES)
> + if (values =3D=3D PRINT_SIMPLE_VALUES
> + || values =3D=3D PRINT_SCALAR_VALUES)
> val =3D evaluate_type (expr.get ());
> else
> val =3D evaluate_expression (expr.get ());
> @@ -2482,31 +2502,19 @@ print_variable_or_computed (const char *expressio=
n, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type =3D check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () !=3D TYPE_CODE_ARRAY
> - && type->code () !=3D TYPE_CODE_STRUCT
> - && type->code () !=3D TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref =3D 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref =3D 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (print_value_p (val, values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref =3D 1;
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] =3D "--no-values";
> +static const char mi_scalar_values[] =3D "--scalar-values";
> static const char mi_simple_values[] =3D "--simple-values";
> static const char mi_all_values[] =3D "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") =3D=3D 0
> || strcmp (name, mi_simple_values) =3D=3D 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") =3D=3D 0
> + || strcmp (name, mi_scalar_values) =3D=3D 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_valu=
es);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..a746f309187 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -232,17 +232,17 @@ py_print_value (struct ui_out *out, struct value *v=
al,
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type =3D=3D MI_PRINT_SIMPLE_VALUES
> + if (args_type =3D=3D MI_PRINT_SCALAR_VALUES
> + || args_type =3D=3D MI_PRINT_SIMPLE_VALUES
> || args_type =3D=3D MI_PRINT_ALL_VALUES)
> {
> - struct type *type =3D check_typedef (value_type (val));
> -
> if (args_type =3D=3D MI_PRINT_ALL_VALUES)
> should_print =3D 1;
> + else if (args_type =3D=3D MI_PRINT_SCALAR_VALUES
> + && val_print_scalar_type_p (value_type (val)))
> + should_print =3D 1;
> else if (args_type =3D=3D MI_PRINT_SIMPLE_VALUES
> - && type->code () !=3D TYPE_CODE_ARRAY
> - && type->code () !=3D TYPE_CODE_STRUCT
> - && type->code () !=3D TYPE_CODE_UNION)
> + && mi_simple_values_type_p (value_type (val)))
> should_print =3D 1;
> }
> else if (args_type !=3D NO_VALUES)
> @@ -371,10 +371,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for scalar and simple values. This
> + seems weird, but this is how MI chooses to format the various outpu=
t
> types. */
> - if (args_type =3D=3D MI_PRINT_SIMPLE_VALUES && val !=3D NULL)
> + if ((args_type =3D=3D MI_PRINT_SCALAR_VALUES
> + || args_type =3D=3D MI_PRINT_SIMPLE_VALUES)
> + && val !=3D NULL)
> py_print_type (out, val);
>
> if (val !=3D NULL)
> @@ -603,7 +605,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" =3D ");
>
> - if (args_type =3D=3D MI_PRINT_SIMPLE_VALUES)
> + if (args_type =3D=3D MI_PRINT_SCALAR_VALUES
> + || args_type =3D=3D MI_PRINT_SIMPLE_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-=
stack.exp
> index d04c8153c65..8aa4e2234ff 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,9 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments 3 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=3D\\\[frame=3D\{level=3D\"0\",args=3D\\\[\=
\\]\},frame=3D\{level=3D\"1\",args=3D\\\[name=3D\"strarg\"\\\]\},frame=3D\{=
level=3D\"2\",args=3D\\\[name=3D\"intarg\",name=3D\"strarg\"\\\]\},frame=3D=
\{level=3D\"3\",args=3D\\\[name=3D\"intarg\",name=3D\"strarg\",name=3D\"flt=
arg\"\\\]\},frame=3D\{level=3D\"4\",args=3D\\\[\\\]\}\\\]" \
> @@ -125,6 +128,14 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=3D\\\[frame=3D\{level=3D\"1\",args=3D\\\[\=
{name=3D\"strarg\",value=3D\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},=
frame=3D\{level=3D\"2\",args=3D\\\[\{name=3D\"intarg\",value=3D\"2\"\},\{na=
me=3D\"strarg\",value=3D\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},fra=
me=3D\{level=3D\"3\",args=3D\\\[\{name=3D\"intarg\",value=3D\"2\"\},\{name=
=3D\"strarg\",value=3D\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=3D\"=
fltarg\",value=3D\"3.5\"\}\\\]\},frame=3D\{level=3D\"4\",args=3D\\\[\\\]\}\=
\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=3D\\\[frame=3D\{level=3D\"1\",args=3D\\\[\=
{name=3D\"strarg\",type=3D\"char \\*\",value=3D\"$hex \\\\\"A string argume=
nt.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments 3 1 1" \
> + "237\\^done,stack-args=3D\\\[frame=3D\{level=3D\"1\",args=3D\\\[\=
{name=3D\"strarg\",type=3D\"char \\*\",value=3D\"$hex \\\\\"A string argume=
nt.\\\\\"\"\}\\\]\}\\\]" \
> + "stack args listing --scalar-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +174,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=3D\\\[name=3D\"A\",name=3D\"B\",name=3D\"C\",n=
ame=3D\"D\"\\\]" \
> @@ -183,6 +194,10 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=3D\\\[\{name=3D\"A\",type=3D\"int\",value=3D\"=
1\"\},\{name=3D\"B\",type=3D\"int\",value=3D\"2\"\},\{name=3D\"C\",type=3D\=
"int\",value=3D\"3\"\},\{name=3D\"D\",type=3D\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex ty=
pe: names and types"
>
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=3D\\\[\{name=3D\"A\",type=3D\"int\",value=3D\"=
1\"\},\{name=3D\"B\",type=3D\"int\",value=3D\"2\"\},\{name=3D\"C\",type=3D\=
"int\",value=3D\"3\"\},\{name=3D\"D\",type=3D\"int \\\[3\\\]\"\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise:=
names and types"
> +
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=3D\"-stack-list-locals: Usage.*PRINT_VALUES.*\""=
\
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.cc b/gdb/testsuite/=
gdb.mi/print-scalar-values.cc
> new file mode 100644
> index 00000000000..fd9daf1d962
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.cc
> @@ -0,0 +1,58 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>.=
*/
> +
> +/* PRINT_SCALAR_VALUES test program.
> +
> + Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> + types, including C++ reference and rvalue reference types.
> +
> + In the function f(), arguments i, ir, and irr are ints or references
> + to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> + but the other arguments are non-scalar, and so their values should
> + not be printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i =3D 1, j =3D 2;
> + int a[1] =3D { 4 }, b[1] =3D { 5 };
> + struct s s =3D { 7 }, t =3D { 8 };
> + union u u =3D { 10 }, v =3D { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-scalar-values.exp b/gdb/testsuite=
/gdb.mi/print-scalar-values.exp
> new file mode 100644
> index 00000000000..3398218c063
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-scalar-values.exp
> @@ -0,0 +1,51 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# PRINT_SCALAR_VALUES test.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +#
> +# In the function f(), arguments i, ir, and irr are ints or references
> +# to ints, and their values should be printed by PRINT_SCALAR_VALUES;
> +# but the other arguments are non-scalar, and so their values should not
> +# be printed by PRINT_SCALAR_VALUES.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug =
c++}] !=3D "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on=
f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp=3D"keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=3D\\\[frame=3D\{level=3D\"0\",args=3D\\\[\{name=
=3D\"i\",type=3D\"int\",value=3D\"1\"\},\{name=3D\"ir\",type=3D\"int &\",va=
lue=3D\"@$hex: 2\"\},\{name=3D\"irr\",type=3D\"int &&\",value=3D\"@$hex: 3\=
"\},\{name=3D\"a\",type=3D\"int \\*\",value=3D\"$hex\"\},\{name=3D\"ar\",ty=
pe=3D\"int \\(&\\)\\\[1\\\]\"\},\{name=3D\"arr\",type=3D\"int \\(&&\\)\\\[1=
\\\]\"\},\{name=3D\"s\",type=3D\"s\"\},\{name=3D\"sr\",type=3D\"s &\"\},\{n=
ame=3D\"srr\",type=3D\"s &&\"\},\{name=3D\"u\",type=3D\"u\"\},\{name=3D\"ur=
\",type=3D\"u &\"\},\{name=3D\"urr\",type=3D\"u &&\"\}\\\]\},frame=3D\{leve=
l=3D\"1\",args=3D\\\[\\\]\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compou=
nd types: names and types"
> +
> +mi_gdb_exit
> --
> 2.26.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-10-12 16:38 ` Andrew Burgess
@ 2022-10-20 17:47 ` Gareth Rees
2022-10-20 18:00 ` Eli Zaretskii
` (3 more replies)
2022-10-20 17:58 ` [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values' Gareth Rees
1 sibling, 4 replies; 49+ messages in thread
From: Gareth Rees @ 2022-10-20 17:47 UTC (permalink / raw)
To: gdb-patches
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 that can be fixed.
1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
for the PRINT-VALUES argument to '-stack-list-arguments' and similar
commands. This option prints the value only for scalars and so matches
the behaviour of the 'scalars' argument to the 'set print
frame-arguments' command. References to structures are not scalars,
and so the option is suitable for use by IDEs.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
---
gdb/NEWS | 9 +++
gdb/doc/gdb.texinfo | 59 ++++++++++-------
gdb/extension.h | 3 +
gdb/mi/mi-cmd-stack.c | 16 ++---
gdb/mi/mi-cmd-var.c | 45 ++++++++++---
gdb/mi/mi-cmds.h | 17 ++++-
gdb/mi/mi-main.c | 35 ++++-------
gdb/mi/mi-parse.c | 8 ++-
gdb/python/py-framefilter.c | 40 ++++++------
gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
.../gdb.python/py-framefilter-mi.exp | 28 +++++++++
13 files changed, 323 insertions(+), 90 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index dee0ac2ecd8..9ad441691ea 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -114,6 +114,15 @@ maintenance info line-table
entry corresponds to an address where a breakpoint should be placed
to be at the first instruction past a function's prologue.
+* MI changes
+
+ ** The '-stack-list-arguments', '-stack-list-locals',
+ '-stack-list-variables', and '-var-list-children' commands
+ support the '--scalar-values' option, which requests the command
+ to print values only for scalar types. Support for this feature
+ can be verified by using the '-list-features' command, which
+ now includes "scalar-values".
+
* New targets
GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 238a49b027d..b2b53de1022 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
@var{high-frame} may be larger than the actual number of frames, in
which case only existing frames will be returned.
-If @var{print-values} is 0 or @code{--no-values}, print only the names of
-the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. If the option @code{--no-frame-filters} is
-supplied, then Python frame filters will not be executed.
+If @var{print-values} is 0 or @code{--no-values}, print only the names
+of the variables; if it is 1 or @code{--all-values}, print also their
+values; if it is 2 or @code{--simple-values}, print the name, type and
+value for simple data types, and the name and type for arrays,
+structures and unions; and if it is 3 or @code{--scalar-values}, print
+the name, type and value for scalar data types, and the name and type
+otherwise. If the option @code{--no-frame-filters} is supplied, then
+Python frame filters will not be executed.
If the @code{--skip-unavailable} option is specified, arguments that
are not available are not listed. Partially available arguments
@@ -33549,13 +33551,15 @@ Show a single frame:
Display the local variable names for the selected frame. If
@var{print-values} is 0 or @code{--no-values}, print only the names of
the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. In this last case, a frontend can immediately
-display the value of simple data types and create variable objects for
-other data types when the user wishes to explore their values in
-more detail. If the option @code{--no-frame-filters} is supplied, then
-Python frame filters will not be executed.
+values; if it is 2 or @code{--simple-values}, print the name, type and
+value for simple data types, and the name and type for arrays,
+structures and unions; and if it is 3 or @code{--scalar-values}, print
+the name, type and value for scalar data types, and the name and type
+otherwise. In the last two cases, a frontend can immediately display
+the value of simple or scalar data types and create variable objects
+for other data types when the user wishes to explore their values in
+more detail. If the option @code{--no-frame-filters} is supplied,
+then Python frame filters will not be executed.
If the @code{--skip-unavailable} option is specified, local variables
that are not available are not listed. Partially available local
@@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
-stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
@end smallexample
-Display the names of local variables and function arguments for the selected frame. If
-@var{print-values} is 0 or @code{--no-values}, print only the names of
-the variables; if it is 1 or @code{--all-values}, print also their
-values; and if it is 2 or @code{--simple-values}, print the name,
-type and value for simple data types, and the name and type for arrays,
-structures and unions. If the option @code{--no-frame-filters} is
-supplied, then Python frame filters will not be executed.
+Display the names of local variables and function arguments for the
+selected frame. If @var{print-values} is 0 or @code{--no-values},
+print only the names of the variables; if it is 1 or
+@code{--all-values}, print also their values; if it is 2 or
+@code{--simple-values}, print the name, type and value for simple data
+types, and the name and type for arrays, structures and unions; and if
+it is 3 or @code{--scalar-values}, print the name, type and value for
+scalar data types, and the name and type otherwise. If the option
+@code{--no-frame-filters} is supplied, then Python frame filters will
+not be executed.
If the @code{--skip-unavailable} option is specified, local variables
and arguments that are not available are not listed. Partially
@@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
a single argument or if @var{print-values} has a value of 0 or
@code{--no-values}, print only the names of the variables; if
@var{print-values} is 1 or @code{--all-values}, also print their
-values; and if it is 2 or @code{--simple-values} print the name and
-value for simple data types and just the name for arrays, structures
-and unions.
+values; if it is 2 or @code{--simple-values} print the name and value
+for simple data types and just the name for arrays, structures and
+unions; and if it is 3 or @code{--scalar-values}, print the name and
+value for scalar data types, and just the name otherwise.
@var{from} and @var{to}, if specified, indicate the range of children
to report. If @var{from} or @var{to} is less than zero, the range is
@@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
@item data-disassemble-a-option
Indicates that the @code{-data-disassemble} command supports the @option{-a}
option (@pxref{GDB/MI Data Manipulation}).
+@item scalar-values
+Indicates that the @code{-stack-list-arguments},
+@code{-stack-list-locals}, @code{-stack-list-variables}, and
+@code{-var-list-children} commands support the
+@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
@end ftable
@subheading The @code{-list-target-features} Command
diff --git a/gdb/extension.h b/gdb/extension.h
index 47839ea50be..16d12f00f41 100644
--- a/gdb/extension.h
+++ b/gdb/extension.h
@@ -121,6 +121,9 @@ enum ext_lang_frame_args
arguments when invoked from the MI. */
MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
+ /* Print only scalar values for arguments when invoked from the MI. */
+ MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
+
/* Print only scalar values for arguments when invoked from the CLI. */
CLI_SCALAR_VALUES,
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 0fe204dbc66..43eea32e460 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
&& arg->error == NULL)
|| values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES
|| (values == PRINT_ALL_VALUES
&& (arg->val != NULL || arg->error != NULL)));
gdb_assert (arg->entry_kind == print_entry_values_no
@@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
if (what == all && arg->sym->is_argument ())
uiout->field_signed ("arg", 1);
- if (values == PRINT_SIMPLE_VALUES)
+ if (values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES)
{
check_typedef (arg->sym->type ());
type_print (arg->sym->type (), "", &stb, -1);
@@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
const struct block *block;
struct symbol *sym;
struct block_iterator iter;
- struct type *type;
const char *name_of_result;
struct ui_out *uiout = current_uiout;
@@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
entryarg.sym = sym2;
entryarg.entry_kind = print_entry_values_no;
- switch (values)
+ if (mi_print_type_p (sym->type (), values))
{
- case PRINT_SIMPLE_VALUES:
- type = check_typedef (sym2->type ());
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
- {
- case PRINT_ALL_VALUES:
if (sym->is_argument ())
read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
else
read_frame_local (sym2, fi, &arg);
- }
- break;
}
if (arg.entry_kind != print_entry_values_only)
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index 3db09cf7815..1d4d3ec8534 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -32,6 +32,7 @@
#include "mi-parse.h"
#include "gdbsupport/gdb_optional.h"
#include "inferior.h"
+#include "valprint.h"
static void varobj_update_one (struct varobj *var,
enum print_values print_values,
@@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
uiout->field_signed ("numchild", varobj_get_num_children (var));
}
+/* See mi-cmds.h. */
+
+bool
+mi_simple_type_p (struct type *type)
+{
+ type = check_typedef (type);
+ switch (type->code ())
+ {
+ case TYPE_CODE_ARRAY:
+ case TYPE_CODE_STRUCT:
+ case TYPE_CODE_UNION:
+ return false;
+ default:
+ return true;
+ }
+}
+
+bool
+mi_print_type_p (struct type *type, enum print_values print_values)
+{
+ switch (print_values)
+ {
+ default:
+ case PRINT_NO_VALUES:
+ return false;
+ case PRINT_ALL_VALUES:
+ return true;
+ case PRINT_SIMPLE_VALUES:
+ return mi_simple_type_p (type);
+ case PRINT_SCALAR_VALUES:
+ return val_print_scalar_type_p (type);
+ }
+}
+
/* Return 1 if given the argument PRINT_VALUES we should display
the varobj VAR. */
@@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
if (type == NULL)
return 1;
else
- {
- type = check_typedef (type);
-
- /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
- and that type is not a compound type. */
- return (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION);
- }
+ return mi_print_type_p (type, print_values);
}
void
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 9ffb11bf997..3a5b6b72be9 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -29,7 +29,8 @@
enum print_values {
PRINT_NO_VALUES,
PRINT_ALL_VALUES,
- PRINT_SIMPLE_VALUES
+ PRINT_SIMPLE_VALUES,
+ PRINT_SCALAR_VALUES
};
typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
@@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
= gdb::function_view<bool (mi_command *)>;
extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
+/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
+ is, if TYPE is not an array, structure or union.
+
+ Note that reference types are always considered simple by this function, even
+ if the referenced type is non-scalar. This behaviour is retained for backwards
+ compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
+ references to non-scalar values. */
+
+extern bool mi_simple_type_p (struct type *type);
+
+/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
+
+extern bool mi_print_type_p (struct type *type, enum print_values values);
+
#endif /* MI_MI_CMDS_H */
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index b758f398e2a..9bb00390370 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
uiout->field_string (NULL, "undefined-command-error-code");
uiout->field_string (NULL, "exec-run-start-option");
uiout->field_string (NULL, "data-disassemble-a-option");
+ uiout->field_string (NULL, "scalar-values");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
@@ -2462,14 +2463,14 @@ static void
print_variable_or_computed (const char *expression, enum print_values values)
{
struct value *val;
- struct type *type;
struct ui_out *uiout = current_uiout;
string_file stb;
expression_up expr = parse_expression (expression);
- if (values == PRINT_SIMPLE_VALUES)
+ if (values == PRINT_SIMPLE_VALUES
+ || values == PRINT_SCALAR_VALUES)
val = evaluate_type (expr.get ());
else
val = evaluate_expression (expr.get ());
@@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (value_type (val));
+ case PRINT_SCALAR_VALUES:
type_print (value_type (val), "", &stb, -1);
uiout->field_stream ("type", stb);
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
- {
- struct value_print_options opts;
-
- get_no_prettyformat_print_options (&opts);
- opts.deref_ref = 1;
- common_val_print (val, &stb, 0, &opts, current_language);
- uiout->field_stream ("value", stb);
- }
break;
- case PRINT_ALL_VALUES:
- {
- struct value_print_options opts;
+ }
- get_no_prettyformat_print_options (&opts);
- opts.deref_ref = 1;
- common_val_print (val, &stb, 0, &opts, current_language);
- uiout->field_stream ("value", stb);
- }
- break;
+ if (mi_print_type_p (value_type (val), values))
+ {
+ struct value_print_options opts;
+ get_no_prettyformat_print_options (&opts);
+ opts.deref_ref = 1;
+ common_val_print (val, &stb, 0, &opts, current_language);
+ uiout->field_stream ("value", stb);
}
}
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index dfa7b462714..dd70e4648a1 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -29,6 +29,7 @@
#include "language.h"
static const char mi_no_values[] = "--no-values";
+static const char mi_scalar_values[] = "--scalar-values";
static const char mi_simple_values[] = "--simple-values";
static const char mi_all_values[] = "--all-values";
@@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
else if (strcmp (name, "2") == 0
|| strcmp (name, mi_simple_values) == 0)
return PRINT_SIMPLE_VALUES;
+ else if (strcmp (name, "3") == 0
+ || strcmp (name, mi_scalar_values) == 0)
+ return PRINT_SCALAR_VALUES;
else
error (_("Unknown value for PRINT_VALUES: must be: \
-0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
- mi_no_values, mi_all_values, mi_simple_values);
+0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
+ mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
}
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 366f3745b9d..e295036f46e 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
enum ext_lang_frame_args args_type,
const struct language_defn *language)
{
- int should_print = 0;
+ int should_print;
/* MI does not print certain values, differentiated by type,
depending on what ARGS_TYPE indicates. Test type against option.
For CLI print all values. */
- if (args_type == MI_PRINT_SIMPLE_VALUES
- || args_type == MI_PRINT_ALL_VALUES)
+ switch (args_type)
{
- struct type *type = check_typedef (value_type (val));
-
- 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)
- should_print = 1;
+ case NO_VALUES:
+ should_print = 0;
+ break;
+ default:
+ case MI_PRINT_ALL_VALUES:
+ should_print = 1;
+ break;
+ case MI_PRINT_SIMPLE_VALUES:
+ should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
+ break;
+ case MI_PRINT_SCALAR_VALUES:
+ should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
+ break;
}
- else if (args_type != NO_VALUES)
- should_print = 1;
if (should_print)
{
@@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
if (print_args_field)
out->field_signed ("arg", 1);
- /* For MI print the type, but only for simple values. This seems
- weird, but this is how MI choose to format the various output
+ /* For MI print the type, but only for simple and scalar values. This
+ seems weird, but this is how MI chooses to format the various output
types. */
- if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
+ if ((args_type == MI_PRINT_SIMPLE_VALUES
+ || args_type == MI_PRINT_SCALAR_VALUES)
+ && val != NULL)
py_print_type (out, val);
if (val != NULL)
@@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
out->field_string ("name", sym_name.get ());
out->text (" = ");
- if (args_type == MI_PRINT_SIMPLE_VALUES)
+ if (args_type == MI_PRINT_SIMPLE_VALUES
+ || args_type == MI_PRINT_SCALAR_VALUES)
py_print_type (out, val);
/* CLI always prints values for locals. MI uses the
diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
index d04c8153c65..2c74da00c18 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.exp
+++ b/gdb/testsuite/gdb.mi/mi-stack.exp
@@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
# -stack-list-arguments 1 1 1
# -stack-list-arguments 1 1 3
# -stack-list-arguments
+ # -stack-list-arguments 1 1 300
+ # -stack-list-arguments 2 1 1
+ # -stack-list-arguments --simple-values 1 1
+ # -stack-list-arguments 3 1 1
+ # -stack-list-arguments --scalar-values 1 1
mi_gdb_test "231-stack-list-arguments 0" \
"231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
@@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
mi_gdb_test "235-stack-list-arguments 1 1 300" \
"235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
"stack args listing 1 1 300"
+
+ mi_gdb_test "236-stack-list-arguments 2 1 1" \
+ "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
+ "stack args listing 2 1 1"
+
+ mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
+ "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
+ "stack args listing --simple-values 1 1"
+
+ mi_gdb_test "238-stack-list-arguments 3 1 1" \
+ "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
+ "stack args listing 3 1 1"
+
+ mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
+ "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
+ "stack args listing --scalar-values 1 1"
}
proc test_stack_info_depth {} {
@@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
# -stack-list-locals 0 (--no-values)
# -stack-list-locals 1 (--all-values)
# -stack-list-locals 2 (--simple-values)
- # -stack-list-arguments
+ # -stack-list-locals 3 (--scalar-values)
mi_gdb_test "232-stack-list-locals 0" \
"232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
@@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
"232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
"stack locals listing of names and values"
- mi_gdb_test "232-stack-list-locals --simple-values" \
+ mi_gdb_test "232-stack-list-locals 2" \
"232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
"stack locals listing, simple types: names and values, complex type: names and types"
+ mi_gdb_test "232-stack-list-locals --simple-values" \
+ "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
+ "stack locals listing with --simple-values"
+
+ mi_gdb_test "233-stack-list-locals 3" \
+ "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
+ "stack locals listing, scalar types: names and values, otherwise: names and types"
+
+ mi_gdb_test "233-stack-list-locals --scalar-values" \
+ "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
+ "stack locals listing with --scalar-values"
+
mi_gdb_test "234-stack-list-locals" \
"234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
"stack locals listing wrong"
diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
new file mode 100644
index 00000000000..b52683d1537
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-values.cc
@@ -0,0 +1,63 @@
+/* This test case is part of GDB, the GNU debugger.
+
+ Copyright 2022 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
+
+ In the function f:
+
+ * The arguments i, ir, and irr are ints or references to ints,
+ which must be printed by both PRINT_SIMPLE_VALUES and
+ PRINT_SCALAR_VALUES.
+
+ * The arguments a, s, and u are non-scalar values, which must not
+ be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
+
+ * The arguments ar, arr, sr, srr, ur, and urr are references to
+ non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
+ but not printed by PRINT_SCALAR_VALUES. */
+
+struct s
+{
+ int v;
+};
+
+union u
+{
+ int v;
+};
+
+int
+f (int i, int &ir, int &&irr,
+ int a[1], int (&ar)[1], int (&&arr)[1],
+ struct s s, struct s &sr, struct s &&srr,
+ union u u, union u &ur, union u &&urr)
+{
+ return (i + ir + irr
+ + a[0] + ar[0] + arr[0]
+ + s.v + sr.v + srr.v
+ + u.v + ur.v + urr.v);
+}
+
+int
+main (void)
+{
+ int i = 1, j = 2;
+ int a[1] = { 4 }, b[1] = { 5 };
+ struct s s = { 7 }, t = { 8 };
+ union u u = { 10 }, v = { 11 };
+ return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
+}
diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
new file mode 100644
index 00000000000..7896d773119
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-values.exp
@@ -0,0 +1,53 @@
+# Copyright 2022 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
+#
+# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
+# types, except for C++ reference and rvalue reference types.
+#
+# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
+# types, including C++ reference and rvalue reference types.
+
+if { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+standard_testfile .cc
+
+if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
+ untested "failed to compile"
+ return -1
+}
+
+mi_clean_restart $binfile
+
+mi_runto_main
+
+mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
+
+mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
+
+mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
+ "run until breakpoint on f"
+
+mi_gdb_test "-stack-list-arguments --simple-values" \
+ "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
+ "stack list arguments, simple types: names, types and values, otherwise: names and types"
+
+mi_gdb_test "-stack-list-arguments --scalar-values" \
+ "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
+ "stack list arguments, scalar types: names, types and values, compound types: names and types"
+
+mi_gdb_exit
diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
index 344067fe4a7..fa4e559e343 100644
--- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
+++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
@@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
"\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
"stack-list-arguments --no-frame-filters 2"
+mi_gdb_test "-stack-list-arguments 3" \
+ "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
+ "stack-list-arguments 3"
+
+mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
+ "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
+ "stack-list-arguments --no-frame-filters 3"
+
mi_gdb_test "-stack-list-arguments 2 0 3" \
"\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
@@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
"\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
"stack-list-arguments --no-frame-filters 2 22 27"
+mi_gdb_test "-stack-list-arguments 3 22 27" \
+ "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
+ "stack-list-arguments 3 22 27"
+
+mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
+ "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
+ "stack-list-arguments --no-frame-filters 3 22 27"
+
#stack-list-locals
mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
"\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
@@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
"\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
"stack-list-locals --no-frame-filters 2"
+mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
+ "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
+ "stack-list-locals --no-frame-filters 3"
+
mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
"\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
"stack-list-locals --no-frame-filters --no-values"
@@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
"\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
"stack-list-locals --no-frame-filters --simple-values"
+mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
+ "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
+ "stack-list-locals --no-frame-filters --scalar-values"
+
mi_gdb_test "-stack-list-locals 0" \
"\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
"stack-list-locals 0"
@@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
"\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
"stack-list-locals 2"
+mi_gdb_test "-stack-list-locals 3" \
+ "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
+ "stack-list-locals 3"
+
# stack-list-variables
mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
"\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
--
2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v4] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-10-12 16:38 ` Andrew Burgess
2022-10-20 17:47 ` [PATCH v5] " Gareth Rees
@ 2022-10-20 17:58 ` Gareth Rees
1 sibling, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-10-20 17:58 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
Thank you for the thorough review. I implemented all your suggestions,
and have attempted to add tests covering all the behaviour of the new
'--scalar-values' option. The revised patch is v5, posted separately.
Andrew Burgess wrote:
> > +/* Print VAL according to VALUES? */
> > +
> > +static bool
> > +print_value_p (struct value *val, enum print_values values)
> > +{
> > + switch (values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_values_type_p (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (value_type (val));
> > + }
> > +}
>
> I think you should probably fold together this print_value_p and
> print_symbol_p in mi-cmd-stack.c. Maybe create an mi_print_type_p
> somewhere, which can contain the core switch table?
I have implemented this suggestion. Note that a consequence is that in
the PRINT_NO_VALUES and PRINT_ALL_VALUES cases, we now incur a call to
value_type(val) or sym->type() when previously we just returned false
or true respectively. I think this is probably worth it, in order to
reduce the amount of duplicated code, but just want to highlight the
small change in behaviour here.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-10-20 17:47 ` [PATCH v5] " Gareth Rees
@ 2022-10-20 18:00 ` Eli Zaretskii
2022-11-03 16:20 ` [PING] " Gareth Rees
` (2 subsequent siblings)
3 siblings, 0 replies; 49+ messages in thread
From: Eli Zaretskii @ 2022-10-20 18:00 UTC (permalink / raw)
To: Gareth Rees; +Cc: gdb-patches
> Date: Thu, 20 Oct 2022 18:47:02 +0100
> From: Gareth Rees via Gdb-patches <gdb-patches@sourceware.org>
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++-------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 16 ++---
> gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> gdb/mi/mi-cmds.h | 17 ++++-
> gdb/mi/mi-main.c | 35 ++++-------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 40 ++++++------
> gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> 13 files changed, 323 insertions(+), 90 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
Thanks, the documentation parts are OK.
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-10-20 17:47 ` [PATCH v5] " Gareth Rees
2022-10-20 18:00 ` Eli Zaretskii
@ 2022-11-03 16:20 ` Gareth Rees
2022-11-14 9:25 ` Gareth Rees
` (5 more replies)
2023-03-08 12:35 ` Andrew Burgess
2023-03-11 11:49 ` [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
3 siblings, 6 replies; 49+ messages in thread
From: Gareth Rees @ 2022-11-03 16:20 UTC (permalink / raw)
To: gdb-patches
After four rounds of review, this must be getting close to being
mergeable! But do let me know if there's anything else that I need to
improve here.
On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
>
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++-------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 16 ++---
> gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> gdb/mi/mi-cmds.h | 17 ++++-
> gdb/mi/mi-main.c | 35 ++++-------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 40 ++++++------
> gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> 13 files changed, 323 insertions(+), 90 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..9ad441691ea 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + now includes "scalar-values".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the selected frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. */
> + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI. */
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..43eea32e460 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> && arg->error == NULL)
> || values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES
> || (values == PRINT_ALL_VALUES
> && (arg->val != NULL || arg->error != NULL)));
> gdb_assert (arg->entry_kind == print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> if (what == all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> entryarg.sym = sym2;
> entryarg.entry_kind = print_entry_values_no;
>
> - switch (values)
> + if (mi_print_type_p (sym->type (), values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind != print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..1d4d3ec8534 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> uiout->field_signed ("numchild", varobj_get_num_children (var));
> }
>
> +/* See mi-cmds.h. */
> +
> +bool
> +mi_simple_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> + }
> +}
> +
> +bool
> +mi_print_type_p (struct type *type, enum print_values print_values)
> +{
> + switch (print_values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_type_p (type);
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (type);
> + }
> +}
> +
> /* Return 1 if given the argument PRINT_VALUES we should display
> the varobj VAR. */
>
> @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> if (type == NULL)
> return 1;
> else
> - {
> - type = check_typedef (type);
> -
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> - }
> + return mi_print_type_p (type, print_values);
> }
>
> void
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..3a5b6b72be9 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> + is, if TYPE is not an array, structure or union.
> +
> + Note that reference types are always considered simple by this function, even
> + if the referenced type is non-scalar. This behaviour is retained for backwards
> + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> + references to non-scalar values. */
> +
> +extern bool mi_simple_type_p (struct type *type);
> +
> +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> +
> +extern bool mi_print_type_p (struct type *type, enum print_values values);
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..9bb00390370 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2462,14 +2463,14 @@ static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
>
> expression_up expr = parse_expression (expression);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> val = evaluate_type (expr.get ());
> else
> val = evaluate_expression (expr.get ());
> @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (mi_print_type_p (value_type (val), values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref = 1;
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] = "--no-values";
> +static const char mi_scalar_values[] = "--scalar-values";
> static const char mi_simple_values[] = "--simple-values";
> static const char mi_all_values[] = "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") == 0
> || strcmp (name, mi_simple_values) == 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") == 0
> + || strcmp (name, mi_scalar_values) == 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..e295036f46e 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> enum ext_lang_frame_args args_type,
> const struct language_defn *language)
> {
> - int should_print = 0;
> + int should_print;
>
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES
> - || args_type == MI_PRINT_ALL_VALUES)
> + switch (args_type)
> {
> - struct type *type = check_typedef (value_type (val));
> -
> - 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)
> - should_print = 1;
> + case NO_VALUES:
> + should_print = 0;
> + break;
> + default:
> + case MI_PRINT_ALL_VALUES:
> + should_print = 1;
> + break;
> + case MI_PRINT_SIMPLE_VALUES:
> + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> + break;
> + case MI_PRINT_SCALAR_VALUES:
> + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> + break;
> }
> - else if (args_type != NO_VALUES)
> - should_print = 1;
>
> if (should_print)
> {
> @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for simple and scalar values. This
> + seems weird, but this is how MI chooses to format the various output
> types. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> + if ((args_type == MI_PRINT_SIMPLE_VALUES
> + || args_type == MI_PRINT_SCALAR_VALUES)
> + && val != NULL)
> py_print_type (out, val);
>
> if (val != NULL)
> @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" = ");
>
> - if (args_type == MI_PRINT_SIMPLE_VALUES)
> + if (args_type == MI_PRINT_SIMPLE_VALUES
> + || args_type == MI_PRINT_SCALAR_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index d04c8153c65..2c74da00c18 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments --simple-values 1 1
> + # -stack-list-arguments 3 1 1
> + # -stack-list-arguments --scalar-values 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing 2 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing 3 1 1"
> +
> + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing --scalar-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> "stack locals listing of names and values"
>
> - mi_gdb_test "232-stack-list-locals --simple-values" \
> + mi_gdb_test "232-stack-list-locals 2" \
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
>
> + mi_gdb_test "232-stack-list-locals --simple-values" \
> + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> + "stack locals listing with --simple-values"
> +
> + mi_gdb_test "233-stack-list-locals 3" \
> + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise: names and types"
> +
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> + "stack locals listing with --scalar-values"
> +
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> new file mode 100644
> index 00000000000..b52683d1537
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-values.cc
> @@ -0,0 +1,63 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> +
> + In the function f:
> +
> + * The arguments i, ir, and irr are ints or references to ints,
> + which must be printed by both PRINT_SIMPLE_VALUES and
> + PRINT_SCALAR_VALUES.
> +
> + * The arguments a, s, and u are non-scalar values, which must not
> + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> +
> + * The arguments ar, arr, sr, srr, ur, and urr are references to
> + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> + but not printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> new file mode 100644
> index 00000000000..7896d773119
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-values.exp
> @@ -0,0 +1,53 @@
> +# Copyright 2022 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> +#
> +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> +# types, except for C++ reference and rvalue reference types.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +
> +if { [skip_cplus_tests] } { continue }
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --simple-values" \
> + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> +
> +mi_gdb_exit
> diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> index 344067fe4a7..fa4e559e343 100644
> --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> "stack-list-arguments --no-frame-filters 2"
>
> +mi_gdb_test "-stack-list-arguments 3" \
> + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments 3"
> +
> +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments --no-frame-filters 3"
> +
>
> mi_gdb_test "-stack-list-arguments 2 0 3" \
> "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> "stack-list-arguments --no-frame-filters 2 22 27"
>
> +mi_gdb_test "-stack-list-arguments 3 22 27" \
> + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments 3 22 27"
> +
> +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments --no-frame-filters 3 22 27"
> +
> #stack-list-locals
> mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> "stack-list-locals --no-frame-filters 2"
>
> +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> + "stack-list-locals --no-frame-filters 3"
> +
> mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> "stack-list-locals --no-frame-filters --no-values"
> @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> "stack-list-locals --no-frame-filters --simple-values"
>
> +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> + "stack-list-locals --no-frame-filters --scalar-values"
> +
> mi_gdb_test "-stack-list-locals 0" \
> "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> "stack-list-locals 0"
> @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> "stack-list-locals 2"
>
> +mi_gdb_test "-stack-list-locals 3" \
> + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> + "stack-list-locals 3"
> +
> # stack-list-variables
> mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> --
> 2.26.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-11-03 16:20 ` [PING] " Gareth Rees
@ 2022-11-14 9:25 ` Gareth Rees
2022-12-01 13:41 ` Gareth Rees
` (4 subsequent siblings)
5 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-11-14 9:25 UTC (permalink / raw)
To: gdb-patches
Ping.
On Thu, 3 Nov 2022 at 16:20, Gareth Rees <grees@undo.io> wrote:
> After four rounds of review, this must be getting close to being
> mergeable! But do let me know if there's anything else that I need to
> improve here.
>
>
> On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
> >
> > 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 that can be fixed.
> >
> > 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> > backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> > for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> > commands. This option prints the value only for scalars and so matches
> > the behaviour of the 'scalars' argument to the 'set print
> > frame-arguments' command. References to structures are not scalars,
> > and so the option is suitable for use by IDEs.
> >
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> > ---
> > gdb/NEWS | 9 +++
> > gdb/doc/gdb.texinfo | 59 ++++++++++-------
> > gdb/extension.h | 3 +
> > gdb/mi/mi-cmd-stack.c | 16 ++---
> > gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> > gdb/mi/mi-cmds.h | 17 ++++-
> > gdb/mi/mi-main.c | 35 ++++-------
> > gdb/mi/mi-parse.c | 8 ++-
> > gdb/python/py-framefilter.c | 40 ++++++------
> > gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> > gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> > .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> > 13 files changed, 323 insertions(+), 90 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index dee0ac2ecd8..9ad441691ea 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
> > + can be verified by using the '-list-features' command, which
> > + now includes "scalar-values".
> > +
> > * New targets
> >
> > GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 238a49b027d..b2b53de1022 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> > @var{high-frame} may be larger than the actual number of frames, in
> > which case only existing frames will be returned.
> >
> > -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +If @var{print-values} is 0 or @code{--no-values}, print only the names
> > +of the variables; if it is 1 or @code{--all-values}, print also their
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. If the option @code{--no-frame-filters} is supplied, then
> > +Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, arguments that
> > are not available are not listed. Partially available arguments
> > @@ -33549,13 +33551,15 @@ Show a single frame:
> > Display the local variable names for the selected frame. If
> > @var{print-values} is 0 or @code{--no-values}, print only the names of
> > the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. In this last case, a frontend can immediately
> > -display the value of simple data types and create variable objects for
> > -other data types when the user wishes to explore their values in
> > -more detail. If the option @code{--no-frame-filters} is supplied, then
> > -Python frame filters will not be executed.
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. In the last two cases, a frontend can immediately display
> > +the value of simple or scalar data types and create variable objects
> > +for other data types when the user wishes to explore their values in
> > +more detail. If the option @code{--no-frame-filters} is supplied,
> > +then Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > that are not available are not listed. Partially available local
> > @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> > -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> > @end smallexample
> >
> > -Display the names of local variables and function arguments for the selected frame. If
> > -@var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +Display the names of local variables and function arguments for the
> > +selected frame. If @var{print-values} is 0 or @code{--no-values},
> > +print only the names of the variables; if it is 1 or
> > +@code{--all-values}, print also their values; if it is 2 or
> > +@code{--simple-values}, print the name, type and value for simple data
> > +types, and the name and type for arrays, structures and unions; and if
> > +it is 3 or @code{--scalar-values}, print the name, type and value for
> > +scalar data types, and the name and type otherwise. If the option
> > +@code{--no-frame-filters} is supplied, then Python frame filters will
> > +not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > and arguments that are not available are not listed. Partially
> > @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> > a single argument or if @var{print-values} has a value of 0 or
> > @code{--no-values}, print only the names of the variables; if
> > @var{print-values} is 1 or @code{--all-values}, also print their
> > -values; and if it is 2 or @code{--simple-values} print the name and
> > -value for simple data types and just the name for arrays, structures
> > -and unions.
> > +values; if it is 2 or @code{--simple-values} print the name and value
> > +for simple data types and just the name for arrays, structures and
> > +unions; and if it is 3 or @code{--scalar-values}, print the name and
> > +value for scalar data types, and just the name otherwise.
> >
> > @var{from} and @var{to}, if specified, indicate the range of children
> > to report. If @var{from} or @var{to} is less than zero, the range is
> > @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item scalar-values
> > +Indicates that the @code{-stack-list-arguments},
> > +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> > +@code{-var-list-children} commands support the
> > +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> > @end ftable
> >
> > @subheading The @code{-list-target-features} Command
> > diff --git a/gdb/extension.h b/gdb/extension.h
> > index 47839ea50be..16d12f00f41 100644
> > --- a/gdb/extension.h
> > +++ b/gdb/extension.h
> > @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> > arguments when invoked from the MI. */
> > MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
> >
> > + /* Print only scalar values for arguments when invoked from the MI. */
> > + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> > +
> > /* Print only scalar values for arguments when invoked from the CLI. */
> > CLI_SCALAR_VALUES,
> >
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 0fe204dbc66..43eea32e460 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> > && arg->error == NULL)
> > || values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES
> > || (values == PRINT_ALL_VALUES
> > && (arg->val != NULL || arg->error != NULL)));
> > gdb_assert (arg->entry_kind == print_entry_values_no
> > @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > if (what == all && arg->sym->is_argument ())
> > uiout->field_signed ("arg", 1);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > {
> > check_typedef (arg->sym->type ());
> > type_print (arg->sym->type (), "", &stb, -1);
> > @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > const struct block *block;
> > struct symbol *sym;
> > struct block_iterator iter;
> > - struct type *type;
> > const char *name_of_result;
> > struct ui_out *uiout = current_uiout;
> >
> > @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > entryarg.sym = sym2;
> > entryarg.entry_kind = print_entry_values_no;
> >
> > - switch (values)
> > + if (mi_print_type_p (sym->type (), values))
> > {
> > - case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (sym2->type ());
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - case PRINT_ALL_VALUES:
> > if (sym->is_argument ())
> > read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> > else
> > read_frame_local (sym2, fi, &arg);
> > - }
> > - break;
> > }
> >
> > if (arg.entry_kind != print_entry_values_only)
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 3db09cf7815..1d4d3ec8534 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -32,6 +32,7 @@
> > #include "mi-parse.h"
> > #include "gdbsupport/gdb_optional.h"
> > #include "inferior.h"
> > +#include "valprint.h"
> >
> > static void varobj_update_one (struct varobj *var,
> > enum print_values print_values,
> > @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> > uiout->field_signed ("numchild", varobj_get_num_children (var));
> > }
> >
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > + }
> > +}
> > +
> > +bool
> > +mi_print_type_p (struct type *type, enum print_values print_values)
> > +{
> > + switch (print_values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_type_p (type);
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (type);
> > + }
> > +}
> > +
> > /* Return 1 if given the argument PRINT_VALUES we should display
> > the varobj VAR. */
> >
> > @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > -
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > - }
> > + return mi_print_type_p (type, print_values);
> > }
> >
> > void
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 9ffb11bf997..3a5b6b72be9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -29,7 +29,8 @@
> > enum print_values {
> > PRINT_NO_VALUES,
> > PRINT_ALL_VALUES,
> > - PRINT_SIMPLE_VALUES
> > + PRINT_SIMPLE_VALUES,
> > + PRINT_SCALAR_VALUES
> > };
> >
> > typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> > @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> > + is, if TYPE is not an array, structure or union.
> > +
> > + Note that reference types are always considered simple by this function, even
> > + if the referenced type is non-scalar. This behaviour is retained for backwards
> > + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> > + references to non-scalar values. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> > +
> > +extern bool mi_print_type_p (struct type *type, enum print_values values);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index b758f398e2a..9bb00390370 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "scalar-values");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2462,14 +2463,14 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> >
> > expression_up expr = parse_expression (expression);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > val = evaluate_type (expr.get ());
> > else
> > val = evaluate_expression (expr.get ());
> > @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > type_print (value_type (val), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - struct value_print_options opts;
> > -
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > break;
> > - case PRINT_ALL_VALUES:
> > - {
> > - struct value_print_options opts;
> > + }
> >
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > - break;
> > + if (mi_print_type_p (value_type (val), values))
> > + {
> > + struct value_print_options opts;
> > + get_no_prettyformat_print_options (&opts);
> > + opts.deref_ref = 1;
> > + common_val_print (val, &stb, 0, &opts, current_language);
> > + uiout->field_stream ("value", stb);
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index dfa7b462714..dd70e4648a1 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -29,6 +29,7 @@
> > #include "language.h"
> >
> > static const char mi_no_values[] = "--no-values";
> > +static const char mi_scalar_values[] = "--scalar-values";
> > static const char mi_simple_values[] = "--simple-values";
> > static const char mi_all_values[] = "--all-values";
> >
> > @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> > else if (strcmp (name, "2") == 0
> > || strcmp (name, mi_simple_values) == 0)
> > return PRINT_SIMPLE_VALUES;
> > + else if (strcmp (name, "3") == 0
> > + || strcmp (name, mi_scalar_values) == 0)
> > + return PRINT_SCALAR_VALUES;
> > else
> > error (_("Unknown value for PRINT_VALUES: must be: \
> > -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> > - mi_no_values, mi_all_values, mi_simple_values);
> > +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> > + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> > }
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 366f3745b9d..e295036f46e 100644
> > --- a/gdb/python/py-framefilter.c
> > +++ b/gdb/python/py-framefilter.c
> > @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> > enum ext_lang_frame_args args_type,
> > const struct language_defn *language)
> > {
> > - int should_print = 0;
> > + int should_print;
> >
> > /* MI does not print certain values, differentiated by type,
> > depending on what ARGS_TYPE indicates. Test type against option.
> > For CLI print all values. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES
> > - || args_type == MI_PRINT_ALL_VALUES)
> > + switch (args_type)
> > {
> > - struct type *type = check_typedef (value_type (val));
> > -
> > - 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)
> > - should_print = 1;
> > + case NO_VALUES:
> > + should_print = 0;
> > + break;
> > + default:
> > + case MI_PRINT_ALL_VALUES:
> > + should_print = 1;
> > + break;
> > + case MI_PRINT_SIMPLE_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> > + break;
> > + case MI_PRINT_SCALAR_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> > + break;
> > }
> > - else if (args_type != NO_VALUES)
> > - should_print = 1;
> >
> > if (should_print)
> > {
> > @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> > if (print_args_field)
> > out->field_signed ("arg", 1);
> >
> > - /* For MI print the type, but only for simple values. This seems
> > - weird, but this is how MI choose to format the various output
> > + /* For MI print the type, but only for simple and scalar values. This
> > + seems weird, but this is how MI chooses to format the various output
> > types. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> > + if ((args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > + && val != NULL)
> > py_print_type (out, val);
> >
> > if (val != NULL)
> > @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> > out->field_string ("name", sym_name.get ());
> > out->text (" = ");
> >
> > - if (args_type == MI_PRINT_SIMPLE_VALUES)
> > + if (args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > py_print_type (out, val);
> >
> > /* CLI always prints values for locals. MI uses the
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index d04c8153c65..2c74da00c18 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> > + # -stack-list-arguments 3 1 1
> > + # -stack-list-arguments --scalar-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > +
> > + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> > + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 3 1 1"
> > +
> > + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> > + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --scalar-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> > + # -stack-list-locals 3 (--scalar-values)
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > - mi_gdb_test "232-stack-list-locals --simple-values" \
> > + mi_gdb_test "232-stack-list-locals 2" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> >
> > + mi_gdb_test "232-stack-list-locals --simple-values" \
> > + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --simple-values"
> > +
> > + mi_gdb_test "233-stack-list-locals 3" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing, scalar types: names and values, otherwise: names and types"
> > +
> > + mi_gdb_test "233-stack-list-locals --scalar-values" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --scalar-values"
> > +
> > mi_gdb_test "234-stack-list-locals" \
> > "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> > "stack locals listing wrong"
> > diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> > new file mode 100644
> > index 00000000000..b52683d1537
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.cc
> > @@ -0,0 +1,63 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints,
> > + which must be printed by both PRINT_SIMPLE_VALUES and
> > + PRINT_SCALAR_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not
> > + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> > + but not printed by PRINT_SCALAR_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> > new file mode 100644
> > index 00000000000..7896d773119
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> > +# types, except for C++ reference and rvalue reference types.
> > +#
> > +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> > +# types, including C++ reference and rvalue reference types.
> > +
> > +if { [skip_cplus_tests] } { continue }
> > +
> > +load_lib mi-support.exp
> > +standard_testfile .cc
> > +
> > +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> > + untested "failed to compile"
> > + return -1
> > +}
> > +
> > +mi_clean_restart $binfile
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> > +
> > +mi_gdb_test "-stack-list-arguments --scalar-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> > +
> > +mi_gdb_exit
> > diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > index 344067fe4a7..fa4e559e343 100644
> > --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-arguments 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3"
> > +
> >
> > mi_gdb_test "-stack-list-arguments 2 0 3" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> > @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> > "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2 22 27"
> >
> > +mi_gdb_test "-stack-list-arguments 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3 22 27"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3 22 27"
> > +
> > #stack-list-locals
> > mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters 3"
> > +
> > mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals --no-frame-filters --no-values"
> > @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters --simple-values"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters --scalar-values"
> > +
> > mi_gdb_test "-stack-list-locals 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals 0"
> > @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals 2"
> >
> > +mi_gdb_test "-stack-list-locals 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals 3"
> > +
> > # stack-list-variables
> > mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> > "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-11-03 16:20 ` [PING] " Gareth Rees
2022-11-14 9:25 ` Gareth Rees
@ 2022-12-01 13:41 ` Gareth Rees
2022-12-14 8:50 ` Gareth Rees
` (3 subsequent siblings)
5 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-12-01 13:41 UTC (permalink / raw)
To: gdb-patches
Is there anything I can do to help progress this?
On Thu, 3 Nov 2022 at 16:20, Gareth Rees <grees@undo.io> wrote:
>
> After four rounds of review, this must be getting close to being
> mergeable! But do let me know if there's anything else that I need to
> improve here.
>
>
> On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
> >
> > 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 that can be fixed.
> >
> > 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> > backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> > for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> > commands. This option prints the value only for scalars and so matches
> > the behaviour of the 'scalars' argument to the 'set print
> > frame-arguments' command. References to structures are not scalars,
> > and so the option is suitable for use by IDEs.
> >
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> > ---
> > gdb/NEWS | 9 +++
> > gdb/doc/gdb.texinfo | 59 ++++++++++-------
> > gdb/extension.h | 3 +
> > gdb/mi/mi-cmd-stack.c | 16 ++---
> > gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> > gdb/mi/mi-cmds.h | 17 ++++-
> > gdb/mi/mi-main.c | 35 ++++-------
> > gdb/mi/mi-parse.c | 8 ++-
> > gdb/python/py-framefilter.c | 40 ++++++------
> > gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> > gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> > .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> > 13 files changed, 323 insertions(+), 90 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index dee0ac2ecd8..9ad441691ea 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
> > + can be verified by using the '-list-features' command, which
> > + now includes "scalar-values".
> > +
> > * New targets
> >
> > GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 238a49b027d..b2b53de1022 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> > @var{high-frame} may be larger than the actual number of frames, in
> > which case only existing frames will be returned.
> >
> > -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +If @var{print-values} is 0 or @code{--no-values}, print only the names
> > +of the variables; if it is 1 or @code{--all-values}, print also their
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. If the option @code{--no-frame-filters} is supplied, then
> > +Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, arguments that
> > are not available are not listed. Partially available arguments
> > @@ -33549,13 +33551,15 @@ Show a single frame:
> > Display the local variable names for the selected frame. If
> > @var{print-values} is 0 or @code{--no-values}, print only the names of
> > the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. In this last case, a frontend can immediately
> > -display the value of simple data types and create variable objects for
> > -other data types when the user wishes to explore their values in
> > -more detail. If the option @code{--no-frame-filters} is supplied, then
> > -Python frame filters will not be executed.
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. In the last two cases, a frontend can immediately display
> > +the value of simple or scalar data types and create variable objects
> > +for other data types when the user wishes to explore their values in
> > +more detail. If the option @code{--no-frame-filters} is supplied,
> > +then Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > that are not available are not listed. Partially available local
> > @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> > -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> > @end smallexample
> >
> > -Display the names of local variables and function arguments for the selected frame. If
> > -@var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +Display the names of local variables and function arguments for the
> > +selected frame. If @var{print-values} is 0 or @code{--no-values},
> > +print only the names of the variables; if it is 1 or
> > +@code{--all-values}, print also their values; if it is 2 or
> > +@code{--simple-values}, print the name, type and value for simple data
> > +types, and the name and type for arrays, structures and unions; and if
> > +it is 3 or @code{--scalar-values}, print the name, type and value for
> > +scalar data types, and the name and type otherwise. If the option
> > +@code{--no-frame-filters} is supplied, then Python frame filters will
> > +not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > and arguments that are not available are not listed. Partially
> > @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> > a single argument or if @var{print-values} has a value of 0 or
> > @code{--no-values}, print only the names of the variables; if
> > @var{print-values} is 1 or @code{--all-values}, also print their
> > -values; and if it is 2 or @code{--simple-values} print the name and
> > -value for simple data types and just the name for arrays, structures
> > -and unions.
> > +values; if it is 2 or @code{--simple-values} print the name and value
> > +for simple data types and just the name for arrays, structures and
> > +unions; and if it is 3 or @code{--scalar-values}, print the name and
> > +value for scalar data types, and just the name otherwise.
> >
> > @var{from} and @var{to}, if specified, indicate the range of children
> > to report. If @var{from} or @var{to} is less than zero, the range is
> > @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item scalar-values
> > +Indicates that the @code{-stack-list-arguments},
> > +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> > +@code{-var-list-children} commands support the
> > +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> > @end ftable
> >
> > @subheading The @code{-list-target-features} Command
> > diff --git a/gdb/extension.h b/gdb/extension.h
> > index 47839ea50be..16d12f00f41 100644
> > --- a/gdb/extension.h
> > +++ b/gdb/extension.h
> > @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> > arguments when invoked from the MI. */
> > MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
> >
> > + /* Print only scalar values for arguments when invoked from the MI. */
> > + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> > +
> > /* Print only scalar values for arguments when invoked from the CLI. */
> > CLI_SCALAR_VALUES,
> >
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 0fe204dbc66..43eea32e460 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> > && arg->error == NULL)
> > || values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES
> > || (values == PRINT_ALL_VALUES
> > && (arg->val != NULL || arg->error != NULL)));
> > gdb_assert (arg->entry_kind == print_entry_values_no
> > @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > if (what == all && arg->sym->is_argument ())
> > uiout->field_signed ("arg", 1);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > {
> > check_typedef (arg->sym->type ());
> > type_print (arg->sym->type (), "", &stb, -1);
> > @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > const struct block *block;
> > struct symbol *sym;
> > struct block_iterator iter;
> > - struct type *type;
> > const char *name_of_result;
> > struct ui_out *uiout = current_uiout;
> >
> > @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > entryarg.sym = sym2;
> > entryarg.entry_kind = print_entry_values_no;
> >
> > - switch (values)
> > + if (mi_print_type_p (sym->type (), values))
> > {
> > - case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (sym2->type ());
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - case PRINT_ALL_VALUES:
> > if (sym->is_argument ())
> > read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> > else
> > read_frame_local (sym2, fi, &arg);
> > - }
> > - break;
> > }
> >
> > if (arg.entry_kind != print_entry_values_only)
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 3db09cf7815..1d4d3ec8534 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -32,6 +32,7 @@
> > #include "mi-parse.h"
> > #include "gdbsupport/gdb_optional.h"
> > #include "inferior.h"
> > +#include "valprint.h"
> >
> > static void varobj_update_one (struct varobj *var,
> > enum print_values print_values,
> > @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> > uiout->field_signed ("numchild", varobj_get_num_children (var));
> > }
> >
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > + }
> > +}
> > +
> > +bool
> > +mi_print_type_p (struct type *type, enum print_values print_values)
> > +{
> > + switch (print_values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_type_p (type);
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (type);
> > + }
> > +}
> > +
> > /* Return 1 if given the argument PRINT_VALUES we should display
> > the varobj VAR. */
> >
> > @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > -
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > - }
> > + return mi_print_type_p (type, print_values);
> > }
> >
> > void
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 9ffb11bf997..3a5b6b72be9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -29,7 +29,8 @@
> > enum print_values {
> > PRINT_NO_VALUES,
> > PRINT_ALL_VALUES,
> > - PRINT_SIMPLE_VALUES
> > + PRINT_SIMPLE_VALUES,
> > + PRINT_SCALAR_VALUES
> > };
> >
> > typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> > @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> > + is, if TYPE is not an array, structure or union.
> > +
> > + Note that reference types are always considered simple by this function, even
> > + if the referenced type is non-scalar. This behaviour is retained for backwards
> > + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> > + references to non-scalar values. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> > +
> > +extern bool mi_print_type_p (struct type *type, enum print_values values);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index b758f398e2a..9bb00390370 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "scalar-values");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2462,14 +2463,14 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> >
> > expression_up expr = parse_expression (expression);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > val = evaluate_type (expr.get ());
> > else
> > val = evaluate_expression (expr.get ());
> > @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > type_print (value_type (val), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - struct value_print_options opts;
> > -
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > break;
> > - case PRINT_ALL_VALUES:
> > - {
> > - struct value_print_options opts;
> > + }
> >
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > - break;
> > + if (mi_print_type_p (value_type (val), values))
> > + {
> > + struct value_print_options opts;
> > + get_no_prettyformat_print_options (&opts);
> > + opts.deref_ref = 1;
> > + common_val_print (val, &stb, 0, &opts, current_language);
> > + uiout->field_stream ("value", stb);
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index dfa7b462714..dd70e4648a1 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -29,6 +29,7 @@
> > #include "language.h"
> >
> > static const char mi_no_values[] = "--no-values";
> > +static const char mi_scalar_values[] = "--scalar-values";
> > static const char mi_simple_values[] = "--simple-values";
> > static const char mi_all_values[] = "--all-values";
> >
> > @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> > else if (strcmp (name, "2") == 0
> > || strcmp (name, mi_simple_values) == 0)
> > return PRINT_SIMPLE_VALUES;
> > + else if (strcmp (name, "3") == 0
> > + || strcmp (name, mi_scalar_values) == 0)
> > + return PRINT_SCALAR_VALUES;
> > else
> > error (_("Unknown value for PRINT_VALUES: must be: \
> > -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> > - mi_no_values, mi_all_values, mi_simple_values);
> > +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> > + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> > }
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 366f3745b9d..e295036f46e 100644
> > --- a/gdb/python/py-framefilter.c
> > +++ b/gdb/python/py-framefilter.c
> > @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> > enum ext_lang_frame_args args_type,
> > const struct language_defn *language)
> > {
> > - int should_print = 0;
> > + int should_print;
> >
> > /* MI does not print certain values, differentiated by type,
> > depending on what ARGS_TYPE indicates. Test type against option.
> > For CLI print all values. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES
> > - || args_type == MI_PRINT_ALL_VALUES)
> > + switch (args_type)
> > {
> > - struct type *type = check_typedef (value_type (val));
> > -
> > - 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)
> > - should_print = 1;
> > + case NO_VALUES:
> > + should_print = 0;
> > + break;
> > + default:
> > + case MI_PRINT_ALL_VALUES:
> > + should_print = 1;
> > + break;
> > + case MI_PRINT_SIMPLE_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> > + break;
> > + case MI_PRINT_SCALAR_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> > + break;
> > }
> > - else if (args_type != NO_VALUES)
> > - should_print = 1;
> >
> > if (should_print)
> > {
> > @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> > if (print_args_field)
> > out->field_signed ("arg", 1);
> >
> > - /* For MI print the type, but only for simple values. This seems
> > - weird, but this is how MI choose to format the various output
> > + /* For MI print the type, but only for simple and scalar values. This
> > + seems weird, but this is how MI chooses to format the various output
> > types. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> > + if ((args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > + && val != NULL)
> > py_print_type (out, val);
> >
> > if (val != NULL)
> > @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> > out->field_string ("name", sym_name.get ());
> > out->text (" = ");
> >
> > - if (args_type == MI_PRINT_SIMPLE_VALUES)
> > + if (args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > py_print_type (out, val);
> >
> > /* CLI always prints values for locals. MI uses the
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index d04c8153c65..2c74da00c18 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> > + # -stack-list-arguments 3 1 1
> > + # -stack-list-arguments --scalar-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > +
> > + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> > + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 3 1 1"
> > +
> > + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> > + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --scalar-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> > + # -stack-list-locals 3 (--scalar-values)
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > - mi_gdb_test "232-stack-list-locals --simple-values" \
> > + mi_gdb_test "232-stack-list-locals 2" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> >
> > + mi_gdb_test "232-stack-list-locals --simple-values" \
> > + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --simple-values"
> > +
> > + mi_gdb_test "233-stack-list-locals 3" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing, scalar types: names and values, otherwise: names and types"
> > +
> > + mi_gdb_test "233-stack-list-locals --scalar-values" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --scalar-values"
> > +
> > mi_gdb_test "234-stack-list-locals" \
> > "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> > "stack locals listing wrong"
> > diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> > new file mode 100644
> > index 00000000000..b52683d1537
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.cc
> > @@ -0,0 +1,63 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints,
> > + which must be printed by both PRINT_SIMPLE_VALUES and
> > + PRINT_SCALAR_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not
> > + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> > + but not printed by PRINT_SCALAR_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> > new file mode 100644
> > index 00000000000..7896d773119
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> > +# types, except for C++ reference and rvalue reference types.
> > +#
> > +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> > +# types, including C++ reference and rvalue reference types.
> > +
> > +if { [skip_cplus_tests] } { continue }
> > +
> > +load_lib mi-support.exp
> > +standard_testfile .cc
> > +
> > +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> > + untested "failed to compile"
> > + return -1
> > +}
> > +
> > +mi_clean_restart $binfile
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> > +
> > +mi_gdb_test "-stack-list-arguments --scalar-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> > +
> > +mi_gdb_exit
> > diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > index 344067fe4a7..fa4e559e343 100644
> > --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-arguments 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3"
> > +
> >
> > mi_gdb_test "-stack-list-arguments 2 0 3" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> > @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> > "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2 22 27"
> >
> > +mi_gdb_test "-stack-list-arguments 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3 22 27"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3 22 27"
> > +
> > #stack-list-locals
> > mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters 3"
> > +
> > mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals --no-frame-filters --no-values"
> > @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters --simple-values"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters --scalar-values"
> > +
> > mi_gdb_test "-stack-list-locals 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals 0"
> > @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals 2"
> >
> > +mi_gdb_test "-stack-list-locals 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals 3"
> > +
> > # stack-list-variables
> > mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> > "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-11-03 16:20 ` [PING] " Gareth Rees
2022-11-14 9:25 ` Gareth Rees
2022-12-01 13:41 ` Gareth Rees
@ 2022-12-14 8:50 ` Gareth Rees
2023-02-01 10:00 ` Gareth Rees
` (2 subsequent siblings)
5 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2022-12-14 8:50 UTC (permalink / raw)
To: gdb-patches
Ping.
On Thu, 3 Nov 2022 at 16:20, Gareth Rees <grees@undo.io> wrote:
>
> After four rounds of review, this must be getting close to being
> mergeable! But do let me know if there's anything else that I need to
> improve here.
>
>
> On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
> >
> > 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 that can be fixed.
> >
> > 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> > backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> > for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> > commands. This option prints the value only for scalars and so matches
> > the behaviour of the 'scalars' argument to the 'set print
> > frame-arguments' command. References to structures are not scalars,
> > and so the option is suitable for use by IDEs.
> >
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> > ---
> > gdb/NEWS | 9 +++
> > gdb/doc/gdb.texinfo | 59 ++++++++++-------
> > gdb/extension.h | 3 +
> > gdb/mi/mi-cmd-stack.c | 16 ++---
> > gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> > gdb/mi/mi-cmds.h | 17 ++++-
> > gdb/mi/mi-main.c | 35 ++++-------
> > gdb/mi/mi-parse.c | 8 ++-
> > gdb/python/py-framefilter.c | 40 ++++++------
> > gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> > gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> > .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> > 13 files changed, 323 insertions(+), 90 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index dee0ac2ecd8..9ad441691ea 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
> > + can be verified by using the '-list-features' command, which
> > + now includes "scalar-values".
> > +
> > * New targets
> >
> > GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 238a49b027d..b2b53de1022 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> > @var{high-frame} may be larger than the actual number of frames, in
> > which case only existing frames will be returned.
> >
> > -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +If @var{print-values} is 0 or @code{--no-values}, print only the names
> > +of the variables; if it is 1 or @code{--all-values}, print also their
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. If the option @code{--no-frame-filters} is supplied, then
> > +Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, arguments that
> > are not available are not listed. Partially available arguments
> > @@ -33549,13 +33551,15 @@ Show a single frame:
> > Display the local variable names for the selected frame. If
> > @var{print-values} is 0 or @code{--no-values}, print only the names of
> > the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. In this last case, a frontend can immediately
> > -display the value of simple data types and create variable objects for
> > -other data types when the user wishes to explore their values in
> > -more detail. If the option @code{--no-frame-filters} is supplied, then
> > -Python frame filters will not be executed.
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. In the last two cases, a frontend can immediately display
> > +the value of simple or scalar data types and create variable objects
> > +for other data types when the user wishes to explore their values in
> > +more detail. If the option @code{--no-frame-filters} is supplied,
> > +then Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > that are not available are not listed. Partially available local
> > @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> > -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> > @end smallexample
> >
> > -Display the names of local variables and function arguments for the selected frame. If
> > -@var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +Display the names of local variables and function arguments for the
> > +selected frame. If @var{print-values} is 0 or @code{--no-values},
> > +print only the names of the variables; if it is 1 or
> > +@code{--all-values}, print also their values; if it is 2 or
> > +@code{--simple-values}, print the name, type and value for simple data
> > +types, and the name and type for arrays, structures and unions; and if
> > +it is 3 or @code{--scalar-values}, print the name, type and value for
> > +scalar data types, and the name and type otherwise. If the option
> > +@code{--no-frame-filters} is supplied, then Python frame filters will
> > +not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > and arguments that are not available are not listed. Partially
> > @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> > a single argument or if @var{print-values} has a value of 0 or
> > @code{--no-values}, print only the names of the variables; if
> > @var{print-values} is 1 or @code{--all-values}, also print their
> > -values; and if it is 2 or @code{--simple-values} print the name and
> > -value for simple data types and just the name for arrays, structures
> > -and unions.
> > +values; if it is 2 or @code{--simple-values} print the name and value
> > +for simple data types and just the name for arrays, structures and
> > +unions; and if it is 3 or @code{--scalar-values}, print the name and
> > +value for scalar data types, and just the name otherwise.
> >
> > @var{from} and @var{to}, if specified, indicate the range of children
> > to report. If @var{from} or @var{to} is less than zero, the range is
> > @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item scalar-values
> > +Indicates that the @code{-stack-list-arguments},
> > +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> > +@code{-var-list-children} commands support the
> > +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> > @end ftable
> >
> > @subheading The @code{-list-target-features} Command
> > diff --git a/gdb/extension.h b/gdb/extension.h
> > index 47839ea50be..16d12f00f41 100644
> > --- a/gdb/extension.h
> > +++ b/gdb/extension.h
> > @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> > arguments when invoked from the MI. */
> > MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
> >
> > + /* Print only scalar values for arguments when invoked from the MI. */
> > + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> > +
> > /* Print only scalar values for arguments when invoked from the CLI. */
> > CLI_SCALAR_VALUES,
> >
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 0fe204dbc66..43eea32e460 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> > && arg->error == NULL)
> > || values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES
> > || (values == PRINT_ALL_VALUES
> > && (arg->val != NULL || arg->error != NULL)));
> > gdb_assert (arg->entry_kind == print_entry_values_no
> > @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > if (what == all && arg->sym->is_argument ())
> > uiout->field_signed ("arg", 1);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > {
> > check_typedef (arg->sym->type ());
> > type_print (arg->sym->type (), "", &stb, -1);
> > @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > const struct block *block;
> > struct symbol *sym;
> > struct block_iterator iter;
> > - struct type *type;
> > const char *name_of_result;
> > struct ui_out *uiout = current_uiout;
> >
> > @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > entryarg.sym = sym2;
> > entryarg.entry_kind = print_entry_values_no;
> >
> > - switch (values)
> > + if (mi_print_type_p (sym->type (), values))
> > {
> > - case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (sym2->type ());
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - case PRINT_ALL_VALUES:
> > if (sym->is_argument ())
> > read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> > else
> > read_frame_local (sym2, fi, &arg);
> > - }
> > - break;
> > }
> >
> > if (arg.entry_kind != print_entry_values_only)
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 3db09cf7815..1d4d3ec8534 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -32,6 +32,7 @@
> > #include "mi-parse.h"
> > #include "gdbsupport/gdb_optional.h"
> > #include "inferior.h"
> > +#include "valprint.h"
> >
> > static void varobj_update_one (struct varobj *var,
> > enum print_values print_values,
> > @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> > uiout->field_signed ("numchild", varobj_get_num_children (var));
> > }
> >
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > + }
> > +}
> > +
> > +bool
> > +mi_print_type_p (struct type *type, enum print_values print_values)
> > +{
> > + switch (print_values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_type_p (type);
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (type);
> > + }
> > +}
> > +
> > /* Return 1 if given the argument PRINT_VALUES we should display
> > the varobj VAR. */
> >
> > @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > -
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > - }
> > + return mi_print_type_p (type, print_values);
> > }
> >
> > void
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 9ffb11bf997..3a5b6b72be9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -29,7 +29,8 @@
> > enum print_values {
> > PRINT_NO_VALUES,
> > PRINT_ALL_VALUES,
> > - PRINT_SIMPLE_VALUES
> > + PRINT_SIMPLE_VALUES,
> > + PRINT_SCALAR_VALUES
> > };
> >
> > typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> > @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> > + is, if TYPE is not an array, structure or union.
> > +
> > + Note that reference types are always considered simple by this function, even
> > + if the referenced type is non-scalar. This behaviour is retained for backwards
> > + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> > + references to non-scalar values. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> > +
> > +extern bool mi_print_type_p (struct type *type, enum print_values values);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index b758f398e2a..9bb00390370 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "scalar-values");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2462,14 +2463,14 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> >
> > expression_up expr = parse_expression (expression);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > val = evaluate_type (expr.get ());
> > else
> > val = evaluate_expression (expr.get ());
> > @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > type_print (value_type (val), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - struct value_print_options opts;
> > -
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > break;
> > - case PRINT_ALL_VALUES:
> > - {
> > - struct value_print_options opts;
> > + }
> >
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > - break;
> > + if (mi_print_type_p (value_type (val), values))
> > + {
> > + struct value_print_options opts;
> > + get_no_prettyformat_print_options (&opts);
> > + opts.deref_ref = 1;
> > + common_val_print (val, &stb, 0, &opts, current_language);
> > + uiout->field_stream ("value", stb);
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index dfa7b462714..dd70e4648a1 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -29,6 +29,7 @@
> > #include "language.h"
> >
> > static const char mi_no_values[] = "--no-values";
> > +static const char mi_scalar_values[] = "--scalar-values";
> > static const char mi_simple_values[] = "--simple-values";
> > static const char mi_all_values[] = "--all-values";
> >
> > @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> > else if (strcmp (name, "2") == 0
> > || strcmp (name, mi_simple_values) == 0)
> > return PRINT_SIMPLE_VALUES;
> > + else if (strcmp (name, "3") == 0
> > + || strcmp (name, mi_scalar_values) == 0)
> > + return PRINT_SCALAR_VALUES;
> > else
> > error (_("Unknown value for PRINT_VALUES: must be: \
> > -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> > - mi_no_values, mi_all_values, mi_simple_values);
> > +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> > + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> > }
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 366f3745b9d..e295036f46e 100644
> > --- a/gdb/python/py-framefilter.c
> > +++ b/gdb/python/py-framefilter.c
> > @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> > enum ext_lang_frame_args args_type,
> > const struct language_defn *language)
> > {
> > - int should_print = 0;
> > + int should_print;
> >
> > /* MI does not print certain values, differentiated by type,
> > depending on what ARGS_TYPE indicates. Test type against option.
> > For CLI print all values. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES
> > - || args_type == MI_PRINT_ALL_VALUES)
> > + switch (args_type)
> > {
> > - struct type *type = check_typedef (value_type (val));
> > -
> > - 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)
> > - should_print = 1;
> > + case NO_VALUES:
> > + should_print = 0;
> > + break;
> > + default:
> > + case MI_PRINT_ALL_VALUES:
> > + should_print = 1;
> > + break;
> > + case MI_PRINT_SIMPLE_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> > + break;
> > + case MI_PRINT_SCALAR_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> > + break;
> > }
> > - else if (args_type != NO_VALUES)
> > - should_print = 1;
> >
> > if (should_print)
> > {
> > @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> > if (print_args_field)
> > out->field_signed ("arg", 1);
> >
> > - /* For MI print the type, but only for simple values. This seems
> > - weird, but this is how MI choose to format the various output
> > + /* For MI print the type, but only for simple and scalar values. This
> > + seems weird, but this is how MI chooses to format the various output
> > types. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> > + if ((args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > + && val != NULL)
> > py_print_type (out, val);
> >
> > if (val != NULL)
> > @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> > out->field_string ("name", sym_name.get ());
> > out->text (" = ");
> >
> > - if (args_type == MI_PRINT_SIMPLE_VALUES)
> > + if (args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > py_print_type (out, val);
> >
> > /* CLI always prints values for locals. MI uses the
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index d04c8153c65..2c74da00c18 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> > + # -stack-list-arguments 3 1 1
> > + # -stack-list-arguments --scalar-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > +
> > + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> > + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 3 1 1"
> > +
> > + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> > + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --scalar-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> > + # -stack-list-locals 3 (--scalar-values)
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > - mi_gdb_test "232-stack-list-locals --simple-values" \
> > + mi_gdb_test "232-stack-list-locals 2" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> >
> > + mi_gdb_test "232-stack-list-locals --simple-values" \
> > + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --simple-values"
> > +
> > + mi_gdb_test "233-stack-list-locals 3" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing, scalar types: names and values, otherwise: names and types"
> > +
> > + mi_gdb_test "233-stack-list-locals --scalar-values" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --scalar-values"
> > +
> > mi_gdb_test "234-stack-list-locals" \
> > "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> > "stack locals listing wrong"
> > diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> > new file mode 100644
> > index 00000000000..b52683d1537
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.cc
> > @@ -0,0 +1,63 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints,
> > + which must be printed by both PRINT_SIMPLE_VALUES and
> > + PRINT_SCALAR_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not
> > + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> > + but not printed by PRINT_SCALAR_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> > new file mode 100644
> > index 00000000000..7896d773119
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> > +# types, except for C++ reference and rvalue reference types.
> > +#
> > +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> > +# types, including C++ reference and rvalue reference types.
> > +
> > +if { [skip_cplus_tests] } { continue }
> > +
> > +load_lib mi-support.exp
> > +standard_testfile .cc
> > +
> > +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> > + untested "failed to compile"
> > + return -1
> > +}
> > +
> > +mi_clean_restart $binfile
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> > +
> > +mi_gdb_test "-stack-list-arguments --scalar-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> > +
> > +mi_gdb_exit
> > diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > index 344067fe4a7..fa4e559e343 100644
> > --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-arguments 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3"
> > +
> >
> > mi_gdb_test "-stack-list-arguments 2 0 3" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> > @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> > "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2 22 27"
> >
> > +mi_gdb_test "-stack-list-arguments 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3 22 27"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3 22 27"
> > +
> > #stack-list-locals
> > mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters 3"
> > +
> > mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals --no-frame-filters --no-values"
> > @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters --simple-values"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters --scalar-values"
> > +
> > mi_gdb_test "-stack-list-locals 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals 0"
> > @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals 2"
> >
> > +mi_gdb_test "-stack-list-locals 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals 3"
> > +
> > # stack-list-variables
> > mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> > "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-11-03 16:20 ` [PING] " Gareth Rees
` (2 preceding siblings ...)
2022-12-14 8:50 ` Gareth Rees
@ 2023-02-01 10:00 ` Gareth Rees
2023-02-16 10:08 ` Gareth Rees
2023-03-06 9:52 ` Gareth Rees
5 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-02-01 10:00 UTC (permalink / raw)
To: gdb-patches
Ping.
On Thu, 3 Nov 2022 at 16:20, Gareth Rees <grees@undo.io> wrote:
> After four rounds of review, this must be getting close to being
> mergeable! But do let me know if there's anything else that I need to
> improve here.
>
>
> On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
> >
> > 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 that can be fixed.
> >
> > 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> > backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> > for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> > commands. This option prints the value only for scalars and so matches
> > the behaviour of the 'scalars' argument to the 'set print
> > frame-arguments' command. References to structures are not scalars,
> > and so the option is suitable for use by IDEs.
> >
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> > ---
> > gdb/NEWS | 9 +++
> > gdb/doc/gdb.texinfo | 59 ++++++++++-------
> > gdb/extension.h | 3 +
> > gdb/mi/mi-cmd-stack.c | 16 ++---
> > gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> > gdb/mi/mi-cmds.h | 17 ++++-
> > gdb/mi/mi-main.c | 35 ++++-------
> > gdb/mi/mi-parse.c | 8 ++-
> > gdb/python/py-framefilter.c | 40 ++++++------
> > gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> > gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> > .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> > 13 files changed, 323 insertions(+), 90 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index dee0ac2ecd8..9ad441691ea 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
> > + can be verified by using the '-list-features' command, which
> > + now includes "scalar-values".
> > +
> > * New targets
> >
> > GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 238a49b027d..b2b53de1022 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> > @var{high-frame} may be larger than the actual number of frames, in
> > which case only existing frames will be returned.
> >
> > -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +If @var{print-values} is 0 or @code{--no-values}, print only the names
> > +of the variables; if it is 1 or @code{--all-values}, print also their
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. If the option @code{--no-frame-filters} is supplied, then
> > +Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, arguments that
> > are not available are not listed. Partially available arguments
> > @@ -33549,13 +33551,15 @@ Show a single frame:
> > Display the local variable names for the selected frame. If
> > @var{print-values} is 0 or @code{--no-values}, print only the names of
> > the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. In this last case, a frontend can immediately
> > -display the value of simple data types and create variable objects for
> > -other data types when the user wishes to explore their values in
> > -more detail. If the option @code{--no-frame-filters} is supplied, then
> > -Python frame filters will not be executed.
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. In the last two cases, a frontend can immediately display
> > +the value of simple or scalar data types and create variable objects
> > +for other data types when the user wishes to explore their values in
> > +more detail. If the option @code{--no-frame-filters} is supplied,
> > +then Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > that are not available are not listed. Partially available local
> > @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> > -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> > @end smallexample
> >
> > -Display the names of local variables and function arguments for the selected frame. If
> > -@var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +Display the names of local variables and function arguments for the
> > +selected frame. If @var{print-values} is 0 or @code{--no-values},
> > +print only the names of the variables; if it is 1 or
> > +@code{--all-values}, print also their values; if it is 2 or
> > +@code{--simple-values}, print the name, type and value for simple data
> > +types, and the name and type for arrays, structures and unions; and if
> > +it is 3 or @code{--scalar-values}, print the name, type and value for
> > +scalar data types, and the name and type otherwise. If the option
> > +@code{--no-frame-filters} is supplied, then Python frame filters will
> > +not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > and arguments that are not available are not listed. Partially
> > @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> > a single argument or if @var{print-values} has a value of 0 or
> > @code{--no-values}, print only the names of the variables; if
> > @var{print-values} is 1 or @code{--all-values}, also print their
> > -values; and if it is 2 or @code{--simple-values} print the name and
> > -value for simple data types and just the name for arrays, structures
> > -and unions.
> > +values; if it is 2 or @code{--simple-values} print the name and value
> > +for simple data types and just the name for arrays, structures and
> > +unions; and if it is 3 or @code{--scalar-values}, print the name and
> > +value for scalar data types, and just the name otherwise.
> >
> > @var{from} and @var{to}, if specified, indicate the range of children
> > to report. If @var{from} or @var{to} is less than zero, the range is
> > @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item scalar-values
> > +Indicates that the @code{-stack-list-arguments},
> > +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> > +@code{-var-list-children} commands support the
> > +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> > @end ftable
> >
> > @subheading The @code{-list-target-features} Command
> > diff --git a/gdb/extension.h b/gdb/extension.h
> > index 47839ea50be..16d12f00f41 100644
> > --- a/gdb/extension.h
> > +++ b/gdb/extension.h
> > @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> > arguments when invoked from the MI. */
> > MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
> >
> > + /* Print only scalar values for arguments when invoked from the MI. */
> > + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> > +
> > /* Print only scalar values for arguments when invoked from the CLI. */
> > CLI_SCALAR_VALUES,
> >
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 0fe204dbc66..43eea32e460 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> > && arg->error == NULL)
> > || values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES
> > || (values == PRINT_ALL_VALUES
> > && (arg->val != NULL || arg->error != NULL)));
> > gdb_assert (arg->entry_kind == print_entry_values_no
> > @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > if (what == all && arg->sym->is_argument ())
> > uiout->field_signed ("arg", 1);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > {
> > check_typedef (arg->sym->type ());
> > type_print (arg->sym->type (), "", &stb, -1);
> > @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > const struct block *block;
> > struct symbol *sym;
> > struct block_iterator iter;
> > - struct type *type;
> > const char *name_of_result;
> > struct ui_out *uiout = current_uiout;
> >
> > @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > entryarg.sym = sym2;
> > entryarg.entry_kind = print_entry_values_no;
> >
> > - switch (values)
> > + if (mi_print_type_p (sym->type (), values))
> > {
> > - case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (sym2->type ());
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - case PRINT_ALL_VALUES:
> > if (sym->is_argument ())
> > read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> > else
> > read_frame_local (sym2, fi, &arg);
> > - }
> > - break;
> > }
> >
> > if (arg.entry_kind != print_entry_values_only)
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 3db09cf7815..1d4d3ec8534 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -32,6 +32,7 @@
> > #include "mi-parse.h"
> > #include "gdbsupport/gdb_optional.h"
> > #include "inferior.h"
> > +#include "valprint.h"
> >
> > static void varobj_update_one (struct varobj *var,
> > enum print_values print_values,
> > @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> > uiout->field_signed ("numchild", varobj_get_num_children (var));
> > }
> >
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > + }
> > +}
> > +
> > +bool
> > +mi_print_type_p (struct type *type, enum print_values print_values)
> > +{
> > + switch (print_values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_type_p (type);
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (type);
> > + }
> > +}
> > +
> > /* Return 1 if given the argument PRINT_VALUES we should display
> > the varobj VAR. */
> >
> > @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > -
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > - }
> > + return mi_print_type_p (type, print_values);
> > }
> >
> > void
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 9ffb11bf997..3a5b6b72be9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -29,7 +29,8 @@
> > enum print_values {
> > PRINT_NO_VALUES,
> > PRINT_ALL_VALUES,
> > - PRINT_SIMPLE_VALUES
> > + PRINT_SIMPLE_VALUES,
> > + PRINT_SCALAR_VALUES
> > };
> >
> > typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> > @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> > + is, if TYPE is not an array, structure or union.
> > +
> > + Note that reference types are always considered simple by this function, even
> > + if the referenced type is non-scalar. This behaviour is retained for backwards
> > + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> > + references to non-scalar values. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> > +
> > +extern bool mi_print_type_p (struct type *type, enum print_values values);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index b758f398e2a..9bb00390370 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "scalar-values");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2462,14 +2463,14 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> >
> > expression_up expr = parse_expression (expression);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > val = evaluate_type (expr.get ());
> > else
> > val = evaluate_expression (expr.get ());
> > @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > type_print (value_type (val), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - struct value_print_options opts;
> > -
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > break;
> > - case PRINT_ALL_VALUES:
> > - {
> > - struct value_print_options opts;
> > + }
> >
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > - break;
> > + if (mi_print_type_p (value_type (val), values))
> > + {
> > + struct value_print_options opts;
> > + get_no_prettyformat_print_options (&opts);
> > + opts.deref_ref = 1;
> > + common_val_print (val, &stb, 0, &opts, current_language);
> > + uiout->field_stream ("value", stb);
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index dfa7b462714..dd70e4648a1 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -29,6 +29,7 @@
> > #include "language.h"
> >
> > static const char mi_no_values[] = "--no-values";
> > +static const char mi_scalar_values[] = "--scalar-values";
> > static const char mi_simple_values[] = "--simple-values";
> > static const char mi_all_values[] = "--all-values";
> >
> > @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> > else if (strcmp (name, "2") == 0
> > || strcmp (name, mi_simple_values) == 0)
> > return PRINT_SIMPLE_VALUES;
> > + else if (strcmp (name, "3") == 0
> > + || strcmp (name, mi_scalar_values) == 0)
> > + return PRINT_SCALAR_VALUES;
> > else
> > error (_("Unknown value for PRINT_VALUES: must be: \
> > -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> > - mi_no_values, mi_all_values, mi_simple_values);
> > +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> > + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> > }
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 366f3745b9d..e295036f46e 100644
> > --- a/gdb/python/py-framefilter.c
> > +++ b/gdb/python/py-framefilter.c
> > @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> > enum ext_lang_frame_args args_type,
> > const struct language_defn *language)
> > {
> > - int should_print = 0;
> > + int should_print;
> >
> > /* MI does not print certain values, differentiated by type,
> > depending on what ARGS_TYPE indicates. Test type against option.
> > For CLI print all values. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES
> > - || args_type == MI_PRINT_ALL_VALUES)
> > + switch (args_type)
> > {
> > - struct type *type = check_typedef (value_type (val));
> > -
> > - 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)
> > - should_print = 1;
> > + case NO_VALUES:
> > + should_print = 0;
> > + break;
> > + default:
> > + case MI_PRINT_ALL_VALUES:
> > + should_print = 1;
> > + break;
> > + case MI_PRINT_SIMPLE_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> > + break;
> > + case MI_PRINT_SCALAR_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> > + break;
> > }
> > - else if (args_type != NO_VALUES)
> > - should_print = 1;
> >
> > if (should_print)
> > {
> > @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> > if (print_args_field)
> > out->field_signed ("arg", 1);
> >
> > - /* For MI print the type, but only for simple values. This seems
> > - weird, but this is how MI choose to format the various output
> > + /* For MI print the type, but only for simple and scalar values. This
> > + seems weird, but this is how MI chooses to format the various output
> > types. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> > + if ((args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > + && val != NULL)
> > py_print_type (out, val);
> >
> > if (val != NULL)
> > @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> > out->field_string ("name", sym_name.get ());
> > out->text (" = ");
> >
> > - if (args_type == MI_PRINT_SIMPLE_VALUES)
> > + if (args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > py_print_type (out, val);
> >
> > /* CLI always prints values for locals. MI uses the
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index d04c8153c65..2c74da00c18 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> > + # -stack-list-arguments 3 1 1
> > + # -stack-list-arguments --scalar-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > +
> > + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> > + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 3 1 1"
> > +
> > + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> > + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --scalar-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> > + # -stack-list-locals 3 (--scalar-values)
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > - mi_gdb_test "232-stack-list-locals --simple-values" \
> > + mi_gdb_test "232-stack-list-locals 2" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> >
> > + mi_gdb_test "232-stack-list-locals --simple-values" \
> > + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --simple-values"
> > +
> > + mi_gdb_test "233-stack-list-locals 3" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing, scalar types: names and values, otherwise: names and types"
> > +
> > + mi_gdb_test "233-stack-list-locals --scalar-values" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --scalar-values"
> > +
> > mi_gdb_test "234-stack-list-locals" \
> > "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> > "stack locals listing wrong"
> > diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> > new file mode 100644
> > index 00000000000..b52683d1537
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.cc
> > @@ -0,0 +1,63 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints,
> > + which must be printed by both PRINT_SIMPLE_VALUES and
> > + PRINT_SCALAR_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not
> > + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> > + but not printed by PRINT_SCALAR_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> > new file mode 100644
> > index 00000000000..7896d773119
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> > +# types, except for C++ reference and rvalue reference types.
> > +#
> > +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> > +# types, including C++ reference and rvalue reference types.
> > +
> > +if { [skip_cplus_tests] } { continue }
> > +
> > +load_lib mi-support.exp
> > +standard_testfile .cc
> > +
> > +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> > + untested "failed to compile"
> > + return -1
> > +}
> > +
> > +mi_clean_restart $binfile
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> > +
> > +mi_gdb_test "-stack-list-arguments --scalar-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> > +
> > +mi_gdb_exit
> > diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > index 344067fe4a7..fa4e559e343 100644
> > --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-arguments 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3"
> > +
> >
> > mi_gdb_test "-stack-list-arguments 2 0 3" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> > @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> > "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2 22 27"
> >
> > +mi_gdb_test "-stack-list-arguments 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3 22 27"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3 22 27"
> > +
> > #stack-list-locals
> > mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters 3"
> > +
> > mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals --no-frame-filters --no-values"
> > @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters --simple-values"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters --scalar-values"
> > +
> > mi_gdb_test "-stack-list-locals 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals 0"
> > @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals 2"
> >
> > +mi_gdb_test "-stack-list-locals 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals 3"
> > +
> > # stack-list-variables
> > mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> > "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-11-03 16:20 ` [PING] " Gareth Rees
` (3 preceding siblings ...)
2023-02-01 10:00 ` Gareth Rees
@ 2023-02-16 10:08 ` Gareth Rees
2023-03-06 9:52 ` Gareth Rees
5 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-02-16 10:08 UTC (permalink / raw)
To: gdb-patches
Ping.
On Thu, 3 Nov 2022 at 16:20, Gareth Rees <grees@undo.io> wrote:
>
> After four rounds of review, this must be getting close to being
> mergeable! But do let me know if there's anything else that I need to
> improve here.
>
>
> On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
> >
> > 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 that can be fixed.
> >
> > 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> > backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> > for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> > commands. This option prints the value only for scalars and so matches
> > the behaviour of the 'scalars' argument to the 'set print
> > frame-arguments' command. References to structures are not scalars,
> > and so the option is suitable for use by IDEs.
> >
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> > ---
> > gdb/NEWS | 9 +++
> > gdb/doc/gdb.texinfo | 59 ++++++++++-------
> > gdb/extension.h | 3 +
> > gdb/mi/mi-cmd-stack.c | 16 ++---
> > gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> > gdb/mi/mi-cmds.h | 17 ++++-
> > gdb/mi/mi-main.c | 35 ++++-------
> > gdb/mi/mi-parse.c | 8 ++-
> > gdb/python/py-framefilter.c | 40 ++++++------
> > gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> > gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> > .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> > 13 files changed, 323 insertions(+), 90 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index dee0ac2ecd8..9ad441691ea 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
> > + can be verified by using the '-list-features' command, which
> > + now includes "scalar-values".
> > +
> > * New targets
> >
> > GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 238a49b027d..b2b53de1022 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> > @var{high-frame} may be larger than the actual number of frames, in
> > which case only existing frames will be returned.
> >
> > -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +If @var{print-values} is 0 or @code{--no-values}, print only the names
> > +of the variables; if it is 1 or @code{--all-values}, print also their
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. If the option @code{--no-frame-filters} is supplied, then
> > +Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, arguments that
> > are not available are not listed. Partially available arguments
> > @@ -33549,13 +33551,15 @@ Show a single frame:
> > Display the local variable names for the selected frame. If
> > @var{print-values} is 0 or @code{--no-values}, print only the names of
> > the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. In this last case, a frontend can immediately
> > -display the value of simple data types and create variable objects for
> > -other data types when the user wishes to explore their values in
> > -more detail. If the option @code{--no-frame-filters} is supplied, then
> > -Python frame filters will not be executed.
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. In the last two cases, a frontend can immediately display
> > +the value of simple or scalar data types and create variable objects
> > +for other data types when the user wishes to explore their values in
> > +more detail. If the option @code{--no-frame-filters} is supplied,
> > +then Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > that are not available are not listed. Partially available local
> > @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> > -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> > @end smallexample
> >
> > -Display the names of local variables and function arguments for the selected frame. If
> > -@var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +Display the names of local variables and function arguments for the
> > +selected frame. If @var{print-values} is 0 or @code{--no-values},
> > +print only the names of the variables; if it is 1 or
> > +@code{--all-values}, print also their values; if it is 2 or
> > +@code{--simple-values}, print the name, type and value for simple data
> > +types, and the name and type for arrays, structures and unions; and if
> > +it is 3 or @code{--scalar-values}, print the name, type and value for
> > +scalar data types, and the name and type otherwise. If the option
> > +@code{--no-frame-filters} is supplied, then Python frame filters will
> > +not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > and arguments that are not available are not listed. Partially
> > @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> > a single argument or if @var{print-values} has a value of 0 or
> > @code{--no-values}, print only the names of the variables; if
> > @var{print-values} is 1 or @code{--all-values}, also print their
> > -values; and if it is 2 or @code{--simple-values} print the name and
> > -value for simple data types and just the name for arrays, structures
> > -and unions.
> > +values; if it is 2 or @code{--simple-values} print the name and value
> > +for simple data types and just the name for arrays, structures and
> > +unions; and if it is 3 or @code{--scalar-values}, print the name and
> > +value for scalar data types, and just the name otherwise.
> >
> > @var{from} and @var{to}, if specified, indicate the range of children
> > to report. If @var{from} or @var{to} is less than zero, the range is
> > @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item scalar-values
> > +Indicates that the @code{-stack-list-arguments},
> > +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> > +@code{-var-list-children} commands support the
> > +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> > @end ftable
> >
> > @subheading The @code{-list-target-features} Command
> > diff --git a/gdb/extension.h b/gdb/extension.h
> > index 47839ea50be..16d12f00f41 100644
> > --- a/gdb/extension.h
> > +++ b/gdb/extension.h
> > @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> > arguments when invoked from the MI. */
> > MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
> >
> > + /* Print only scalar values for arguments when invoked from the MI. */
> > + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> > +
> > /* Print only scalar values for arguments when invoked from the CLI. */
> > CLI_SCALAR_VALUES,
> >
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 0fe204dbc66..43eea32e460 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> > && arg->error == NULL)
> > || values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES
> > || (values == PRINT_ALL_VALUES
> > && (arg->val != NULL || arg->error != NULL)));
> > gdb_assert (arg->entry_kind == print_entry_values_no
> > @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > if (what == all && arg->sym->is_argument ())
> > uiout->field_signed ("arg", 1);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > {
> > check_typedef (arg->sym->type ());
> > type_print (arg->sym->type (), "", &stb, -1);
> > @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > const struct block *block;
> > struct symbol *sym;
> > struct block_iterator iter;
> > - struct type *type;
> > const char *name_of_result;
> > struct ui_out *uiout = current_uiout;
> >
> > @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > entryarg.sym = sym2;
> > entryarg.entry_kind = print_entry_values_no;
> >
> > - switch (values)
> > + if (mi_print_type_p (sym->type (), values))
> > {
> > - case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (sym2->type ());
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - case PRINT_ALL_VALUES:
> > if (sym->is_argument ())
> > read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> > else
> > read_frame_local (sym2, fi, &arg);
> > - }
> > - break;
> > }
> >
> > if (arg.entry_kind != print_entry_values_only)
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 3db09cf7815..1d4d3ec8534 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -32,6 +32,7 @@
> > #include "mi-parse.h"
> > #include "gdbsupport/gdb_optional.h"
> > #include "inferior.h"
> > +#include "valprint.h"
> >
> > static void varobj_update_one (struct varobj *var,
> > enum print_values print_values,
> > @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> > uiout->field_signed ("numchild", varobj_get_num_children (var));
> > }
> >
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > + }
> > +}
> > +
> > +bool
> > +mi_print_type_p (struct type *type, enum print_values print_values)
> > +{
> > + switch (print_values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_type_p (type);
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (type);
> > + }
> > +}
> > +
> > /* Return 1 if given the argument PRINT_VALUES we should display
> > the varobj VAR. */
> >
> > @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > -
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > - }
> > + return mi_print_type_p (type, print_values);
> > }
> >
> > void
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 9ffb11bf997..3a5b6b72be9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -29,7 +29,8 @@
> > enum print_values {
> > PRINT_NO_VALUES,
> > PRINT_ALL_VALUES,
> > - PRINT_SIMPLE_VALUES
> > + PRINT_SIMPLE_VALUES,
> > + PRINT_SCALAR_VALUES
> > };
> >
> > typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> > @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> > + is, if TYPE is not an array, structure or union.
> > +
> > + Note that reference types are always considered simple by this function, even
> > + if the referenced type is non-scalar. This behaviour is retained for backwards
> > + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> > + references to non-scalar values. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> > +
> > +extern bool mi_print_type_p (struct type *type, enum print_values values);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index b758f398e2a..9bb00390370 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "scalar-values");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2462,14 +2463,14 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> >
> > expression_up expr = parse_expression (expression);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > val = evaluate_type (expr.get ());
> > else
> > val = evaluate_expression (expr.get ());
> > @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > type_print (value_type (val), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - struct value_print_options opts;
> > -
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > break;
> > - case PRINT_ALL_VALUES:
> > - {
> > - struct value_print_options opts;
> > + }
> >
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > - break;
> > + if (mi_print_type_p (value_type (val), values))
> > + {
> > + struct value_print_options opts;
> > + get_no_prettyformat_print_options (&opts);
> > + opts.deref_ref = 1;
> > + common_val_print (val, &stb, 0, &opts, current_language);
> > + uiout->field_stream ("value", stb);
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index dfa7b462714..dd70e4648a1 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -29,6 +29,7 @@
> > #include "language.h"
> >
> > static const char mi_no_values[] = "--no-values";
> > +static const char mi_scalar_values[] = "--scalar-values";
> > static const char mi_simple_values[] = "--simple-values";
> > static const char mi_all_values[] = "--all-values";
> >
> > @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> > else if (strcmp (name, "2") == 0
> > || strcmp (name, mi_simple_values) == 0)
> > return PRINT_SIMPLE_VALUES;
> > + else if (strcmp (name, "3") == 0
> > + || strcmp (name, mi_scalar_values) == 0)
> > + return PRINT_SCALAR_VALUES;
> > else
> > error (_("Unknown value for PRINT_VALUES: must be: \
> > -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> > - mi_no_values, mi_all_values, mi_simple_values);
> > +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> > + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> > }
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 366f3745b9d..e295036f46e 100644
> > --- a/gdb/python/py-framefilter.c
> > +++ b/gdb/python/py-framefilter.c
> > @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> > enum ext_lang_frame_args args_type,
> > const struct language_defn *language)
> > {
> > - int should_print = 0;
> > + int should_print;
> >
> > /* MI does not print certain values, differentiated by type,
> > depending on what ARGS_TYPE indicates. Test type against option.
> > For CLI print all values. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES
> > - || args_type == MI_PRINT_ALL_VALUES)
> > + switch (args_type)
> > {
> > - struct type *type = check_typedef (value_type (val));
> > -
> > - 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)
> > - should_print = 1;
> > + case NO_VALUES:
> > + should_print = 0;
> > + break;
> > + default:
> > + case MI_PRINT_ALL_VALUES:
> > + should_print = 1;
> > + break;
> > + case MI_PRINT_SIMPLE_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> > + break;
> > + case MI_PRINT_SCALAR_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> > + break;
> > }
> > - else if (args_type != NO_VALUES)
> > - should_print = 1;
> >
> > if (should_print)
> > {
> > @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> > if (print_args_field)
> > out->field_signed ("arg", 1);
> >
> > - /* For MI print the type, but only for simple values. This seems
> > - weird, but this is how MI choose to format the various output
> > + /* For MI print the type, but only for simple and scalar values. This
> > + seems weird, but this is how MI chooses to format the various output
> > types. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> > + if ((args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > + && val != NULL)
> > py_print_type (out, val);
> >
> > if (val != NULL)
> > @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> > out->field_string ("name", sym_name.get ());
> > out->text (" = ");
> >
> > - if (args_type == MI_PRINT_SIMPLE_VALUES)
> > + if (args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > py_print_type (out, val);
> >
> > /* CLI always prints values for locals. MI uses the
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index d04c8153c65..2c74da00c18 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> > + # -stack-list-arguments 3 1 1
> > + # -stack-list-arguments --scalar-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > +
> > + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> > + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 3 1 1"
> > +
> > + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> > + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --scalar-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> > + # -stack-list-locals 3 (--scalar-values)
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > - mi_gdb_test "232-stack-list-locals --simple-values" \
> > + mi_gdb_test "232-stack-list-locals 2" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> >
> > + mi_gdb_test "232-stack-list-locals --simple-values" \
> > + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --simple-values"
> > +
> > + mi_gdb_test "233-stack-list-locals 3" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing, scalar types: names and values, otherwise: names and types"
> > +
> > + mi_gdb_test "233-stack-list-locals --scalar-values" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --scalar-values"
> > +
> > mi_gdb_test "234-stack-list-locals" \
> > "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> > "stack locals listing wrong"
> > diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> > new file mode 100644
> > index 00000000000..b52683d1537
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.cc
> > @@ -0,0 +1,63 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints,
> > + which must be printed by both PRINT_SIMPLE_VALUES and
> > + PRINT_SCALAR_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not
> > + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> > + but not printed by PRINT_SCALAR_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> > new file mode 100644
> > index 00000000000..7896d773119
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> > +# types, except for C++ reference and rvalue reference types.
> > +#
> > +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> > +# types, including C++ reference and rvalue reference types.
> > +
> > +if { [skip_cplus_tests] } { continue }
> > +
> > +load_lib mi-support.exp
> > +standard_testfile .cc
> > +
> > +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> > + untested "failed to compile"
> > + return -1
> > +}
> > +
> > +mi_clean_restart $binfile
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> > +
> > +mi_gdb_test "-stack-list-arguments --scalar-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> > +
> > +mi_gdb_exit
> > diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > index 344067fe4a7..fa4e559e343 100644
> > --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-arguments 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3"
> > +
> >
> > mi_gdb_test "-stack-list-arguments 2 0 3" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> > @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> > "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2 22 27"
> >
> > +mi_gdb_test "-stack-list-arguments 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3 22 27"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3 22 27"
> > +
> > #stack-list-locals
> > mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters 3"
> > +
> > mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals --no-frame-filters --no-values"
> > @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters --simple-values"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters --scalar-values"
> > +
> > mi_gdb_test "-stack-list-locals 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals 0"
> > @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals 2"
> >
> > +mi_gdb_test "-stack-list-locals 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals 3"
> > +
> > # stack-list-variables
> > mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> > "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-11-03 16:20 ` [PING] " Gareth Rees
` (4 preceding siblings ...)
2023-02-16 10:08 ` Gareth Rees
@ 2023-03-06 9:52 ` Gareth Rees
5 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-06 9:52 UTC (permalink / raw)
To: gdb-patches
Ping.
On Thu, 3 Nov 2022 at 16:20, Gareth Rees <grees@undo.io> wrote:
>
> After four rounds of review, this must be getting close to being
> mergeable! But do let me know if there's anything else that I need to
> improve here.
>
>
> On Thu, 20 Oct 2022 at 18:47, Gareth Rees <grees@undo.io> wrote:
> >
> > 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 that can be fixed.
> >
> > 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> > backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> > for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> > commands. This option prints the value only for scalars and so matches
> > the behaviour of the 'scalars' argument to the 'set print
> > frame-arguments' command. References to structures are not scalars,
> > and so the option is suitable for use by IDEs.
> >
> > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> > ---
> > gdb/NEWS | 9 +++
> > gdb/doc/gdb.texinfo | 59 ++++++++++-------
> > gdb/extension.h | 3 +
> > gdb/mi/mi-cmd-stack.c | 16 ++---
> > gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> > gdb/mi/mi-cmds.h | 17 ++++-
> > gdb/mi/mi-main.c | 35 ++++-------
> > gdb/mi/mi-parse.c | 8 ++-
> > gdb/python/py-framefilter.c | 40 ++++++------
> > gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> > gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> > .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
> > 13 files changed, 323 insertions(+), 90 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index dee0ac2ecd8..9ad441691ea 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -114,6 +114,15 @@ maintenance info line-table
> > entry corresponds to an address where a breakpoint should be placed
> > to be at the first instruction past a function's prologue.
> >
> > +* MI changes
> > +
> > + ** The '-stack-list-arguments', '-stack-list-locals',
> > + '-stack-list-variables', and '-var-list-children' commands
> > + support the '--scalar-values' option, which requests the command
> > + to print values only for scalar types. Support for this feature
> > + can be verified by using the '-list-features' command, which
> > + now includes "scalar-values".
> > +
> > * New targets
> >
> > GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 238a49b027d..b2b53de1022 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> > @var{high-frame} may be larger than the actual number of frames, in
> > which case only existing frames will be returned.
> >
> > -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +If @var{print-values} is 0 or @code{--no-values}, print only the names
> > +of the variables; if it is 1 or @code{--all-values}, print also their
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. If the option @code{--no-frame-filters} is supplied, then
> > +Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, arguments that
> > are not available are not listed. Partially available arguments
> > @@ -33549,13 +33551,15 @@ Show a single frame:
> > Display the local variable names for the selected frame. If
> > @var{print-values} is 0 or @code{--no-values}, print only the names of
> > the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. In this last case, a frontend can immediately
> > -display the value of simple data types and create variable objects for
> > -other data types when the user wishes to explore their values in
> > -more detail. If the option @code{--no-frame-filters} is supplied, then
> > -Python frame filters will not be executed.
> > +values; if it is 2 or @code{--simple-values}, print the name, type and
> > +value for simple data types, and the name and type for arrays,
> > +structures and unions; and if it is 3 or @code{--scalar-values}, print
> > +the name, type and value for scalar data types, and the name and type
> > +otherwise. In the last two cases, a frontend can immediately display
> > +the value of simple or scalar data types and create variable objects
> > +for other data types when the user wishes to explore their values in
> > +more detail. If the option @code{--no-frame-filters} is supplied,
> > +then Python frame filters will not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > that are not available are not listed. Partially available local
> > @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> > -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> > @end smallexample
> >
> > -Display the names of local variables and function arguments for the selected frame. If
> > -@var{print-values} is 0 or @code{--no-values}, print only the names of
> > -the variables; if it is 1 or @code{--all-values}, print also their
> > -values; and if it is 2 or @code{--simple-values}, print the name,
> > -type and value for simple data types, and the name and type for arrays,
> > -structures and unions. If the option @code{--no-frame-filters} is
> > -supplied, then Python frame filters will not be executed.
> > +Display the names of local variables and function arguments for the
> > +selected frame. If @var{print-values} is 0 or @code{--no-values},
> > +print only the names of the variables; if it is 1 or
> > +@code{--all-values}, print also their values; if it is 2 or
> > +@code{--simple-values}, print the name, type and value for simple data
> > +types, and the name and type for arrays, structures and unions; and if
> > +it is 3 or @code{--scalar-values}, print the name, type and value for
> > +scalar data types, and the name and type otherwise. If the option
> > +@code{--no-frame-filters} is supplied, then Python frame filters will
> > +not be executed.
> >
> > If the @code{--skip-unavailable} option is specified, local variables
> > and arguments that are not available are not listed. Partially
> > @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> > a single argument or if @var{print-values} has a value of 0 or
> > @code{--no-values}, print only the names of the variables; if
> > @var{print-values} is 1 or @code{--all-values}, also print their
> > -values; and if it is 2 or @code{--simple-values} print the name and
> > -value for simple data types and just the name for arrays, structures
> > -and unions.
> > +values; if it is 2 or @code{--simple-values} print the name and value
> > +for simple data types and just the name for arrays, structures and
> > +unions; and if it is 3 or @code{--scalar-values}, print the name and
> > +value for scalar data types, and just the name otherwise.
> >
> > @var{from} and @var{to}, if specified, indicate the range of children
> > to report. If @var{from} or @var{to} is less than zero, the range is
> > @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item scalar-values
> > +Indicates that the @code{-stack-list-arguments},
> > +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> > +@code{-var-list-children} commands support the
> > +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> > @end ftable
> >
> > @subheading The @code{-list-target-features} Command
> > diff --git a/gdb/extension.h b/gdb/extension.h
> > index 47839ea50be..16d12f00f41 100644
> > --- a/gdb/extension.h
> > +++ b/gdb/extension.h
> > @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> > arguments when invoked from the MI. */
> > MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
> >
> > + /* Print only scalar values for arguments when invoked from the MI. */
> > + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> > +
> > /* Print only scalar values for arguments when invoked from the CLI. */
> > CLI_SCALAR_VALUES,
> >
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 0fe204dbc66..43eea32e460 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> > && arg->error == NULL)
> > || values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES
> > || (values == PRINT_ALL_VALUES
> > && (arg->val != NULL || arg->error != NULL)));
> > gdb_assert (arg->entry_kind == print_entry_values_no
> > @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> > if (what == all && arg->sym->is_argument ())
> > uiout->field_signed ("arg", 1);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > {
> > check_typedef (arg->sym->type ());
> > type_print (arg->sym->type (), "", &stb, -1);
> > @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > const struct block *block;
> > struct symbol *sym;
> > struct block_iterator iter;
> > - struct type *type;
> > const char *name_of_result;
> > struct ui_out *uiout = current_uiout;
> >
> > @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > entryarg.sym = sym2;
> > entryarg.entry_kind = print_entry_values_no;
> >
> > - switch (values)
> > + if (mi_print_type_p (sym->type (), values))
> > {
> > - case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (sym2->type ());
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - case PRINT_ALL_VALUES:
> > if (sym->is_argument ())
> > read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> > else
> > read_frame_local (sym2, fi, &arg);
> > - }
> > - break;
> > }
> >
> > if (arg.entry_kind != print_entry_values_only)
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index 3db09cf7815..1d4d3ec8534 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -32,6 +32,7 @@
> > #include "mi-parse.h"
> > #include "gdbsupport/gdb_optional.h"
> > #include "inferior.h"
> > +#include "valprint.h"
> >
> > static void varobj_update_one (struct varobj *var,
> > enum print_values print_values,
> > @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> > uiout->field_signed ("numchild", varobj_get_num_children (var));
> > }
> >
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > + }
> > +}
> > +
> > +bool
> > +mi_print_type_p (struct type *type, enum print_values print_values)
> > +{
> > + switch (print_values)
> > + {
> > + default:
> > + case PRINT_NO_VALUES:
> > + return false;
> > + case PRINT_ALL_VALUES:
> > + return true;
> > + case PRINT_SIMPLE_VALUES:
> > + return mi_simple_type_p (type);
> > + case PRINT_SCALAR_VALUES:
> > + return val_print_scalar_type_p (type);
> > + }
> > +}
> > +
> > /* Return 1 if given the argument PRINT_VALUES we should display
> > the varobj VAR. */
> >
> > @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > -
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > - }
> > + return mi_print_type_p (type, print_values);
> > }
> >
> > void
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 9ffb11bf997..3a5b6b72be9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -29,7 +29,8 @@
> > enum print_values {
> > PRINT_NO_VALUES,
> > PRINT_ALL_VALUES,
> > - PRINT_SIMPLE_VALUES
> > + PRINT_SIMPLE_VALUES,
> > + PRINT_SCALAR_VALUES
> > };
> >
> > typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> > @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> > + is, if TYPE is not an array, structure or union.
> > +
> > + Note that reference types are always considered simple by this function, even
> > + if the referenced type is non-scalar. This behaviour is retained for backwards
> > + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> > + references to non-scalar values. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> > +
> > +extern bool mi_print_type_p (struct type *type, enum print_values values);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index b758f398e2a..9bb00390370 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "scalar-values");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2462,14 +2463,14 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> >
> > expression_up expr = parse_expression (expression);
> >
> > - if (values == PRINT_SIMPLE_VALUES)
> > + if (values == PRINT_SIMPLE_VALUES
> > + || values == PRINT_SCALAR_VALUES)
> > val = evaluate_type (expr.get ());
> > else
> > val = evaluate_expression (expr.get ());
> > @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (value_type (val));
> > + case PRINT_SCALAR_VALUES:
> > type_print (value_type (val), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > - {
> > - struct value_print_options opts;
> > -
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > break;
> > - case PRINT_ALL_VALUES:
> > - {
> > - struct value_print_options opts;
> > + }
> >
> > - get_no_prettyformat_print_options (&opts);
> > - opts.deref_ref = 1;
> > - common_val_print (val, &stb, 0, &opts, current_language);
> > - uiout->field_stream ("value", stb);
> > - }
> > - break;
> > + if (mi_print_type_p (value_type (val), values))
> > + {
> > + struct value_print_options opts;
> > + get_no_prettyformat_print_options (&opts);
> > + opts.deref_ref = 1;
> > + common_val_print (val, &stb, 0, &opts, current_language);
> > + uiout->field_stream ("value", stb);
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> > index dfa7b462714..dd70e4648a1 100644
> > --- a/gdb/mi/mi-parse.c
> > +++ b/gdb/mi/mi-parse.c
> > @@ -29,6 +29,7 @@
> > #include "language.h"
> >
> > static const char mi_no_values[] = "--no-values";
> > +static const char mi_scalar_values[] = "--scalar-values";
> > static const char mi_simple_values[] = "--simple-values";
> > static const char mi_all_values[] = "--all-values";
> >
> > @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> > else if (strcmp (name, "2") == 0
> > || strcmp (name, mi_simple_values) == 0)
> > return PRINT_SIMPLE_VALUES;
> > + else if (strcmp (name, "3") == 0
> > + || strcmp (name, mi_scalar_values) == 0)
> > + return PRINT_SCALAR_VALUES;
> > else
> > error (_("Unknown value for PRINT_VALUES: must be: \
> > -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> > - mi_no_values, mi_all_values, mi_simple_values);
> > +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> > + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> > }
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 366f3745b9d..e295036f46e 100644
> > --- a/gdb/python/py-framefilter.c
> > +++ b/gdb/python/py-framefilter.c
> > @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> > enum ext_lang_frame_args args_type,
> > const struct language_defn *language)
> > {
> > - int should_print = 0;
> > + int should_print;
> >
> > /* MI does not print certain values, differentiated by type,
> > depending on what ARGS_TYPE indicates. Test type against option.
> > For CLI print all values. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES
> > - || args_type == MI_PRINT_ALL_VALUES)
> > + switch (args_type)
> > {
> > - struct type *type = check_typedef (value_type (val));
> > -
> > - 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)
> > - should_print = 1;
> > + case NO_VALUES:
> > + should_print = 0;
> > + break;
> > + default:
> > + case MI_PRINT_ALL_VALUES:
> > + should_print = 1;
> > + break;
> > + case MI_PRINT_SIMPLE_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> > + break;
> > + case MI_PRINT_SCALAR_VALUES:
> > + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> > + break;
> > }
> > - else if (args_type != NO_VALUES)
> > - should_print = 1;
> >
> > if (should_print)
> > {
> > @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> > if (print_args_field)
> > out->field_signed ("arg", 1);
> >
> > - /* For MI print the type, but only for simple values. This seems
> > - weird, but this is how MI choose to format the various output
> > + /* For MI print the type, but only for simple and scalar values. This
> > + seems weird, but this is how MI chooses to format the various output
> > types. */
> > - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> > + if ((args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > + && val != NULL)
> > py_print_type (out, val);
> >
> > if (val != NULL)
> > @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> > out->field_string ("name", sym_name.get ());
> > out->text (" = ");
> >
> > - if (args_type == MI_PRINT_SIMPLE_VALUES)
> > + if (args_type == MI_PRINT_SIMPLE_VALUES
> > + || args_type == MI_PRINT_SCALAR_VALUES)
> > py_print_type (out, val);
> >
> > /* CLI always prints values for locals. MI uses the
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index d04c8153c65..2c74da00c18 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> > + # -stack-list-arguments 3 1 1
> > + # -stack-list-arguments --scalar-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > +
> > + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> > + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 3 1 1"
> > +
> > + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> > + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --scalar-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> > + # -stack-list-locals 3 (--scalar-values)
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > - mi_gdb_test "232-stack-list-locals --simple-values" \
> > + mi_gdb_test "232-stack-list-locals 2" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> >
> > + mi_gdb_test "232-stack-list-locals --simple-values" \
> > + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --simple-values"
> > +
> > + mi_gdb_test "233-stack-list-locals 3" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing, scalar types: names and values, otherwise: names and types"
> > +
> > + mi_gdb_test "233-stack-list-locals --scalar-values" \
> > + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> > + "stack locals listing with --scalar-values"
> > +
> > mi_gdb_test "234-stack-list-locals" \
> > "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> > "stack locals listing wrong"
> > diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> > new file mode 100644
> > index 00000000000..b52683d1537
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.cc
> > @@ -0,0 +1,63 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints,
> > + which must be printed by both PRINT_SIMPLE_VALUES and
> > + PRINT_SCALAR_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not
> > + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> > + but not printed by PRINT_SCALAR_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> > new file mode 100644
> > index 00000000000..7896d773119
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> > +# types, except for C++ reference and rvalue reference types.
> > +#
> > +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> > +# types, including C++ reference and rvalue reference types.
> > +
> > +if { [skip_cplus_tests] } { continue }
> > +
> > +load_lib mi-support.exp
> > +standard_testfile .cc
> > +
> > +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> > + untested "failed to compile"
> > + return -1
> > +}
> > +
> > +mi_clean_restart $binfile
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> > +
> > +mi_gdb_test "-stack-list-arguments --scalar-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> > +
> > +mi_gdb_exit
> > diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > index 344067fe4a7..fa4e559e343 100644
> > --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> > @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-arguments 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> > + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3"
> > +
> >
> > mi_gdb_test "-stack-list-arguments 2 0 3" \
> > "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> > @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> > "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > "stack-list-arguments --no-frame-filters 2 22 27"
> >
> > +mi_gdb_test "-stack-list-arguments 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments 3 22 27"
> > +
> > +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> > + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> > + "stack-list-arguments --no-frame-filters 3 22 27"
> > +
> > #stack-list-locals
> > mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters 2"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters 3"
> > +
> > mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals --no-frame-filters --no-values"
> > @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals --no-frame-filters --simple-values"
> >
> > +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals --no-frame-filters --scalar-values"
> > +
> > mi_gdb_test "-stack-list-locals 0" \
> > "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> > "stack-list-locals 0"
> > @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> > "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > "stack-list-locals 2"
> >
> > +mi_gdb_test "-stack-list-locals 3" \
> > + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> > + "stack-list-locals 3"
> > +
> > # stack-list-variables
> > mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> > "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2022-10-20 17:47 ` [PATCH v5] " Gareth Rees
2022-10-20 18:00 ` Eli Zaretskii
2022-11-03 16:20 ` [PING] " Gareth Rees
@ 2023-03-08 12:35 ` Andrew Burgess
2023-03-10 11:04 ` Gareth Rees
2023-03-11 11:49 ` [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
3 siblings, 1 reply; 49+ messages in thread
From: Andrew Burgess @ 2023-03-08 12:35 UTC (permalink / raw)
To: Gareth Rees, gdb-patches
Gareth Rees via Gdb-patches <gdb-patches@sourceware.org> writes:
Hi Gareth,
Thanks for continuing to work on this change, and sorry it's taken so
long to get a new review.
My thoughts are inline below...
> 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 that can be fixed.
>
> 1. If the current behaviour is a bug that can be fixed, 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, or cannot be changed due to
> backwards compatibility concerns, 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 (2), adding a '--scalar-values' option
> for the PRINT-VALUES argument to '-stack-list-arguments' and similar
> commands. This option prints the value only for scalars and so matches
> the behaviour of the 'scalars' argument to the 'set print
> frame-arguments' command. References to structures are not scalars,
> and so the option is suitable for use by IDEs.
I would love to see some more information here about why #2 was selected
over #1.
I know in V1 and V2 you did implement #1, then in V3 you switched to #2.
I saw that Eli preferred #2, but didn't seem to offer any reasons why.
Did you run into some problems implementing #1? Do you think it would
break some MI users?
I'm happy to go with option #2, but I still think option #1 would be a
better choice. It would change IDE behaviour in some cases, but I don't
see why that change would break any IDEs, and I can't imagine how the
current behaviour can be considered the right thing to do.
I suspect what we're really doing here is just collecting more technical
debt; just another option '--simple-values' that nobody ever actually
uses, but which we feel we have to maintain forever "just in case".
>
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29554
> ---
> gdb/NEWS | 9 +++
> gdb/doc/gdb.texinfo | 59 ++++++++++-------
> gdb/extension.h | 3 +
> gdb/mi/mi-cmd-stack.c | 16 ++---
> gdb/mi/mi-cmd-var.c | 45 ++++++++++---
> gdb/mi/mi-cmds.h | 17 ++++-
> gdb/mi/mi-main.c | 35 ++++-------
> gdb/mi/mi-parse.c | 8 ++-
> gdb/python/py-framefilter.c | 40 ++++++------
> gdb/testsuite/gdb.mi/mi-stack.exp | 37 ++++++++++-
> gdb/testsuite/gdb.mi/print-values.cc | 63 +++++++++++++++++++
> gdb/testsuite/gdb.mi/print-values.exp | 53 ++++++++++++++++
> .../gdb.python/py-framefilter-mi.exp | 28 +++++++++
I did get this merged in the end, but I had to manually apply the patch
in some places, GDB has moved on in conflicting (but not seriously so)
ways.
> 13 files changed, 323 insertions(+), 90 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index dee0ac2ecd8..9ad441691ea 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -114,6 +114,15 @@ maintenance info line-table
> entry corresponds to an address where a breakpoint should be placed
> to be at the first instruction past a function's prologue.
>
> +* MI changes
> +
> + ** The '-stack-list-arguments', '-stack-list-locals',
> + '-stack-list-variables', and '-var-list-children' commands
> + support the '--scalar-values' option, which requests the command
> + to print values only for scalar types. Support for this feature
> + can be verified by using the '-list-features' command, which
> + now includes "scalar-values".
> +
> * New targets
>
> GNU/Linux/LoongArch (gdbserver) loongarch*-*-linux*
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 238a49b027d..b2b53de1022 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -33326,12 +33326,14 @@ larger than the actual number of frames. On the other hand,
> @var{high-frame} may be larger than the actual number of frames, in
> which case only existing frames will be returned.
>
> -If @var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +If @var{print-values} is 0 or @code{--no-values}, print only the names
> +of the variables; if it is 1 or @code{--all-values}, print also their
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. If the option @code{--no-frame-filters} is supplied, then
> +Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, arguments that
> are not available are not listed. Partially available arguments
> @@ -33549,13 +33551,15 @@ Show a single frame:
> Display the local variable names for the selected frame. If
> @var{print-values} is 0 or @code{--no-values}, print only the names of
> the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. In this last case, a frontend can immediately
> -display the value of simple data types and create variable objects for
> -other data types when the user wishes to explore their values in
> -more detail. If the option @code{--no-frame-filters} is supplied, then
> -Python frame filters will not be executed.
> +values; if it is 2 or @code{--simple-values}, print the name, type and
> +value for simple data types, and the name and type for arrays,
> +structures and unions; and if it is 3 or @code{--scalar-values}, print
> +the name, type and value for scalar data types, and the name and type
> +otherwise. In the last two cases, a frontend can immediately display
> +the value of simple or scalar data types and create variable objects
> +for other data types when the user wishes to explore their values in
> +more detail. If the option @code{--no-frame-filters} is supplied,
> +then Python frame filters will not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> that are not available are not listed. Partially available local
> @@ -33594,13 +33598,16 @@ This command is deprecated in favor of the
> -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
> @end smallexample
>
> -Display the names of local variables and function arguments for the selected frame. If
> -@var{print-values} is 0 or @code{--no-values}, print only the names of
> -the variables; if it is 1 or @code{--all-values}, print also their
> -values; and if it is 2 or @code{--simple-values}, print the name,
> -type and value for simple data types, and the name and type for arrays,
> -structures and unions. If the option @code{--no-frame-filters} is
> -supplied, then Python frame filters will not be executed.
> +Display the names of local variables and function arguments for the
> +selected frame. If @var{print-values} is 0 or @code{--no-values},
> +print only the names of the variables; if it is 1 or
> +@code{--all-values}, print also their values; if it is 2 or
> +@code{--simple-values}, print the name, type and value for simple data
> +types, and the name and type for arrays, structures and unions; and if
> +it is 3 or @code{--scalar-values}, print the name, type and value for
> +scalar data types, and the name and type otherwise. If the option
> +@code{--no-frame-filters} is supplied, then Python frame filters will
> +not be executed.
>
> If the @code{--skip-unavailable} option is specified, local variables
> and arguments that are not available are not listed. Partially
> @@ -34029,9 +34036,10 @@ create variable objects for them, if they do not already exist. With
> a single argument or if @var{print-values} has a value of 0 or
> @code{--no-values}, print only the names of the variables; if
> @var{print-values} is 1 or @code{--all-values}, also print their
> -values; and if it is 2 or @code{--simple-values} print the name and
> -value for simple data types and just the name for arrays, structures
> -and unions.
> +values; if it is 2 or @code{--simple-values} print the name and value
> +for simple data types and just the name for arrays, structures and
> +unions; and if it is 3 or @code{--scalar-values}, print the name and
> +value for scalar data types, and just the name otherwise.
>
> @var{from} and @var{to}, if specified, indicate the range of children
> to report. If @var{from} or @var{to} is less than zero, the range is
> @@ -37295,6 +37303,11 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item scalar-values
> +Indicates that the @code{-stack-list-arguments},
> +@code{-stack-list-locals}, @code{-stack-list-variables}, and
> +@code{-var-list-children} commands support the
> +@option{--scalar-values} option (@pxref{GDB/MI Stack Manipulation}).
> @end ftable
>
> @subheading The @code{-list-target-features} Command
> diff --git a/gdb/extension.h b/gdb/extension.h
> index 47839ea50be..16d12f00f41 100644
> --- a/gdb/extension.h
> +++ b/gdb/extension.h
> @@ -121,6 +121,9 @@ enum ext_lang_frame_args
> arguments when invoked from the MI. */
> MI_PRINT_SIMPLE_VALUES = PRINT_SIMPLE_VALUES,
>
> + /* Print only scalar values for arguments when invoked from the MI. */
> + MI_PRINT_SCALAR_VALUES = PRINT_SCALAR_VALUES,
> +
> /* Print only scalar values for arguments when invoked from the CLI. */
> CLI_SCALAR_VALUES,
>
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 0fe204dbc66..43eea32e460 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -494,6 +494,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> gdb_assert ((values == PRINT_NO_VALUES && arg->val == NULL
> && arg->error == NULL)
> || values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES
> || (values == PRINT_ALL_VALUES
> && (arg->val != NULL || arg->error != NULL)));
> gdb_assert (arg->entry_kind == print_entry_values_no
> @@ -525,7 +526,8 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
> if (what == all && arg->sym->is_argument ())
> uiout->field_signed ("arg", 1);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> {
> check_typedef (arg->sym->type ());
> type_print (arg->sym->type (), "", &stb, -1);
> @@ -571,7 +573,6 @@ list_args_or_locals (const frame_print_options &fp_opts,
> const struct block *block;
> struct symbol *sym;
> struct block_iterator iter;
> - struct type *type;
> const char *name_of_result;
> struct ui_out *uiout = current_uiout;
>
> @@ -647,21 +648,12 @@ list_args_or_locals (const frame_print_options &fp_opts,
> entryarg.sym = sym2;
> entryarg.entry_kind = print_entry_values_no;
>
> - switch (values)
> + if (mi_print_type_p (sym->type (), values))
> {
> - case PRINT_SIMPLE_VALUES:
> - type = check_typedef (sym2->type ());
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - case PRINT_ALL_VALUES:
> if (sym->is_argument ())
> read_frame_arg (fp_opts, sym2, fi, &arg, &entryarg);
> else
> read_frame_local (sym2, fi, &arg);
> - }
> - break;
> }
>
> if (arg.entry_kind != print_entry_values_only)
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index 3db09cf7815..1d4d3ec8534 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -32,6 +32,7 @@
> #include "mi-parse.h"
> #include "gdbsupport/gdb_optional.h"
> #include "inferior.h"
> +#include "valprint.h"
>
> static void varobj_update_one (struct varobj *var,
> enum print_values print_values,
> @@ -314,6 +315,40 @@ mi_cmd_var_info_num_children (const char *command, char **argv, int argc)
> uiout->field_signed ("numchild", varobj_get_num_children (var));
> }
>
> +/* See mi-cmds.h. */
> +
> +bool
> +mi_simple_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> + }
> +}
This function is only used in mi_print_type_p below, so should be static
in this file.
> +
> +bool
> +mi_print_type_p (struct type *type, enum print_values print_values)
This function needs a '/* See mi-cmds.h. */' comment.
> +{
> + switch (print_values)
> + {
> + default:
> + case PRINT_NO_VALUES:
> + return false;
> + case PRINT_ALL_VALUES:
> + return true;
> + case PRINT_SIMPLE_VALUES:
> + return mi_simple_type_p (type);
> + case PRINT_SCALAR_VALUES:
> + return val_print_scalar_type_p (type);
> + }
> +}
> +
> /* Return 1 if given the argument PRINT_VALUES we should display
> the varobj VAR. */
>
> @@ -335,15 +370,7 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> if (type == NULL)
> return 1;
> else
> - {
> - type = check_typedef (type);
> -
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> - }
> + return mi_print_type_p (type, print_values);
> }
>
> void
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 9ffb11bf997..3a5b6b72be9 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -29,7 +29,8 @@
> enum print_values {
> PRINT_NO_VALUES,
> PRINT_ALL_VALUES,
> - PRINT_SIMPLE_VALUES
> + PRINT_SIMPLE_VALUES,
> + PRINT_SCALAR_VALUES
> };
>
> typedef void (mi_cmd_argv_ftype) (const char *command, char **argv, int argc);
> @@ -226,4 +227,18 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if TYPE is suitable for printing with PRINT_SIMPLE_VALUES: that
> + is, if TYPE is not an array, structure or union.
> +
> + Note that reference types are always considered simple by this function, even
> + if the referenced type is non-scalar. This behaviour is retained for backwards
> + compatibility, and PRINT_SCALAR_VALUES may be used instead to avoid printing
> + references to non-scalar values. */
> +
> +extern bool mi_simple_type_p (struct type *type);
> +
> +/* Return true if TYPE is suitable for printing with PRINT_VALUES. */
> +
> +extern bool mi_print_type_p (struct type *type, enum print_values values);
In the comment s/PRINT_VALUES/VALUES/.
Also, I'm not a fan of the wording, 'printing with' doesn't seem right
to me. How about:
/* Return true if the contents of a value with type TYPE should be
printed when using value printing mode VALUES. Otherwise return
false and the value contents should not be printed. */
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index b758f398e2a..9bb00390370 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1663,6 +1663,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "scalar-values");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2462,14 +2463,14 @@ static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
>
> expression_up expr = parse_expression (expression);
>
> - if (values == PRINT_SIMPLE_VALUES)
> + if (values == PRINT_SIMPLE_VALUES
> + || values == PRINT_SCALAR_VALUES)
> val = evaluate_type (expr.get ());
> else
> val = evaluate_expression (expr.get ());
> @@ -2482,31 +2483,19 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (value_type (val));
> + case PRINT_SCALAR_VALUES:
> type_print (value_type (val), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> - {
> - struct value_print_options opts;
> -
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> break;
> - case PRINT_ALL_VALUES:
> - {
> - struct value_print_options opts;
> + }
>
> - get_no_prettyformat_print_options (&opts);
> - opts.deref_ref = 1;
> - common_val_print (val, &stb, 0, &opts, current_language);
> - uiout->field_stream ("value", stb);
> - }
> - break;
> + if (mi_print_type_p (value_type (val), values))
> + {
> + struct value_print_options opts;
> + get_no_prettyformat_print_options (&opts);
> + opts.deref_ref = 1;
I think deref_ref has changed to a bool recently, so this line needs updating.
> + common_val_print (val, &stb, 0, &opts, current_language);
> + uiout->field_stream ("value", stb);
> }
> }
>
> diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
> index dfa7b462714..dd70e4648a1 100644
> --- a/gdb/mi/mi-parse.c
> +++ b/gdb/mi/mi-parse.c
> @@ -29,6 +29,7 @@
> #include "language.h"
>
> static const char mi_no_values[] = "--no-values";
> +static const char mi_scalar_values[] = "--scalar-values";
> static const char mi_simple_values[] = "--simple-values";
> static const char mi_all_values[] = "--all-values";
>
> @@ -383,8 +384,11 @@ mi_parse_print_values (const char *name)
> else if (strcmp (name, "2") == 0
> || strcmp (name, mi_simple_values) == 0)
> return PRINT_SIMPLE_VALUES;
> + else if (strcmp (name, "3") == 0
> + || strcmp (name, mi_scalar_values) == 0)
> + return PRINT_SCALAR_VALUES;
> else
> error (_("Unknown value for PRINT_VALUES: must be: \
> -0 or \"%s\", 1 or \"%s\", 2 or \"%s\""),
> - mi_no_values, mi_all_values, mi_simple_values);
> +0 or \"%s\", 1 or \"%s\", 2 or \"%s\", 3 or \"%s\""),
> + mi_no_values, mi_all_values, mi_simple_values, mi_scalar_values);
> }
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 366f3745b9d..e295036f46e 100644
> --- a/gdb/python/py-framefilter.c
> +++ b/gdb/python/py-framefilter.c
> @@ -227,26 +227,27 @@ py_print_value (struct ui_out *out, struct value *val,
> enum ext_lang_frame_args args_type,
> const struct language_defn *language)
> {
> - int should_print = 0;
> + int should_print;
>
> /* MI does not print certain values, differentiated by type,
> depending on what ARGS_TYPE indicates. Test type against option.
> For CLI print all values. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES
> - || args_type == MI_PRINT_ALL_VALUES)
> + switch (args_type)
> {
> - struct type *type = check_typedef (value_type (val));
> -
> - 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)
> - should_print = 1;
> + case NO_VALUES:
> + should_print = 0;
> + break;
> + default:
> + case MI_PRINT_ALL_VALUES:
> + should_print = 1;
> + break;
> + case MI_PRINT_SIMPLE_VALUES:
> + should_print = mi_print_type_p (value_type (val), PRINT_SIMPLE_VALUES);
> + break;
> + case MI_PRINT_SCALAR_VALUES:
> + should_print = mi_print_type_p (value_type (val), PRINT_SCALAR_VALUES);
> + break;
> }
> - else if (args_type != NO_VALUES)
> - should_print = 1;
>
> if (should_print)
> {
> @@ -371,10 +372,12 @@ py_print_single_arg (struct ui_out *out,
> if (print_args_field)
> out->field_signed ("arg", 1);
>
> - /* For MI print the type, but only for simple values. This seems
> - weird, but this is how MI choose to format the various output
> + /* For MI print the type, but only for simple and scalar values. This
> + seems weird, but this is how MI chooses to format the various output
> types. */
> - if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
> + if ((args_type == MI_PRINT_SIMPLE_VALUES
> + || args_type == MI_PRINT_SCALAR_VALUES)
> + && val != NULL)
> py_print_type (out, val);
>
> if (val != NULL)
> @@ -603,7 +606,8 @@ enumerate_locals (PyObject *iter,
> out->field_string ("name", sym_name.get ());
> out->text (" = ");
>
> - if (args_type == MI_PRINT_SIMPLE_VALUES)
> + if (args_type == MI_PRINT_SIMPLE_VALUES
> + || args_type == MI_PRINT_SCALAR_VALUES)
> py_print_type (out, val);
>
> /* CLI always prints values for locals. MI uses the
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index d04c8153c65..2c74da00c18 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -93,6 +93,11 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments --simple-values 1 1
> + # -stack-list-arguments 3 1 1
> + # -stack-list-arguments --scalar-values 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -125,6 +130,22 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing 2 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing --simple-values 1 1"
> +
> + mi_gdb_test "238-stack-list-arguments 3 1 1" \
> + "238\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing 3 1 1"
> +
> + mi_gdb_test "239-stack-list-arguments --scalar-values 1 1" \
> + "239\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing --scalar-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -163,7 +184,7 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
> + # -stack-list-locals 3 (--scalar-values)
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -179,10 +200,22 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> "stack locals listing of names and values"
>
> - mi_gdb_test "232-stack-list-locals --simple-values" \
> + mi_gdb_test "232-stack-list-locals 2" \
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
>
> + mi_gdb_test "232-stack-list-locals --simple-values" \
> + "232\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> + "stack locals listing with --simple-values"
> +
> + mi_gdb_test "233-stack-list-locals 3" \
> + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> + "stack locals listing, scalar types: names and values, otherwise: names and types"
> +
> + mi_gdb_test "233-stack-list-locals --scalar-values" \
> + "233\\^done,locals=\\\[\\{name=\"A\",type=\"int\",value=\"1\"\\},\\{name=\"B\",type=\"int\",value=\"2\"\\},\\{name=\"C\",type=\"int\",value=\"3\"\\},\\{name=\"D\",type=\"int \\\[3\\\]\"\\}\\\]" \
> + "stack locals listing with --scalar-values"
> +
> mi_gdb_test "234-stack-list-locals" \
> "234\\^error,msg=\"-stack-list-locals: Usage.*PRINT_VALUES.*\"" \
> "stack locals listing wrong"
> diff --git a/gdb/testsuite/gdb.mi/print-values.cc b/gdb/testsuite/gdb.mi/print-values.cc
> new file mode 100644
> index 00000000000..b52683d1537
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-values.cc
> @@ -0,0 +1,63 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022 Free Software Foundation, Inc.
Copyright year needs updating to 2022-2023.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* Test program for PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> +
> + In the function f:
> +
> + * The arguments i, ir, and irr are ints or references to ints,
> + which must be printed by both PRINT_SIMPLE_VALUES and
> + PRINT_SCALAR_VALUES.
> +
> + * The arguments a, s, and u are non-scalar values, which must not
> + be printed by either PRINT_SIMPLE_VALUES or PRINT_SCALAR_VALUES.
> +
> + * The arguments ar, arr, sr, srr, ur, and urr are references to
> + non-scalar values, which must be printed by PRINT_SIMPLE_VALUES
> + but not printed by PRINT_SCALAR_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-values.exp b/gdb/testsuite/gdb.mi/print-values.exp
> new file mode 100644
> index 00000000000..7896d773119
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-values.exp
> @@ -0,0 +1,53 @@
> +# Copyright 2022 Free Software Foundation, Inc.
Copyright year needs updating to 2022-2023.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test of PRINT_SIMPLE_VALUES and PRINT_SCALAR_VALUES.
> +#
> +# Test that PRINT_SIMPLE_VALUES distinguishes scalar and non-scalar
> +# types, except for C++ reference and rvalue reference types.
> +#
> +# Test that PRINT_SCALAR_VALUES distinguishes scalar and non-scalar
> +# types, including C++ reference and rvalue reference types.
> +
> +if { [skip_cplus_tests] } { continue }
This should now be written:
require allow_cplus_tests
> +
> +load_lib mi-support.exp
> +standard_testfile .cc
> +
> +if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable {debug c++}] != "" } {
> + untested "failed to compile"
> + return -1
> +}
Better I think to use build_executable, like:
if {[build_executable "failed to prepare" $testfile $srcfile {debug c++}]} {
return -1
}
this just calls gdb_compile under the hood, but I think is preferred now
over direct gdb_compile calls.
Thanks,
Andrew
> +
> +mi_clean_restart $binfile
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments --simple-values" \
> + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\",value=\"@$hex: \\{5\\}\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\",value=\"@$hex: \\{6\\}\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\",value=\"@$hex: \\{v = 8\\}\"\\},\\{name=\"srr\",type=\"s &&\",value=\"@$hex: \\{v = 9\\}\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\",value=\"@$hex: \\{v = 11\\}\"\\},\\{name=\"urr\",type=\"u &&\",value=\"@$hex: \\{v = 12\\}\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> + "stack list arguments, simple types: names, types and values, otherwise: names and types"
> +
> +mi_gdb_test "-stack-list-arguments --scalar-values" \
> + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> + "stack list arguments, scalar types: names, types and values, compound types: names and types"
> +
> +mi_gdb_exit
> diff --git a/gdb/testsuite/gdb.python/py-framefilter-mi.exp b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> index 344067fe4a7..fa4e559e343 100644
> --- a/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> +++ b/gdb/testsuite/gdb.python/py-framefilter-mi.exp
> @@ -120,6 +120,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2" \
> "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> "stack-list-arguments --no-frame-filters 2"
>
> +mi_gdb_test "-stack-list-arguments 3" \
> + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"\}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments 3"
> +
> +mi_gdb_test "-stack-list-arguments --no-frame-filters 3" \
> + "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},.*frame={level=\"22\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments --no-frame-filters 3"
> +
>
> mi_gdb_test "-stack-list-arguments 2 0 3" \
> "\\^done,stack-args=\\\[frame={level=\"0\",args=\\\[{name=\"foo\",type=\"int\",value=\"21\"},{name=\"bar\",type=\"char \\\*\",value=\"$hex \\\\\"Param\\\\\"\"},{name=\"fb\",type=\"foobar \\\*\",value=\"$hex\"},{name=\"bf\",type=\"foobar\"}\\\]},frame={level=\"1\",args=\\\[\\\]},frame={level=\"2\",args=\\\[{name=\"j\",type=\"int\",value=\"10\"}\\\]},frame={level=\"3\",args=\\\[\\\]}\\\]" \
> @@ -133,6 +141,14 @@ mi_gdb_test "-stack-list-arguments --no-frame-filters 2 22 27" \
> "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> "stack-list-arguments --no-frame-filters 2 22 27"
>
> +mi_gdb_test "-stack-list-arguments 3 22 27" \
> + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\],children=\\\[frame={level=\"23\",args=\\\[\\\]}\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments 3 22 27"
> +
> +mi_gdb_test "-stack-list-arguments --no-frame-filters 3 22 27" \
> + "\\^done,stack-args=\\\[frame={level=\"22\",args=\\\[\\\]},frame={level=\"23\",args=\\\[\\\]},.*frame={level=\"26\",args=\\\[{name=\"f\",type=\"int\",value=\"3\"},{name=\"d\",type=\"int\",value=\"5\"}\\\]},frame={level=\"27\",args=\\\[\\\]}\\\]" \
> + "stack-list-arguments --no-frame-filters 3 22 27"
> +
> #stack-list-locals
> mi_gdb_test "-stack-list-locals --no-frame-filters 0" \
> "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> @@ -146,6 +162,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters 2" \
> "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> "stack-list-locals --no-frame-filters 2"
>
> +mi_gdb_test "-stack-list-locals --no-frame-filters 3" \
> + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> + "stack-list-locals --no-frame-filters 3"
> +
> mi_gdb_test "-stack-list-locals --no-frame-filters --no-values" \
> "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> "stack-list-locals --no-frame-filters --no-values"
> @@ -158,6 +178,10 @@ mi_gdb_test "-stack-list-locals --no-frame-filters --simple-values" \
> "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> "stack-list-locals --no-frame-filters --simple-values"
>
> +mi_gdb_test "-stack-list-locals --no-frame-filters --scalar-values" \
> + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> + "stack-list-locals --no-frame-filters --scalar-values"
> +
> mi_gdb_test "-stack-list-locals 0" \
> "\\^done,locals=\\\[name=\"str\",name=\"st2\",name=\"b\",name=\"c\"\\\]" \
> "stack-list-locals 0"
> @@ -170,6 +194,10 @@ mi_gdb_test "-stack-list-locals 2" \
> "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> "stack-list-locals 2"
>
> +mi_gdb_test "-stack-list-locals 3" \
> + "\\^done,locals=\\\[{name=\"str\",type=\"const char \\\*\",value=\"$hex \\\\\"The End\\\\\"\"},{name=\"st2\",type=\"const char \\\*\",value=\"$hex \\\\\"Is Near\\\\\"\"},{name=\"b\",type=\"int\",value=\"12\"},{name=\"c\",type=\"short\",value=\"5\"}\\\]" \
> + "stack-list-locals 3"
> +
> # stack-list-variables
> mi_gdb_test "-stack-list-variables --no-frame-filters 0" \
> "\\^done,variables=\\\[{name=\"foo\",arg=\"1\"},{name=\"bar\",arg=\"1\"},{name=\"fb\",arg=\"1\"},{name=\"bf\",arg=\"1\"},{name=\"str\"},{name=\"st2\"},{name=\"b\"},{name=\"c\"}\\\]" \
> --
> 2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-08 12:35 ` Andrew Burgess
@ 2023-03-10 11:04 ` Gareth Rees
2023-03-10 12:05 ` Eli Zaretskii
2023-03-11 11:58 ` Gareth Rees
0 siblings, 2 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-10 11:04 UTC (permalink / raw)
To: Andrew Burgess, Eli Zaretskii; +Cc: gdb-patches
Thanks for following up.
Andrew Burgess wrote:
> I would love to see some more information here about why #2 was selected
> over #1.
>
> I know in V1 and V2 you did implement #1, then in V3 you switched to #2.
>
> I saw that Eli preferred #2, but didn't seem to offer any reasons why.
>
> Did you run into some problems implementing #1? Do you think it would
> break some MI users?
I switched from solution #1 (modify the existing option) to solution
#2 (add a new option) entirely because of Eli's comment. For my use
case (improving the performance of getting the stack trace in Visual
Studio Code), either solution works, and as a new GDB developer I
don't have the experience and expertise to make this kind of design
decision. I can only presume that Eli had good reasons for his
comment, presumably due to concerns about backwards compatibility, and
since it doesn't matter for my use case, I went with Eli's stated
preference.
> I'm happy to go with option #2, but I still think option #1 would be a
> better choice. It would change IDE behaviour in some cases, but I don't
> see why that change would break any IDEs, and I can't imagine how the
> current behaviour can be considered the right thing to do.
>
> I suspect what we're really doing here is just collecting more technical
> debt; just another option '--simple-values' that nobody ever actually
> uses, but which we feel we have to maintain forever "just in case".
This also makes sense to me, but this is not a decision that I am in a
position to make! The experienced GDB developers -- in particular, you
and Eli -- need to come to an agreement about which approach is best
in this case: do you prefer to take the risk of a backward-
incompatible change (GDB/MI clients can no longer get the values for
references to compound types in C++ programs using --simple-values) or
do you prefer to accept the cost of leaving (what looks like) a
mistake to stand forever? I can implement whichever you think is best.
For the moment I will prepare a revised patch implementing solution #1
and addressing your other review comments. If Eli can also follow up
and help us reach a conclusion on the best design, that would be
great.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-10 11:04 ` Gareth Rees
@ 2023-03-10 12:05 ` Eli Zaretskii
2023-03-10 12:58 ` Gareth Rees
2023-03-13 17:17 ` Andrew Burgess
2023-03-11 11:58 ` Gareth Rees
1 sibling, 2 replies; 49+ messages in thread
From: Eli Zaretskii @ 2023-03-10 12:05 UTC (permalink / raw)
To: Gareth Rees; +Cc: aburgess, gdb-patches
> From: Gareth Rees <grees@undo.io>
> Date: Fri, 10 Mar 2023 11:04:42 +0000
> Cc: gdb-patches@sourceware.org
>
> This also makes sense to me, but this is not a decision that I am in a
> position to make! The experienced GDB developers -- in particular, you
> and Eli -- need to come to an agreement about which approach is best
> in this case: do you prefer to take the risk of a backward-
> incompatible change (GDB/MI clients can no longer get the values for
> references to compound types in C++ programs using --simple-values) or
> do you prefer to accept the cost of leaving (what looks like) a
> mistake to stand forever? I can implement whichever you think is best.
>
> For the moment I will prepare a revised patch implementing solution #1
> and addressing your other review comments. If Eli can also follow up
> and help us reach a conclusion on the best design, that would be
> great.
The reason why I preferred #2 is simple: it avoids incompatible
changes in the behavior of existing options. Since it was not really
clear-cut that the previous behavior was a bug, the backward
incompatibility could cause trouble to some application or use case
which didn't consider it was a bug and relied on that behavior.
Introducing a new option is free from this problem.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-10 12:05 ` Eli Zaretskii
@ 2023-03-10 12:58 ` Gareth Rees
2023-03-13 17:17 ` Andrew Burgess
1 sibling, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-10 12:58 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: aburgess, gdb-patches
Eli Zaretskii wrote:
> The reason why I preferred #2 is simple: it avoids incompatible
> changes in the behavior of existing options. Since it was not really
> clear-cut that the previous behavior was a bug, the backward
> incompatibility could cause trouble to some application or use case
> which didn't consider it was a bug and relied on that behavior.
> Introducing a new option is free from this problem.
Let me set out an argument for the existing behaviour being a bug. The
documentation for the -stack-list-arguments GDB/MI command [1] says:
> If print-values is [...] 2 or --simple-values, print the name, type
> and value for simple data types, and the name and type for arrays,
> structures and unions.
There is similar wording for the -stack-list-locals and
-stack-list-variables GDB/MI commands. The documentation does not say
what happens for reference types, but a natural way to read it is that
references to simple data types are simple, and references to compound
data types are not simple. That's certainly how I interpreted the
documentation when trying to fix the Visual Studio Code stack trace
performance issue [2]: my first attempt a pull request for this
problem used --simple-values [3] and you can see from the review
comments on the pull request that I wasn't the first developer to
interpret the documentation in this way: previously Visual Studio Code
had used --simple-values but this turned out not to work due to
references to compound types being considered simple [4].
This discrepancy between documentation and behaviour seems likely that
the current behaviour of --simple-values is a mistake (perhaps the
original implementer neglected to consider reference types, because
languages like C don't have them).
Anyway, this is not a blocker for me: I am happy to implement a new
option if that's what the GDB developers agree is the best approach.
But I also think the history of work on the Visual Studio Code issue
shows that the current behaviour of --simple-values is itself a bug
magnet.
[1] https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Stack-Manipulation.html
[2] https://github.com/microsoft/MIEngine/issues/1349
[3] https://github.com/microsoft/MIEngine/pull/1350
[4] https://github.com/microsoft/MIEngine/pull/673
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2022-10-20 17:47 ` [PATCH v5] " Gareth Rees
` (2 preceding siblings ...)
2023-03-08 12:35 ` Andrew Burgess
@ 2023-03-11 11:49 ` Gareth Rees
2023-03-21 9:50 ` [PING] " Gareth Rees
2023-03-27 14:34 ` Tom Tromey
3 siblings, 2 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-11 11:49 UTC (permalink / raw)
To: gdb-patches; +Cc: Gareth Rees
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
---
gdb/NEWS | 8 +++
gdb/doc/gdb.texinfo | 7 +++
gdb/mi/mi-cmd-stack.c | 9 +--
gdb/mi/mi-cmd-var.c | 27 ++++++---
gdb/mi/mi-cmds.h | 5 ++
gdb/mi/mi-main.c | 7 +--
gdb/python/py-framefilter.c | 6 +-
gdb/testsuite/gdb.mi/mi-stack.exp | 16 ++++-
gdb/testsuite/gdb.mi/print-simple-values.cc | 62 ++++++++++++++++++++
gdb/testsuite/gdb.mi/print-simple-values.exp | 53 +++++++++++++++++
10 files changed, 175 insertions(+), 25 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index cc262f1f8a6..1971b76a736 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -104,6 +104,14 @@ show always-read-ctf
without a thread restriction. The same is also true for the 'task'
field of an Ada task-specific breakpoint.
+** The '--simple-values' argument to the '-stack-list-arguments',
+ '-stack-list-locals', '-stack-list-variables', and '-var-list-children'
+ commands now takes reference types into account: that is, a value is now
+ considered simple if it is neither an array, structure, or union, nor a
+ reference to an array, structure, or union. (Previously all references were
+ considered simple.) Support for this feature can be verified by using the
+ '-list-features' command, which should contain "simple-values-ref-types".
+
*** Changes in GDB 13
* MI version 1 is deprecated, and will be removed in GDB 14.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 954f1481dae..dff7ba374bd 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -37948,6 +37948,13 @@ option (@pxref{GDB/MI Program Execution}).
@item data-disassemble-a-option
Indicates that the @code{-data-disassemble} command supports the @option{-a}
option (@pxref{GDB/MI Data Manipulation}).
+@item simple-values-ref-types
+Indicates that the @code{--simple-values} argument to the
+@code{-stack-list-arguments}, @code{-stack-list-locals},
+@code{-stack-list-variables}, and @code{-var-list-children} commands
+takes reference types into account: that is, a value is considered
+simple if it is neither an array, structure, or union, nor a reference
+to an array, structure, or union.
@end ftable
@findex -list-target-features
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 4c4662ab5d7..406bf85ceec 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -645,13 +645,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
switch (values)
{
case PRINT_SIMPLE_VALUES:
- {
- struct type *type = check_typedef (sym2->type ());
- if (type->code () == TYPE_CODE_ARRAY
- || type->code () == TYPE_CODE_STRUCT
- || type->code () == TYPE_CODE_UNION)
- break;
- }
+ if (!mi_simple_type_p (sym2->type ()))
+ break;
/* FALLTHROUGH */
case PRINT_ALL_VALUES:
diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
index e026c239b87..36eea4619a7 100644
--- a/gdb/mi/mi-cmd-var.c
+++ b/gdb/mi/mi-cmd-var.c
@@ -335,14 +335,27 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
if (type == NULL)
return 1;
else
- {
- type = check_typedef (type);
+ return mi_simple_type_p (type);
+}
- /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
- and that type is not a compound type. */
- return (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION);
+/* See mi-cmds.h. */
+
+bool
+mi_simple_type_p (struct type *type)
+{
+ type = check_typedef (type);
+
+ if (TYPE_IS_REFERENCE (type))
+ type = check_typedef (type->target_type ());
+
+ switch (type->code ())
+ {
+ case TYPE_CODE_ARRAY:
+ case TYPE_CODE_STRUCT:
+ case TYPE_CODE_UNION:
+ return false;
+ default:
+ return true;
}
}
diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
index 490f50484d9..d867c298df9 100644
--- a/gdb/mi/mi-cmds.h
+++ b/gdb/mi/mi-cmds.h
@@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
= gdb::function_view<bool (mi_command *)>;
extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
+/* Return true if type is a simple type: that is, neither an array, structure,
+ or union, nor a reference to an array, structure, or union. */
+
+extern bool mi_simple_type_p (struct type *type);
+
#endif /* MI_MI_CMDS_H */
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 0013e5dfafd..cedad60d0b8 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1656,6 +1656,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
uiout->field_string (NULL, "undefined-command-error-code");
uiout->field_string (NULL, "exec-run-start-option");
uiout->field_string (NULL, "data-disassemble-a-option");
+ uiout->field_string (NULL, "simple-values-ref-types");
if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
uiout->field_string (NULL, "python");
@@ -2458,7 +2459,6 @@ static void
print_variable_or_computed (const char *expression, enum print_values values)
{
struct value *val;
- struct type *type;
struct ui_out *uiout = current_uiout;
string_file stb;
@@ -2478,12 +2478,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (val->type ());
type_print (val->type (), "", &stb, -1);
uiout->field_stream ("type", stb);
- if (type->code () != TYPE_CODE_ARRAY
- && type->code () != TYPE_CODE_STRUCT
- && type->code () != TYPE_CODE_UNION)
+ if (mi_simple_type_p (val->type ()))
{
struct value_print_options opts;
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 0e8b2409636..e555dc3d879 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)
diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
index 633e090c13a..777a425894f 100644
--- a/gdb/testsuite/gdb.mi/mi-stack.exp
+++ b/gdb/testsuite/gdb.mi/mi-stack.exp
@@ -87,6 +87,9 @@ proc test_stack_args_listing {} {
# -stack-list-arguments 1 1 1
# -stack-list-arguments 1 1 3
# -stack-list-arguments
+ # -stack-list-arguments 1 1 300
+ # -stack-list-arguments 2 1 1
+ # -stack-list-arguments --simple-values 1 1
mi_gdb_test "231-stack-list-arguments 0" \
"231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
@@ -119,6 +122,14 @@ proc test_stack_args_listing {} {
mi_gdb_test "235-stack-list-arguments 1 1 300" \
"235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
"stack args listing 1 1 300"
+
+ mi_gdb_test "236-stack-list-arguments 2 1 1" \
+ "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
+ "stack args listing 2 1 1"
+
+ mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
+ "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
+ "stack args listing --simple-values 1 1"
}
proc test_stack_info_depth {} {
@@ -157,7 +168,6 @@ proc test_stack_locals_listing {} {
# -stack-list-locals 0 (--no-values)
# -stack-list-locals 1 (--all-values)
# -stack-list-locals 2 (--simple-values)
- # -stack-list-arguments
mi_gdb_test "232-stack-list-locals 0" \
"232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
@@ -173,6 +183,10 @@ proc test_stack_locals_listing {} {
"232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
"stack locals listing of names and values"
+ mi_gdb_test "232-stack-list-locals 2" \
+ "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
+ "stack locals listing 2"
+
mi_gdb_test "232-stack-list-locals --simple-values" \
"232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
"stack locals listing, simple types: names and values, complex type: names and types"
diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
new file mode 100644
index 00000000000..1aad724efb9
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
@@ -0,0 +1,62 @@
+/* This test case is part of GDB, the GNU debugger.
+
+ Copyright 2022-2023 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Test program for PRINT_SIMPLE_VALUES.
+
+ In the function f:
+
+ * The arguments i, ir, and irr are ints or references to ints, which
+ must be printed by PRINT_SIMPLE_VALUES.
+
+ * The arguments a, s, and u are non-scalar values, which must not be
+ printed by PRINT_SIMPLE_VALUES.
+
+ * The arguments ar, arr, sr, srr, ur, and urr are references to
+ non-scalar values, which must not be printed by
+ PRINT_SIMPLE_VALUES. */
+
+struct s
+{
+ int v;
+};
+
+union u
+{
+ int v;
+};
+
+int
+f (int i, int &ir, int &&irr,
+ int a[1], int (&ar)[1], int (&&arr)[1],
+ struct s s, struct s &sr, struct s &&srr,
+ union u u, union u &ur, union u &&urr)
+{
+ return (i + ir + irr
+ + a[0] + ar[0] + arr[0]
+ + s.v + sr.v + srr.v
+ + u.v + ur.v + urr.v);
+}
+
+int
+main (void)
+{
+ int i = 1, j = 2;
+ int a[1] = { 4 }, b[1] = { 5 };
+ struct s s = { 7 }, t = { 8 };
+ union u u = { 10 }, v = { 11 };
+ return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
+}
diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
new file mode 100644
index 00000000000..9436645df84
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
@@ -0,0 +1,53 @@
+# Copyright 2022-2023 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test of PRINT_SIMPLE_VALUES.
+#
+# Test that PRINT_SIMPLE_VALUES distinguishes simple and compound types,
+# including C++ reference and rvalue reference types.
+
+require allow_cplus_tests
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile .cc
+
+if [build_executable "failed to prepare" $testfile $srcfile {debug c++}] {
+ return -1
+}
+
+if [mi_clean_restart $binfile] {
+ return
+}
+
+mi_runto_main
+
+mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
+
+mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
+
+mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
+ "run until breakpoint on f"
+
+mi_gdb_test "-stack-list-arguments 2" \
+ "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
+ "stack arguments listing 2"
+
+mi_gdb_test "-stack-list-arguments --simple-values" \
+ "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
+ "stack arguments listing --simple-values"
+
+mi_gdb_exit
--
2.26.0
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-10 11:04 ` Gareth Rees
2023-03-10 12:05 ` Eli Zaretskii
@ 2023-03-11 11:58 ` Gareth Rees
2023-04-11 13:15 ` Pedro Alves
1 sibling, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2023-03-11 11:58 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
Andrew Burgess wrote:
> I'm happy to go with option #2, but I still think option #1 would be a
> better choice. It would change IDE behaviour in some cases, but I don't
> see why that change would break any IDEs, and I can't imagine how the
> current behaviour can be considered the right thing to do.
I've posted a patch v6 implementing solution #1 (that is, updating the
--simple-values option). I've also taken account of all your review
comments, where they applied to solution #1. I rebased the patch so that
it now applies cleanly to the GDB master branch.
I think it's worth trying to see if we can get agreement on solution #1
as it is the simpler solution. But I'd also be happy to go with solution
#2 (that is, adding a new --scalar-values option) if the GDB maintainers
agree that is the better solution.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-10 12:05 ` Eli Zaretskii
2023-03-10 12:58 ` Gareth Rees
@ 2023-03-13 17:17 ` Andrew Burgess
2023-03-16 12:28 ` Gareth Rees
1 sibling, 1 reply; 49+ messages in thread
From: Andrew Burgess @ 2023-03-13 17:17 UTC (permalink / raw)
To: Eli Zaretskii, Gareth Rees; +Cc: gdb-patches
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Gareth Rees <grees@undo.io>
>> Date: Fri, 10 Mar 2023 11:04:42 +0000
>> Cc: gdb-patches@sourceware.org
>>
>> This also makes sense to me, but this is not a decision that I am in a
>> position to make! The experienced GDB developers -- in particular, you
>> and Eli -- need to come to an agreement about which approach is best
>> in this case: do you prefer to take the risk of a backward-
>> incompatible change (GDB/MI clients can no longer get the values for
>> references to compound types in C++ programs using --simple-values) or
>> do you prefer to accept the cost of leaving (what looks like) a
>> mistake to stand forever? I can implement whichever you think is best.
>>
>> For the moment I will prepare a revised patch implementing solution #1
>> and addressing your other review comments. If Eli can also follow up
>> and help us reach a conclusion on the best design, that would be
>> great.
>
> The reason why I preferred #2 is simple: it avoids incompatible
> changes in the behavior of existing options.
I think we need to be careful not to paint this change as worse than it
really is.
If we picked option #1 then this would change the output in some cases,
so obviously, there could be a user out there that depends on a
particular output in a given situation, and any changes will break their
use case. But....
... for a well written front-end, picking option #1 should be a
transparent change. They already have to handle passing non-references
to non-scalar types. Option #1 simply redistributes which value types
fall into which category, it doesn't do anything that we didn't do
before.
> Since it was not really
> clear-cut that the previous behavior was a bug, the backward
> incompatibility could cause trouble to some application or use case
> which didn't consider it was a bug and relied on that behavior.
I agree, we will likely never know with certainty if the existing GDB
behaviour was by design, or by accident.
That said, my guess would be accident, but I also think that's likely
irrelevant here.
GDB isn't printing something that's incorrect -- that would clearly be a
bug. And GDB isn't crashing -- that too would clearly be a bug.
So I think this becomes more a GDB development question: if we release a
miss-feature does that mean we have to guarantee to support that
miss-feature forever? Or are we allowed to go in an make adjustments?
On one extreme we can take the position that once somethings out the
door we must NEVER break compatibility. EVER.
On the other extreme everything could change with every release.
I think the both of these positions would not be good for GDB.
Personally, I'm more toward the conservative end. I think stability is
good.
But I also think we do need to be open to making considered changes,
otherwise, we end up carrying around an increasing volume of technical
debt that makes future work progressively harder.
In this case my think was:
1. The option #1 behaviour is now inline with GDB's CLI behaviour,
i.e. hiding the values of non-scalar reference variables by default,
2. A well written application should transparently handle this case
anyway as we're not adding a new output format, and
3. The current behaviour (I would say) is clearly unexpected, you ask
GDB for simple values only, and you could get back a value of
(almost) unlimited size.
4. The option #1 patch already included an MI feature flag. This
doesn't stop a badly written MI front-end from breaking, but it
does mean the maintainer can query the flag to figure out when to
apply the fix-up behaviour.
> Introducing a new option is free from this problem.
But not free in maintenance cost.
If we really feel that the old behaviour is worth saving then adding a
new flag isn't the end of the world. I'd just want to make sure we
really have considered the alternatives first.
Thanks,
Andrew
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-13 17:17 ` Andrew Burgess
@ 2023-03-16 12:28 ` Gareth Rees
0 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-16 12:28 UTC (permalink / raw)
To: Andrew Burgess; +Cc: Eli Zaretskii, gdb-patches
Andrew Burgess wrote:
> If we really feel that the old behaviour is worth saving then adding a
> new flag isn't the end of the world. I'd just want to make sure we
> really have considered the alternatives first.
I agree with Andrew's analysis. Another consideration is that it is
likely that existing GDB/MI clients that use --simple-values are subject
to latent bugs or performance issues that could be fixed by changing the
behaviour of the option.
When implementing a GDB/MI client for an IDE, you typically want to
update the displayed call stack every time the debuggee stops, and the
most convenient way to do this is to use the -stack-list-arguments
command. Since it is helpful for the user to be able to see the type of
each argument, it is natural to use the --simple-values option, as
otherwise you have to loop over the arguments calling -var-create.
If you use -stack-list-arguments with --simple-values, it can be hard to
spot that you are introducing bugs or performance issues when debugging
C++ programs with functions taking references to large data structures,
and it is easy to omit this case in testing. Visual Studio Code's
initial implementation of their GDB/MI client had exactly such an issue.
Searching GitHub, I found a couple of other bugs that might take this
form, in particular [1] and [2] are hangs in gdbgui whose descriptions
suggest that they might be related to the handling of reference types by
the --simple-values option.
[1] https://github.com/cs01/gdbgui/issues/205
[2] https://github.com/cs01/gdbgui/issues/206
^ permalink raw reply [flat|nested] 49+ messages in thread
* [PING] [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-11 11:49 ` [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
@ 2023-03-21 9:50 ` Gareth Rees
2023-03-26 9:56 ` Gareth Rees
` (3 more replies)
2023-03-27 14:34 ` Tom Tromey
1 sibling, 4 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-21 9:50 UTC (permalink / raw)
To: gdb-patches
This is a patch modifying the behaviour of the --simple-values option
but as discussed previously, if GDB maintainers agree that adding a
new option is the best approach, I would be happy to submit a patch
for that solution instead.
On Sat, 11 Mar 2023 at 11:49, Gareth Rees <grees@undo.io> wrote:
>
> 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
> ---
> gdb/NEWS | 8 +++
> gdb/doc/gdb.texinfo | 7 +++
> gdb/mi/mi-cmd-stack.c | 9 +--
> gdb/mi/mi-cmd-var.c | 27 ++++++---
> gdb/mi/mi-cmds.h | 5 ++
> gdb/mi/mi-main.c | 7 +--
> gdb/python/py-framefilter.c | 6 +-
> gdb/testsuite/gdb.mi/mi-stack.exp | 16 ++++-
> gdb/testsuite/gdb.mi/print-simple-values.cc | 62 ++++++++++++++++++++
> gdb/testsuite/gdb.mi/print-simple-values.exp | 53 +++++++++++++++++
> 10 files changed, 175 insertions(+), 25 deletions(-)
> create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
> create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index cc262f1f8a6..1971b76a736 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -104,6 +104,14 @@ show always-read-ctf
> without a thread restriction. The same is also true for the 'task'
> field of an Ada task-specific breakpoint.
>
> +** The '--simple-values' argument to the '-stack-list-arguments',
> + '-stack-list-locals', '-stack-list-variables', and '-var-list-children'
> + commands now takes reference types into account: that is, a value is now
> + considered simple if it is neither an array, structure, or union, nor a
> + reference to an array, structure, or union. (Previously all references were
> + considered simple.) Support for this feature can be verified by using the
> + '-list-features' command, which should contain "simple-values-ref-types".
> +
> *** Changes in GDB 13
>
> * MI version 1 is deprecated, and will be removed in GDB 14.
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 954f1481dae..dff7ba374bd 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -37948,6 +37948,13 @@ option (@pxref{GDB/MI Program Execution}).
> @item data-disassemble-a-option
> Indicates that the @code{-data-disassemble} command supports the @option{-a}
> option (@pxref{GDB/MI Data Manipulation}).
> +@item simple-values-ref-types
> +Indicates that the @code{--simple-values} argument to the
> +@code{-stack-list-arguments}, @code{-stack-list-locals},
> +@code{-stack-list-variables}, and @code{-var-list-children} commands
> +takes reference types into account: that is, a value is considered
> +simple if it is neither an array, structure, or union, nor a reference
> +to an array, structure, or union.
> @end ftable
>
> @findex -list-target-features
> diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> index 4c4662ab5d7..406bf85ceec 100644
> --- a/gdb/mi/mi-cmd-stack.c
> +++ b/gdb/mi/mi-cmd-stack.c
> @@ -645,13 +645,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - {
> - struct type *type = check_typedef (sym2->type ());
> - if (type->code () == TYPE_CODE_ARRAY
> - || type->code () == TYPE_CODE_STRUCT
> - || type->code () == TYPE_CODE_UNION)
> - break;
> - }
> + if (!mi_simple_type_p (sym2->type ()))
> + break;
> /* FALLTHROUGH */
>
> case PRINT_ALL_VALUES:
> diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> index e026c239b87..36eea4619a7 100644
> --- a/gdb/mi/mi-cmd-var.c
> +++ b/gdb/mi/mi-cmd-var.c
> @@ -335,14 +335,27 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> if (type == NULL)
> return 1;
> else
> - {
> - type = check_typedef (type);
> + return mi_simple_type_p (type);
> +}
>
> - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> - and that type is not a compound type. */
> - return (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION);
> +/* See mi-cmds.h. */
> +
> +bool
> +mi_simple_type_p (struct type *type)
> +{
> + type = check_typedef (type);
> +
> + if (TYPE_IS_REFERENCE (type))
> + type = check_typedef (type->target_type ());
> +
> + switch (type->code ())
> + {
> + case TYPE_CODE_ARRAY:
> + case TYPE_CODE_STRUCT:
> + case TYPE_CODE_UNION:
> + return false;
> + default:
> + return true;
> }
> }
>
> diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> index 490f50484d9..d867c298df9 100644
> --- a/gdb/mi/mi-cmds.h
> +++ b/gdb/mi/mi-cmds.h
> @@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
> = gdb::function_view<bool (mi_command *)>;
> extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
>
> +/* Return true if type is a simple type: that is, neither an array, structure,
> + or union, nor a reference to an array, structure, or union. */
> +
> +extern bool mi_simple_type_p (struct type *type);
> +
> #endif /* MI_MI_CMDS_H */
> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> index 0013e5dfafd..cedad60d0b8 100644
> --- a/gdb/mi/mi-main.c
> +++ b/gdb/mi/mi-main.c
> @@ -1656,6 +1656,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> uiout->field_string (NULL, "undefined-command-error-code");
> uiout->field_string (NULL, "exec-run-start-option");
> uiout->field_string (NULL, "data-disassemble-a-option");
> + uiout->field_string (NULL, "simple-values-ref-types");
>
> if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> uiout->field_string (NULL, "python");
> @@ -2458,7 +2459,6 @@ static void
> print_variable_or_computed (const char *expression, enum print_values values)
> {
> struct value *val;
> - struct type *type;
> struct ui_out *uiout = current_uiout;
>
> string_file stb;
> @@ -2478,12 +2478,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
> switch (values)
> {
> case PRINT_SIMPLE_VALUES:
> - type = check_typedef (val->type ());
> type_print (val->type (), "", &stb, -1);
> uiout->field_stream ("type", stb);
> - if (type->code () != TYPE_CODE_ARRAY
> - && type->code () != TYPE_CODE_STRUCT
> - && type->code () != TYPE_CODE_UNION)
> + if (mi_simple_type_p (val->type ()))
> {
> struct value_print_options opts;
>
> diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> index 0e8b2409636..e555dc3d879 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)
> diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> index 633e090c13a..777a425894f 100644
> --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> @@ -87,6 +87,9 @@ proc test_stack_args_listing {} {
> # -stack-list-arguments 1 1 1
> # -stack-list-arguments 1 1 3
> # -stack-list-arguments
> + # -stack-list-arguments 1 1 300
> + # -stack-list-arguments 2 1 1
> + # -stack-list-arguments --simple-values 1 1
>
> mi_gdb_test "231-stack-list-arguments 0" \
> "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> @@ -119,6 +122,14 @@ proc test_stack_args_listing {} {
> mi_gdb_test "235-stack-list-arguments 1 1 300" \
> "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> "stack args listing 1 1 300"
> +
> + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing 2 1 1"
> +
> + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> + "stack args listing --simple-values 1 1"
> }
>
> proc test_stack_info_depth {} {
> @@ -157,7 +168,6 @@ proc test_stack_locals_listing {} {
> # -stack-list-locals 0 (--no-values)
> # -stack-list-locals 1 (--all-values)
> # -stack-list-locals 2 (--simple-values)
> - # -stack-list-arguments
>
> mi_gdb_test "232-stack-list-locals 0" \
> "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> @@ -173,6 +183,10 @@ proc test_stack_locals_listing {} {
> "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> "stack locals listing of names and values"
>
> + mi_gdb_test "232-stack-list-locals 2" \
> + "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> + "stack locals listing 2"
> +
> mi_gdb_test "232-stack-list-locals --simple-values" \
> "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> "stack locals listing, simple types: names and values, complex type: names and types"
> diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
> new file mode 100644
> index 00000000000..1aad724efb9
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
> @@ -0,0 +1,62 @@
> +/* This test case is part of GDB, the GNU debugger.
> +
> + Copyright 2022-2023 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* Test program for PRINT_SIMPLE_VALUES.
> +
> + In the function f:
> +
> + * The arguments i, ir, and irr are ints or references to ints, which
> + must be printed by PRINT_SIMPLE_VALUES.
> +
> + * The arguments a, s, and u are non-scalar values, which must not be
> + printed by PRINT_SIMPLE_VALUES.
> +
> + * The arguments ar, arr, sr, srr, ur, and urr are references to
> + non-scalar values, which must not be printed by
> + PRINT_SIMPLE_VALUES. */
> +
> +struct s
> +{
> + int v;
> +};
> +
> +union u
> +{
> + int v;
> +};
> +
> +int
> +f (int i, int &ir, int &&irr,
> + int a[1], int (&ar)[1], int (&&arr)[1],
> + struct s s, struct s &sr, struct s &&srr,
> + union u u, union u &ur, union u &&urr)
> +{
> + return (i + ir + irr
> + + a[0] + ar[0] + arr[0]
> + + s.v + sr.v + srr.v
> + + u.v + ur.v + urr.v);
> +}
> +
> +int
> +main (void)
> +{
> + int i = 1, j = 2;
> + int a[1] = { 4 }, b[1] = { 5 };
> + struct s s = { 7 }, t = { 8 };
> + union u u = { 10 }, v = { 11 };
> + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> +}
> diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
> new file mode 100644
> index 00000000000..9436645df84
> --- /dev/null
> +++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
> @@ -0,0 +1,53 @@
> +# Copyright 2022-2023 Free Software Foundation, Inc.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> +
> +# Test of PRINT_SIMPLE_VALUES.
> +#
> +# Test that PRINT_SIMPLE_VALUES distinguishes simple and compound types,
> +# including C++ reference and rvalue reference types.
> +
> +require allow_cplus_tests
> +
> +load_lib mi-support.exp
> +set MIFLAGS "-i=mi"
> +
> +standard_testfile .cc
> +
> +if [build_executable "failed to prepare" $testfile $srcfile {debug c++}] {
> + return -1
> +}
> +
> +if [mi_clean_restart $binfile] {
> + return
> +}
> +
> +mi_runto_main
> +
> +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> +
> +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> +
> +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> + "run until breakpoint on f"
> +
> +mi_gdb_test "-stack-list-arguments 2" \
> + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> + "stack arguments listing 2"
> +
> +mi_gdb_test "-stack-list-arguments --simple-values" \
> + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> + "stack arguments listing --simple-values"
> +
> +mi_gdb_exit
> --
> 2.26.0
>
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-21 9:50 ` [PING] " Gareth Rees
@ 2023-03-26 9:56 ` Gareth Rees
2023-04-03 9:22 ` Gareth Rees
2023-04-18 9:23 ` Gareth Rees
` (2 subsequent siblings)
3 siblings, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2023-03-26 9:56 UTC (permalink / raw)
To: gdb-patches
Second ping.
On Tue, 21 Mar 2023 at 09:50, Gareth Rees <grees@undo.io> wrote:
>
> This is a patch modifying the behaviour of the --simple-values option
> but as discussed previously, if GDB maintainers agree that adding a
> new option is the best approach, I would be happy to submit a patch
> for that solution instead.
>
> On Sat, 11 Mar 2023 at 11:49, Gareth Rees <grees@undo.io> wrote:
> >
> > 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
> > ---
> > gdb/NEWS | 8 +++
> > gdb/doc/gdb.texinfo | 7 +++
> > gdb/mi/mi-cmd-stack.c | 9 +--
> > gdb/mi/mi-cmd-var.c | 27 ++++++---
> > gdb/mi/mi-cmds.h | 5 ++
> > gdb/mi/mi-main.c | 7 +--
> > gdb/python/py-framefilter.c | 6 +-
> > gdb/testsuite/gdb.mi/mi-stack.exp | 16 ++++-
> > gdb/testsuite/gdb.mi/print-simple-values.cc | 62 ++++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-simple-values.exp | 53 +++++++++++++++++
> > 10 files changed, 175 insertions(+), 25 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index cc262f1f8a6..1971b76a736 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -104,6 +104,14 @@ show always-read-ctf
> > without a thread restriction. The same is also true for the 'task'
> > field of an Ada task-specific breakpoint.
> >
> > +** The '--simple-values' argument to the '-stack-list-arguments',
> > + '-stack-list-locals', '-stack-list-variables', and '-var-list-children'
> > + commands now takes reference types into account: that is, a value is now
> > + considered simple if it is neither an array, structure, or union, nor a
> > + reference to an array, structure, or union. (Previously all references were
> > + considered simple.) Support for this feature can be verified by using the
> > + '-list-features' command, which should contain "simple-values-ref-types".
> > +
> > *** Changes in GDB 13
> >
> > * MI version 1 is deprecated, and will be removed in GDB 14.
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 954f1481dae..dff7ba374bd 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -37948,6 +37948,13 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item simple-values-ref-types
> > +Indicates that the @code{--simple-values} argument to the
> > +@code{-stack-list-arguments}, @code{-stack-list-locals},
> > +@code{-stack-list-variables}, and @code{-var-list-children} commands
> > +takes reference types into account: that is, a value is considered
> > +simple if it is neither an array, structure, or union, nor a reference
> > +to an array, structure, or union.
> > @end ftable
> >
> > @findex -list-target-features
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 4c4662ab5d7..406bf85ceec 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -645,13 +645,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - {
> > - struct type *type = check_typedef (sym2->type ());
> > - if (type->code () == TYPE_CODE_ARRAY
> > - || type->code () == TYPE_CODE_STRUCT
> > - || type->code () == TYPE_CODE_UNION)
> > - break;
> > - }
> > + if (!mi_simple_type_p (sym2->type ()))
> > + break;
> > /* FALLTHROUGH */
> >
> > case PRINT_ALL_VALUES:
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index e026c239b87..36eea4619a7 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -335,14 +335,27 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > + return mi_simple_type_p (type);
> > +}
> >
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > +
> > + if (TYPE_IS_REFERENCE (type))
> > + type = check_typedef (type->target_type ());
> > +
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 490f50484d9..d867c298df9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if type is a simple type: that is, neither an array, structure,
> > + or union, nor a reference to an array, structure, or union. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index 0013e5dfafd..cedad60d0b8 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1656,6 +1656,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "simple-values-ref-types");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2458,7 +2459,6 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> > @@ -2478,12 +2478,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (val->type ());
> > type_print (val->type (), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > + if (mi_simple_type_p (val->type ()))
> > {
> > struct value_print_options opts;
> >
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 0e8b2409636..e555dc3d879 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)
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index 633e090c13a..777a425894f 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -87,6 +87,9 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -119,6 +122,14 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -157,7 +168,6 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -173,6 +183,10 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > + mi_gdb_test "232-stack-list-locals 2" \
> > + "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > + "stack locals listing 2"
> > +
> > mi_gdb_test "232-stack-list-locals --simple-values" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> > diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
> > new file mode 100644
> > index 00000000000..1aad724efb9
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
> > @@ -0,0 +1,62 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022-2023 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints, which
> > + must be printed by PRINT_SIMPLE_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not be
> > + printed by PRINT_SIMPLE_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must not be printed by
> > + PRINT_SIMPLE_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
> > new file mode 100644
> > index 00000000000..9436645df84
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022-2023 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes simple and compound types,
> > +# including C++ reference and rvalue reference types.
> > +
> > +require allow_cplus_tests
> > +
> > +load_lib mi-support.exp
> > +set MIFLAGS "-i=mi"
> > +
> > +standard_testfile .cc
> > +
> > +if [build_executable "failed to prepare" $testfile $srcfile {debug c++}] {
> > + return -1
> > +}
> > +
> > +if [mi_clean_restart $binfile] {
> > + return
> > +}
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments 2" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack arguments listing 2"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack arguments listing --simple-values"
> > +
> > +mi_gdb_exit
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-11 11:49 ` [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple" Gareth Rees
2023-03-21 9:50 ` [PING] " Gareth Rees
@ 2023-03-27 14:34 ` Tom Tromey
2023-03-29 9:14 ` Gareth Rees
2023-04-06 17:18 ` Gareth Rees
1 sibling, 2 replies; 49+ messages in thread
From: Tom Tromey @ 2023-03-27 14:34 UTC (permalink / raw)
To: Gareth Rees via Gdb-patches; +Cc: Gareth Rees
>>>>> "Gareth" == Gareth Rees via Gdb-patches <gdb-patches@sourceware.org> writes:
Gareth> The '--simple-values' argument to '-stack-list-arguments' and similar
Gareth> GDB/MI commands does not take reference types into account, so that
Gareth> references to arbitrarily large structures are considered "simple" and
Gareth> printed. This means that the '--simple-values' argument cannot be used
Gareth> by IDEs when tracing the stack due to the time taken to print large
Gareth> structures passed by reference.
Hi. Thank you for the patch.
This looks good to me. I haven't been following the progress of this
patch -- have the documentation changes been reviewed? If so, please
check it in.
Tom
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-27 14:34 ` Tom Tromey
@ 2023-03-29 9:14 ` Gareth Rees
2023-04-06 17:18 ` Gareth Rees
1 sibling, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-03-29 9:14 UTC (permalink / raw)
To: Tom Tromey; +Cc: Gareth Rees via Gdb-patches
Tom Tromey wrote:
> This looks good to me. I haven't been following the progress of this
> patch -- have the documentation changes been reviewed?
Thank you for looking at this. The documentation changes were reviewed by Eli
Zaretskii in message <834jxif0yp.fsf@gnu.org> on 8 September 2022.
> If so, please check it in.
I'm not sure how to do this. I'm not a GDB maintainer, so I am unable to commit
the patch.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-26 9:56 ` Gareth Rees
@ 2023-04-03 9:22 ` Gareth Rees
2023-05-04 15:08 ` Tom Tromey
0 siblings, 1 reply; 49+ messages in thread
From: Gareth Rees @ 2023-04-03 9:22 UTC (permalink / raw)
To: gdb-patches
Third ping.
On Tue, 21 Mar 2023 at 09:50, Gareth Rees <grees@undo.io> wrote:
>
> This is a patch modifying the behaviour of the --simple-values option
> but as discussed previously, if GDB maintainers agree that adding a
> new option is the best approach, I would be happy to submit a patch
> for that solution instead.
>
> On Sat, 11 Mar 2023 at 11:49, Gareth Rees <grees@undo.io> wrote:
> >
> > 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
> > ---
> > gdb/NEWS | 8 +++
> > gdb/doc/gdb.texinfo | 7 +++
> > gdb/mi/mi-cmd-stack.c | 9 +--
> > gdb/mi/mi-cmd-var.c | 27 ++++++---
> > gdb/mi/mi-cmds.h | 5 ++
> > gdb/mi/mi-main.c | 7 +--
> > gdb/python/py-framefilter.c | 6 +-
> > gdb/testsuite/gdb.mi/mi-stack.exp | 16 ++++-
> > gdb/testsuite/gdb.mi/print-simple-values.cc | 62 ++++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-simple-values.exp | 53 +++++++++++++++++
> > 10 files changed, 175 insertions(+), 25 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index cc262f1f8a6..1971b76a736 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -104,6 +104,14 @@ show always-read-ctf
> > without a thread restriction. The same is also true for the 'task'
> > field of an Ada task-specific breakpoint.
> >
> > +** The '--simple-values' argument to the '-stack-list-arguments',
> > + '-stack-list-locals', '-stack-list-variables', and '-var-list-children'
> > + commands now takes reference types into account: that is, a value is now
> > + considered simple if it is neither an array, structure, or union, nor a
> > + reference to an array, structure, or union. (Previously all references were
> > + considered simple.) Support for this feature can be verified by using the
> > + '-list-features' command, which should contain "simple-values-ref-types".
> > +
> > *** Changes in GDB 13
> >
> > * MI version 1 is deprecated, and will be removed in GDB 14.
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 954f1481dae..dff7ba374bd 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -37948,6 +37948,13 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item simple-values-ref-types
> > +Indicates that the @code{--simple-values} argument to the
> > +@code{-stack-list-arguments}, @code{-stack-list-locals},
> > +@code{-stack-list-variables}, and @code{-var-list-children} commands
> > +takes reference types into account: that is, a value is considered
> > +simple if it is neither an array, structure, or union, nor a reference
> > +to an array, structure, or union.
> > @end ftable
> >
> > @findex -list-target-features
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 4c4662ab5d7..406bf85ceec 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -645,13 +645,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - {
> > - struct type *type = check_typedef (sym2->type ());
> > - if (type->code () == TYPE_CODE_ARRAY
> > - || type->code () == TYPE_CODE_STRUCT
> > - || type->code () == TYPE_CODE_UNION)
> > - break;
> > - }
> > + if (!mi_simple_type_p (sym2->type ()))
> > + break;
> > /* FALLTHROUGH */
> >
> > case PRINT_ALL_VALUES:
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index e026c239b87..36eea4619a7 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -335,14 +335,27 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > + return mi_simple_type_p (type);
> > +}
> >
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > +
> > + if (TYPE_IS_REFERENCE (type))
> > + type = check_typedef (type->target_type ());
> > +
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 490f50484d9..d867c298df9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if type is a simple type: that is, neither an array, structure,
> > + or union, nor a reference to an array, structure, or union. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index 0013e5dfafd..cedad60d0b8 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1656,6 +1656,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "simple-values-ref-types");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2458,7 +2459,6 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> > @@ -2478,12 +2478,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (val->type ());
> > type_print (val->type (), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > + if (mi_simple_type_p (val->type ()))
> > {
> > struct value_print_options opts;
> >
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 0e8b2409636..e555dc3d879 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)
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index 633e090c13a..777a425894f 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -87,6 +87,9 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -119,6 +122,14 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -157,7 +168,6 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -173,6 +183,10 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > + mi_gdb_test "232-stack-list-locals 2" \
> > + "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > + "stack locals listing 2"
> > +
> > mi_gdb_test "232-stack-list-locals --simple-values" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> > diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
> > new file mode 100644
> > index 00000000000..1aad724efb9
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
> > @@ -0,0 +1,62 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022-2023 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints, which
> > + must be printed by PRINT_SIMPLE_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not be
> > + printed by PRINT_SIMPLE_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must not be printed by
> > + PRINT_SIMPLE_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
> > new file mode 100644
> > index 00000000000..9436645df84
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022-2023 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes simple and compound types,
> > +# including C++ reference and rvalue reference types.
> > +
> > +require allow_cplus_tests
> > +
> > +load_lib mi-support.exp
> > +set MIFLAGS "-i=mi"
> > +
> > +standard_testfile .cc
> > +
> > +if [build_executable "failed to prepare" $testfile $srcfile {debug c++}] {
> > + return -1
> > +}
> > +
> > +if [mi_clean_restart $binfile] {
> > + return
> > +}
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments 2" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack arguments listing 2"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack arguments listing --simple-values"
> > +
> > +mi_gdb_exit
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-27 14:34 ` Tom Tromey
2023-03-29 9:14 ` Gareth Rees
@ 2023-04-06 17:18 ` Gareth Rees
1 sibling, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-04-06 17:18 UTC (permalink / raw)
To: Tom Tromey; +Cc: Gareth Rees via Gdb-patches
Tom Tromey wrote:
>
> >>>>> "Gareth" == Gareth Rees via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Gareth> The '--simple-values' argument to '-stack-list-arguments' and similar
> Gareth> GDB/MI commands does not take reference types into account, so that
> Gareth> references to arbitrarily large structures are considered "simple" and
> Gareth> printed. This means that the '--simple-values' argument cannot be used
> Gareth> by IDEs when tracing the stack due to the time taken to print large
> Gareth> structures passed by reference.
>
> This looks good to me. I haven't been following the progress of this
> patch -- have the documentation changes been reviewed? If so, please
> check it in.
Following up again. I don't have commit rights, so I can't check it in
myself. Could you check it in for me? But before you do, I just want
to check that you're happy with the solution I've picked here.
There are two ways to fix the problem of '--simple-values' printing
references to compound values:
First, if it's acceptable to modify the behaviour of the
'--simple-values' option, then we can suppress the printing of
references to compound types, as in this patch. This solution was
preferred by Andrew Burgess [1] [2] [3] out of concern about the
maintenance cost of accumulating backwards-compatible but arguably
broken features. I added an argument that the original behaviour was a
bug, and that it remains hard to use correctly [4].
Second, if we have to preserve the behaviour of the '--simple-values'
option, then we need to add a new option. This solution was preferred
by Eli Zaretskii [5] [6] out of concern about backwards compatibility.
I've proposed a patch that applies the first solution, but I could
work with either. So I need someone to break the tie between Andrew
and Eli. Take a look at the cited messages and let me know if you're
happy, and if you are, then commit the patch.
[1] https://sourceware.org/pipermail/gdb-patches/2022-September/191747.html
[2] https://sourceware.org/pipermail/gdb-patches/2023-March/197736.html
[3] https://sourceware.org/pipermail/gdb-patches/2023-March/197894.html
[4] https://sourceware.org/pipermail/gdb-patches/2023-March/197799.html
[5] https://sourceware.org/pipermail/gdb-patches/2022-September/191754.html
[6] https://sourceware.org/pipermail/gdb-patches/2023-March/197798.html
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PATCH v5] [PR mi/29554] New PRINT-VALUES option '--scalar-values'.
2023-03-11 11:58 ` Gareth Rees
@ 2023-04-11 13:15 ` Pedro Alves
0 siblings, 0 replies; 49+ messages in thread
From: Pedro Alves @ 2023-04-11 13:15 UTC (permalink / raw)
To: Gareth Rees, Andrew Burgess; +Cc: gdb-patches
On 2023-03-11 11:58 a.m., Gareth Rees via Gdb-patches wrote:
> Andrew Burgess wrote:
>> I'm happy to go with option #2, but I still think option #1 would be a
>> better choice. It would change IDE behaviour in some cases, but I don't
>> see why that change would break any IDEs, and I can't imagine how the
>> current behaviour can be considered the right thing to do.
>
> I've posted a patch v6 implementing solution #1 (that is, updating the
> --simple-values option). I've also taken account of all your review
> comments, where they applied to solution #1. I rebased the patch so that
> it now applies cleanly to the GDB master branch.
>
> I think it's worth trying to see if we can get agreement on solution #1
> as it is the simpler solution. But I'd also be happy to go with solution
> #2 (that is, adding a new --scalar-values option) if the GDB maintainers
> agree that is the better solution.
>
FWIW, I read the discussion from v1 to v5 (here), and I also think solution #1 is
appropriate here.
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-21 9:50 ` [PING] " Gareth Rees
2023-03-26 9:56 ` Gareth Rees
@ 2023-04-18 9:23 ` Gareth Rees
2023-04-24 9:53 ` Gareth Rees
2023-05-02 9:13 ` Gareth Rees
3 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-04-18 9:23 UTC (permalink / raw)
To: Gareth Rees via Gdb-patches
Fourth ping.
On Tue, 21 Mar 2023 at 09:50, Gareth Rees <grees@undo.io> wrote:
>
> This is a patch modifying the behaviour of the --simple-values option
> but as discussed previously, if GDB maintainers agree that adding a
> new option is the best approach, I would be happy to submit a patch
> for that solution instead.
>
> On Sat, 11 Mar 2023 at 11:49, Gareth Rees <grees@undo.io> wrote:
> >
> > 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
> > ---
> > gdb/NEWS | 8 +++
> > gdb/doc/gdb.texinfo | 7 +++
> > gdb/mi/mi-cmd-stack.c | 9 +--
> > gdb/mi/mi-cmd-var.c | 27 ++++++---
> > gdb/mi/mi-cmds.h | 5 ++
> > gdb/mi/mi-main.c | 7 +--
> > gdb/python/py-framefilter.c | 6 +-
> > gdb/testsuite/gdb.mi/mi-stack.exp | 16 ++++-
> > gdb/testsuite/gdb.mi/print-simple-values.cc | 62 ++++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-simple-values.exp | 53 +++++++++++++++++
> > 10 files changed, 175 insertions(+), 25 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index cc262f1f8a6..1971b76a736 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -104,6 +104,14 @@ show always-read-ctf
> > without a thread restriction. The same is also true for the 'task'
> > field of an Ada task-specific breakpoint.
> >
> > +** The '--simple-values' argument to the '-stack-list-arguments',
> > + '-stack-list-locals', '-stack-list-variables', and '-var-list-children'
> > + commands now takes reference types into account: that is, a value is now
> > + considered simple if it is neither an array, structure, or union, nor a
> > + reference to an array, structure, or union. (Previously all references were
> > + considered simple.) Support for this feature can be verified by using the
> > + '-list-features' command, which should contain "simple-values-ref-types".
> > +
> > *** Changes in GDB 13
> >
> > * MI version 1 is deprecated, and will be removed in GDB 14.
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 954f1481dae..dff7ba374bd 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -37948,6 +37948,13 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item simple-values-ref-types
> > +Indicates that the @code{--simple-values} argument to the
> > +@code{-stack-list-arguments}, @code{-stack-list-locals},
> > +@code{-stack-list-variables}, and @code{-var-list-children} commands
> > +takes reference types into account: that is, a value is considered
> > +simple if it is neither an array, structure, or union, nor a reference
> > +to an array, structure, or union.
> > @end ftable
> >
> > @findex -list-target-features
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 4c4662ab5d7..406bf85ceec 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -645,13 +645,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - {
> > - struct type *type = check_typedef (sym2->type ());
> > - if (type->code () == TYPE_CODE_ARRAY
> > - || type->code () == TYPE_CODE_STRUCT
> > - || type->code () == TYPE_CODE_UNION)
> > - break;
> > - }
> > + if (!mi_simple_type_p (sym2->type ()))
> > + break;
> > /* FALLTHROUGH */
> >
> > case PRINT_ALL_VALUES:
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index e026c239b87..36eea4619a7 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -335,14 +335,27 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > + return mi_simple_type_p (type);
> > +}
> >
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > +
> > + if (TYPE_IS_REFERENCE (type))
> > + type = check_typedef (type->target_type ());
> > +
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 490f50484d9..d867c298df9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if type is a simple type: that is, neither an array, structure,
> > + or union, nor a reference to an array, structure, or union. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index 0013e5dfafd..cedad60d0b8 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1656,6 +1656,7 @@ mi_cmd_list_features (const char *command, char **argv, int argc)
> > uiout->field_string (NULL, "undefined-command-error-code");
> > uiout->field_string (NULL, "exec-run-start-option");
> > uiout->field_string (NULL, "data-disassemble-a-option");
> > + uiout->field_string (NULL, "simple-values-ref-types");
> >
> > if (ext_lang_initialized_p (get_ext_lang_defn (EXT_LANG_PYTHON)))
> > uiout->field_string (NULL, "python");
> > @@ -2458,7 +2459,6 @@ static void
> > print_variable_or_computed (const char *expression, enum print_values values)
> > {
> > struct value *val;
> > - struct type *type;
> > struct ui_out *uiout = current_uiout;
> >
> > string_file stb;
> > @@ -2478,12 +2478,9 @@ print_variable_or_computed (const char *expression, enum print_values values)
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - type = check_typedef (val->type ());
> > type_print (val->type (), "", &stb, -1);
> > uiout->field_stream ("type", stb);
> > - if (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION)
> > + if (mi_simple_type_p (val->type ()))
> > {
> > struct value_print_options opts;
> >
> > diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
> > index 0e8b2409636..e555dc3d879 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)
> > diff --git a/gdb/testsuite/gdb.mi/mi-stack.exp b/gdb/testsuite/gdb.mi/mi-stack.exp
> > index 633e090c13a..777a425894f 100644
> > --- a/gdb/testsuite/gdb.mi/mi-stack.exp
> > +++ b/gdb/testsuite/gdb.mi/mi-stack.exp
> > @@ -87,6 +87,9 @@ proc test_stack_args_listing {} {
> > # -stack-list-arguments 1 1 1
> > # -stack-list-arguments 1 1 3
> > # -stack-list-arguments
> > + # -stack-list-arguments 1 1 300
> > + # -stack-list-arguments 2 1 1
> > + # -stack-list-arguments --simple-values 1 1
> >
> > mi_gdb_test "231-stack-list-arguments 0" \
> > "231\\^done,stack-args=\\\[frame=\{level=\"0\",args=\\\[\\\]\},frame=\{level=\"1\",args=\\\[name=\"strarg\"\\\]\},frame=\{level=\"2\",args=\\\[name=\"intarg\",name=\"strarg\"\\\]\},frame=\{level=\"3\",args=\\\[name=\"intarg\",name=\"strarg\",name=\"fltarg\"\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > @@ -119,6 +122,14 @@ proc test_stack_args_listing {} {
> > mi_gdb_test "235-stack-list-arguments 1 1 300" \
> > "235\\^done,stack-args=\\\[frame=\{level=\"1\",args=\\\[\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"2\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\}\\\]\},frame=\{level=\"3\",args=\\\[\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}\\\]\},frame=\{level=\"4\",args=\\\[\\\]\}\\\]" \
> > "stack args listing 1 1 300"
> > +
> > + mi_gdb_test "236-stack-list-arguments 2 1 1" \
> > + "236\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing 2 1 1"
> > +
> > + mi_gdb_test "237-stack-list-arguments --simple-values 1 1" \
> > + "237\\^done,stack-args=\\\[frame=\\{level=\"1\",args=\\\[\\{name=\"strarg\",type=\"char \\*\",value=\"$hex \\\\\"A string argument.\\\\\"\"\\}\\\]\\}\\\]" \
> > + "stack args listing --simple-values 1 1"
> > }
> >
> > proc test_stack_info_depth {} {
> > @@ -157,7 +168,6 @@ proc test_stack_locals_listing {} {
> > # -stack-list-locals 0 (--no-values)
> > # -stack-list-locals 1 (--all-values)
> > # -stack-list-locals 2 (--simple-values)
> > - # -stack-list-arguments
> >
> > mi_gdb_test "232-stack-list-locals 0" \
> > "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
> > @@ -173,6 +183,10 @@ proc test_stack_locals_listing {} {
> > "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
> > "stack locals listing of names and values"
> >
> > + mi_gdb_test "232-stack-list-locals 2" \
> > + "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > + "stack locals listing 2"
> > +
> > mi_gdb_test "232-stack-list-locals --simple-values" \
> > "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
> > "stack locals listing, simple types: names and values, complex type: names and types"
> > diff --git a/gdb/testsuite/gdb.mi/print-simple-values.cc b/gdb/testsuite/gdb.mi/print-simple-values.cc
> > new file mode 100644
> > index 00000000000..1aad724efb9
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-simple-values.cc
> > @@ -0,0 +1,62 @@
> > +/* This test case is part of GDB, the GNU debugger.
> > +
> > + Copyright 2022-2023 Free Software Foundation, Inc.
> > +
> > + This program is free software; you can redistribute it and/or modify
> > + it under the terms of the GNU General Public License as published by
> > + the Free Software Foundation; either version 3 of the License, or
> > + (at your option) any later version.
> > +
> > + This program is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > + GNU General Public License for more details.
> > +
> > + You should have received a copy of the GNU General Public License
> > + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> > +
> > +/* Test program for PRINT_SIMPLE_VALUES.
> > +
> > + In the function f:
> > +
> > + * The arguments i, ir, and irr are ints or references to ints, which
> > + must be printed by PRINT_SIMPLE_VALUES.
> > +
> > + * The arguments a, s, and u are non-scalar values, which must not be
> > + printed by PRINT_SIMPLE_VALUES.
> > +
> > + * The arguments ar, arr, sr, srr, ur, and urr are references to
> > + non-scalar values, which must not be printed by
> > + PRINT_SIMPLE_VALUES. */
> > +
> > +struct s
> > +{
> > + int v;
> > +};
> > +
> > +union u
> > +{
> > + int v;
> > +};
> > +
> > +int
> > +f (int i, int &ir, int &&irr,
> > + int a[1], int (&ar)[1], int (&&arr)[1],
> > + struct s s, struct s &sr, struct s &&srr,
> > + union u u, union u &ur, union u &&urr)
> > +{
> > + return (i + ir + irr
> > + + a[0] + ar[0] + arr[0]
> > + + s.v + sr.v + srr.v
> > + + u.v + ur.v + urr.v);
> > +}
> > +
> > +int
> > +main (void)
> > +{
> > + int i = 1, j = 2;
> > + int a[1] = { 4 }, b[1] = { 5 };
> > + struct s s = { 7 }, t = { 8 };
> > + union u u = { 10 }, v = { 11 };
> > + return f (i, j, 3, a, b, { 6 }, s, t, { 9 }, u, v, { 12 });
> > +}
> > diff --git a/gdb/testsuite/gdb.mi/print-simple-values.exp b/gdb/testsuite/gdb.mi/print-simple-values.exp
> > new file mode 100644
> > index 00000000000..9436645df84
> > --- /dev/null
> > +++ b/gdb/testsuite/gdb.mi/print-simple-values.exp
> > @@ -0,0 +1,53 @@
> > +# Copyright 2022-2023 Free Software Foundation, Inc.
> > +#
> > +# This program is free software; you can redistribute it and/or modify
> > +# it under the terms of the GNU General Public License as published by
> > +# the Free Software Foundation; either version 3 of the License, or
> > +# (at your option) any later version.
> > +#
> > +# This program is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public License
> > +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> > +
> > +# Test of PRINT_SIMPLE_VALUES.
> > +#
> > +# Test that PRINT_SIMPLE_VALUES distinguishes simple and compound types,
> > +# including C++ reference and rvalue reference types.
> > +
> > +require allow_cplus_tests
> > +
> > +load_lib mi-support.exp
> > +set MIFLAGS "-i=mi"
> > +
> > +standard_testfile .cc
> > +
> > +if [build_executable "failed to prepare" $testfile $srcfile {debug c++}] {
> > + return -1
> > +}
> > +
> > +if [mi_clean_restart $binfile] {
> > + return
> > +}
> > +
> > +mi_runto_main
> > +
> > +mi_gdb_test "-break-insert f" "\\^done.*" "set breakpoint on f"
> > +
> > +mi_send_resuming_command "exec-continue" "exec-continue to breakpoint on f"
> > +
> > +mi_expect_stop "breakpoint-hit" "f" ".*" ".*" ".*" {.* disp="keep"} \
> > + "run until breakpoint on f"
> > +
> > +mi_gdb_test "-stack-list-arguments 2" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack arguments listing 2"
> > +
> > +mi_gdb_test "-stack-list-arguments --simple-values" \
> > + "\\^done,stack-args=\\\[frame=\\{level=\"0\",args=\\\[\\{name=\"i\",type=\"int\",value=\"1\"\\},\\{name=\"ir\",type=\"int &\",value=\"@$hex: 2\"\\},\\{name=\"irr\",type=\"int &&\",value=\"@$hex: 3\"\\},\\{name=\"a\",type=\"int \\*\",value=\"$hex\"\\},\\{name=\"ar\",type=\"int \\(&\\)\\\[1\\\]\"\\},\\{name=\"arr\",type=\"int \\(&&\\)\\\[1\\\]\"\\},\\{name=\"s\",type=\"s\"\\},\\{name=\"sr\",type=\"s &\"\\},\\{name=\"srr\",type=\"s &&\"\\},\\{name=\"u\",type=\"u\"\\},\\{name=\"ur\",type=\"u &\"\\},\\{name=\"urr\",type=\"u &&\"\\}\\\]\\},frame=\\{level=\"1\",args=\\\[\\\]\\}\\\]" \
> > + "stack arguments listing --simple-values"
> > +
> > +mi_gdb_exit
> > --
> > 2.26.0
> >
^ permalink raw reply [flat|nested] 49+ messages in thread
* Re: [PING] [PATCH v6] [gdb/mi] Don't treat references to compound values as "simple".
2023-03-21 9:50 ` [PING] " Gareth Rees
2023-03-26 9:56 ` Gareth Rees
2023-04-18 9:23 ` Gareth Rees
@ 2023-04-24 9:53 ` Gareth Rees
2023-05-02 9:13 ` Gareth Rees
3 siblings, 0 replies; 49+ messages in thread
From: Gareth Rees @ 2023-04-24 9:53 UTC (permalink / raw)
To: gdb-patches
Fifth ping.
On Tue, 21 Mar 2023 at 09:50, Gareth Rees <grees@undo.io> wrote:
>
> This is a patch modifying the behaviour of the --simple-values option
> but as discussed previously, if GDB maintainers agree that adding a
> new option is the best approach, I would be happy to submit a patch
> for that solution instead.
>
> On Sat, 11 Mar 2023 at 11:49, Gareth Rees <grees@undo.io> wrote:
> >
> > 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
> > ---
> > gdb/NEWS | 8 +++
> > gdb/doc/gdb.texinfo | 7 +++
> > gdb/mi/mi-cmd-stack.c | 9 +--
> > gdb/mi/mi-cmd-var.c | 27 ++++++---
> > gdb/mi/mi-cmds.h | 5 ++
> > gdb/mi/mi-main.c | 7 +--
> > gdb/python/py-framefilter.c | 6 +-
> > gdb/testsuite/gdb.mi/mi-stack.exp | 16 ++++-
> > gdb/testsuite/gdb.mi/print-simple-values.cc | 62 ++++++++++++++++++++
> > gdb/testsuite/gdb.mi/print-simple-values.exp | 53 +++++++++++++++++
> > 10 files changed, 175 insertions(+), 25 deletions(-)
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.cc
> > create mode 100644 gdb/testsuite/gdb.mi/print-simple-values.exp
> >
> > diff --git a/gdb/NEWS b/gdb/NEWS
> > index cc262f1f8a6..1971b76a736 100644
> > --- a/gdb/NEWS
> > +++ b/gdb/NEWS
> > @@ -104,6 +104,14 @@ show always-read-ctf
> > without a thread restriction. The same is also true for the 'task'
> > field of an Ada task-specific breakpoint.
> >
> > +** The '--simple-values' argument to the '-stack-list-arguments',
> > + '-stack-list-locals', '-stack-list-variables', and '-var-list-children'
> > + commands now takes reference types into account: that is, a value is now
> > + considered simple if it is neither an array, structure, or union, nor a
> > + reference to an array, structure, or union. (Previously all references were
> > + considered simple.) Support for this feature can be verified by using the
> > + '-list-features' command, which should contain "simple-values-ref-types".
> > +
> > *** Changes in GDB 13
> >
> > * MI version 1 is deprecated, and will be removed in GDB 14.
> > diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> > index 954f1481dae..dff7ba374bd 100644
> > --- a/gdb/doc/gdb.texinfo
> > +++ b/gdb/doc/gdb.texinfo
> > @@ -37948,6 +37948,13 @@ option (@pxref{GDB/MI Program Execution}).
> > @item data-disassemble-a-option
> > Indicates that the @code{-data-disassemble} command supports the @option{-a}
> > option (@pxref{GDB/MI Data Manipulation}).
> > +@item simple-values-ref-types
> > +Indicates that the @code{--simple-values} argument to the
> > +@code{-stack-list-arguments}, @code{-stack-list-locals},
> > +@code{-stack-list-variables}, and @code{-var-list-children} commands
> > +takes reference types into account: that is, a value is considered
> > +simple if it is neither an array, structure, or union, nor a reference
> > +to an array, structure, or union.
> > @end ftable
> >
> > @findex -list-target-features
> > diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
> > index 4c4662ab5d7..406bf85ceec 100644
> > --- a/gdb/mi/mi-cmd-stack.c
> > +++ b/gdb/mi/mi-cmd-stack.c
> > @@ -645,13 +645,8 @@ list_args_or_locals (const frame_print_options &fp_opts,
> > switch (values)
> > {
> > case PRINT_SIMPLE_VALUES:
> > - {
> > - struct type *type = check_typedef (sym2->type ());
> > - if (type->code () == TYPE_CODE_ARRAY
> > - || type->code () == TYPE_CODE_STRUCT
> > - || type->code () == TYPE_CODE_UNION)
> > - break;
> > - }
> > + if (!mi_simple_type_p (sym2->type ()))
> > + break;
> > /* FALLTHROUGH */
> >
> > case PRINT_ALL_VALUES:
> > diff --git a/gdb/mi/mi-cmd-var.c b/gdb/mi/mi-cmd-var.c
> > index e026c239b87..36eea4619a7 100644
> > --- a/gdb/mi/mi-cmd-var.c
> > +++ b/gdb/mi/mi-cmd-var.c
> > @@ -335,14 +335,27 @@ mi_print_value_p (struct varobj *var, enum print_values print_values)
> > if (type == NULL)
> > return 1;
> > else
> > - {
> > - type = check_typedef (type);
> > + return mi_simple_type_p (type);
> > +}
> >
> > - /* For PRINT_SIMPLE_VALUES, only print the value if it has a type
> > - and that type is not a compound type. */
> > - return (type->code () != TYPE_CODE_ARRAY
> > - && type->code () != TYPE_CODE_STRUCT
> > - && type->code () != TYPE_CODE_UNION);
> > +/* See mi-cmds.h. */
> > +
> > +bool
> > +mi_simple_type_p (struct type *type)
> > +{
> > + type = check_typedef (type);
> > +
> > + if (TYPE_IS_REFERENCE (type))
> > + type = check_typedef (type->target_type ());
> > +
> > + switch (type->code ())
> > + {
> > + case TYPE_CODE_ARRAY:
> > + case TYPE_CODE_STRUCT:
> > + case TYPE_CODE_UNION:
> > + return false;
> > + default:
> > + return true;
> > }
> > }
> >
> > diff --git a/gdb/mi/mi-cmds.h b/gdb/mi/mi-cmds.h
> > index 490f50484d9..d867c298df9 100644
> > --- a/gdb/mi/mi-cmds.h
> > +++ b/gdb/mi/mi-cmds.h
> > @@ -226,4 +226,9 @@ using remove_mi_cmd_entries_ftype
> > = gdb::function_view<bool (mi_command *)>;
> > extern void remove_mi_cmd_entries (remove_mi_cmd_entries_ftype callback);
> >
> > +/* Return true if type is a simple type: that is, neither an array, structure,
> > + or union, nor a reference to an array, structure, or union. */
> > +
> > +extern bool mi_simple_type_p (struct type *type);
> > +
> > #endif /* MI_MI_CMDS_H */
> > diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
> > index 0013e5dfafd..cedad60d0b8 100644
> > --- a/gdb/mi/mi-main.c
> > +++ b/gdb/mi/mi-main.c
> > @@ -1656,6 +1656,7 @@ mi_cmd_list_features (const char *command, char **argv, int