Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Stephen Cross <scross@undo-software.com>
To: gdb-patches@sourceware.org
Subject: Always run GDB command post-hook after pre-hook has been run
Date: Mon, 30 Nov 2015 18:17:00 -0000	[thread overview]
Message-ID: <CA+gYvweEDqcaBAa_v189usDPtcFxCZ13UjMC5DFZBev3aNy6dg@mail.gmail.com> (raw)

Hello,

We've observed that a command post-hook isn't run if an exception is
thrown (inside GDB) when running the command. Here's a trace of this:

(gdb) define hook-print
>echo hook-print\n
>end
(gdb) define hookpost-print
>echo hookpost-print\n
>end
(gdb) print test
hook-print
No symbol table is loaded.  Use the "file" command.
(gdb) print "test"
hook-print
$1 = "test"
hookpost-print

This issue can be fixed by adding a cleanup action for the post-hook
call via the patch below. With this change we get the following trace:

(gdb) define hook-print
>echo hook-print\n
>end
(gdb) define hookpost-print
>echo hookpost-print\n
>end
(gdb) print test
hook-print
hookpost-print
No symbol table is loaded.  Use the "file" command.
(gdb) print "test"
hook-print
$1 = "test"
hookpost-print

As you can see the post-hook is now always being called, even if the
command fails.

diff --git a/gdb/top.c b/gdb/top.c
index d1e2271..43b3b7f 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -388,13 +388,19 @@ maybe_wait_sync_command_done (int was_sync)
     wait_sync_command_done ();
 }

+static void
+call_post_hook_cleanup(void* p)
+{
+    execute_cmd_post_hook (p);
+}
+
 /* Execute the line P as a command, in the current user context.
    Pass FROM_TTY as second argument to the defining function.  */

 void
 execute_command (char *p, int from_tty)
 {
-  struct cleanup *cleanup_if_error, *cleanup;
+  struct cleanup *cleanup_if_error, *cleanup, *cmd_cleanup;
   struct cmd_list_element *c;
   char *line;

@@ -456,6 +462,7 @@ execute_command (char *p, int from_tty)

       /* If this command has been pre-hooked, run the hook first.  */
       execute_cmd_pre_hook (c);
+      cmd_cleanup = make_cleanup (call_post_hook_cleanup, c);

       if (c->deprecated_warn_user)
        deprecated_cmd_warning (line);
@@ -477,7 +484,7 @@ execute_command (char *p, int from_tty)
       maybe_wait_sync_command_done (was_sync);

       /* If this command has been post-hooked, run the hook last.  */
-      execute_cmd_post_hook (c);
+      do_cleanups (cmd_cleanup);

     }

I've run the test suite before and after this change and I can't see
any relevant failures. Presumably the patch will also need to include
a test, but I'm hoping to just get comments on the implementation
change first.

Thanks,
Stephen

-- 
Stephen Cross

Software Engineer at Undo Software


             reply	other threads:[~2015-11-30 18:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-30 18:17 Stephen Cross [this message]
2015-12-02 18:24 ` Stephen Cross
2015-12-03 11:54   ` Pedro Alves
2015-12-03 16:11     ` Stephen Cross
2015-12-09 17:03       ` Pedro Alves
2016-01-13 15:21         ` Stephen Cross
2016-02-24 14:46           ` Stephen Cross
2016-02-24 18:01             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+gYvweEDqcaBAa_v189usDPtcFxCZ13UjMC5DFZBev3aNy6dg@mail.gmail.com \
    --to=scross@undo-software.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox