From 5913bcb0f6f0e0b63bdbb528cadd0de6887bf7a6 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Sun, 17 Mar 2002 19:53:39 +0000 Subject: * command.h: (execute_cmd_post_hook): Declare. (execute_cmd_pre_hook): Declare. * cli/cli-script.c (clear_hook_in_cleanup): New function. (execute_cmd_post_hook, execute_cmd_pre_hook): New functions. Execute pre/post hook while ensuring that afterwords hook_in is cleared. * top.c (execute_command): Use execute_cmd_post_hook, and execute_cmd_pre_hook to execute pre/post commands. * infrun.c (normal_stop): Pass stop_command and not pre_hook to hook_stop_stub. (hook_stop_stub): Call execute_cmd_pre_hook. --- gdb/cli/cli-script.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'gdb/cli') diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 4545117..b438fef 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -213,6 +213,39 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd, } /* while (list) */ } +/* Handle pre-post hooks. */ + +void +clear_hook_in_cleanup (void *data) +{ + struct cmd_list_element *c = data; + c->hook_in = 0; /* Allow hook to work again once it is complete */ +} + +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); + c->hook_in = 1; /* Prevent recursive hooking */ + execute_user_command (c->hook_pre, (char *) 0); + do_cleanups (cleanups); + } +} + +void +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); + c->hook_in = 1; /* Prevent recursive hooking */ + execute_user_command (c->hook_post, (char *) 0); + do_cleanups (cleanups); + } +} + /* Execute the command in CMD. */ void -- cgit v1.1