[RFA 13/23] Replace tui_restore_gdbout with scoped_restore

Tom Tromey
2017-05-03T22:46:40Z

This patch replaces tui_restore_gdbout (a cleaup function) with a use
of scoped_restore. This one is broken out into its own patch because
it might slightly change the behavior of gdb: it saves and restores
pagination_enabled, whereas the tui_restore_gdbout unconditionally set
pagination_enabled to 1; and I think this warrants closer review.

2017-05-02 Tom Tromey <tom@tromey.com>

* tui/tui-regs.c (tui_restore_gdbout): Remove.
(tui_register_format): Use scoped_restore.
---
gdb/ChangeLog | 5 +++++
gdb/tui/tui-regs.c | 26 ++++++--------------------
2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d288de4..daa7dae 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2017-05-02 Tom Tromey <tom@tromey.com>

+ * tui/tui-regs.c (tui_restore_gdbout): Remove.
+ (tui_register_format): Use scoped_restore.
+
+2017-05-02 Tom Tromey <tom@tromey.com>
+
* reverse.c (exec_direction_default): Remove.
(exec_reverse_once): Use scoped_restore.
* remote.c (restore_remote_timeout): Remove.
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 3f9a007..ade9cd6 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -708,13 +708,6 @@ TUI command to control the register window."), tuicmd);
** STATIC LOCAL FUNCTIONS **
******************************************/

-static void
-tui_restore_gdbout (void *ui)
-{
- gdb_stdout = (struct ui_file*) ui;
- pagination_enabled = 1;
-}
-
/* Get the register from the frame and return a printable
representation of it. */

@@ -722,17 +715,14 @@ static char *
tui_register_format (struct frame_info *frame, int regnum)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
- struct ui_file *old_stdout;
- struct cleanup *cleanups;
- char *p, *s;
- char *ret;

string_file stream;

- pagination_enabled = 0;
- old_stdout = gdb_stdout;
- gdb_stdout = &stream;
- cleanups = make_cleanup (tui_restore_gdbout, (void*) old_stdout);
+ scoped_restore save_pagination
+ = make_scoped_restore (&pagination_enabled, 0);
+ scoped_restore save_stdout
+ = make_scoped_restore (&gdb_stdout, &stream);
+
gdbarch_print_registers_info (gdbarch, &stream, frame, regnum, 1);

/* Remove the possible \n. */
@@ -741,11 +731,7 @@ tui_register_format (struct frame_info *frame, int regnum)
str.resize (str.size () - 1);

/* Expand tabs into spaces, since ncurses on MS-Windows doesn't. */
- ret = tui_expand_tabs (str.c_str (), 0);
-
- do_cleanups (cleanups);
-
- return ret;
+ return tui_expand_tabs (str.c_str (), 0);
}

/* Get the register value from the given frame and format it for the
--
2.9.3