aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-04-26 22:53:40 -0600
committerTom Tromey <tom@tromey.com>2017-08-03 07:59:00 -0600
commit2ec845e758762030f2333c21fa532fc57fe3762f (patch)
tree9732e9de0eb998580859fcc3d2a33285b454d561 /gdb/cli
parentb3bc84537bc6de78e2bbd550ce9c57dd4b7e2ec6 (diff)
downloadgdb-2ec845e758762030f2333c21fa532fc57fe3762f.zip
gdb-2ec845e758762030f2333c21fa532fc57fe3762f.tar.gz
gdb-2ec845e758762030f2333c21fa532fc57fe3762f.tar.bz2
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 <tom@tromey.com> * 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.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-cmds.c16
-rw-r--r--gdb/cli/cli-script.c60
2 files changed, 19 insertions, 57 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 4650532..a0d566b 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -645,26 +645,14 @@ source_script (const char *file, int from_tty)
source_script_with_search (file, from_tty, 0);
}
-/* Return the source_verbose global variable to its previous state
- on exit from the source command, by whatever means. */
-static void
-source_verbose_cleanup (void *old_value)
-{
- source_verbose = *(int *)old_value;
- xfree (old_value);
-}
-
static void
source_command (char *args, int from_tty)
{
- struct cleanup *old_cleanups;
char *file = args;
int *old_source_verbose = XNEW (int);
int search_path = 0;
- *old_source_verbose = source_verbose;
- old_cleanups = make_cleanup (source_verbose_cleanup,
- old_source_verbose);
+ scoped_restore save_source_verbose = make_scoped_restore (&source_verbose);
/* -v causes the source command to run in verbose mode.
-s causes the file to be searched in the source search path,
@@ -705,8 +693,6 @@ source_command (char *args, int from_tty)
}
source_script_with_search (file, from_tty, search_path);
-
- do_cleanups (old_cleanups);
}
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 5674404..a6d5456 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1585,58 +1585,34 @@ document_command (char *comname, int from_tty)
}
}
-struct source_cleanup_lines_args
-{
- int old_line;
- const char *old_file;
-};
-
-static void
-source_cleanup_lines (void *args)
-{
- struct source_cleanup_lines_args *p =
- (struct source_cleanup_lines_args *) args;
-
- source_line_number = p->old_line;
- source_file_name = p->old_file;
-}
-
/* Used to implement source_command. */
void
script_from_file (FILE *stream, const char *file)
{
- struct cleanup *old_cleanups;
- struct source_cleanup_lines_args old_lines;
-
if (stream == NULL)
internal_error (__FILE__, __LINE__, _("called with NULL file pointer!"));
- old_lines.old_line = source_line_number;
- old_lines.old_file = source_file_name;
- old_cleanups = make_cleanup (source_cleanup_lines, &old_lines);
- source_line_number = 0;
- source_file_name = file;
-
- {
- scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
+ scoped_restore restore_line_number
+ = make_scoped_restore (&source_line_number, 0);
+ scoped_restore resotre_file
+ = make_scoped_restore (&source_file_name, file);
- TRY
- {
- read_command_file (stream);
- }
- CATCH (e, RETURN_MASK_ERROR)
- {
- /* Re-throw the error, but with the file name information
- prepended. */
- throw_error (e.error,
- _("%s:%d: Error in sourced command file:\n%s"),
- source_file_name, source_line_number, e.message);
- }
- END_CATCH
- }
+ scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
- do_cleanups (old_cleanups);
+ TRY
+ {
+ read_command_file (stream);
+ }
+ CATCH (e, RETURN_MASK_ERROR)
+ {
+ /* Re-throw the error, but with the file name information
+ prepended. */
+ throw_error (e.error,
+ _("%s:%d: Error in sourced command file:\n%s"),
+ source_file_name, source_line_number, e.message);
+ }
+ END_CATCH
}
/* Print the definition of user command C to STREAM. Or, if C is a