+/* Terminal related info we need to keep track of. Each inferior
+ holds an instance of this structure --- we save it whenever the
+ corresponding inferior stops, and restore it to the terminal when
+ the inferior is resumed in the foreground. */
+struct terminal_info
+{
+ terminal_info () = default;
+ ~terminal_info ();
+
+ terminal_info &operator= (const terminal_info &) = default;
+
+ /* The name of the tty (from the `tty' command) that we gave to the
+ inferior when it was started. */
+ char *run_terminal = nullptr;
+
+ /* TTY state. We save it whenever the inferior stops, and restore
+ it when it resumes in the foreground. */
+ serial_ttystate ttystate {};
+
+#ifdef HAVE_TERMIOS_H
+ /* The terminal's foreground process group. Saved whenever the
+ inferior stops. This is the pgrp displayed by "info terminal".
+ Note that this may be not the inferior's actual process group,
+ since each inferior that we spawn has its own process group, and
+ only one can be in the foreground at a time. When the inferior
+ resumes, if we can determine the inferior's actual pgrp, then we
+ make that the foreground pgrp instead of what was saved here.
+ While it's a bit arbitrary which inferior's pgrp ends up in the
+ foreground when we resume several inferiors, this at least makes
+ 'resume inf1+inf2' + 'stop all' + 'resume inf2' end up with
+ inf2's pgrp in the foreground instead of inf1's (which would be
+ problematic since it would be left stopped: Ctrl-C wouldn't work,
+ for example). */
+ pid_t process_group = 0;
+#endif
+
+ /* fcntl flags. Saved and restored just like ttystate. */
+ int tflags = 0;
+};
+
+/* Our own tty state, which we restore every time we need to deal with
+ the terminal. This is set once, when GDB first starts, and then
+ whenever we enter/leave TUI mode (gdb_save_tty_state). The
+ settings of flags which readline saves and restores are
+ unimportant. */
+static struct terminal_info our_terminal_info;
+
+/* Snapshot of the initial tty state taken during initialization of
+ GDB, before readline/ncurses have had a chance to change it. This
+ is used as the initial tty state given to each new spawned
+ inferior. Unlike our_terminal_info, this is only ever set
+ once. */
+static serial_ttystate initial_gdb_ttystate;
+
+static struct terminal_info *get_inflow_inferior_data (struct inferior *);