summaryrefslogtreecommitdiff
path: root/gdb/compile
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-09-22 20:29:11 -0600
committerTom Tromey <tom@tromey.com>2016-10-21 14:17:31 -0600
commitb7b633e9b13fc5697af035f4504c9790c612a8c7 (patch)
tree0da81b5f31738da5c2aa84819d709a66ef9d4583 /gdb/compile
parent9a1e3f003122c97d6e1822c472bcd37f59fb1a74 (diff)
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.
Diffstat (limited to 'gdb/compile')
-rw-r--r--gdb/compile/compile.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 0c4a7387ad..73fae22d1a 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -91,8 +91,7 @@ compile_file_command (char *arg, int from_tty)
char *buffer;
struct cleanup *cleanup;
- cleanup = make_cleanup_restore_integer (&current_ui->async);
- current_ui->async = 0;
+ scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
/* Check the user did not just <enter> after command. */
if (arg == NULL)
@@ -115,7 +114,7 @@ compile_file_command (char *arg, int from_tty)
arg = skip_spaces (arg);
arg = gdb_abspath (arg);
- make_cleanup (xfree, arg);
+ cleanup = make_cleanup (xfree, arg);
buffer = xstrprintf ("#include \"%s\"\n", arg);
make_cleanup (xfree, buffer);
eval_compile_command (NULL, buffer, scope, NULL);
@@ -130,11 +129,9 @@ compile_file_command (char *arg, int from_tty)
static void
compile_code_command (char *arg, int from_tty)
{
- struct cleanup *cleanup;
enum compile_i_scope_types scope = COMPILE_I_SIMPLE_SCOPE;
- cleanup = make_cleanup_restore_integer (&current_ui->async);
- current_ui->async = 0;
+ scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
if (arg != NULL && check_raw_argument (&arg))
{
@@ -155,13 +152,12 @@ compile_code_command (char *arg, int from_tty)
else
{
struct command_line *l = get_command_line (compile_control, "");
+ struct cleanup *cleanup = make_cleanup_free_command_lines (&l);
- make_cleanup_free_command_lines (&l);
l->control_u.compile.scope = scope;
execute_control_command_untraced (l);
+ do_cleanups (cleanup);
}
-
- do_cleanups (cleanup);
}
/* Callback for compile_print_command. */
@@ -183,12 +179,10 @@ static void
compile_print_command (char *arg_param, int from_tty)
{
const char *arg = arg_param;
- struct cleanup *cleanup;
enum compile_i_scope_types scope = COMPILE_I_PRINT_ADDRESS_SCOPE;
struct format_data fmt;
- cleanup = make_cleanup_restore_integer (&current_ui->async);
- current_ui->async = 0;
+ scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
/* Passing &FMT as SCOPE_DATA is safe as do_module_cleanup will not
touch the stale pointer if compile_object_run has already quit. */
@@ -199,14 +193,13 @@ compile_print_command (char *arg_param, int from_tty)
else
{
struct command_line *l = get_command_line (compile_control, "");
+ struct cleanup *cleanup = make_cleanup_free_command_lines (&l);
- make_cleanup_free_command_lines (&l);
l->control_u.compile.scope = scope;
l->control_u.compile.scope_data = &fmt;
execute_control_command_untraced (l);
+ do_cleanups (cleanup);
}
-
- do_cleanups (cleanup);
}
/* A cleanup function to remove a directory and all its contents. */