Remove make_cleanup_restore_target_terminal
authorTom Tromey <tom@tromey.com>
Wed, 20 Sep 2017 03:56:36 +0000 (21:56 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 20 Sep 2017 22:09:50 +0000 (16:09 -0600)
This removes make_cleanup_restore_target_terminal and generally
C++-ifies target terminal handling.  It changes all target_terminal_*
functions to be static members of a new target_terminal class and
changes the cleanup to be a scoped_* class.
make_cleanup_override_quit_handler is also removed in favor of simply
using scoped_restore.

Note that there are some files in this patch that I could not compile.
Considering that some of the rewrites were automated, and that none of
these files involed cleanups, I feel that this is relatively safe.

Regression tested by the buildbot.

gdb/ChangeLog
2017-09-20  Tom Tromey  <tom@tromey.com>

* windows-nat.c (get_windows_debug_event, windows_wait)
(do_initial_windows_stuff, windows_attach): Update.
* utils.c (vwarning, internal_vproblem): Update.
(ui_unregister_input_event_handler_cleanup)
(prepare_to_handle_input): Remove.
(class scoped_input_handler): New.
(defaulted_query, prompt_for_continue): Update.
* tui/tui-hooks.c (tui_refresh_frame_and_register_information):
Update.
* top.c (undo_terminal_modifications_before_exit): Update.
* target/target.h (target_terminal_init, target_terminal_inferior)
(target_terminal_ours): Don't declare.
(class target_terminal): New.
* target.h (target_terminal_is_inferior, target_terminal_is_ours)
(target_terminal_ours_for_output)
(make_cleanup_restore_target_terminal): Don't declare.
(target_terminal_info): Remove.
* target.c (enum terminal_state, terminal_state): Remove.
(target_terminal::terminal_state): Define.
(target_terminal::init): Rename from target_terminal_init.
(target_terminal::inferior): Rename from
target_terminal_inferior.
(target_terminal::ours): Rename from target_terminal_ours.
(target_terminal::ours_for_output): Rename from
target_terminal_ours_for_output.
(target_terminal::info): New method.
(cleanup_restore_target_terminal)
(make_cleanup_restore_target_terminal): Remove.
* solib.c (handle_solib_event): Update.
* remote.c (remote_serial_quit_handler): Update.
(remote_terminal_inferior, remote_wait_as): Update.
* record-full.c (record_full_wait_1): Update.
* nto-procfs.c (procfs_create_inferior): Update.
* nat/fork-inferior.c (startup_inferior): Update.
* mi/mi-interp.c (mi_new_thread, mi_thread_exit)
(mi_record_changed, mi_inferior_added, mi_inferior_appeared)
(mi_inferior_exit, mi_inferior_removed, mi_traceframe_changed)
(mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
(mi_breakpoint_created, mi_breakpoint_deleted)
(mi_breakpoint_modified, mi_on_resume, mi_solib_loaded)
(mi_solib_unloaded, mi_command_param_changed, mi_memory_changed)
(mi_user_selected_context_changed, report_initial_inferior):
Update.
* linux-nat.c (linux_nat_attach, linux_nat_terminal_ours)
(linux_nat_terminal_inferior): Update.
* infrun.c (follow_fork_inferior)
(handle_vfork_child_exec_or_exit, do_target_resume)
(check_curr_ui_sync_execution_done, handle_inferior_event_1)
(handle_signal_stop, maybe_remove_breakpoints, normal_stop):
Update.
* inflow.c (child_terminal_init, info_terminal_command): Update.
* infcmd.c (post_create_inferior, continue_1, prepare_one_step)
(attach_command): Update.
* infcall.c (call_thread_fsm_should_stop): Update.
* gnu-nat.c (gnu_attach): Update.
* extension.c (struct active_ext_lang_state)
(restore_active_ext_lang): Update.
* exceptions.c (print_flush): Update.
* event-top.c (async_enable_stdin, default_quit_handler): Update.
(struct quit_handler_cleanup_data, restore_quit_handler)
(restore_quit_handler_dtor, make_cleanup_override_quit_handler):
Remove.
* cp-support.c (gdb_demangle): Update.
* breakpoint.c (update_inserted_breakpoint_locations)
(insert_breakpoint_locations, handle_jit_event)
(disable_breakpoints_in_unloaded_shlib): Update.
* annotate.c (annotate_breakpoints_invalid)
(annotate_frames_invalid): Update.

gdb/gdbserver/ChangeLog
2017-09-20  Tom Tromey  <tom@tromey.com>

* target.c (target_terminal::terminal_state): Define.
(target_terminal::init): Rename from target_terminal_init.
(target_terminal::inferior): Rename from
target_terminal_inferior.
(target_terminal::ours): Rename from target_terminal_ours.
(target_terminal::ours_for_output, target_terminal::info): New.

28 files changed:
gdb/ChangeLog
gdb/annotate.c
gdb/breakpoint.c
gdb/cp-support.c
gdb/event-top.c
gdb/exceptions.c
gdb/extension.c
gdb/gdbserver/ChangeLog
gdb/gdbserver/target.c
gdb/gnu-nat.c
gdb/infcall.c
gdb/infcmd.c
gdb/inflow.c
gdb/infrun.c
gdb/linux-nat.c
gdb/mi/mi-interp.c
gdb/nat/fork-inferior.c
gdb/nto-procfs.c
gdb/record-full.c
gdb/remote.c
gdb/solib.c
gdb/target.c
gdb/target.h
gdb/target/target.h
gdb/top.c
gdb/tui/tui-hooks.c
gdb/utils.c
gdb/windows-nat.c

index 4140f559bc407ab532810e9976f881bf785a7207..89a6c292f5dc491788c1567b9d7347f6dc1ae62f 100644 (file)
@@ -1,3 +1,74 @@
+2017-09-20  Tom Tromey  <tom@tromey.com>
+
+       * windows-nat.c (get_windows_debug_event, windows_wait)
+       (do_initial_windows_stuff, windows_attach): Update.
+       * utils.c (vwarning, internal_vproblem): Update.
+       (ui_unregister_input_event_handler_cleanup)
+       (prepare_to_handle_input): Remove.
+       (class scoped_input_handler): New.
+       (defaulted_query, prompt_for_continue): Update.
+       * tui/tui-hooks.c (tui_refresh_frame_and_register_information):
+       Update.
+       * top.c (undo_terminal_modifications_before_exit): Update.
+       * target/target.h (target_terminal_init, target_terminal_inferior)
+       (target_terminal_ours): Don't declare.
+       (class target_terminal): New.
+       * target.h (target_terminal_is_inferior, target_terminal_is_ours)
+       (target_terminal_ours_for_output)
+       (make_cleanup_restore_target_terminal): Don't declare.
+       (target_terminal_info): Remove.
+       * target.c (enum terminal_state, terminal_state): Remove.
+       (target_terminal::terminal_state): Define.
+       (target_terminal::init): Rename from target_terminal_init.
+       (target_terminal::inferior): Rename from
+       target_terminal_inferior.
+       (target_terminal::ours): Rename from target_terminal_ours.
+       (target_terminal::ours_for_output): Rename from
+       target_terminal_ours_for_output.
+       (target_terminal::info): New method.
+       (cleanup_restore_target_terminal)
+       (make_cleanup_restore_target_terminal): Remove.
+       * solib.c (handle_solib_event): Update.
+       * remote.c (remote_serial_quit_handler): Update.
+       (remote_terminal_inferior, remote_wait_as): Update.
+       * record-full.c (record_full_wait_1): Update.
+       * nto-procfs.c (procfs_create_inferior): Update.
+       * nat/fork-inferior.c (startup_inferior): Update.
+       * mi/mi-interp.c (mi_new_thread, mi_thread_exit)
+       (mi_record_changed, mi_inferior_added, mi_inferior_appeared)
+       (mi_inferior_exit, mi_inferior_removed, mi_traceframe_changed)
+       (mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
+       (mi_breakpoint_created, mi_breakpoint_deleted)
+       (mi_breakpoint_modified, mi_on_resume, mi_solib_loaded)
+       (mi_solib_unloaded, mi_command_param_changed, mi_memory_changed)
+       (mi_user_selected_context_changed, report_initial_inferior):
+       Update.
+       * linux-nat.c (linux_nat_attach, linux_nat_terminal_ours)
+       (linux_nat_terminal_inferior): Update.
+       * infrun.c (follow_fork_inferior)
+       (handle_vfork_child_exec_or_exit, do_target_resume)
+       (check_curr_ui_sync_execution_done, handle_inferior_event_1)
+       (handle_signal_stop, maybe_remove_breakpoints, normal_stop):
+       Update.
+       * inflow.c (child_terminal_init, info_terminal_command): Update.
+       * infcmd.c (post_create_inferior, continue_1, prepare_one_step)
+       (attach_command): Update.
+       * infcall.c (call_thread_fsm_should_stop): Update.
+       * gnu-nat.c (gnu_attach): Update.
+       * extension.c (struct active_ext_lang_state)
+       (restore_active_ext_lang): Update.
+       * exceptions.c (print_flush): Update.
+       * event-top.c (async_enable_stdin, default_quit_handler): Update.
+       (struct quit_handler_cleanup_data, restore_quit_handler)
+       (restore_quit_handler_dtor, make_cleanup_override_quit_handler):
+       Remove.
+       * cp-support.c (gdb_demangle): Update.
+       * breakpoint.c (update_inserted_breakpoint_locations)
+       (insert_breakpoint_locations, handle_jit_event)
+       (disable_breakpoints_in_unloaded_shlib): Update.
+       * annotate.c (annotate_breakpoints_invalid)
+       (annotate_frames_invalid): Update.
+
 2017-09-20  Tom Tromey  <tom@tromey.com>
 
        * main.c (catch_command_errors): Rename from
index f68ff1098f1b86bedb754d090ef9b409f7dd9807..6a02f732991fbfeaed61d97c801a31f9fff94847 100644 (file)
@@ -63,14 +63,14 @@ annotate_breakpoints_invalid (void)
     {
       /* If the inferior owns the terminal (e.g., we're resuming),
         make sure to leave with the inferior still owning it.  */
-      int was_inferior = target_terminal_is_inferior ();
+      int was_inferior = target_terminal::is_inferior ();
 
-      target_terminal_ours_for_output ();
+      target_terminal::ours_for_output ();
 
       printf_unfiltered (("\n\032\032breakpoints-invalid\n"));
 
       if (was_inferior)
-       target_terminal_inferior ();
+       target_terminal::inferior ();
 
       breakpoints_invalid_emitted = 1;
     }
@@ -210,14 +210,14 @@ annotate_frames_invalid (void)
     {
       /* If the inferior owns the terminal (e.g., we're resuming),
         make sure to leave with the inferior still owning it.  */
-      int was_inferior = target_terminal_is_inferior ();
+      int was_inferior = target_terminal::is_inferior ();
 
-      target_terminal_ours_for_output ();
+      target_terminal::ours_for_output ();
 
       printf_unfiltered (("\n\032\032frames-invalid\n"));
 
       if (was_inferior)
-       target_terminal_inferior ();
+       target_terminal::inferior ();
 
       frames_invalid_emitted = 1;
     }
index 235dab48ce686c23da0277e1bf01f3876b555ebd..cdebdc75cf42ed7f10a696d78f0900c3d0d0cbf3 100644 (file)
@@ -3126,7 +3126,7 @@ update_inserted_breakpoint_locations (void)
 
   if (error_flag)
     {
-      target_terminal_ours_for_output ();
+      target_terminal::ours_for_output ();
       error_stream (tmp_error_stream);
     }
 }
@@ -3225,7 +3225,7 @@ insert_breakpoint_locations (void)
          tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\
 You may have requested too many hardware breakpoints/watchpoints.\n");
        }
-      target_terminal_ours_for_output ();
+      target_terminal::ours_for_output ();
       error_stream (tmp_error_stream);
     }
 }
@@ -5792,14 +5792,14 @@ handle_jit_event (void)
 
   /* Switch terminal for any messages produced by
      breakpoint_re_set.  */
-  target_terminal_ours_for_output ();
+  target_terminal::ours_for_output ();
 
   frame = get_current_frame ();
   gdbarch = get_frame_arch (frame);
 
   jit_event_handler (gdbarch);
 
-  target_terminal_inferior ();
+  target_terminal::inferior ();
 }
 
 /* Prepare WHAT final decision for infrun.  */
@@ -7925,7 +7925,7 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
 
        if (!disabled_shlib_breaks)
          {
-           target_terminal_ours_for_output ();
+           target_terminal::ours_for_output ();
            warning (_("Temporarily disabling breakpoints "
                       "for unloaded shared library \"%s\""),
                     solib->so_name);
index 11318efbcbfa80a8ead3a4553dc0442559bb64dd..aa0229f6d9ec886b6ef040d0743879d369dacd70 100644 (file)
@@ -1559,8 +1559,8 @@ gdb_demangle (const char *name, int options)
                                    "demangler-warning", short_msg);
              make_cleanup (xfree, long_msg);
 
-             make_cleanup_restore_target_terminal ();
-             target_terminal_ours_for_output ();
+             target_terminal::scoped_restore_terminal_state term_state;
+             target_terminal::ours_for_output ();
 
              begin_line ();
              if (core_dump_allowed)
index 1281df89225d80ee50643f7ce4531a99ad4609bc..b1cc8b9794a8eb2296b55a5469772da317a6093d 100644 (file)
@@ -548,7 +548,7 @@ async_enable_stdin (void)
 
   if (ui->prompt_state == PROMPT_BLOCKED)
     {
-      target_terminal_ours ();
+      target_terminal::ours ();
       ui_register_input_event_handler (ui);
       ui->prompt_state = PROMPT_NEEDED;
     }
@@ -957,7 +957,7 @@ default_quit_handler (void)
 {
   if (check_quit_flag ())
     {
-      if (target_terminal_is_ours ())
+      if (target_terminal::is_ours ())
        quit ();
       else
        target_pass_ctrlc ();
@@ -967,51 +967,6 @@ default_quit_handler (void)
 /* See defs.h.  */
 quit_handler_ftype *quit_handler = default_quit_handler;
 
-/* Data for make_cleanup_override_quit_handler.  Wrap the previous
-   handler pointer in a data struct because it's not portable to cast
-   a function pointer to a data pointer, which is what make_cleanup
-   expects.  */
-struct quit_handler_cleanup_data
-{
-  /* The previous quit handler.  */
-  quit_handler_ftype *prev_handler;
-};
-
-/* Cleanup call that restores the previous quit handler.  */
-
-static void
-restore_quit_handler (void *arg)
-{
-  struct quit_handler_cleanup_data *data
-    = (struct quit_handler_cleanup_data *) arg;
-
-  quit_handler = data->prev_handler;
-}
-
-/* Destructor for the quit handler cleanup.  */
-
-static void
-restore_quit_handler_dtor (void *arg)
-{
-  xfree (arg);
-}
-
-/* See defs.h.  */
-
-struct cleanup *
-make_cleanup_override_quit_handler (quit_handler_ftype *new_quit_handler)
-{
-  struct cleanup *old_chain;
-  struct quit_handler_cleanup_data *data;
-
-  data = XNEW (struct quit_handler_cleanup_data);
-  data->prev_handler = quit_handler;
-  old_chain = make_cleanup_dtor (restore_quit_handler, data,
-                                restore_quit_handler_dtor);
-  quit_handler = new_quit_handler;
-  return old_chain;
-}
-
 /* Handle a SIGINT.  */
 
 void
index f9a80a0b3fabff4faf5078c2d0eeb1385964bdf0..dd11b6e4a640371360ea7a38b09a88d4a141db0e 100644 (file)
 #include "serial.h"
 #include "gdbthread.h"
 #include "top.h"
+#include "common/gdb_optional.h"
 
 static void
 print_flush (void)
 {
   struct ui *ui = current_ui;
   struct serial *gdb_stdout_serial;
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
 
   if (deprecated_error_begin_hook)
     deprecated_error_begin_hook ();
 
+  gdb::optional<target_terminal::scoped_restore_terminal_state> term_state;
   if (target_supports_terminal_ours ())
     {
-      make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      term_state.emplace ();
+      target_terminal::ours_for_output ();
     }
 
   /* We want all output to appear now, before we print the error.  We
@@ -66,8 +67,6 @@ print_flush (void)
     }
 
   annotate_error_begin ();
-
-  do_cleanups (old_chain);
 }
 
 static void
index 54ce4a22ba7cacebd8982ffc0b8fe9e7aba8248f..4ffad038c91f71f9415710fcd5247c69906ca22d 100644 (file)
@@ -750,7 +750,7 @@ set_active_ext_lang (const struct extension_language_defn *now_active)
   previous->sigint_handler.handler_saved = 0;
   active_ext_lang = now_active;
 
-  if (target_terminal_is_ours ())
+  if (target_terminal::is_ours ())
     {
       /* If the newly active extension language uses cooperative SIGINT
         handling then ensure GDB's SIGINT handler is installed.  */
@@ -776,7 +776,7 @@ restore_active_ext_lang (struct active_ext_lang_state *previous)
 {
   active_ext_lang = previous->ext_lang;
 
-  if (target_terminal_is_ours ())
+  if (target_terminal::is_ours ())
     {
       /* Restore the previous SIGINT handler if one was saved.  */
       if (previous->sigint_handler.handler_saved)
index 00e789187e78def3907f6fc3095036a8cef67c90..fe30e91c0590d2845ba7dfe165bc427c2c2894ee 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-20  Tom Tromey  <tom@tromey.com>
+
+       * target.c (target_terminal::terminal_state): Define.
+       (target_terminal::init): Rename from target_terminal_init.
+       (target_terminal::inferior): Rename from
+       target_terminal_inferior.
+       (target_terminal::ours): Rename from target_terminal_ours.
+       (target_terminal::ours_for_output, target_terminal::info): New.
+
 2017-09-16  Simon Marchi  <simon.marchi@ericsson.com>
 
        * server.c (accumulate_file_name_length): Remove.
index 752646310a7f6168d8fbfe3b18f6219006dc6ca0..abd14b8775da89ee573cb06889cc5b66fd62bdb6 100644 (file)
@@ -388,10 +388,15 @@ default_breakpoint_kind_from_pc (CORE_ADDR *pcptr)
   return size;
 }
 
+/* Define it.  */
+
+enum target_terminal::terminal_state target_terminal::terminal_state
+  = target_terminal::terminal_is_ours;
+
 /* See target/target.h.  */
 
 void
-target_terminal_init ()
+target_terminal::init ()
 {
   /* Placeholder needed because of fork_inferior.  Not necessary on
      GDBserver.  */
@@ -400,7 +405,7 @@ target_terminal_init ()
 /* See target/target.h.  */
 
 void
-target_terminal_inferior ()
+target_terminal::inferior ()
 {
   /* Placeholder needed because of fork_inferior.  Not necessary on
      GDBserver.  */
@@ -409,8 +414,24 @@ target_terminal_inferior ()
 /* See target/target.h.  */
 
 void
-target_terminal_ours ()
+target_terminal::ours ()
 {
   /* Placeholder needed because of fork_inferior.  Not necessary on
      GDBserver.  */
 }
+
+/* See target/target.h.  */
+
+void
+target_terminal::ours_for_output (void)
+{
+  /* Placeholder.  */
+}
+
+/* See target/target.h.  */
+
+void
+target_terminal::info (const char *arg, int from_tty)
+{
+  /* Placeholder.  */
+}
index d3726e78424ec21a31c548a2f17ecdd95d3edb97..0ad35ca33acd317410b0517929f4670827443f0b 100644 (file)
@@ -2230,7 +2230,7 @@ gnu_attach (struct target_ops *ops, const char *args, int from_tty)
 
   /* We have to initialize the terminal settings now, since the code
      below might try to restore them.  */
-  target_terminal_init ();
+  target_terminal::init ();
 
   /* If the process was stopped before we attached, make it continue the next
      time the user does a continue.  */
index 5df04e3b9a957e207abb93e6f4c7f34593375e95..d384d16c2913f967b869f118096f5d720cef2f47 100644 (file)
@@ -544,7 +544,7 @@ call_thread_fsm_should_stop (struct thread_fsm *self,
 
       /* Break out of wait_sync_command_done.  */
       scoped_restore save_ui = make_scoped_restore (&current_ui, f->waiting_ui);
-      target_terminal_ours ();
+      target_terminal::ours ();
       f->waiting_ui->prompt_state = PROMPT_NEEDED;
     }
 
index c38b00adc454ebe025a2560c01ef5e061cfb269b..9c0cead4345969d26b20608080e91fa08fff693a 100644 (file)
@@ -411,7 +411,7 @@ post_create_inferior (struct target_ops *target, int from_tty)
 {
 
   /* Be sure we own the terminal in case write operations are performed.  */ 
-  target_terminal_ours_for_output ();
+  target_terminal::ours_for_output ();
 
   /* If the target hasn't taken care of this already, do it now.
      Targets which need to access registers during to_open,
@@ -783,7 +783,7 @@ continue_1 (int all_threads)
              Continuing.
              <no thread was resumed, but the inferior now owns the terminal>
          */
-         target_terminal_inferior ();
+         target_terminal::inferior ();
        }
     }
   else
@@ -1172,7 +1172,7 @@ prepare_one_step (struct step_command_fsm *sm)
                                            &tp->control.step_range_end) == 0)
                error (_("Cannot find bounds of current function"));
 
-             target_terminal_ours_for_output ();
+             target_terminal::ours_for_output ();
              printf_filtered (_("Single stepping until exit from function %s,"
                                 "\nwhich has no line number information.\n"),
                               name);
@@ -2839,7 +2839,7 @@ attach_command (char *args, int from_tty)
 
   /* Set up the "saved terminal modes" of the inferior
      based on what modes we are starting it with.  */
-  target_terminal_init ();
+  target_terminal::init ();
 
   /* Install inferior's terminal modes.  This may look like a no-op,
      as we've just saved them above, however, this does more than
@@ -2855,7 +2855,7 @@ attach_command (char *args, int from_tty)
        while we're in the event loop waiting for that stop.  That is,
        before the attach continuation runs and the command is really
        finished.  */
-  target_terminal_inferior ();
+  target_terminal::inferior ();
 
   /* Set up execution context to know that we should return from
      wait_for_inferior as soon as the target reports a stop.  */
index 0e8c0f3c80d9b8378b1709e3176b98b0b03a76bc..d54b8f83454d5d6ffde6718a794b8c81114901d5 100644 (file)
@@ -226,7 +226,7 @@ child_terminal_init (struct target_ops *self)
 {
 #ifdef PROCESS_GROUP_TYPE
   /* This is for Lynx, and should be cleaned up by having Lynx be a
-     separate debugging target with a version of target_terminal_init
+     separate debugging target with a version of target_terminal::init
      which passes in the process group to a generic routine which does
      all the work (and the non-threaded child_terminal_init can just
      pass in inferior_ptid to the same routine).  */
@@ -536,7 +536,7 @@ copy_terminal_info (struct inferior *to, struct inferior *from)
 void
 info_terminal_command (char *arg, int from_tty)
 {
-  target_terminal_info (arg, from_tty);
+  target_terminal::info (arg, from_tty);
 }
 
 void
index 3f2ac85b919fe60fef399c673a0c05e82cc9ce72..26853b1a8d17663a6b86bddf03231e1d7ca61c50 100644 (file)
@@ -478,7 +478,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
              /* Ensure that we have a process ptid.  */
              ptid_t process_ptid = pid_to_ptid (ptid_get_pid (child_ptid));
 
-             target_terminal_ours_for_output ();
+             target_terminal::ours_for_output ();
              fprintf_filtered (gdb_stdlog,
                                _("Detaching after %s from child %s.\n"),
                                has_vforked ? "vfork" : "fork",
@@ -563,7 +563,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
 
       if (info_verbose || debug_infrun)
        {
-         target_terminal_ours_for_output ();
+         target_terminal::ours_for_output ();
          fprintf_filtered (gdb_stdlog,
                            _("Attaching after %s %s to child %s.\n"),
                            target_pid_to_str (parent_ptid),
@@ -611,7 +611,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
              /* Ensure that we have a process ptid.  */
              ptid_t process_ptid = pid_to_ptid (ptid_get_pid (child_ptid));
 
-             target_terminal_ours_for_output ();
+             target_terminal::ours_for_output ();
              fprintf_filtered (gdb_stdlog,
                                _("Detaching after fork from "
                                  "child %s.\n"),
@@ -970,7 +970,7 @@ handle_vfork_child_exec_or_exit (int exec)
 
          if (debug_infrun || info_verbose)
            {
-             target_terminal_ours_for_output ();
+             target_terminal::ours_for_output ();
 
              if (exec)
                {
@@ -2339,7 +2339,7 @@ do_target_resume (ptid_t resume_ptid, int step, enum gdb_signal sig)
   gdb_assert (!tp->stop_requested);
 
   /* Install inferior's terminal modes.  */
-  target_terminal_inferior ();
+  target_terminal::inferior ();
 
   /* Avoid confusing the next resume, if the next stop/resume
      happens to apply to another thread.  */
@@ -3818,7 +3818,7 @@ check_curr_ui_sync_execution_done (void)
       && ui->async
       && !gdb_in_secondary_prompt_p (ui))
     {
-      target_terminal_ours ();
+      target_terminal::ours ();
       observer_notify_sync_execution_done ();
       ui_register_input_event_handler (ui);
     }
@@ -5056,7 +5056,7 @@ handle_inferior_event_1 (struct execution_control_state *ecs)
       set_current_inferior (find_inferior_ptid (ecs->ptid));
       set_current_program_space (current_inferior ()->pspace);
       handle_vfork_child_exec_or_exit (0);
-      target_terminal_ours (); /* Must do this before mourn anyway.  */
+      target_terminal::ours ();        /* Must do this before mourn anyway.  */
 
       /* Clearing any previous state of convenience variables.  */
       clear_exit_convenience_vars ();
@@ -6098,9 +6098,9 @@ handle_signal_stop (struct execution_control_state *ecs)
       if (signal_print[ecs->event_thread->suspend.stop_signal])
        {
          /* The signal table tells us to print about this signal.  */
-         target_terminal_ours_for_output ();
+         target_terminal::ours_for_output ();
          observer_notify_signal_received (ecs->event_thread->suspend.stop_signal);
-         target_terminal_inferior ();
+         target_terminal::inferior ();
        }
 
       /* Clear the signal if it should not be passed.  */
@@ -8084,7 +8084,7 @@ maybe_remove_breakpoints (void)
     {
       if (remove_breakpoints ())
        {
-         target_terminal_ours_for_output ();
+         target_terminal::ours_for_output ();
          printf_filtered (_("Cannot remove breakpoints because "
                             "program is no longer writable.\nFurther "
                             "execution is probably impossible.\n"));
@@ -8241,7 +8241,7 @@ normal_stop (void)
     {
       SWITCH_THRU_ALL_UIS ()
        {
-         target_terminal_ours_for_output ();
+         target_terminal::ours_for_output ();
          printf_filtered (_("[Switching to %s]\n"),
                           target_pid_to_str (inferior_ptid));
          annotate_thread_changed ();
@@ -8254,7 +8254,7 @@ normal_stop (void)
       SWITCH_THRU_ALL_UIS ()
        if (current_ui->prompt_state == PROMPT_BLOCKED)
          {
-           target_terminal_ours_for_output ();
+           target_terminal::ours_for_output ();
            printf_filtered (_("No unwaited-for children left.\n"));
          }
     }
index 89e0c62fb13d3527801dcd4e36a126d15d81cb35..cc48d7eba83f799a8e397d45acbd74b6e254e40e 100644 (file)
@@ -1251,7 +1251,7 @@ linux_nat_attach (struct target_ops *ops, const char *args, int from_tty)
        {
          int exit_code = WEXITSTATUS (status);
 
-         target_terminal_ours ();
+         target_terminal::ours ();
          target_mourn_inferior (inferior_ptid);
          if (exit_code == 0)
            error (_("Unable to attach: program exited normally."));
@@ -1263,7 +1263,7 @@ linux_nat_attach (struct target_ops *ops, const char *args, int from_tty)
        {
          enum gdb_signal signo;
 
-         target_terminal_ours ();
+         target_terminal::ours ();
          target_mourn_inferior (inferior_ptid);
 
          signo = gdb_signal_from_host (WTERMSIG (status));
@@ -4458,13 +4458,13 @@ linux_nat_terminal_inferior (struct target_ops *self)
   set_sigint_trap ();
 }
 
-/* target_terminal_ours implementation.
+/* target_terminal::ours implementation.
 
    This is a wrapper around child_terminal_ours to add async support (and
-   implement the target_terminal_ours vs target_terminal_ours_for_output
+   implement the target_terminal::ours vs target_terminal::ours_for_output
    distinction).  child_terminal_ours is currently no different than
    child_terminal_ours_for_output.
-   We leave target_terminal_ours_for_output alone, leaving it to
+   We leave target_terminal::ours_for_output alone, leaving it to
    child_terminal_ours_for_output.  */
 
 static void
index f96c59a64b91bec48b73b954a86e5dd5d3405d9a..714bb4b28b35b9c8c2898c37808af6dbb520f76a 100644 (file)
@@ -341,20 +341,17 @@ mi_new_thread (struct thread_info *t)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel,
                          "thread-created,id=\"%d\",group-id=\"i%d\"",
                          t->global_num, inf->num);
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -367,19 +364,16 @@ mi_thread_exit (struct thread_info *t, int silent)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
       fprintf_unfiltered (mi->event_channel,
                          "thread-exited,id=\"%d\",group-id=\"i%d\"",
                          t->global_num, t->inf->num);
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -392,13 +386,12 @@ mi_record_changed (struct inferior *inferior, int started, const char *method,
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       if (started)
        {
@@ -425,8 +418,6 @@ mi_record_changed (struct inferior *inferior, int started, const char *method,
        }
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -437,7 +428,6 @@ mi_inferior_added (struct inferior *inf)
     {
       struct interp *interp;
       struct mi_interp *mi;
-      struct cleanup *old_chain;
 
       /* We'll be called once for the initial inferior, before the top
         level interpreter is set.  */
@@ -449,15 +439,13 @@ mi_inferior_added (struct inferior *inf)
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel,
                          "thread-group-added,id=\"i%d\"",
                          inf->num);
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -467,19 +455,17 @@ mi_inferior_appeared (struct inferior *inf)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel,
                          "thread-group-started,id=\"i%d\",pid=\"%d\"",
                          inf->num, inf->pid);
       gdb_flush (mi->event_channel);
-      do_cleanups (old_chain);
     }
 }
 
@@ -489,13 +475,12 @@ mi_inferior_exit (struct inferior *inf)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       if (inf->has_exit_code)
        fprintf_unfiltered (mi->event_channel,
@@ -506,7 +491,6 @@ mi_inferior_exit (struct inferior *inf)
                            "thread-group-exited,id=\"i%d\"", inf->num);
 
       gdb_flush (mi->event_channel);
-      do_cleanups (old_chain);
     }
 }
 
@@ -516,20 +500,17 @@ mi_inferior_removed (struct inferior *inf)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel,
                          "thread-group-removed,id=\"i%d\"",
                          inf->num);
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -746,13 +727,12 @@ mi_traceframe_changed (int tfnum, int tpnum)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       if (tfnum >= 0)
        fprintf_unfiltered (mi->event_channel, "traceframe-changed,"
@@ -762,8 +742,6 @@ mi_traceframe_changed (int tfnum, int tpnum)
        fprintf_unfiltered (mi->event_channel, "traceframe-changed,end");
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -775,21 +753,18 @@ mi_tsv_created (const struct trace_state_variable *tsv)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel, "tsv-created,"
                          "name=\"%s\",initial=\"%s\"\n",
                          tsv->name, plongest (tsv->initial_value));
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -801,13 +776,12 @@ mi_tsv_deleted (const struct trace_state_variable *tsv)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       if (tsv != NULL)
        fprintf_unfiltered (mi->event_channel, "tsv-deleted,"
@@ -816,8 +790,6 @@ mi_tsv_deleted (const struct trace_state_variable *tsv)
        fprintf_unfiltered (mi->event_channel, "tsv-deleted\n");
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -830,15 +802,14 @@ mi_tsv_modified (const struct trace_state_variable *tsv)
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *mi_uiout;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
       mi_uiout = interp_ui_out (top_level_interpreter ());
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel,
                          "tsv-modified");
@@ -854,8 +825,6 @@ mi_tsv_modified (const struct trace_state_variable *tsv)
       mi_uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -874,15 +843,14 @@ mi_breakpoint_created (struct breakpoint *b)
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *mi_uiout;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
       mi_uiout = interp_ui_out (top_level_interpreter ());
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel,
                          "breakpoint-created");
@@ -906,8 +874,6 @@ mi_breakpoint_created (struct breakpoint *b)
       mi_uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -925,20 +891,17 @@ mi_breakpoint_deleted (struct breakpoint *b)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel, "breakpoint-deleted,id=\"%d\"",
                          b->number);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -956,13 +919,12 @@ mi_breakpoint_modified (struct breakpoint *b)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
       fprintf_unfiltered (mi->event_channel,
                          "breakpoint-modified");
       /* We want the output from gdb_breakpoint_query to go to
@@ -985,8 +947,6 @@ mi_breakpoint_modified (struct breakpoint *b)
       mi->mi_uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -1094,17 +1054,14 @@ mi_on_resume (ptid_t ptid)
   SWITCH_THRU_ALL_UIS ()
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       mi_on_resume_1 (mi, ptid);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -1138,15 +1095,14 @@ mi_solib_loaded (struct so_list *solib)
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *uiout;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
       uiout = interp_ui_out (top_level_interpreter ());
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel, "library-loaded");
 
@@ -1157,8 +1113,6 @@ mi_solib_loaded (struct so_list *solib)
       uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -1169,15 +1123,14 @@ mi_solib_unloaded (struct so_list *solib)
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *uiout;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
       uiout = interp_ui_out (top_level_interpreter ());
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel, "library-unloaded");
 
@@ -1194,8 +1147,6 @@ mi_solib_unloaded (struct so_list *solib)
       uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -1211,15 +1162,14 @@ mi_command_param_changed (const char *param, const char *value)
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *mi_uiout;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
       mi_uiout = interp_ui_out (top_level_interpreter ());
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel, "cmd-param-changed");
 
@@ -1231,8 +1181,6 @@ mi_command_param_changed (const char *param, const char *value)
       mi_uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -1250,15 +1198,14 @@ mi_memory_changed (struct inferior *inferior, CORE_ADDR memaddr,
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *mi_uiout;
       struct obj_section *sec;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
 
       mi_uiout = interp_ui_out (top_level_interpreter ());
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       fprintf_unfiltered (mi->event_channel, "memory-changed");
 
@@ -1283,8 +1230,6 @@ mi_memory_changed (struct inferior *inferior, CORE_ADDR memaddr,
       mi_uiout->redirect (NULL);
 
       gdb_flush (mi->event_channel);
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -1306,7 +1251,6 @@ mi_user_selected_context_changed (user_selected_what selection)
     {
       struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
       struct ui_out *mi_uiout;
-      struct cleanup *old_chain;
 
       if (mi == NULL)
        continue;
@@ -1316,8 +1260,8 @@ mi_user_selected_context_changed (user_selected_what selection)
       mi_uiout->redirect (mi->event_channel);
       ui_out_redirect_pop redirect_popper (mi_uiout);
 
-      old_chain = make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
 
       if (selection & USER_SELECTED_INFERIOR)
        print_selected_inferior (mi->cli_uiout);
@@ -1340,7 +1284,6 @@ mi_user_selected_context_changed (user_selected_what selection)
        }
 
       gdb_flush (mi->event_channel);
-      do_cleanups (old_chain);
     }
 }
 
@@ -1352,17 +1295,15 @@ report_initial_inferior (struct inferior *inf, void *closure)
      and top_level_interpreter_data is set, we cannot call
      it here.  */
   struct mi_interp *mi = (struct mi_interp *) closure;
-  struct cleanup *old_chain;
 
-  old_chain = make_cleanup_restore_target_terminal ();
-  target_terminal_ours_for_output ();
+  target_terminal::scoped_restore_terminal_state term_state;
+  target_terminal::ours_for_output ();
 
   fprintf_unfiltered (mi->event_channel,
                      "thread-group-added,id=\"i%d\"",
                      inf->num);
   gdb_flush (mi->event_channel);
 
-  do_cleanups (old_chain);
   return 0;
 }
 
index b9eab7fcd87eea12c9fdea57be246aea9b3a4964..6ff119768c2358dc286ea937f93d9f812d791520 100644 (file)
@@ -502,7 +502,7 @@ startup_inferior (pid_t pid, int ntraps,
            break;
 
          case TARGET_WAITKIND_SIGNALLED:
-           target_terminal_ours ();
+           target_terminal::ours ();
            target_mourn_inferior (event_ptid);
            error (_("During startup program terminated with signal %s, %s."),
                   gdb_signal_to_name (ws.value.sig),
@@ -510,7 +510,7 @@ startup_inferior (pid_t pid, int ntraps,
            return resume_ptid;
 
          case TARGET_WAITKIND_EXITED:
-           target_terminal_ours ();
+           target_terminal::ours ();
            target_mourn_inferior (event_ptid);
            if (ws.value.integer)
              error (_("During startup program exited with code %d."),
@@ -549,10 +549,10 @@ startup_inferior (pid_t pid, int ntraps,
 
              /* Set up the "saved terminal modes" of the inferior
                 based on what modes we are starting it with.  */
-             target_terminal_init ();
+             target_terminal::init ();
 
              /* Install inferior's terminal modes.  */
-             target_terminal_inferior ();
+             target_terminal::inferior ();
 
              terminal_initted = 1;
            }
index a6fe390b02995a43e31ee90e482cd33c3ae40b9b..cabec0fa709ad371639e05a128a3aadac937b89e 100644 (file)
@@ -1285,7 +1285,7 @@ procfs_create_inferior (struct target_ops *ops, const char *exec_file,
     }
   if (!target_is_pushed (ops))
     push_target (ops);
-  target_terminal_init ();
+  target_terminal::init ();
 
   if (exec_bfd != NULL
       || (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
index d3cf78906abb6f46c326866406c62e2dc3763769..93c43a1367dc99429f0844ef4cb94ff35ae2d6a5 100644 (file)
@@ -1218,7 +1218,7 @@ record_full_wait_1 (struct target_ops *ops,
          And in GDB replay mode, GDB doesn't need to be in terminal_inferior
          mode, because inferior will not executed.
          Then set it to terminal_ours to make GDB get the signal.  */
-      target_terminal_ours ();
+      target_terminal::ours ();
 
       /* In EXEC_FORWARD mode, record_full_list points to the tail of prev
          instruction.  */
index 0963693a22567567c0c7e697b2966abc7d19a1ae..0988a250a28b42205ca3f02ff645a415adfa04c3 100644 (file)
@@ -4933,7 +4933,7 @@ remote_query_supported (void)
      instead.
 
    - The target has been resumed in the foreground
-     (target_terminal_is_ours is false) with a synchronous resume
+     (target_terminal::is_ours is false) with a synchronous resume
      packet, and we're blocked waiting for the stop reply, thus a
      Ctrl-C should be immediately sent to the target.
 
@@ -4964,11 +4964,11 @@ remote_serial_quit_handler (void)
            remote_unpush_and_throw ();
        }
       /* If ^C has already been sent once, offer to disconnect.  */
-      else if (!target_terminal_is_ours () && rs->ctrlc_pending_p)
+      else if (!target_terminal::is_ours () && rs->ctrlc_pending_p)
        interrupt_query ();
       /* All-stop protocol, and blocked waiting for stop reply.  Send
         an interrupt request.  */
-      else if (!target_terminal_is_ours () && rs->waiting_for_stop_reply)
+      else if (!target_terminal::is_ours () && rs->waiting_for_stop_reply)
        target_interrupt (inferior_ptid);
       else
        rs->got_ctrlc_during_io = 1;
@@ -6280,7 +6280,7 @@ interrupt_query (void)
 static void
 remote_terminal_inferior (struct target_ops *self)
 {
-  /* FIXME: cagney/1999-09-27: Make calls to target_terminal_*()
+  /* FIXME: cagney/1999-09-27: Make calls to target_terminal::*()
      idempotent.  The event-loop GDB talking to an asynchronous target
      with a synchronous command calls this function from both
      event-top.c and infrun.c/infcmd.c.  Once GDB stops trying to
@@ -7412,12 +7412,12 @@ remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
        {
          /* Zero length reply means that we tried 'S' or 'C' and the
             remote system doesn't support it.  */
-         target_terminal_ours_for_output ();
+         target_terminal::ours_for_output ();
          printf_filtered
            ("Can't send signals to this remote system.  %s not sent.\n",
             gdb_signal_to_name (rs->last_sent_signal));
          rs->last_sent_signal = GDB_SIGNAL_0;
-         target_terminal_inferior ();
+         target_terminal::inferior ();
 
          strcpy (buf, rs->last_sent_step ? "s" : "c");
          putpkt (buf);
index 0684297842adde10ad7301d76e35984fe3dc2bf2..4f7fd9069625c1d1972806ef41b6ebf2553bd7c7 100644 (file)
@@ -1285,9 +1285,9 @@ handle_solib_event (void)
   /* Check for any newly added shared libraries if we're supposed to
      be adding them automatically.  Switch terminal for any messages
      produced by breakpoint_re_set.  */
-  target_terminal_ours_for_output ();
+  target_terminal::ours_for_output ();
   solib_add (NULL, 0, auto_solib_add);
-  target_terminal_inferior ();
+  target_terminal::inferior ();
 }
 
 /* Reload shared libraries, but avoid reloading the same symbol file
index 3e2b4d08fc2f56362f9c8cc3f23d016334e8b56d..55ff99e3153440535a50fab48c1ea5343052b957 100644 (file)
@@ -433,53 +433,25 @@ target_load (const char *arg, int from_tty)
   (*current_target.to_load) (&current_target, arg, from_tty);
 }
 
-/* Possible terminal states.  */
+/* Define it.  */
 
-enum terminal_state
-  {
-    /* The inferior's terminal settings are in effect.  */
-    terminal_is_inferior = 0,
+enum target_terminal::terminal_state target_terminal::terminal_state
+  = target_terminal::terminal_is_ours;
 
-    /* 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 = terminal_is_ours;
-
-/* See target.h.  */
+/* See target/target.h.  */
 
 void
-target_terminal_init (void)
+target_terminal::init (void)
 {
   (*current_target.to_terminal_init) (&current_target);
 
   terminal_state = terminal_is_ours;
 }
 
-/* See target.h.  */
-
-int
-target_terminal_is_inferior (void)
-{
-  return (terminal_state == terminal_is_inferior);
-}
-
-/* See target.h.  */
-
-int
-target_terminal_is_ours (void)
-{
-  return (terminal_state == terminal_is_ours);
-}
-
-/* See target.h.  */
+/* See target/target.h.  */
 
 void
-target_terminal_inferior (void)
+target_terminal::inferior (void)
 {
   struct ui *ui = current_ui;
 
@@ -490,8 +462,8 @@ target_terminal_inferior (void)
 
   /* Since we always run the inferior in the main console (unless "set
      inferior-tty" is in effect), when some UI other than the main one
-     calls target_terminal_inferior/target_terminal_inferior, then we
-     leave the main UI's terminal settings as is.  */
+     calls target_terminal::inferior, then we leave the main UI's
+     terminal settings as is.  */
   if (ui != main_ui)
     return;
 
@@ -509,14 +481,14 @@ target_terminal_inferior (void)
     target_pass_ctrlc ();
 }
 
-/* See target.h.  */
+/* See target/target.h.  */
 
 void
-target_terminal_ours (void)
+target_terminal::ours ()
 {
   struct ui *ui = current_ui;
 
-  /* See target_terminal_inferior.  */
+  /* See target_terminal::inferior.  */
   if (ui != main_ui)
     return;
 
@@ -527,14 +499,14 @@ target_terminal_ours (void)
   terminal_state = terminal_is_ours;
 }
 
-/* See target.h.  */
+/* See target/target.h.  */
 
 void
-target_terminal_ours_for_output (void)
+target_terminal::ours_for_output ()
 {
   struct ui *ui = current_ui;
 
-  /* See target_terminal_inferior.  */
+  /* See target_terminal::inferior.  */
   if (ui != main_ui)
     return;
 
@@ -544,6 +516,14 @@ target_terminal_ours_for_output (void)
   terminal_state = terminal_is_ours_for_output;
 }
 
+/* See target/target.h.  */
+
+void
+target_terminal::info (const char *arg, int from_tty)
+{
+  (*current_target.to_terminal_info) (&current_target, arg, from_tty);
+}
+
 /* See target.h.  */
 
 int
@@ -561,40 +541,6 @@ target_supports_terminal_ours (void)
   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 = (enum terminal_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 = XNEW (enum terminal_state);
-
-  *ts = terminal_state;
-
-  return make_cleanup_dtor (cleanup_restore_target_terminal, ts, xfree);
-}
-
 static void
 tcomplain (void)
 {
index a3f00ab57e4298b58c2622c9deada0dfc5c54434..f7dc486fc05aceafb3d95c83413cd2900eedede1 100644 (file)
@@ -1533,41 +1533,11 @@ extern int target_remove_breakpoint (struct gdbarch *gdbarch,
                                     struct bp_target_info *bp_tgt,
                                     enum remove_bp_reason reason);
 
-/* Returns true if the terminal settings of the inferior are in
-   effect.  */
-
-extern int target_terminal_is_inferior (void);
-
-/* Returns true if our terminal settings are in effect.  */
-
-extern int target_terminal_is_ours (void);
-
-/* For target_terminal_init, target_terminal_inferior and
-   target_terminal_ours, see target/target.h.  */
-
-/* Put some of our terminal settings into effect, enough to get proper
-   results from our output, but do not change into or out of RAW mode
-   so that no input is discarded.  This is a no-op if terminal_ours
-   was most recently called.  This is a no-op unless called with the main
-   UI as current UI.  */
-
-extern void target_terminal_ours_for_output (void);
-
 /* Return true if the target stack has a non-default
   "to_terminal_ours" method.  */
 
 extern int target_supports_terminal_ours (void);
 
-/* Make a cleanup that restores the state of the terminal to the current
-   state.  */
-extern struct cleanup *make_cleanup_restore_target_terminal (void);
-
-/* Print useful information about our terminal status, if such a thing
-   exists.  */
-
-#define target_terminal_info(arg, from_tty) \
-     (*current_target.to_terminal_info) (&current_target, arg, from_tty)
-
 /* Kill the inferior process.   Make it go away.  */
 
 extern void target_kill (void);
index 052876683eed1f57d184ad7a9c3c572e32a97b4d..e99160304337339ee0c769f894a133564a4665cd 100644 (file)
@@ -95,18 +95,109 @@ extern void target_mourn_inferior (ptid_t ptid);
 
 extern int target_supports_multi_process (void);
 
-/* Initialize the terminal settings we record for the inferior,
-   before we actually run the inferior.  */
-extern void target_terminal_init ();
-
-/* Put the inferior's terminal settings into effect.  This is
-   preparation for starting or resuming the inferior.  This is a no-op
-   unless called with the main UI as current UI.  */
-extern void target_terminal_inferior ();
-
-/* Put our terminal settings into effect.  First record the inferior's
-   terminal settings so they can be restored properly later.  This is
-   a no-op unless called with the main UI as current UI.  */
-extern void target_terminal_ours ();
+/* Represents the state of the target terminal.  */
+class target_terminal
+{
+public:
+
+  target_terminal () = delete;
+  ~target_terminal () = delete;
+  DISABLE_COPY_AND_ASSIGN (target_terminal);
+
+  /* Initialize the terminal settings we record for the inferior,
+     before we actually run the inferior.  */
+  static void init ();
+
+  /* Put the inferior's terminal settings into effect.  This is
+     preparation for starting or resuming the inferior.  This is a no-op
+     unless called with the main UI as current UI.  */
+  static void inferior ();
+
+  /* Put our terminal settings into effect.  First record the inferior's
+     terminal settings so they can be restored properly later.  This is
+     a no-op unless called with the main UI as current UI.  */
+  static void ours ();
+
+  /* Put some of our terminal settings into effect, enough to get proper
+     results from our output, but do not change into or out of RAW mode
+     so that no input is discarded.  This is a no-op if terminal_ours
+     was most recently called.  This is a no-op unless called with the main
+     UI as current UI.  */
+  static void ours_for_output ();
+
+  /* Returns true if the terminal settings of the inferior are in
+     effect.  */
+  static bool is_inferior ()
+  {
+    return terminal_state == terminal_is_inferior;
+  }
+
+  /* Returns true if our terminal settings are in effect.  */
+  static bool is_ours ()
+  {
+    return terminal_state == terminal_is_ours;
+  }
+
+  /* Print useful information about our terminal status, if such a thing
+     exists.  */
+  static void info (const char *arg, int from_tty);
+
+private:
+
+  /* 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
+    };
+
+public:
+
+  /* A class that restores the state of the terminal to the current
+     state.  */
+  class scoped_restore_terminal_state
+  {
+  public:
+
+    scoped_restore_terminal_state ()
+      : m_state (terminal_state)
+    {
+    }
+
+    ~scoped_restore_terminal_state ()
+    {
+      switch (m_state)
+       {
+       case terminal_is_ours:
+         ours ();
+         break;
+       case terminal_is_ours_for_output:
+         ours_for_output ();
+         break;
+       case terminal_is_inferior:
+         inferior ();
+         break;
+       }
+    }
+
+    DISABLE_COPY_AND_ASSIGN (scoped_restore_terminal_state);
+
+  private:
+
+    target_terminal::terminal_state m_state;
+  };
+
+private:
+
+  static terminal_state terminal_state;
+};
 
 #endif /* TARGET_COMMON_H */
index 742c1e7a07e8fae2ee5a6b07b517f0e2ab00939c..404e096755c51b1301f2687a93062546ae45f2c8 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1571,7 +1571,7 @@ undo_terminal_modifications_before_exit (void)
 {
   struct ui *saved_top_level = current_ui;
 
-  target_terminal_ours ();
+  target_terminal::ours ();
 
   current_ui = main_ui;
 
index acb63812a4d4a7c82a990849f27a3ab7d788265b..2dd1bc02d04a1cf261502c52085df54fe522b96b 100644 (file)
@@ -118,14 +118,13 @@ tui_refresh_frame_and_register_information (int registers_too_p)
 {
   struct frame_info *fi;
   CORE_ADDR pc;
-  struct cleanup *old_chain;
   int frame_info_changed_p;
 
   if (!has_stack_frames ())
     return;
 
-  old_chain = make_cleanup_restore_target_terminal ();
-  target_terminal_ours_for_output ();
+  target_terminal::scoped_restore_terminal_state term_state;
+  target_terminal::ours_for_output ();
 
   fi = get_selected_frame (NULL);
   /* Ensure that symbols for this frame are read in.  Also, determine
@@ -156,8 +155,6 @@ tui_refresh_frame_and_register_information (int registers_too_p)
       tui_check_data_values (fi);
       tui_refreshing_registers = 0;
     }
-
-  do_cleanups (old_chain);
 }
 
 /* Dummy callback for deprecated_print_frame_info_listing_hook which is called
index c660c6bafc0f64c9337931bf81886715d7a290a9..9fea0f77b803f9bf0ed8412f3f30773442168f63 100644 (file)
@@ -67,6 +67,7 @@
 #include "gdb_regex.h"
 #include "job-control.h"
 #include "common/selftest.h"
+#include "common/gdb_optional.h"
 
 #if !HAVE_DECL_MALLOC
 extern PTR malloc ();          /* ARI: PTR */
@@ -276,12 +277,11 @@ vwarning (const char *string, va_list args)
     (*deprecated_warning_hook) (string, args);
   else
     {
-      struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-
+      gdb::optional<target_terminal::scoped_restore_terminal_state> term_state;
       if (target_supports_terminal_ours ())
        {
-         make_cleanup_restore_target_terminal ();
-         target_terminal_ours_for_output ();
+         term_state.emplace ();
+         target_terminal::ours_for_output ();
        }
       if (filtered_printing_initialized ())
        wrap_here ("");         /* Force out any buffered output.  */
@@ -290,8 +290,6 @@ vwarning (const char *string, va_list args)
        fputs_unfiltered (warning_pre_print, gdb_stderr);
       vfprintf_unfiltered (gdb_stderr, string, args);
       fprintf_unfiltered (gdb_stderr, "\n");
-
-      do_cleanups (old_chain);
     }
 }
 
@@ -485,10 +483,11 @@ internal_vproblem (struct internal_problem *problem,
     }
 
   /* Try to get the message out and at the start of a new line.  */
+  gdb::optional<target_terminal::scoped_restore_terminal_state> term_state;
   if (target_supports_terminal_ours ())
     {
-      make_cleanup_restore_target_terminal ();
-      target_terminal_ours_for_output ();
+      term_state.emplace ();
+      target_terminal::ours_for_output ();
     }
   if (filtered_printing_initialized ())
     begin_line ();
@@ -897,32 +896,43 @@ make_hex_string (const gdb_byte *data, size_t length)
 
 \f
 
-/* A cleanup that simply calls ui_unregister_input_event_handler.  */
+/* An RAII class that sets up to handle input and then tears down
+   during destruction.  */
 
-static void
-ui_unregister_input_event_handler_cleanup (void *ui)
+class scoped_input_handler
 {
-  ui_unregister_input_event_handler ((struct ui *) ui);
-}
+public:
 
-/* Set up to handle input.  */
+  scoped_input_handler ()
+    : m_quit_handler (make_scoped_restore (&quit_handler,
+                                          default_quit_handler)),
+      m_ui (NULL)
+  {
+    target_terminal::ours ();
+    ui_register_input_event_handler (current_ui);
+    if (current_ui->prompt_state == PROMPT_BLOCKED)
+      m_ui = current_ui;
+  }
 
-static struct cleanup *
-prepare_to_handle_input (void)
-{
-  struct cleanup *old_chain;
+  ~scoped_input_handler ()
+  {
+    if (m_ui != NULL)
+      ui_unregister_input_event_handler (m_ui);
+  }
 
-  old_chain = make_cleanup_restore_target_terminal ();
-  target_terminal_ours ();
+  DISABLE_COPY_AND_ASSIGN (scoped_input_handler);
 
-  ui_register_input_event_handler (current_ui);
-  if (current_ui->prompt_state == PROMPT_BLOCKED)
-    make_cleanup (ui_unregister_input_event_handler_cleanup, current_ui);
+private:
 
-  make_cleanup_override_quit_handler (default_quit_handler);
+  /* Save and restore the terminal state.  */
+  target_terminal::scoped_restore_terminal_state m_term_state;
 
-  return old_chain;
-}
+  /* Save and restore the quit handler.  */
+  scoped_restore m_quit_handler;
+
+  /* The saved UI, if non-NULL.  */
+  struct ui *m_ui;
+};
 
 \f
 
@@ -987,9 +997,8 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
       /* Restrict queries to the main UI.  */
       || current_ui != main_ui)
     {
-      old_chain = make_cleanup_restore_target_terminal ();
-
-      target_terminal_ours_for_output ();
+      target_terminal::scoped_restore_terminal_state term_state;
+      target_terminal::ours_for_output ();
       wrap_here ("");
       vfprintf_filtered (gdb_stdout, ctlstr, args);
 
@@ -998,18 +1007,13 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
                       y_string, n_string, def_answer);
       gdb_flush (gdb_stdout);
 
-      do_cleanups (old_chain);
       return def_value;
     }
 
   if (deprecated_query_hook)
     {
-      int res;
-
-      old_chain = make_cleanup_restore_target_terminal ();
-      res = deprecated_query_hook (ctlstr, args);
-      do_cleanups (old_chain);
-      return res;
+      target_terminal::scoped_restore_terminal_state term_state;
+      return deprecated_query_hook (ctlstr, args);
     }
 
   /* Format the question outside of the loop, to avoid reusing args.  */
@@ -1026,7 +1030,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
   using namespace std::chrono;
   steady_clock::time_point prompt_started = steady_clock::now ();
 
-  prepare_to_handle_input ();
+  scoped_input_handler prepare_input;
 
   while (1)
     {
@@ -1590,7 +1594,7 @@ prompt_for_continue (void)
      beyond the end of the screen.  */
   reinitialize_more_filter ();
 
-  prepare_to_handle_input ();
+  scoped_input_handler prepare_input;
 
   /* Call gdb_readline_wrapper, not readline, in order to keep an
      event loop running.  */
index ab5582d46cf3a0873ab32d9c955e95ee75371d4e..3e1894410d23d9fc891971f036478d3e91b6a544 100644 (file)
@@ -1519,7 +1519,7 @@ get_windows_debug_event (struct target_ops *ops,
                     "EXIT_PROCESS_DEBUG_EVENT"));
       if (!windows_initialization_done)
        {
-         target_terminal_ours ();
+         target_terminal::ours ();
          target_mourn_inferior (inferior_ptid);
          error (_("During startup program exited with code 0x%x."),
                 (unsigned int) current_event.u.ExitProcess.dwExitCode);
@@ -1626,7 +1626,7 @@ windows_wait (struct target_ops *ops,
 {
   int pid = -1;
 
-  target_terminal_ours ();
+  target_terminal::ours ();
 
   /* We loop when we get a non-standard exception rather than return
      with a SPURIOUS because resume can try and step or modify things,
@@ -1771,8 +1771,8 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
      current thread until we report an event out of windows_wait.  */
   inferior_ptid = pid_to_ptid (pid);
 
-  target_terminal_init ();
-  target_terminal_inferior ();
+  target_terminal::init ();
+  target_terminal::inferior ();
 
   windows_initialization_done = 0;
 
@@ -1912,7 +1912,7 @@ windows_attach (struct target_ops *ops, const char *args, int from_tty)
     }
 
   do_initial_windows_stuff (ops, pid, 1);
-  target_terminal_ours ();
+  target_terminal::ours ();
 }
 
 static void