* [PATCH v2 0/1] gdb: add 'set print shadowed' to hide shadowed variables
@ 2026-08-18 8:14 Stephan Rohr
2026-08-18 8:14 ` [PATCH v2 1/1] gdb: Introduce new setting to filter out " Stephan Rohr
0 siblings, 1 reply; 5+ messages in thread
From: Stephan Rohr @ 2026-08-18 8:14 UTC (permalink / raw)
To: gdb-patches; +Cc: simark
From: "Rohr, Stephan" <stephan.rohr@intel.com>
Hello all,
this is version 2 of the patch adding a new print option "set print
shadowed on|off". You can find v1 of the patch at:
https://sourceware.org/pipermail/gdb-patches/2026-August/229335.html
Simon posted feedback:
https://sourceware.org/pipermail/gdb-patches/2026-August/229420.html
I addressed the feedback from v1 and implemented the following:
* Added an option '-shadowed on|off' to the 'info locals' command.
* Rephrased the "use 'set print shadowed on|off' .." message.
* Fixed the corner case identified by Simon:
Breakpoint 1, main () at test.c:3
3 { int x = 2; x = x + 1; /* bp */ return x; }
(gdb) set print shadowed off
(gdb) info locals -t double
No matching locals.
Some shadowed variables were omitted, use 'set print shadowed on'
to include them.
* Avoid printing the "use 'set print shadowed' .." hint for every
frame in the backtrace command.
I appreciate your feedback.
Thanks
Stephan
Sargsyan, Eduard (1):
gdb: Introduce new setting to filter out shadowed variables.
gdb/NEWS | 14 +++
gdb/doc/gdb.texinfo | 22 +++-
gdb/stack.c | 143 +++++++++++++++++++----
gdb/testsuite/gdb.ada/var_shadowing.exp | 1 +
gdb/testsuite/gdb.base/options.exp | 23 ++++
gdb/testsuite/gdb.base/var-shadowing.c | 2 +-
gdb/testsuite/gdb.base/var-shadowing.exp | 81 +++++++++++++
7 files changed, 263 insertions(+), 23 deletions(-)
--
2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/1] gdb: Introduce new setting to filter out shadowed variables.
2026-08-18 8:14 [PATCH v2 0/1] gdb: add 'set print shadowed' to hide shadowed variables Stephan Rohr
@ 2026-08-18 8:14 ` Stephan Rohr
2026-08-21 19:03 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Stephan Rohr @ 2026-08-18 8:14 UTC (permalink / raw)
To: gdb-patches; +Cc: simark
From: "Sargsyan, Eduard" <eduard.sargsyan@intel.com>
Add a new setting 'print shadowed on|off' to control the printing of
shadowed variables in 'info locals'. Add a new option '-shadowed
on|off' to overwrite this setting for the invocation of the command.
When shadowed variables are present, each variable involved in a
shadowing relationship is annotated with its declaration location
'<file:line>'; the ones hidden by an inner declaration are additionally
marked ', shadowed'.
Given this code, stopped at line 10:
1 int num = 1;
2 int
3 main ()
4 {
5 const char *str = "main";
6 int num = 3;
7 {
8 const char *str = "nested";
9 int num = 5;
10 num = 0; // break here
11 }
12 return num;
13 }
By default, 'info locals' prints shadowed variables:
(gdb) info locals
str = 0x555555556009 "nested" <main.c:8>
num = 5 <main.c:9>
str = 0x555555556004 "main" <main.c:5, shadowed>
num = 3 <main.c:6, shadowed>
Use 'set print shadowed off' to hide shadowed variables.
The user may not want to print shadowed variables:
(gdb) set print shadowed off
(gdb) info locals
str = 0x555555556009 "nested"
num = 5
Some shadowed variables were omitted, use 'set print shadowed on'
to include them.
Co-Authored-By: Stephan Rohr <stephan.rohr@intel.com>
---
gdb/NEWS | 14 +++
gdb/doc/gdb.texinfo | 22 +++-
gdb/stack.c | 143 +++++++++++++++++++----
gdb/testsuite/gdb.ada/var_shadowing.exp | 1 +
gdb/testsuite/gdb.base/options.exp | 23 ++++
gdb/testsuite/gdb.base/var-shadowing.c | 2 +-
gdb/testsuite/gdb.base/var-shadowing.exp | 81 +++++++++++++
7 files changed, 263 insertions(+), 23 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 10c182067f9..3a1799143a6 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,20 @@
*** Changes since GDB 18
+* New commands
+
+set print shadowed on|off
+show print shadowed
+This controls the output of the "info locals" command. If the option is 'off'
+shadowed variables will be omitted in output. The default is to print
+shadowed variables.
+
+* Changed commands
+
+info locals
+ The new "-shadowed on|off" option overrides the "set print shadowed"
+ setting for a single invocation of the command.
+
*** Changes in GDB 18
* Support for the Common Trace Format (CTF) has been removed. GDB now
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 0030698dcee..502d92c6b1d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -9178,7 +9178,7 @@ If both @var{regexp} and @var{type_regexp} are provided, an argument
is printed only if its name matches @var{regexp} and its type matches
@var{type_regexp}.
-@item info locals [-q]
+@item info locals [-q] [-shadowed [@code{on}|@code{off}]]
@kindex info locals
Print the local variables of the selected frame, each on a separate
line. These are all variables (declared either static or automatic)
@@ -9188,6 +9188,9 @@ The optional flag @samp{-q}, which stands for @samp{quiet}, disables
printing header information and messages explaining why no local variables
have been printed.
+The optional flag @samp{-shadowed} overrides the @code{set print shadowed}
+setting (@pxref{set print shadowed}) for this invocation of the command.
+
@smallexample
@group
1: int x = 3;
@@ -9202,6 +9205,7 @@ have been printed.
x = 4 <file.c:3>
y = 52
x = 3 <file.c:1, shadowed>
+Use 'set print shadowed off' to hide shadowed variables.
@end group
@end smallexample
@@ -9212,7 +9216,8 @@ same name which is declared within an inner scope (decision block,
method, or inner class). When shadowing is detected, location
information is added to all instances of the shadowed variable name.
The outermost instances are additionally followed by @samp{shadowed}
-to indicate that they are not the active variable.
+to indicate that they are not the active variable. Printing shadowed
+variables can be controlled by @ref{set print shadowed}.
@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
Like @kbd{info locals}, but only print the local variables selected
@@ -12829,6 +12834,19 @@ Do not pretty print C@t{++} virtual function tables.
@item show print vtbl
Show whether C@t{++} virtual function tables are pretty printed, or not.
+
+@anchor{set print shadowed}
+@item set print shadowed
+@itemx set print shadowed on
+@cindex printing shadowed variables
+Print variables that are shadowed by a declaration in an inner scope
+(@pxref{shadowed variables}). The default is on.
+
+@item set print shadowed off
+Do not print shadowed variables.
+
+@item show print shadowed
+Show whether shadowed variables are printed or not.
@end table
@node Pretty Printing
diff --git a/gdb/stack.c b/gdb/stack.c
index 954ef6b11a4..56f3d7d599b 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -217,10 +217,45 @@ static const gdb::option::option_def backtrace_command_option_defs[] = {
},
};
+/* Option for printing shadowed variables. */
+
+struct shadowed_print_options
+{
+ bool print_shadowed = true;
+};
+
+static shadowed_print_options user_shadowed_print_options;
+
+/* Implement "show print shadowed". */
+
+static void
+show_print_shadowed (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ gdb_printf (file, _("Printing of shadowed variables is %s.\n"), value);
+}
+
+/* Option definitions for the shadowed variables setting. */
+
+static const gdb::option::option_def shadowed_print_option_defs[] = {
+
+ gdb::option::boolean_option_def<shadowed_print_options> {
+ "shadowed",
+ [] (shadowed_print_options *opt) { return &opt->print_shadowed; },
+ show_print_shadowed, /* show_cmd_cb */
+ N_("Set printing of shadowed variables."),
+ N_("Show printing of shadowed variables."),
+ N_("When on, variables that are shadowed by a declaration in an inner\n\
+scope are printed, annotated with the location of their declaration.\n\
+When off, such variables are omitted."),
+ },
+};
+
/* Prototypes for local functions. */
static void print_frame_local_vars (const frame_info_ptr &frame,
- bool quiet,
+ const shadowed_print_options &sh_opts,
+ bool quiet, bool print_shadowed_msg,
const char *regexp, const char *t_regexp,
int num_tabs, struct ui_file *stream);
@@ -1985,7 +2020,8 @@ backtrace_command_1 (const frame_print_options &fp_opts,
print_frame_info (fp_opts, fi, 1, LOCATION, 1, 0);
if ((flags & PRINT_LOCALS) != 0)
- print_frame_local_vars (fi, false, NULL, NULL, 1, gdb_stdout);
+ print_frame_local_vars (fi, user_shadowed_print_options, false,
+ false, NULL, NULL, 1, gdb_stdout);
/* Save the last frame to check for error conditions. */
trailing = fi;
@@ -2258,6 +2294,9 @@ struct print_variable_and_value_data
int num_tabs;
struct ui_file *stream;
int values_printed;
+ bool print_shadowed = true;
+ bool printed_shadowed_variables = false;
+ bool omitted_shadowed_variables = false;
void operator() (const char *print_name, struct symbol *sym,
var_shadowing shadow_status);
@@ -2281,6 +2320,12 @@ print_variable_and_value_data::operator() (const char *print_name,
if (language_def (sym->language ())->symbol_printing_suppressed (sym))
return;
+ if (!print_shadowed && shadow_status == var_shadowing::SHADOWED)
+ {
+ omitted_shadowed_variables = true;
+ return;
+ }
+
frame = frame_find_by_id (frame_id);
if (frame == NULL)
{
@@ -2289,9 +2334,13 @@ print_variable_and_value_data::operator() (const char *print_name,
}
print_variable_and_value (print_name, sym, frame, stream, num_tabs,
- shadow_status);
+ print_shadowed ? shadow_status
+ : var_shadowing::NONE);
values_printed = 1;
+
+ if (shadow_status == var_shadowing::SHADOWED)
+ printed_shadowed_variables = true;
}
/* Prepares the regular expression REG from REGEXP.
@@ -2312,6 +2361,9 @@ prepare_reg (const char *regexp, std::optional<compiled_regex> *reg)
/* Print all variables from the innermost up to the function block of FRAME.
Print them with values to STREAM indented by NUM_TABS.
+ SH_OPTS controls whether shadowed variables are printed.
+ PRINT_SHADOWED_MSG controls whether a trailing "set print shadowed" message
+ is printed.
If REGEXP is not NULL, only print local variables whose name
matches REGEXP.
If T_REGEXP is not NULL, only print local variables whose type
@@ -2321,7 +2373,8 @@ prepare_reg (const char *regexp, std::optional<compiled_regex> *reg)
static void
print_frame_local_vars (const frame_info_ptr &frame,
- bool quiet,
+ const shadowed_print_options &sh_opts,
+ bool quiet, bool print_shadowed_msg,
const char *regexp, const char *t_regexp,
int num_tabs, struct ui_file *stream)
{
@@ -2351,6 +2404,7 @@ print_frame_local_vars (const frame_info_ptr &frame,
cb_data.num_tabs = 4 * num_tabs;
cb_data.stream = stream;
cb_data.values_printed = 0;
+ cb_data.print_shadowed = sh_opts.print_shadowed;
/* Temporarily change the selected frame to the given FRAME.
This allows routines that rely on the selected frame instead
@@ -2360,13 +2414,28 @@ print_frame_local_vars (const frame_info_ptr &frame,
iterate_over_block_local_vars_printing (block, cb_data);
- if (!cb_data.values_printed && !quiet)
+ if (quiet)
+ return;
+
+ if (!cb_data.values_printed)
{
if (regexp == NULL && t_regexp == NULL)
gdb_printf (stream, _("No locals.\n"));
else
gdb_printf (stream, _("No matching locals.\n"));
}
+
+ if (!print_shadowed_msg)
+ return;
+
+ if (cb_data.printed_shadowed_variables)
+ gdb_printf (stream,
+ _("Use 'set print shadowed off' "
+ "to hide shadowed variables.\n"));
+ else if (cb_data.omitted_shadowed_variables)
+ gdb_printf (stream,
+ _("Some shadowed variables were omitted, use "
+ "'set print shadowed on' to include them.\n"));
}
/* Structure to hold the values of the options used by the 'info
@@ -2397,24 +2466,51 @@ static const gdb::option::option_def info_print_options_defs[] = {
}
};
-/* Returns the option group used by 'info locals' and 'info args'
- commands. */
+/* Returns the option group used by the 'info args' command. */
static gdb::option::option_def_group
-make_info_print_options_def_group (info_print_options *opts)
+make_info_args_options_def_group (info_print_options *opts)
{
return {{info_print_options_defs}, opts};
}
-/* Command completer for 'info locals' and 'info args'. */
+/* Returns the option groups used by the 'info locals' command. */
+
+static std::array<gdb::option::option_def_group, 2>
+make_info_locals_options_def_group (info_print_options *opts,
+ shadowed_print_options *sh_opts)
+{
+ return {{
+ { {info_print_options_defs}, opts },
+ { {shadowed_print_option_defs}, sh_opts }
+ }};
+}
+
+/* Command completer for 'info args'. */
static void
-info_print_command_completer (struct cmd_list_element *ignore,
- completion_tracker &tracker,
- const char *text, const char * /* word */)
+info_args_command_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char * /* word */)
{
const auto group
- = make_info_print_options_def_group (nullptr);
+ = make_info_args_options_def_group (nullptr);
+ if (gdb::option::complete_options
+ (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
+ return;
+
+ const char *word = advance_to_expression_complete_word_point (tracker, text);
+ symbol_completer (ignore, tracker, text, word);
+}
+
+/* Command completer for 'info locals'. */
+
+static void
+info_locals_command_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char * /* word */)
+{
+ const auto group = make_info_locals_options_def_group (nullptr, nullptr);
if (gdb::option::complete_options
(tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
return;
@@ -2429,7 +2525,8 @@ void
info_locals_command (const char *args, int from_tty)
{
info_print_options opts;
- auto grp = make_info_print_options_def_group (&opts);
+ shadowed_print_options sh_opts = user_shadowed_print_options;
+ auto grp = make_info_locals_options_def_group (&opts, &sh_opts);
gdb::option::process_options
(&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
if (args != nullptr && *args == '\0')
@@ -2437,7 +2534,7 @@ info_locals_command (const char *args, int from_tty)
print_frame_local_vars
(get_selected_frame (_("No frame selected.")),
- opts.quiet, args,
+ sh_opts, opts.quiet, true, args,
opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (),
0, gdb_stdout);
}
@@ -2546,7 +2643,7 @@ void
info_args_command (const char *args, int from_tty)
{
info_print_options opts;
- auto grp = make_info_print_options_def_group (&opts);
+ auto grp = make_info_args_options_def_group (&opts);
gdb::option::process_options
(&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
if (args != nullptr && *args == '\0')
@@ -3508,11 +3605,13 @@ Usage: info frame level LEVEL"),
cmd = add_info ("locals", info_locals_command,
info_print_args_help (_("\
All local variables of current stack frame or those matching REGEXPs.\n\
-Usage: info locals [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
-Prints the local variables of the current stack frame.\n"),
+Usage: info locals [-q] [-shadowed [on|off]] [-t TYPEREGEXP] [NAMEREGEXP]\n\
+Prints the local variables of the current stack frame.\n\
+The -shadowed option overrides the \"set print shadowed\" setting for this\n\
+command.\n"),
_("local variables"),
false));
- set_cmd_completer_handle_brkchars (cmd, info_print_command_completer);
+ set_cmd_completer_handle_brkchars (cmd, info_locals_command_completer);
cmd = add_info ("args", info_args_command,
info_print_args_help (_("\
All argument variables of current stack frame or those matching REGEXPs.\n\
@@ -3520,7 +3619,7 @@ Usage: info args [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\
Prints the argument variables of the current stack frame.\n"),
_("argument variables"),
false));
- set_cmd_completer_handle_brkchars (cmd, info_print_command_completer);
+ set_cmd_completer_handle_brkchars (cmd, info_args_command_completer);
/* Install "set print raw frame-arguments", a deprecated spelling of
"set print raw-frame-arguments". */
@@ -3560,4 +3659,8 @@ source line."),
gdb::option::add_setshow_cmds_for_options
(class_stack, &user_frame_print_options,
frame_print_option_defs, &setprintlist, &showprintlist);
+
+ gdb::option::add_setshow_cmds_for_options
+ (class_support, &user_shadowed_print_options,
+ shadowed_print_option_defs, &setprintlist, &showprintlist);
}
diff --git a/gdb/testsuite/gdb.ada/var_shadowing.exp b/gdb/testsuite/gdb.ada/var_shadowing.exp
index ffa96b049cf..d927b0d9888 100644
--- a/gdb/testsuite/gdb.ada/var_shadowing.exp
+++ b/gdb/testsuite/gdb.ada/var_shadowing.exp
@@ -36,4 +36,5 @@ gdb_test "info locals" [multi_line \
"i = 111\t<$testfile.adb:$i_level3>" \
"i = 11\t<$testfile.adb:$i_level2, shadowed>" \
"i = 1\t<$testfile.adb:$i_level1, shadowed>" \
+ "Use 'set print shadowed off' to hide shadowed variables." \
] "info locals at innermost level"
diff --git a/gdb/testsuite/gdb.base/options.exp b/gdb/testsuite/gdb.base/options.exp
index 35487ead6a7..aa4293f1016 100644
--- a/gdb/testsuite/gdb.base/options.exp
+++ b/gdb/testsuite/gdb.base/options.exp
@@ -30,6 +30,7 @@
# - tfaas
# - thread apply
# - taas
+# - info locals
load_lib compile-support.exp
load_lib completion-support.exp
@@ -531,6 +532,25 @@ proc_with_prefix test-info-threads {} {
test_gdb_complete_none "info threads I"
}
+# Basic option-machinery + "info locals" command integration tests.
+proc_with_prefix test-info-locals {} {
+ clean_restart $::testfile
+
+ if {![runto_main]} {
+ return
+ }
+
+ test_gdb_complete_multiple "info locals " "-" "" {
+ "-q"
+ "-shadowed"
+ "-t"
+ }
+
+ test_gdb_complete_unique \
+ "info locals -s" \
+ "info locals -shadowed"
+}
+
# Miscellaneous tests.
proc_with_prefix test-misc {variant} {
global all_options
@@ -1175,6 +1195,9 @@ test-thread-apply
# Basic "info threads" integration tests.
test-info-threads
+# Basic "info locals" integration tests.
+test-info-locals
+
# There was a bug where the "metasyntactic variable" was glued to the
# option.
gdb_test "help maintenance test-options unknown-is-operand" \
diff --git a/gdb/testsuite/gdb.base/var-shadowing.c b/gdb/testsuite/gdb.base/var-shadowing.c
index 7886ea31aec..a3ab8d9bb01 100644
--- a/gdb/testsuite/gdb.base/var-shadowing.c
+++ b/gdb/testsuite/gdb.base/var-shadowing.c
@@ -24,7 +24,7 @@ shadowing (void)
a = 101; /* bp for locals 1 */
{
unsigned int val2 = 3; /* val2-d2 */
- unsigned int val3 = 4; /* val3-d1 */
+ double val3 = 4; /* val3-d1 */
a = 102; /* bp for locals 2 */
{
unsigned int val1 = 5; /* val1-d2 */
diff --git a/gdb/testsuite/gdb.base/var-shadowing.exp b/gdb/testsuite/gdb.base/var-shadowing.exp
index 502cbad11f6..8efbabadd0c 100644
--- a/gdb/testsuite/gdb.base/var-shadowing.exp
+++ b/gdb/testsuite/gdb.base/var-shadowing.exp
@@ -54,6 +54,7 @@ gdb_test "info locals" [multi_line \
"a = 101" \
"val1 = 1" \
"val2 = 2\t<$srcfile:$val2_d1, shadowed>" \
+ "Use 'set print shadowed off' to hide shadowed variables." \
] "info locals first level"
gdb_breakpoint $srcfile:$bp_line3
@@ -65,6 +66,7 @@ gdb_test "info locals" [multi_line \
"a = 102" \
"val1 = 1\t<$srcfile:$val1_d1, shadowed>" \
"val2 = 2\t<$srcfile:$val2_d1, shadowed>" \
+ "Use 'set print shadowed off' to hide shadowed variables." \
] "info locals second level"
gdb_breakpoint $srcfile:$bp_line4
@@ -80,8 +82,87 @@ gdb_test "info locals" [multi_line \
"a = 103\t<$srcfile:$a_line, shadowed>" \
"val1 = 1\t<$srcfile:$val1_d1, shadowed>" \
"val2 = 2\t<$srcfile:$val2_d1, shadowed>" \
+ "Use 'set print shadowed off' to hide shadowed variables." \
] "info locals at innermost level"
+gdb_test "info locals -shadowed off" [multi_line \
+ "a = 999" \
+ "val1 = 6" \
+ "val2 = 7" \
+ "val3 = 8" \
+ "Some shadowed variables were omitted, use 'set print shadowed on' to include them." \
+ ] "info locals -shadowed off at innermost level"
+
+# 'val3' is declared as a 'double' in the outer scope only, so a type filter
+# selects the shadowed variable only.
+gdb_test "info locals -t double" [multi_line \
+ "val3 = 4\t<$srcfile:$val3_d1, shadowed>" \
+ "Use 'set print shadowed off' to hide shadowed variables." \
+ ] "info locals -t double at innermost level"
+
+# Ensure 'backtrace -full' does not print the shadowed variables hint.
+gdb_test "backtrace -full" [multi_line \
+ "#0 +shadowing \\(\\) at .*" \
+ "\[ \t\]+a = 999\t<${testfile}2.c:16>" \
+ "\[ \t\]+val1 = 6\t<$srcfile:$val1_d3>" \
+ "\[ \t\]+val2 = 7\t<$srcfile:$val2_d3>" \
+ "\[ \t\]+val3 = 8\t<$srcfile:$val3_d2>" \
+ "\[ \t\]+val1 = 5\t<$srcfile:$val1_d2, shadowed>" \
+ "\[ \t\]+val2 = 3\t<$srcfile:$val2_d2, shadowed>" \
+ "\[ \t\]+val3 = 4\t<$srcfile:$val3_d1, shadowed>" \
+ "\[ \t\]+a = 103\t<$srcfile:$a_line, shadowed>" \
+ "\[ \t\]+val1 = 1\t<$srcfile:$val1_d1, shadowed>" \
+ "\[ \t\]+val2 = 2\t<$srcfile:$val2_d1, shadowed>" \
+ "#1 +$hex in main \\(\\) at .*" \
+ "No locals\\." \
+ ] "bt -full at innermost level"
+
+gdb_test_no_output "set print shadowed off"
+
+gdb_test "show print shadowed" \
+ "Printing of shadowed variables is off\\." \
+ "show print shadowed off"
+
+gdb_test "info locals" [multi_line \
+ "a = 999" \
+ "val1 = 6" \
+ "val2 = 7" \
+ "val3 = 8" \
+ "Some shadowed variables were omitted, use 'set print shadowed on' to include them." \
+ ] "info locals at innermost level with filtered out shadowed"
+
+# Only the shadowed 'val3' matches the type filter, so nothing is printed.
+# Still, the user is told that variables were omitted due to shadowing.
+gdb_test "info locals -t double" [multi_line \
+ "No matching locals\\." \
+ "Some shadowed variables were omitted, use 'set print shadowed on' to include them." \
+ ] "info locals -t double with filtered out shadowed"
+
+# A variable filtered out by a regexp is not reported as omitted due to
+# shadowing.
+gdb_test "info locals -t float" "No matching locals\\." \
+ "info locals -t float with filtered out shadowed"
+
+# The '-shadowed' option overrides the setting for one invocation.
+gdb_test "info locals -shadowed on" [multi_line \
+ "a = 999\t<${testfile}2.c:16>" \
+ "val1 = 6\t<$srcfile:$val1_d3>" \
+ "val2 = 7\t<$srcfile:$val2_d3>" \
+ "val3 = 8\t<$srcfile:$val3_d2>" \
+ "val1 = 5\t<$srcfile:$val1_d2, shadowed>" \
+ "val2 = 3\t<$srcfile:$val2_d2, shadowed>" \
+ "val3 = 4\t<$srcfile:$val3_d1, shadowed>" \
+ "a = 103\t<$srcfile:$a_line, shadowed>" \
+ "val1 = 1\t<$srcfile:$val1_d1, shadowed>" \
+ "val2 = 2\t<$srcfile:$val2_d1, shadowed>" \
+ "Use 'set print shadowed off' to hide shadowed variables." \
+ ] "info locals -shadowed on at innermost level"
+
+# '-q' suppresses the hint about the setting.
+gdb_test_no_output "info locals -q -t double"
+
+gdb_test_no_output "set print shadowed on"
+
gdb_breakpoint $srcfile:$bp_line5
gdb_continue_to_breakpoint "continue to outermost level last" \
".*$srcfile:$bp_line5.*"
--
2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] gdb: Introduce new setting to filter out shadowed variables.
2026-08-18 8:14 ` [PATCH v2 1/1] gdb: Introduce new setting to filter out " Stephan Rohr
@ 2026-08-21 19:03 ` Tom Tromey
2026-08-24 15:05 ` Rohr, Stephan
0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2026-08-21 19:03 UTC (permalink / raw)
To: Stephan Rohr; +Cc: gdb-patches, simark
>>>>> "Stephan" == Stephan Rohr <stephan.rohr@intel.com> writes:
Stephan> +* New commands
Stephan> +
Stephan> +set print shadowed on|off
Stephan> +show print shadowed
Stephan> +This controls the output of the "info locals" command. If the option is 'off'
Stephan> +shadowed variables will be omitted in output. The default is to print
Stephan> +shadowed variables.
Needs a doc review but I think the explanation lines should be indented.
Stephan> +/* Option for printing shadowed variables. */
Stephan> +
Stephan> +struct shadowed_print_options
Stephan> +{
Stephan> + bool print_shadowed = true;
I don't really follow why this type is needed.
Stephan> print_variable_and_value (print_name, sym, frame, stream, num_tabs,
Stephan> - shadow_status);
Stephan> + print_shadowed ? shadow_status
Stephan> + : var_shadowing::NONE);
Lining things up like this isn't really the gdb style; you could break
before the "?" instead.
Stephan> + if (cb_data.printed_shadowed_variables)
Stephan> + gdb_printf (stream,
Stephan> + _("Use 'set print shadowed off' "
Stephan> + "to hide shadowed variables.\n"));
Stephan> + else if (cb_data.omitted_shadowed_variables)
Stephan> + gdb_printf (stream,
Stephan> + _("Some shadowed variables were omitted, use "
Stephan> + "'set print shadowed on' to include them.\n"));
I'm slowly trying to transition gdb to using double quotes rather than
the current mishmash of quoting styles.
Also command names should be styled using command_style.
thanks,
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH v2 1/1] gdb: Introduce new setting to filter out shadowed variables.
2026-08-21 19:03 ` Tom Tromey
@ 2026-08-24 15:05 ` Rohr, Stephan
2026-08-27 15:43 ` Tom Tromey
0 siblings, 1 reply; 5+ messages in thread
From: Rohr, Stephan @ 2026-08-24 15:05 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches, simark
Hi Tom,
thanks for the feedback. I will follow up with a v3 of the patch. I have one
question regarding your feedback, please see inline below.
Thanks
Stephan
> -----Original Message-----
> From: Tom Tromey <tom@tromey.com>
> Sent: Friday, 21 August 2026 21:03
> To: Rohr, Stephan <stephan.rohr@intel.com>
> Cc: gdb-patches@sourceware.org; simark@simark.ca
> Subject: Re: [PATCH v2 1/1] gdb: Introduce new setting to filter out shadowed
> variables.
>
> >>>>> "Stephan" == Stephan Rohr <stephan.rohr@intel.com> writes:
>
> Stephan> +* New commands
> Stephan> +
> Stephan> +set print shadowed on|off
> Stephan> +show print shadowed
> Stephan> +This controls the output of the "info locals" command. If the
> option is 'off'
> Stephan> +shadowed variables will be omitted in output. The default is to
> print
> Stephan> +shadowed variables.
>
> Needs a doc review but I think the explanation lines should be indented.
>
> Stephan> +/* Option for printing shadowed variables. */
> Stephan> +
> Stephan> +struct shadowed_print_options
> Stephan> +{
> Stephan> + bool print_shadowed = true;
>
> I don't really follow why this type is needed.
Do you mean why we need the flag or why it is encapsulated into a new
"shadowed_print_options" type? Or why it is not included in any other
print related options struct?
I removed the "-shadowed" option from the "value_print_options" to
avoid the unnecessary "print -shadowed" option in v2. The "shadowed"
option is used to store the user's setting for the session and can be overwritten
by the "info locals" command. Thus, I added a new type here similar to
"maintenance_selftest_options" in maint.c.
I separated this from the "info_print_options" as these are per invocation and I
need to store the "print_shadowed" option for the lifetime of the session. Also,
the "-shadowed" option is only used by the "info locals" command.
>
> Stephan> print_variable_and_value (print_name, sym, frame, stream,
> num_tabs,
> Stephan> - shadow_status);
> Stephan> + print_shadowed ? shadow_status
> Stephan> + : var_shadowing::NONE);
>
> Lining things up like this isn't really the gdb style; you could break
> before the "?" instead.
>
> Stephan> + if (cb_data.printed_shadowed_variables)
> Stephan> + gdb_printf (stream,
> Stephan> + _("Use 'set print shadowed off' "
> Stephan> + "to hide shadowed variables.\n"));
> Stephan> + else if (cb_data.omitted_shadowed_variables)
> Stephan> + gdb_printf (stream,
> Stephan> + _("Some shadowed variables were omitted, use "
> Stephan> + "'set print shadowed on' to include them.\n"));
>
> I'm slowly trying to transition gdb to using double quotes rather than
> the current mishmash of quoting styles.
>
> Also command names should be styled using command_style.
>
> thanks,
> Tom
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] gdb: Introduce new setting to filter out shadowed variables.
2026-08-24 15:05 ` Rohr, Stephan
@ 2026-08-27 15:43 ` Tom Tromey
0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-08-27 15:43 UTC (permalink / raw)
To: Rohr, Stephan; +Cc: Tom Tromey, gdb-patches, simark
>>>>> Rohr, Stephan <stephan.rohr@intel.com> writes:
Stephan> +/* Option for printing shadowed variables. */
Stephan> +
Stephan> +struct shadowed_print_options
Stephan> +{
Stephan> + bool print_shadowed = true;
>> I don't really follow why this type is needed.
> Do you mean why we need the flag or why it is encapsulated into a new
> "shadowed_print_options" type? Or why it is not included in any other
> print related options struct?
Sorry for being unclear. It just seemed strange to me to have a
structure that just holds a single boolean.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-27 15:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-18 8:14 [PATCH v2 0/1] gdb: add 'set print shadowed' to hide shadowed variables Stephan Rohr
2026-08-18 8:14 ` [PATCH v2 1/1] gdb: Introduce new setting to filter out " Stephan Rohr
2026-08-21 19:03 ` Tom Tromey
2026-08-24 15:05 ` Rohr, Stephan
2026-08-27 15:43 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox