/* Select target systems and architectures at runtime for GDB.
- Copyright (C) 1990-2014 Free Software Foundation, Inc.
+ Copyright (C) 1990-2015 Free Software Foundation, Inc.
Contributed by Cygnus Support.
(*current_target.to_load) (¤t_target, arg, from_tty);
}
+/* Possible terminal states. */
+
+enum terminal_state
+ {
+ /* The inferior's terminal settings are in effect. */
+ terminal_is_inferior = 0,
+
+ /* Some of our terminal settings are in effect, enough to get
+ proper output. */
+ terminal_is_ours_for_output = 1,
+
+ /* Our terminal settings are in effect, for output and input. */
+ terminal_is_ours = 2
+ };
+
+static enum terminal_state terminal_state;
+
+/* See target.h. */
+
+void
+target_terminal_init (void)
+{
+ (*current_target.to_terminal_init) (¤t_target);
+
+ terminal_state = terminal_is_ours;
+}
+
+/* See target.h. */
+
+int
+target_terminal_is_inferior (void)
+{
+ return (terminal_state == terminal_is_inferior);
+}
+
+/* See target.h. */
+
void
target_terminal_inferior (void)
{
if (target_can_async_p () && !sync_execution)
return;
+ if (terminal_state == terminal_is_inferior)
+ return;
+
/* If GDB is resuming the inferior in the foreground, install
inferior's terminal modes. */
(*current_target.to_terminal_inferior) (¤t_target);
+ terminal_state = terminal_is_inferior;
+}
+
+/* See target.h. */
+
+void
+target_terminal_ours (void)
+{
+ if (terminal_state == terminal_is_ours)
+ return;
+
+ (*current_target.to_terminal_ours) (¤t_target);
+ terminal_state = terminal_is_ours;
+}
+
+/* See target.h. */
+
+void
+target_terminal_ours_for_output (void)
+{
+ if (terminal_state != terminal_is_inferior)
+ return;
+ (*current_target.to_terminal_ours_for_output) (¤t_target);
+ terminal_state = terminal_is_ours_for_output;
}
/* See target.h. */
return 0;
}
+/* Restore the terminal to its previous state (helper for
+ make_cleanup_restore_target_terminal). */
+
+static void
+cleanup_restore_target_terminal (void *arg)
+{
+ enum terminal_state *previous_state = arg;
+
+ switch (*previous_state)
+ {
+ case terminal_is_ours:
+ target_terminal_ours ();
+ break;
+ case terminal_is_ours_for_output:
+ target_terminal_ours_for_output ();
+ break;
+ case terminal_is_inferior:
+ target_terminal_inferior ();
+ break;
+ }
+}
+
+/* See target.h. */
+
+struct cleanup *
+make_cleanup_restore_target_terminal (void)
+{
+ enum terminal_state *ts = xmalloc (sizeof (*ts));
+
+ *ts = terminal_state;
+
+ return make_cleanup_dtor (cleanup_restore_target_terminal, ts, xfree);
+}
+
static void
tcomplain (void)
{
return TARGET_XFER_E_IO;
if (!ptid_equal (inferior_ptid, null_ptid))
- inf = find_inferior_pid (ptid_get_pid (inferior_ptid));
+ inf = find_inferior_ptid (inferior_ptid);
else
inf = NULL;
struct inferior *inf;
/* Fall-back to the "main" address space of the inferior. */
- inf = find_inferior_pid (ptid_get_pid (ptid));
+ inf = find_inferior_ptid (ptid);
if (inf == NULL || inf->aspace == NULL)
internal_error (__FILE__, __LINE__,