diff options
author | Tom Tromey <tom@tromey.com> | 2017-08-13 14:44:08 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-09-11 16:15:09 -0600 |
commit | a9921622de0a7332a333c5206ce8cd632803df97 (patch) | |
tree | d6fd47ffb7622621a9d7ec74568d931cc0199068 | |
parent | be0d7abb5e3b0be4cb928845e70a9134f1b19700 (diff) | |
download | gdb-a9921622de0a7332a333c5206ce8cd632803df97.zip gdb-a9921622de0a7332a333c5206ce8cd632803df97.tar.gz gdb-a9921622de0a7332a333c5206ce8cd632803df97.tar.bz2 |
Replace clear_hook_in_cleanup with scoped_restore_hook_in
This removes clear_hook_in_cleanup in favor of a scoped_restore-like
class. scoped_restore itself can't be used because hook_in is a
bitfield.
ChangeLog
2017-09-11 Tom Tromey <tom@tromey.com>
* cli/cli-script.c (class scoped_restore_hook_in): New.
(clear_hook_in_cleanup): Remove.
(execute_cmd_pre_hook, execute_cmd_post_hook): Use
scoped_restore_hook_in.
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/cli/cli-script.c | 31 |
2 files changed, 28 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 00fbd0b..a0dfb78 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2017-09-11 Tom Tromey <tom@tromey.com> + * cli/cli-script.c (class scoped_restore_hook_in): New. + (clear_hook_in_cleanup): Remove. + (execute_cmd_pre_hook, execute_cmd_post_hook): Use + scoped_restore_hook_in. + +2017-09-11 Tom Tromey <tom@tromey.com> + * cli/cli-script.c (restore_interp): Remove. (read_command_lines): Use scoped_restore_interp. * interps.c (scoped_restore_interp::set_temp): Rename from diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index dc3e856..37466fd 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -340,23 +340,36 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd, /* Handle pre-post hooks. */ -static void -clear_hook_in_cleanup (void *data) +class scoped_restore_hook_in { - struct cmd_list_element *c = (struct cmd_list_element *) data; +public: - c->hook_in = 0; /* Allow hook to work again once it is complete. */ -} + scoped_restore_hook_in (struct cmd_list_element *c) + : m_cmd (c) + { + } + + ~scoped_restore_hook_in () + { + m_cmd->hook_in = 0; + } + + scoped_restore_hook_in (const scoped_restore_hook_in &) = delete; + scoped_restore_hook_in &operator= (const scoped_restore_hook_in &) = delete; + +private: + + struct cmd_list_element *m_cmd; +}; void execute_cmd_pre_hook (struct cmd_list_element *c) { if ((c->hook_pre) && (!c->hook_in)) { - struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c); + scoped_restore_hook_in restore_hook (c); c->hook_in = 1; /* Prevent recursive hooking. */ execute_user_command (c->hook_pre, (char *) 0); - do_cleanups (cleanups); } } @@ -365,11 +378,9 @@ execute_cmd_post_hook (struct cmd_list_element *c) { if ((c->hook_post) && (!c->hook_in)) { - struct cleanup *cleanups = make_cleanup (clear_hook_in_cleanup, c); - + scoped_restore_hook_in restore_hook (c); c->hook_in = 1; /* Prevent recursive hooking. */ execute_user_command (c->hook_post, (char *) 0); - do_cleanups (cleanups); } } |