* command.h: (execute_cmd_post_hook): Declare.
authorAndrew Cagney <cagney@redhat.com>
Sun, 17 Mar 2002 19:53:39 +0000 (19:53 +0000)
committerAndrew Cagney <cagney@redhat.com>
Sun, 17 Mar 2002 19:53:39 +0000 (19:53 +0000)
(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/ChangeLog
gdb/cli/cli-script.c
gdb/command.h
gdb/infrun.c
gdb/top.c

index 5332ca337294bf91a7202248899a2c3212409696..d6dc6dc9ad9025c6739cacf0d7ee5210b6b04a2f 100644 (file)
@@ -1,3 +1,17 @@
+2002-03-17  Andrew Cagney  <ac131313@redhat.com>
+
+       * 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.
+
 2002-03-17  Andrew Cagney  <ac131313@redhat.com>
 
        * kod.c (kod_set_os): Revert previous change.  Is called by ``info
index 45451175560a96a1e406cb3de340f3e2bea16efa..b438fef02df1560cc83c40acb4c9bd5396e0da33 100644 (file)
@@ -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
index bebf6eb3b13ad7783488e9c3214ed94c55466db2..58574f41428803513ac115635cd342c9ae0f2675 100644 (file)
@@ -300,6 +300,12 @@ extern void set_cmd_completer (struct cmd_list_element *cmd,
 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
                         void (*cfunc) (char *args, int from_tty));
 
+/* Execute CMD's pre/post hook.  Throw an error if the command fails.
+   If already executing this pre/post hook, or there is no pre/post
+   hook, the call is silently ignored.  */
+extern void execute_cmd_pre_hook (struct cmd_list_element *cmd);
+extern void execute_cmd_post_hook (struct cmd_list_element *cmd);
+
 extern struct cmd_list_element *lookup_cmd (char **,
                                            struct cmd_list_element *, char *,
                                            int, int);
index 6ae8f7c468b837563642da3001c6f2fbc7658b56..466305f987008798c3bce8b281045f97c1dea56f 100644 (file)
@@ -3414,13 +3414,11 @@ and/or watchpoints.\n");
 
   target_terminal_ours ();
 
-  /* Look up the hook_stop and run it if it exists.  */
-
-  if (stop_command && stop_command->hook_pre)
-    {
-      catch_errors (hook_stop_stub, stop_command->hook_pre,
-                   "Error while running hook_stop:\n", RETURN_MASK_ALL);
-    }
+  /* Look up the hook_stop and run it (CLI internally handles problem
+     of stop_command's pre-hook not existing).  */
+  if (stop_command)
+    catch_errors (hook_stop_stub, stop_command,
+                 "Error while running hook_stop:\n", RETURN_MASK_ALL);
 
   if (!target_has_stack)
     {
@@ -3521,7 +3519,7 @@ done:
 static int
 hook_stop_stub (void *cmd)
 {
-  execute_user_command ((struct cmd_list_element *) cmd, 0);
+  execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
   return (0);
 }
 \f
index 16d590fa7d86049fab80d7a365227fb7bedc0709..83c84413c26dfc1f4df2b3c0bcae27475b120ac7 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -693,12 +693,7 @@ execute_command (char *p, int from_tty)
        }
 
       /* If this command has been pre-hooked, run the hook first. */
-      if ((c->hook_pre) && (!c->hook_in))
-      {
-        c->hook_in = 1; /* Prevent recursive hooking */
-        execute_user_command (c->hook_pre, (char *) 0);
-        c->hook_in = 0; /* Allow hook to work again once it is complete */
-      }
+      execute_cmd_pre_hook (c);
 
       if (c->flags & DEPRECATED_WARN_USER)
        deprecated_cmd_warning (&line);
@@ -715,12 +710,7 @@ execute_command (char *p, int from_tty)
        (*c->func) (c, arg, from_tty & caution);
        
       /* If this command has been post-hooked, run the hook last. */
-      if ((c->hook_post) && (!c->hook_in))
-      {
-        c->hook_in = 1; /* Prevent recursive hooking */
-        execute_user_command (c->hook_post, (char *) 0);
-        c->hook_in = 0; /* allow hook to work again once it is complete */
-      }
+      execute_cmd_post_hook (c);
 
     }