From 2ec845e758762030f2333c21fa532fc57fe3762f Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 26 Apr 2017 22:53:40 -0600 Subject: More uses of scoped_restore There were a few more places in gdb that could easily use scoped_restore, replacing some cleanups. ChangeLog 2017-08-03 Tom Tromey * reverse.c (exec_direction_default): Remove. (exec_reverse_once): Use scoped_restore. * remote.c (restore_remote_timeout): Remove. (remote_flash_erase, remote_flash_write, remote_flash_done) (readchar, remote_serial_write): Use scoped_restore. * cli/cli-script.c (struct source_cleanup_lines_args) (source_cleanup_lines): Remove. (script_from_file): Use scoped_restore. * cli/cli-cmds.c (source_verbose_cleanup): Remove. (source_command): Use scoped_restore. --- gdb/reverse.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'gdb/reverse.c') diff --git a/gdb/reverse.c b/gdb/reverse.c index 4080616..c8f3811 100644 --- a/gdb/reverse.c +++ b/gdb/reverse.c @@ -30,13 +30,6 @@ /* User interface: reverse-step, reverse-next etc. */ -static void -exec_direction_default (void *notused) -{ - /* Return execution direction to default state. */ - execution_direction = EXEC_FORWARD; -} - /* exec_reverse_once -- accepts an arbitrary gdb command (string), and executes it with exec-direction set to 'reverse'. @@ -45,9 +38,7 @@ exec_direction_default (void *notused) static void exec_reverse_once (const char *cmd, char *args, int from_tty) { - char *reverse_command; enum exec_direction_kind dir = execution_direction; - struct cleanup *old_chain; if (dir == EXEC_REVERSE) error (_("Already in reverse mode. Use '%s' or 'set exec-dir forward'."), @@ -56,12 +47,10 @@ exec_reverse_once (const char *cmd, char *args, int from_tty) if (!target_can_execute_reverse) error (_("Target %s does not support this command."), target_shortname); - reverse_command = xstrprintf ("%s %s", cmd, args ? args : ""); - old_chain = make_cleanup (exec_direction_default, NULL); - make_cleanup (xfree, reverse_command); - execution_direction = EXEC_REVERSE; - execute_command (reverse_command, from_tty); - do_cleanups (old_chain); + std::string reverse_command = string_printf ("%s %s", cmd, args ? args : ""); + scoped_restore restore_exec_dir + = make_scoped_restore (&execution_direction, EXEC_REVERSE); + execute_command (&reverse_command[0], from_tty); } static void -- cgit v1.1