[RFA 09/22] Remove make_cleanup_restore_current_ui

Tom Tromey
2016-09-27T04:48:41Z

This removes make_cleanup_restore_current_ui by converting the last
use. The last use was in a few functions used to iterate over all
UIs. This patch replaces these functions with a class, and arranges
for the class destructor to do the needed cleanup.

2016-09-26 Tom Tromey <tom@tromey.com>

* tui/tui-interp.c (tui_on_normal_stop, tui_on_signal_received)
(tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited)
(tui_on_no_history): Update.
* top.h (switch_thru_all_uis): New class.
(SWITCH_THRU_ALL_UIS): Rewrite.
(make_cleanup_restore_current_ui, switch_thru_all_uis_init)
(switch_thru_all_uis_cond, switch_thru_all_uis_next): Don't
declare.
* 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_on_signal_received)
(mi_on_end_stepping_range, mi_on_signal_exited, mi_on_exited)
(mi_on_no_history, mi_on_normal_stop, mi_traceframe_changed)
(mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
(mi_breakpoint_created, mi_breakpoint_deleted)
(mi_breakpoint_modified, mi_output_running_pid, mi_on_resume)
(mi_solib_loaded, mi_solib_unloaded, mi_command_param_changed)
(mi_memory_changed): Update.
* infrun.c (all_uis_check_sync_execution_done)
(all_uis_on_sync_execution_starting, normal_stop): Update.
* event-top.c (restore_ui_cleanup)
(make_cleanup_restore_current_ui, switch_thru_all_uis_init)
(switch_thru_all_uis_cond, switch_thru_all_uis_next): Remove.
* cli/cli-interp.c (cli_on_normal_stop, cli_on_signal_received)
(cli_on_end_stepping_range, cli_on_signal_exited, cli_on_exited)
(cli_on_no_history): Update.
* breakpoint.c (watchpoint_check): Update.
---
gdb/ChangeLog | 30 +++++++++++++++
gdb/breakpoint.c | 8 +---
gdb/cli/cli-interp.c | 24 +++---------
gdb/event-top.c | 50 -------------------------
gdb/infrun.c | 15 +++-----
gdb/mi/mi-interp.c | 101 +++++++++++++--------------------------------------
gdb/top.h | 56 +++++++++++++++++++---------
gdb/tui/tui-interp.c | 24 +++---------
8 files changed, 114 insertions(+), 194 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 717408f..954d658 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,35 @@
2016-09-26 Tom Tromey <tom@tromey.com>

+ * tui/tui-interp.c (tui_on_normal_stop, tui_on_signal_received)
+ (tui_on_end_stepping_range, tui_on_signal_exited, tui_on_exited)
+ (tui_on_no_history): Update.
+ * top.h (switch_thru_all_uis): New class.
+ (SWITCH_THRU_ALL_UIS): Rewrite.
+ (make_cleanup_restore_current_ui, switch_thru_all_uis_init)
+ (switch_thru_all_uis_cond, switch_thru_all_uis_next): Don't
+ declare.
+ * 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_on_signal_received)
+ (mi_on_end_stepping_range, mi_on_signal_exited, mi_on_exited)
+ (mi_on_no_history, mi_on_normal_stop, mi_traceframe_changed)
+ (mi_tsv_created, mi_tsv_deleted, mi_tsv_modified)
+ (mi_breakpoint_created, mi_breakpoint_deleted)
+ (mi_breakpoint_modified, mi_output_running_pid, mi_on_resume)
+ (mi_solib_loaded, mi_solib_unloaded, mi_command_param_changed)
+ (mi_memory_changed): Update.
+ * infrun.c (all_uis_check_sync_execution_done)
+ (all_uis_on_sync_execution_starting, normal_stop): Update.
+ * event-top.c (restore_ui_cleanup)
+ (make_cleanup_restore_current_ui, switch_thru_all_uis_init)
+ (switch_thru_all_uis_cond, switch_thru_all_uis_next): Remove.
+ * cli/cli-interp.c (cli_on_normal_stop, cli_on_signal_received)
+ (cli_on_end_stepping_range, cli_on_signal_exited, cli_on_exited)
+ (cli_on_no_history): Update.
+ * breakpoint.c (watchpoint_check): Update.
+
+2016-09-26 Tom Tromey <tom@tromey.com>
+
* xcoffread.c (record_minimal_symbol, scan_xcoff_symtab): Add
"reader" argument. Update.
(xcoff_initial_scan): Update.
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 1e05932..7f0061a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5238,8 +5238,6 @@ watchpoint_check (void *p)
}
else
{
- struct switch_thru_all_uis state;
-
/* This seems like the only logical thing to do because
if we temporarily ignored the watchpoint, then when
we reenter the block in which it is valid it contains
@@ -5254,7 +5252,7 @@ watchpoint_check (void *p)
already. So we have no choice but print the information
here. */

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct ui_out *uiout = current_uiout;

@@ -5435,9 +5433,7 @@ bpstat_check_watchpoint (bpstat bs)
case 0:
/* Error from catch_errors. */
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
printf_filtered (_("Watchpoint %d deleted.\n"),
b->base.number);
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 5d67ba4..132ecdb 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -93,12 +93,10 @@ should_print_stop_to_console (struct interp *console_interp,
static void
cli_on_normal_stop (struct bpstats *bs, int print_frame)
{
- struct switch_thru_all_uis state;
-
if (!print_frame)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *interp = top_level_interpreter ();
struct cli_interp *cli = as_cli_interp (interp);
@@ -118,9 +116,7 @@ cli_on_normal_stop (struct bpstats *bs, int print_frame)
static void
cli_on_signal_received (enum gdb_signal siggnal)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct cli_interp *cli = as_cli_interp (top_level_interpreter ());

@@ -136,9 +132,7 @@ cli_on_signal_received (enum gdb_signal siggnal)
static void
cli_on_end_stepping_range (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct cli_interp *cli = as_cli_interp (top_level_interpreter ());

@@ -154,9 +148,7 @@ cli_on_end_stepping_range (void)
static void
cli_on_signal_exited (enum gdb_signal siggnal)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct cli_interp *cli = as_cli_interp (top_level_interpreter ());

@@ -172,9 +164,7 @@ cli_on_signal_exited (enum gdb_signal siggnal)
static void
cli_on_exited (int exitstatus)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct cli_interp *cli = as_cli_interp (top_level_interpreter ());

@@ -190,9 +180,7 @@ cli_on_exited (int exitstatus)
static void
cli_on_no_history (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct cli_interp *cli = as_cli_interp (top_level_interpreter ());

diff --git a/gdb/event-top.c b/gdb/event-top.c
index 576eded..9b0ccbc 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -447,56 +447,6 @@ struct ui *main_ui;
struct ui *current_ui;
struct ui *ui_list;

-/* A cleanup handler that restores the current UI. */
-
-static void
-restore_ui_cleanup (void *data)
-{
- current_ui = (struct ui *) data;
-}
-
-/* See top.h. */
-
-struct cleanup *
-make_cleanup_restore_current_ui (void)
-{
- return make_cleanup (restore_ui_cleanup, current_ui);
-}
-
-/* See top.h. */
-
-void
-switch_thru_all_uis_init (struct switch_thru_all_uis *state)
-{
- state->iter = ui_list;
- state->old_chain = make_cleanup_restore_current_ui ();
-}
-
-/* See top.h. */
-
-int
-switch_thru_all_uis_cond (struct switch_thru_all_uis *state)
-{
- if (state->iter != NULL)
- {
- current_ui = state->iter;
- return 1;
- }
- else
- {
- do_cleanups (state->old_chain);
- return 0;
- }
-}
-
-/* See top.h. */
-
-void
-switch_thru_all_uis_next (struct switch_thru_all_uis *state)
-{
- state->iter = state->iter->next;
-}
-
/* Get a pointer to the current UI's line buffer. This is used to
construct a whole line of input from partial input. */

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 6d96af9..1736526 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3857,9 +3857,7 @@ check_curr_ui_sync_execution_done (void)
void
all_uis_check_sync_execution_done (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
check_curr_ui_sync_execution_done ();
}
@@ -3870,9 +3868,7 @@ all_uis_check_sync_execution_done (void)
void
all_uis_on_sync_execution_starting (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
if (current_ui->prompt_state == PROMPT_NEEDED)
async_disable_stdin ();
@@ -8217,7 +8213,6 @@ normal_stop (void)
ptid_t last_ptid;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
ptid_t pid_ptid;
- struct switch_thru_all_uis state;

get_last_target_status (&last_ptid, &last);

@@ -8282,7 +8277,7 @@ normal_stop (void)
&& last.kind != TARGET_WAITKIND_EXITED
&& last.kind != TARGET_WAITKIND_NO_RESUMED)
{
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
target_terminal_ours_for_output ();
printf_filtered (_("[Switching to %s]\n"),
@@ -8294,7 +8289,7 @@ normal_stop (void)

if (last.kind == TARGET_WAITKIND_NO_RESUMED)
{
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
if (current_ui->prompt_state == PROMPT_BLOCKED)
{
target_terminal_ours_for_output ();
@@ -8311,7 +8306,7 @@ normal_stop (void)
if (stopped_by_random_signal)
disable_current_display ();

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
async_enable_stdin ();
}
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index e3c7dbd..9584cd8 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -344,11 +344,10 @@ static void
mi_new_thread (struct thread_info *t)
{
struct inferior *inf = find_inferior_ptid (t->ptid);
- struct switch_thru_all_uis state;

gdb_assert (inf);

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -371,12 +370,10 @@ mi_new_thread (struct thread_info *t)
static void
mi_thread_exit (struct thread_info *t, int silent)
{
- struct switch_thru_all_uis state;
-
if (silent)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -401,9 +398,7 @@ static void
mi_record_changed (struct inferior *inferior, int started, const char *method,
const char *format)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -447,9 +442,7 @@ mi_record_changed (struct inferior *inferior, int started, const char *method,
static void
mi_inferior_added (struct inferior *inf)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *interp;
struct mi_interp *mi;
@@ -480,9 +473,7 @@ mi_inferior_added (struct inferior *inf)
static void
mi_inferior_appeared (struct inferior *inf)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -504,9 +495,7 @@ mi_inferior_appeared (struct inferior *inf)
static void
mi_inferior_exit (struct inferior *inf)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -533,9 +522,7 @@ mi_inferior_exit (struct inferior *inf)
static void
mi_inferior_removed (struct inferior *inf)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -584,9 +571,7 @@ find_mi_interp (void)
static void
mi_on_signal_received (enum gdb_signal siggnal)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = find_mi_interp ();

@@ -603,9 +588,7 @@ mi_on_signal_received (enum gdb_signal siggnal)
static void
mi_on_end_stepping_range (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = find_mi_interp ();

@@ -622,9 +605,7 @@ mi_on_end_stepping_range (void)
static void
mi_on_signal_exited (enum gdb_signal siggnal)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = find_mi_interp ();

@@ -641,9 +622,7 @@ mi_on_signal_exited (enum gdb_signal siggnal)
static void
mi_on_exited (int exitstatus)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = find_mi_interp ();

@@ -660,9 +639,7 @@ mi_on_exited (int exitstatus)
static void
mi_on_no_history (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = find_mi_interp ();

@@ -734,9 +711,7 @@ mi_on_normal_stop_1 (struct bpstats *bs, int print_frame)
static void
mi_on_normal_stop (struct bpstats *bs, int print_frame)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
if (as_mi_interp (top_level_interpreter ()) == NULL)
continue;
@@ -776,12 +751,10 @@ struct mi_suppress_notification mi_suppress_notification =
static void
mi_traceframe_changed (int tfnum, int tpnum)
{
- struct switch_thru_all_uis state;
-
if (mi_suppress_notification.traceframe)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -810,9 +783,7 @@ mi_traceframe_changed (int tfnum, int tpnum)
static void
mi_tsv_created (const struct trace_state_variable *tsv)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -838,9 +809,7 @@ mi_tsv_created (const struct trace_state_variable *tsv)
static void
mi_tsv_deleted (const struct trace_state_variable *tsv)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -868,9 +837,7 @@ mi_tsv_deleted (const struct trace_state_variable *tsv)
static void
mi_tsv_modified (const struct trace_state_variable *tsv)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct ui_out *mi_uiout;
@@ -908,15 +875,13 @@ mi_tsv_modified (const struct trace_state_variable *tsv)
static void
mi_breakpoint_created (struct breakpoint *b)
{
- struct switch_thru_all_uis state;
-
if (mi_suppress_notification.breakpoint)
return;

if (b->number <= 0)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct ui_out *mi_uiout;
@@ -962,15 +927,13 @@ mi_breakpoint_created (struct breakpoint *b)
static void
mi_breakpoint_deleted (struct breakpoint *b)
{
- struct switch_thru_all_uis state;
-
if (mi_suppress_notification.breakpoint)
return;

if (b->number <= 0)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -995,15 +958,13 @@ mi_breakpoint_deleted (struct breakpoint *b)
static void
mi_breakpoint_modified (struct breakpoint *b)
{
- struct switch_thru_all_uis state;
-
if (mi_suppress_notification.breakpoint)
return;

if (b->number <= 0)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -1044,9 +1005,8 @@ static int
mi_output_running_pid (struct thread_info *info, void *arg)
{
ptid_t *ptid = (ptid_t *) arg;
- struct switch_thru_all_uis state;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());

@@ -1132,7 +1092,6 @@ static void
mi_on_resume (ptid_t ptid)
{
struct thread_info *tp = NULL;
- struct switch_thru_all_uis state;

if (ptid_equal (ptid, minus_one_ptid) || ptid_is_pid (ptid))
tp = inferior_thread ();
@@ -1143,7 +1102,7 @@ mi_on_resume (ptid_t ptid)
if (tp->control.in_infcall)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct cleanup *old_chain;
@@ -1163,9 +1122,7 @@ mi_on_resume (ptid_t ptid)
static void
mi_solib_loaded (struct so_list *solib)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct ui_out *uiout;
@@ -1204,9 +1161,7 @@ mi_solib_loaded (struct so_list *solib)
static void
mi_solib_unloaded (struct so_list *solib)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct ui_out *uiout;
@@ -1246,12 +1201,10 @@ mi_solib_unloaded (struct so_list *solib)
static void
mi_command_param_changed (const char *param, const char *value)
{
- struct switch_thru_all_uis state;
-
if (mi_suppress_notification.cmd_param_changed)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct ui_out *mi_uiout;
@@ -1286,12 +1239,10 @@ static void
mi_memory_changed (struct inferior *inferior, CORE_ADDR memaddr,
ssize_t len, const bfd_byte *myaddr)
{
- struct switch_thru_all_uis state;
-
if (mi_suppress_notification.memory)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
struct ui_out *mi_uiout;
diff --git a/gdb/top.h b/gdb/top.h
index acdb8e9..ca1ae17 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -155,27 +155,52 @@ extern struct ui *current_ui;
/* The list of all UIs. */
extern struct ui *ui_list;

-/* State for SWITCH_THRU_ALL_UIS. Declared here because it is meant
- to be created on the stack, but should be treated as opaque. */
-struct switch_thru_all_uis
+/* State for SWITCH_THRU_ALL_UIS. */
+class switch_thru_all_uis
{
+public:
+
+ switch_thru_all_uis () : iter (nullptr), save_ui (&current_ui)
+ {
+ iter = ui_list;
+ }
+
+ ~switch_thru_all_uis ()
+ {
+ }
+
+ // If done iterating, return true; otherwise return false.
+ bool done () const
+ {
+ return iter == nullptr;
+ }
+
+ // Move to the next UI, setting current_ui if iteration is not yet
+ // complete.
+ void next ()
+ {
+ iter = iter->next;
+ if (iter != nullptr)
+ current_ui = iter;
+ }
+
+ private:
+
+ // No need for these. They are intentionally not defined anywhere.
+ switch_thru_all_uis &operator= (const switch_thru_all_uis &);
+ switch_thru_all_uis (const switch_thru_all_uis &);
+
+ // Used to iterate through the UIs.
struct ui *iter;
- struct cleanup *old_chain;
-};

-/* Functions to drive SWITCH_THRU_ALL_UIS. Though declared here by
- necessity, these functions should not be used other than via the
- SWITCH_THRU_ALL_UIS macro defined below. */
-extern void switch_thru_all_uis_init (struct switch_thru_all_uis *state);
-extern int switch_thru_all_uis_cond (struct switch_thru_all_uis *state);
-extern void switch_thru_all_uis_next (struct switch_thru_all_uis *state);
+ // Save and restore current_ui.
+ scoped_restore<struct ui *> save_ui;
+};

/* Traverse through all UI, and switch the current UI to the one
being iterated. */
#define SWITCH_THRU_ALL_UIS(STATE) \
- for (switch_thru_all_uis_init (&STATE); \
- switch_thru_all_uis_cond (&STATE); \
- switch_thru_all_uis_next (&STATE))
+ for (switch_thru_all_uis stau_state; !stau_state.done (); stau_state.next ())

/* Traverse over all UIs. */
#define ALL_UIS(UI) \
@@ -188,9 +213,6 @@ extern void delete_ui (struct ui *todel);
/* Cleanup that deletes a UI. */
extern struct cleanup *make_delete_ui_cleanup (struct ui *ui);

-/* Make a cleanup that restores the current UI. */
-extern struct cleanup *make_cleanup_restore_current_ui (void);
-
/* Register the UI's input file descriptor in the event loop. */
extern void ui_register_input_event_handler (struct ui *ui);

diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 3856382..ba468b4 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -70,12 +70,10 @@ tui_exit (void)
static void
tui_on_normal_stop (struct bpstats *bs, int print_frame)
{
- struct switch_thru_all_uis state;
-
if (!print_frame)
return;

- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *interp = top_level_interpreter ();
struct interp *tui = as_tui_interp (interp);
@@ -95,9 +93,7 @@ tui_on_normal_stop (struct bpstats *bs, int print_frame)
static void
tui_on_signal_received (enum gdb_signal siggnal)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *tui = as_tui_interp (top_level_interpreter ());

@@ -113,9 +109,7 @@ tui_on_signal_received (enum gdb_signal siggnal)
static void
tui_on_end_stepping_range (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *tui = as_tui_interp (top_level_interpreter ());

@@ -131,9 +125,7 @@ tui_on_end_stepping_range (void)
static void
tui_on_signal_exited (enum gdb_signal siggnal)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *tui = as_tui_interp (top_level_interpreter ());

@@ -149,9 +141,7 @@ tui_on_signal_exited (enum gdb_signal siggnal)
static void
tui_on_exited (int exitstatus)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *tui = as_tui_interp (top_level_interpreter ());

@@ -167,9 +157,7 @@ tui_on_exited (int exitstatus)
static void
tui_on_no_history (void)
{
- struct switch_thru_all_uis state;
-
- SWITCH_THRU_ALL_UIS (state)
+ SWITCH_THRU_ALL_UIS ()
{
struct interp *tui = as_tui_interp (top_level_interpreter ());

--
2.7.4