+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
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. */
/* 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. */
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,
{
/* 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
{
/* 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 *
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)
{
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. */
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;
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;
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
}
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: ");
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. */
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 ();
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) *
/* 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])
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'."));
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
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)
{