From patchwork Mon Nov 30 18:17:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Cross X-Patchwork-Id: 9846 Received: (qmail 130472 invoked by alias); 30 Nov 2015 18:17:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 129793 invoked by uid 89); 30 Nov 2015 18:17:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 30 Nov 2015 18:17:40 +0000 Received: by wmec201 with SMTP id c201so169257502wme.0 for ; Mon, 30 Nov 2015 10:17:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=iGjoWbEuEqY0HaYbuyjyylcfo8zD5/ddKSSh6lBPBGo=; b=myfzUKGBi9CRiEAGhqjqvmBFoCZ1EUoYd0j/Fv37u3MwQbJk/f0VfC+yGgHQtS90PY rY4ZlcmFSnsy/XVTxht6G5P9LIKZMEblFEzIuyj7vMT7I1ufG79STMV9NIK/Cte4QNFm MhD8UNo/kbHu71QY786WqV/F6+yhU6nURWxc79N3J8JldxBRp57a6260QVjMMQND2pIV CfpK0qMLIAo/J8d5We7nHF3jqObOUf9GIIKWwivK9ZAM3n9ukpKUwZonecQe7/t7UpJG 6vmfTz+9OjStISGYnzQcJHkRKtX+OR59gJqGhyhdaFD0N5N12WZO5IjDXUUe8aK6LfFL l8Uw== X-Gm-Message-State: ALoCoQl9zwivHmv+MjGDnG6rGUYIKT5IdTG8Tzeq7iwrCs3Bv7HJgE3rIcaZTSITDC87ZGkxJs7l MIME-Version: 1.0 X-Received: by 10.194.2.193 with SMTP id 1mr69842447wjw.26.1448907457589; Mon, 30 Nov 2015 10:17:37 -0800 (PST) Received: by 10.28.25.4 with HTTP; Mon, 30 Nov 2015 10:17:37 -0800 (PST) Date: Mon, 30 Nov 2015 18:17:37 +0000 Message-ID: Subject: Always run GDB command post-hook after pre-hook has been run From: Stephen Cross To: gdb-patches@sourceware.org X-IsSubscribed: yes 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. 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 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); }