]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: do not recompute values for inferior parameters when showing them
authorSébastien Darche <sdarche@efficios.com>
Mon, 29 Sep 2025 14:22:49 +0000 (10:22 -0400)
committerSébastien Darche <sdarche@efficios.com>
Wed, 8 Oct 2025 20:00:33 +0000 (16:00 -0400)
When calling the `show` command on a few inferior-specific settings
(inferior-tty, args, cwd), GDB will recompute the values despite them
being provided by a getter.

For instance, When `show cwd` is called, `do_show_command` will query
the value of the `cwd` through `get_inferior_cwd`, which already gets
the per-inferior value. The current version seems to be a workaround
from when settings could not provide a getter function and per-inferior
settings could thus not be implemented properly, forcing the `show`
implementation to recompute the value itself.

The changes clean up the code and makes the show command trust the
values it is being forwarded, as they will always be computed by the
getter function.

Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3b25f61f9101d98a6df7d50cee50131aec7e25c9
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/infcmd.c

index 771e47d76a23784810b7829ebc835d1f8c84bfd6..e4b3e5b61f82be5b4020f3a732ffa7454ec9af9b 100644 (file)
@@ -111,13 +111,9 @@ static void
 show_inferior_tty_command (struct ui_file *file, int from_tty,
                           struct cmd_list_element *c, const char *value)
 {
-  /* Note that we ignore the passed-in value in favor of computing it
-     directly.  */
-  const std::string &inferior_tty = current_inferior ()->tty ();
-
   gdb_printf (file,
              _("Terminal for future runs of program being debugged "
-               "is \"%s\".\n"), inferior_tty.c_str ());
+               "is \"%s\".\n"), value);
 }
 
 /* Store the new value passed to 'set args'.  */
@@ -142,11 +138,9 @@ static void
 show_args_command (struct ui_file *file, int from_tty,
                   struct cmd_list_element *c, const char *value)
 {
-  /* Ignore the passed in value, pull the argument directly from the
-     inferior.  However, these should always be the same.  */
   gdb_printf (file, _("\
 Argument list to give program being debugged when it is started is \"%s\".\n"),
-             current_inferior ()->args ().c_str ());
+             value);
 }
 
 /* See gdbsupport/common-inferior.h.  */
@@ -171,9 +165,7 @@ static void
 show_cwd_command (struct ui_file *file, int from_tty,
                  struct cmd_list_element *c, const char *value)
 {
-  const std::string &cwd = current_inferior ()->cwd ();
-
-  if (cwd.empty ())
+  if (strlen (value) == 0)
     gdb_printf (file,
                _("\
 You have not set the inferior's current working directory.\n\
@@ -183,7 +175,7 @@ server's cwd if remote debugging.\n"));
     gdb_printf (file,
                _("Current working directory that will be used "
                  "when starting the inferior is \"%s\".\n"),
-               cwd.c_str ());
+               value);
 }