CLI, that the MI allowed it was a long standing bug, which has now
been fixed.
+** 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".
+
* Python API
** The gdb.unwinder.Unwinder.name attribute is now read-only.
@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
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:
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;
}
}
= 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 */
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");
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;
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;
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)
# -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=\\\[\\\]\}\\\]" \
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 {} {
# -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\"\\\]" \
"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"
--- /dev/null
+/* 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 });
+}
--- /dev/null
+# 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