[4/5] gdb: make set/show inferior-tty work with $_gdb_setting_str

Message ID 47a6f80078752b45ea06e9fe60ae7c57f1cb0b88.1680608960.git.aburgess@redhat.com
State New
Headers
Series Fixes for per-inferior settings and $_gdb_setting_str() |

Commit Message

Andrew Burgess April 4, 2023, 12:45 p.m. UTC
  Like the previous two commits, this commit fixes set/show inferior-tty
to work with $_gdb_setting_str.

Instead of using a scratch variable which is then pushed into the
current inferior from a set callback, move to the API that allows for
getters and setters, and store the value directly within the current
inferior.

Update an existing test to check the inferior-tty setting.
---
 gdb/infcmd.c                              | 30 +++++++++++++----------
 gdb/testsuite/gdb.base/inferior-clone.exp |  9 +++++++
 2 files changed, 26 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 2e26ae9b934..de586f830f6 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -66,11 +66,6 @@  static void step_1 (int, int, const char *);
 #define ERROR_NO_INFERIOR \
    if (!target_has_execution ()) error (_("The program is not being run."));
 
-/* Scratch area where 'set inferior-tty' will store user-provided value.
-   We'll immediate copy it into per-inferior storage.  */
-
-static std::string inferior_io_terminal_scratch;
-
 /* Pid of our debugged inferior, or 0 if no inferior now.
    Since various parts of infrun.c test this to see whether there is a program
    being debugged it should be nonzero (currently 3 is used) for remote
@@ -94,15 +89,24 @@  static bool finish_print = true;
 
 
 
+/* Store the new value passed to 'set inferior-tty'.  */
+
 static void
-set_inferior_tty_command (const char *args, int from_tty,
-			  struct cmd_list_element *c)
+set_tty_value (const std::string &tty)
 {
-  /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
-     Now route it to current inferior.  */
-  current_inferior ()->set_tty (inferior_io_terminal_scratch);
+  current_inferior ()->set_tty (tty);
 }
 
+/* Get the current 'inferior-tty' value.  */
+
+static const std::string &
+get_tty_value ()
+{
+  return current_inferior ()->tty ();
+}
+
+/* Implement 'show inferior-tty' command.  */
+
 static void
 show_inferior_tty_command (struct ui_file *file, int from_tty,
 			   struct cmd_list_element *c, const char *value)
@@ -3136,14 +3140,14 @@  _initialize_infcmd ()
 
   /* Add the filename of the terminal connected to inferior I/O.  */
   auto tty_set_show =
-    add_setshow_optional_filename_cmd ("inferior-tty", class_run,
-				       &inferior_io_terminal_scratch, _("\
+    add_setshow_optional_filename_cmd ("inferior-tty", class_run, _("\
 Set terminal for future runs of program being debugged."), _("		\
 Show terminal for future runs of program being debugged."), _("\
 Usage: set inferior-tty [TTY]\n\n\
 If TTY is omitted, the default behavior of using the same terminal as GDB\n\
 is restored."),
-				       set_inferior_tty_command,
+				       set_tty_value,
+				       get_tty_value,
 				       show_inferior_tty_command,
 				       &setlist, &showlist);
   add_alias_cmd ("tty", tty_set_show.set, class_run, 0, &cmdlist);
diff --git a/gdb/testsuite/gdb.base/inferior-clone.exp b/gdb/testsuite/gdb.base/inferior-clone.exp
index 8e0378323f9..806ec0ad68c 100644
--- a/gdb/testsuite/gdb.base/inferior-clone.exp
+++ b/gdb/testsuite/gdb.base/inferior-clone.exp
@@ -30,6 +30,8 @@  with_test_prefix "setup inferior 1" {
     gdb_test_no_output "set environment FOO foo"
     gdb_test_no_output "set environment BAR bar"
     gdb_test_no_output "set inferior-tty some_tty"
+    gdb_test {print $_gdb_setting_str("inferior-tty")} \
+	" = \"some_tty\""
 }
 
 # Check that properties of inferior 1 have been copied
@@ -45,6 +47,8 @@  with_test_prefix "inferior 2" {
     gdb_test "show environment ENVVAR" "ENVVAR = var"
     gdb_test "show inferior-tty" \
 	"Terminal for future runs of program being debugged is \"some_tty\"\."
+    gdb_test {print $_gdb_setting_str("inferior-tty")} \
+	" = \"some_tty\""
 }
 
 # Change this second inferior, to check that the next clone-inferior
@@ -54,6 +58,9 @@  with_test_prefix "update inferior 2" {
     gdb_test_no_output "set args foo"
     gdb_test_no_output "set cwd /somewhere/else"
     gdb_test_no_output "set environment FOO oof"
+    gdb_test_no_output "set inferior-tty another_tty"
+    gdb_test {print $_gdb_setting_str("inferior-tty")} \
+	" = \"another_tty\""
 }
 
 with_test_prefix "inferior 1" {
@@ -67,6 +74,8 @@  with_test_prefix "inferior 1" {
     gdb_test "show environment ENVVAR" "ENVVAR = var"
     gdb_test "show inferior-tty" \
 	"Terminal for future runs of program being debugged is \"some_tty\"\."
+    gdb_test {print $_gdb_setting_str("inferior-tty")} \
+	" = \"some_tty\""
 }
 
 # Tweak inferior 1 a bit more.