Use RAII to save and restore scalars
This patch replaces many (but not all) uses of make_cleanup_restore_integer with a simple RAII-based template class. It also removes the similar restore_execution_direction cleanup in favor of this new class. Subsequent patches will replace other similar cleanups with this class. The class is typically instantiated using make_scoped_restore. This allows for template argument deduction. 2016-10-21 Tom Tromey <tom@tromey.com> * common/scoped_restore.h: New file. * utils.h: Include scoped_restore.h. * top.c (execute_command_to_string): Use scoped_restore. * python/python.c (python_interactive_command): Use scoped_restore. (python_command, execute_gdb_command): Likewise. * printcmd.c (do_one_display): Use scoped_restore. * mi/mi-main.c (exec_continue): Use scoped_restore. * mi/mi-cmd-var.c (mi_cmd_var_assign): Use scoped_restore. * linux-fork.c (checkpoint_command): Use scoped_restore. * infrun.c (restore_execution_direction): Remove. (fetch_inferior_event): Use scoped_restore. * compile/compile.c (compile_file_command): Use scoped_restore. (compile_code_command, compile_print_command): Likewise. * cli/cli-script.c (execute_user_command): Use scoped_restore. (while_command, if_command, script_from_file): Likewise. * arm-tdep.c (arm_insert_single_step_breakpoint): Use scoped_restore.
This commit is contained in:
parent
9a1e3f0031
commit
b7b633e9b1
13 changed files with 155 additions and 77 deletions
|
@ -380,8 +380,7 @@ execute_user_command (struct cmd_list_element *c, char *args)
|
|||
not confused with Insight. */
|
||||
in_user_command = 1;
|
||||
|
||||
make_cleanup_restore_integer (¤t_ui->async);
|
||||
current_ui->async = 0;
|
||||
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
|
||||
|
||||
command_nest_depth++;
|
||||
while (cmdlines)
|
||||
|
@ -654,7 +653,6 @@ static void
|
|||
while_command (char *arg, int from_tty)
|
||||
{
|
||||
struct command_line *command = NULL;
|
||||
struct cleanup *old_chain;
|
||||
|
||||
control_level = 1;
|
||||
command = get_command_line (while_control, arg);
|
||||
|
@ -662,13 +660,10 @@ while_command (char *arg, int from_tty)
|
|||
if (command == NULL)
|
||||
return;
|
||||
|
||||
old_chain = make_cleanup_restore_integer (¤t_ui->async);
|
||||
current_ui->async = 0;
|
||||
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
|
||||
|
||||
execute_control_command_untraced (command);
|
||||
free_command_lines (&command);
|
||||
|
||||
do_cleanups (old_chain);
|
||||
}
|
||||
|
||||
/* "if" command support. Execute either the true or false arm depending
|
||||
|
@ -686,13 +681,10 @@ if_command (char *arg, int from_tty)
|
|||
if (command == NULL)
|
||||
return;
|
||||
|
||||
old_chain = make_cleanup_restore_integer (¤t_ui->async);
|
||||
current_ui->async = 0;
|
||||
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
|
||||
|
||||
execute_control_command_untraced (command);
|
||||
free_command_lines (&command);
|
||||
|
||||
do_cleanups (old_chain);
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
|
@ -1693,10 +1685,8 @@ script_from_file (FILE *stream, const char *file)
|
|||
source_line_number = 0;
|
||||
source_file_name = file;
|
||||
|
||||
make_cleanup_restore_integer (¤t_ui->async);
|
||||
current_ui->async = 0;
|
||||
|
||||
{
|
||||
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
|
||||
|
||||
TRY
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue