Make {get,set}_inferior_io_terminal inferior methods
authorPedro Alves <palves@redhat.com>
Sat, 27 Jun 2020 13:56:05 +0000 (14:56 +0100)
committerPedro Alves <palves@redhat.com>
Sat, 27 Jun 2020 13:56:05 +0000 (14:56 +0100)
This converts the get_inferior_io_terminal and
set_inferior_io_terminal free functions to inferior methods.

Since the related commands are called "tty", "{set,show}
inferior-tty", and MI's "-inferior-tty-{set,show}", to make the
connection between the commands and the code more obvious, the methods
are named set_tty/tty instead of set_io_terminal/io_terminal.

gdb/ChangeLog:

* fork-child.c (prefork_hook): Adjust.
* infcmd.c (set_inferior_io_terminal, get_inferior_io_terminal):
Delete.
(set_inferior_tty_command, show_inferior_tty_command): Adjust.
* inferior.c (inferior::set_tty, inferior::tty): New methods.
* inferior.h (set_inferior_io_terminal, get_inferior_io_terminal):
Remove declarations.
(struct inferior) <set_tty, tty>: New methods.
(struct inferior) <terminal>: Rename to ...
(struct inferior) <m_terminal>: ... this and make private.
* main.c (captured_main_1): Adjust.
* mi/mi-cmd-env.c (mi_cmd_inferior_tty_set): Adjust.
(mi_cmd_inferior_tty_show): Adjust.
* nto-procfs.c (nto_procfs_target::create_inferior): Adjust.
* windows-nat.c (windows_nat_target::create_inferior): Adjust.

gdb/ChangeLog
gdb/fork-child.c
gdb/infcmd.c
gdb/inferior.c
gdb/inferior.h
gdb/main.c
gdb/mi/mi-cmd-env.c
gdb/nto-procfs.c
gdb/windows-nat.c

index d09d316f76602b021a25a1cf2b824e5585ba27e0..0ab251ddc4a1fd0ed3bb933f7b4c1a032a8f5c34 100644 (file)
@@ -1,3 +1,21 @@
+2020-06-27  Pedro Alves  <palves@redhat.com>
+
+       * fork-child.c (prefork_hook): Adjust.
+       * infcmd.c (set_inferior_io_terminal, get_inferior_io_terminal):
+       Delete.
+       (set_inferior_tty_command, show_inferior_tty_command): Adjust.
+       * inferior.c (inferior::set_tty, inferior::tty): New methods.
+       * inferior.h (set_inferior_io_terminal, get_inferior_io_terminal):
+       Remove declarations.
+       (struct inferior) <set_tty, tty>: New methods.
+       (struct inferior) <terminal>: Rename to ...
+       (struct inferior) <m_terminal>: ... this and make private.
+       * main.c (captured_main_1): Adjust.
+       * mi/mi-cmd-env.c (mi_cmd_inferior_tty_set): Adjust.
+       (mi_cmd_inferior_tty_show): Adjust.
+       * nto-procfs.c (nto_procfs_target::create_inferior): Adjust.
+       * windows-nat.c (windows_nat_target::create_inferior): Adjust.
+
 2020-06-26  Nick Alcock  <nick.alcock@oracle.com>
 
        * configure.ac: Add --enable-libctf: handle --disable-static
index 90a01b2b16f08332c90fcc09df59718960bb4b2f..bcf077d0ebaa1e66ec0faa572625f2d2fb7fbc01 100644 (file)
@@ -61,8 +61,6 @@ static struct ui *saved_ui = NULL;
 void
 prefork_hook (const char *args)
 {
-  const char *inferior_io_terminal = get_inferior_io_terminal ();
-
   gdb_assert (saved_ui == NULL);
   /* Retain a copy of our UI, since the child will replace this value
      and if we're vforked, we have to restore it.  */
@@ -70,7 +68,7 @@ prefork_hook (const char *args)
 
   /* Tell the terminal handling subsystem what tty we plan to run on;
      it will just record the information for later.  */
-  new_tty_prefork (inferior_io_terminal);
+  new_tty_prefork (current_inferior ()->tty ());
 }
 
 /* See nat/fork-inferior.h.  */
index 17f7b9abeac3dd0ef7fce6c73318c8b8ba3eaa82..64eea883cb6a64470f91afa6f542567722a1ef16 100644 (file)
@@ -100,25 +100,6 @@ enum stop_stack_kind stop_stack_dummy;
 int stopped_by_random_signal;
 
 \f
-/* Accessor routines.  */
-
-/* Set the io terminal for the current inferior.  Ownership of
-   TERMINAL_NAME is not transferred.  */
-
-void 
-set_inferior_io_terminal (const char *terminal_name)
-{
-  if (terminal_name != NULL && *terminal_name != '\0')
-    current_inferior ()->terminal = make_unique_xstrdup (terminal_name);
-  else
-    current_inferior ()->terminal = NULL;
-}
-
-const char *
-get_inferior_io_terminal (void)
-{
-  return current_inferior ()->terminal.get ();
-}
 
 static void
 set_inferior_tty_command (const char *args, int from_tty,
@@ -126,7 +107,7 @@ set_inferior_tty_command (const char *args, int from_tty,
 {
   /* CLI has assigned the user-provided value to inferior_io_terminal_scratch.
      Now route it to current inferior.  */
-  set_inferior_io_terminal (inferior_io_terminal_scratch);
+  current_inferior ()->set_tty (inferior_io_terminal_scratch);
 }
 
 static void
@@ -135,13 +116,13 @@ show_inferior_tty_command (struct ui_file *file, int from_tty,
 {
   /* Note that we ignore the passed-in value in favor of computing it
      directly.  */
-  const char *inferior_io_terminal = get_inferior_io_terminal ();
+  const char *inferior_tty = current_inferior ()->tty ();
 
-  if (inferior_io_terminal == NULL)
-    inferior_io_terminal = "";
+  if (inferior_tty == nullptr)
+    inferior_tty = "";
   fprintf_filtered (gdb_stdout,
                    _("Terminal for future runs of program being debugged "
-                     "is \"%s\".\n"), inferior_io_terminal);
+                     "is \"%s\".\n"), inferior_tty);
 }
 
 const char *
index d3bece029dd4a7152088c591937f9d050bed57eb..f775938721db5f5136b5693f095d20c6e05c3a56 100644 (file)
@@ -93,6 +93,21 @@ inferior::inferior (int pid_)
   m_target_stack.push (get_dummy_target ());
 }
 
+void
+inferior::set_tty (const char *terminal_name)
+{
+  if (terminal_name != nullptr && *terminal_name != '\0')
+    m_terminal = make_unique_xstrdup (terminal_name);
+  else
+    m_terminal = NULL;
+}
+
+const char *
+inferior::tty ()
+{
+  return m_terminal.get ();
+}
+
 struct inferior *
 add_inferior_silent (int pid)
 {
index 5002b0b8b3d31d370038e1a01b4e4bc07de9eeb6..572c5f3ae72dcf5e571a7a1433f668846b29e961 100644 (file)
@@ -118,11 +118,6 @@ extern void set_sigint_trap (void);
 
 extern void clear_sigint_trap (void);
 
-/* Set/get file name for default use for standard in/out in the inferior.  */
-
-extern void set_inferior_io_terminal (const char *terminal_name);
-extern const char *get_inferior_io_terminal (void);
-
 /* Collected pid, tid, etc. of the debugged inferior.  When there's
    no inferior, inferior_ptid.pid () will be 0.  */
 
@@ -411,6 +406,14 @@ public:
   inline safe_inf_threads_range threads_safe ()
   { return safe_inf_threads_range (this->thread_list); }
 
+  /* Set/get file name for default use for standard in/out in the
+     inferior.  On Unix systems, we try to make TERMINAL_NAME the
+     inferior's controlling terminal.  If TERMINAL_NAME is nullptr or
+     the empty string, then the inferior inherits GDB's terminal (or
+     GDBserver's if spawning a remote process).  */
+  void set_tty (const char *terminal_name);
+  const char *tty ();
+
   /* Convenient handle (GDB inferior id).  Unique across all
      inferiors.  */
   int num = 0;
@@ -456,9 +459,6 @@ public:
      this inferior.  */
   gdb::unique_xmalloc_ptr<char> cwd;
 
-  /* The name of terminal device to use for I/O.  */
-  gdb::unique_xmalloc_ptr<char> terminal;
-
   /* The terminal state as set by the last target_terminal::terminal_*
      call.  */
   target_terminal_state terminal_state = target_terminal_state::is_ours;
@@ -541,6 +541,9 @@ public:
 private:
   /* The inferior's target stack.  */
   target_stack m_target_stack;
+
+  /* The name of terminal device to use for I/O.  */
+  gdb::unique_xmalloc_ptr<char> m_terminal;
 };
 
 /* Keep a registry of per-inferior data-pointers required by other GDB
index 3649e4a22018667380237c63fedf425dfe26f531..19bbb92388951d87fad7384aefe52df8221ce386 100644 (file)
@@ -1171,7 +1171,7 @@ captured_main_1 (struct captured_main_args *context)
     }
 
   if (ttyarg != NULL)
-    set_inferior_io_terminal (ttyarg);
+    current_inferior ()->set_tty (ttyarg);
 
   /* Error messages should no longer be distinguished with extra output.  */
   warning_pre_print = _("warning: ");
index 88158cee56f7831d92c602d9ac385e269b9f3e2a..52ba0065bba53b67649655fa1215a3bd3cb0d38b 100644 (file)
@@ -244,7 +244,7 @@ mi_cmd_env_dir (const char *command, char **argv, int argc)
 void
 mi_cmd_inferior_tty_set (const char *command, char **argv, int argc)
 {
-  set_inferior_io_terminal (argv[0]);
+  current_inferior ()->set_tty (argv[0]);
 }
 
 /* Print the inferior terminal device name.  */
@@ -252,13 +252,12 @@ mi_cmd_inferior_tty_set (const char *command, char **argv, int argc)
 void
 mi_cmd_inferior_tty_show (const char *command, char **argv, int argc)
 {
-  const char *inferior_io_terminal = get_inferior_io_terminal ();
-  
   if ( !mi_valid_noargs ("-inferior-tty-show", argc, argv))
     error (_("-inferior-tty-show: Usage: No args"));
 
-  if (inferior_io_terminal)
-    current_uiout->field_string ("inferior_tty_terminal", inferior_io_terminal);
+  const char *inferior_tty = current_inferior ()->tty ();
+  if (inferior_tty != NULL)
+    current_uiout->field_string ("inferior_tty_terminal", inferior_tty);
 }
 
 void _initialize_mi_cmd_env ();
index f649b6cf58bd9add321fc502f2d1c2f32a957698..91d2cc5914dd3c2d2928790736ad794a19dea3e6 100644 (file)
@@ -1208,7 +1208,6 @@ nto_procfs_target::create_inferior (const char *exec_file,
   const char *in = "", *out = "", *err = "";
   int fd, fds[3];
   sigset_t set;
-  const char *inferior_io_terminal = get_inferior_io_terminal ();
   struct inferior *inf;
 
   argv = xmalloc ((allargs.size () / (unsigned) 2 + 2) *
@@ -1233,14 +1232,15 @@ nto_procfs_target::create_inferior (const char *exec_file,
 
   /* If the user specified I/O via gdb's --tty= arg, use it, but only
      if the i/o is not also being specified via redirection.  */
-  if (inferior_io_terminal)
+  const char *inferior_tty = current_inferior ()->tty ();
+  if (inferior_tty != nullptr)
     {
       if (!in[0])
-       in = inferior_io_terminal;
+       in = inferior_tty;
       if (!out[0])
-       out = inferior_io_terminal;
+       out = inferior_tty;
       if (!err[0])
-       err = inferior_io_terminal;
+       err = inferior_tty;
     }
 
   if (in[0])
index 68df87d1bf2275d006a4dab254f0c890c7d29ca6..188a920cbb061f0d8639340ffec40b7d9afd4b3b 100644 (file)
@@ -2730,7 +2730,7 @@ windows_nat_target::create_inferior (const char *exec_file,
   PROCESS_INFORMATION pi;
   BOOL ret;
   DWORD flags = 0;
-  const char *inferior_io_terminal = get_inferior_io_terminal ();
+  const char *inferior_tty = current_inferior ()->tty ();
 
   if (!exec_file)
     error (_("No executable specified, use `target exec'."));
@@ -2829,14 +2829,14 @@ windows_nat_target::create_inferior (const char *exec_file,
       w32_env = NULL;
     }
 
-  if (!inferior_io_terminal)
+  if (inferior_tty == nullptr)
     tty = ostdin = ostdout = ostderr = -1;
   else
     {
-      tty = open (inferior_io_terminal, O_RDWR | O_NOCTTY);
+      tty = open (inferior_tty, O_RDWR | O_NOCTTY);
       if (tty < 0)
        {
-         print_sys_errmsg (inferior_io_terminal, errno);
+         print_sys_errmsg (inferior_tty, errno);
          ostdin = ostdout = ostderr = -1;
        }
       else
@@ -2901,19 +2901,19 @@ windows_nat_target::create_inferior (const char *exec_file,
       allargs_len = strlen (allargs_copy);
     }
   /* If not all the standard streams are redirected by the command
-     line, use inferior_io_terminal for those which aren't.  */
-  if (inferior_io_terminal
+     line, use INFERIOR_TTY for those which aren't.  */
+  if (inferior_tty != nullptr
       && !(fd_inp >= 0 && fd_out >= 0 && fd_err >= 0))
     {
       SECURITY_ATTRIBUTES sa;
       sa.nLength = sizeof(sa);
       sa.lpSecurityDescriptor = 0;
       sa.bInheritHandle = TRUE;
-      tty = CreateFileA (inferior_io_terminal, GENERIC_READ | GENERIC_WRITE,
+      tty = CreateFileA (inferior_tty, GENERIC_READ | GENERIC_WRITE,
                         0, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
       if (tty == INVALID_HANDLE_VALUE)
        warning (_("Warning: Failed to open TTY %s, error %#x."),
-                inferior_io_terminal, (unsigned) GetLastError ());
+                inferior_tty, (unsigned) GetLastError ());
     }
   if (redirected || tty != INVALID_HANDLE_VALUE)
     {
This page took 0.04278 seconds and 4 git commands to generate.