From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56859 invoked by alias); 2 Dec 2015 18:24:32 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 56839 invoked by uid 89); 2 Dec 2015 18:24:32 -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-f49.google.com Received: from mail-wm0-f49.google.com (HELO mail-wm0-f49.google.com) (74.125.82.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 02 Dec 2015 18:24:31 +0000 Received: by wmww144 with SMTP id w144so226690458wmw.1 for ; Wed, 02 Dec 2015 10:24:28 -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:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=9cLZ39xaky5FK++W2KqnizMQ/zbMZkLe9AObO/zXwM8=; b=azpVQTOYY2HNTjHUrOzRQqpYgiCbOuhSeTTmMLR7gca8CV+sx+esRt+7wP1O9tQUj9 GcH91kER29qtePWKkftqQ3rMl1Bq5m3EXKndaA0zKRybjxCBtZDXjpL7zYGHU3iBxkqb sm5T9exJgsopqvfkH8rnf5tFhjAZaKYgdvBPGt9Z2i4aOyPwWLiHcbzHI5LbK6RElR5h XsaG0vpSBVg23p3YhCOQs+zSWJIJKmCYOpcmxcuFmpnj9zwGbGsAzN8LEk6F9yPPHMu4 7y34gcqQ+TBGSs1pb8TPBQT60pdNW9fepx2NSl7jtYftJBT57qkOis+4Sj5zU572XpIp dCiw== X-Gm-Message-State: ALoCoQlLm6pSGIfGOWI0z0D9J/JEqctvLNM8oKkl//pAUOI6vItPwkxg6Aaa3mbUhFG0wlkuWw8E MIME-Version: 1.0 X-Received: by 10.28.8.15 with SMTP id 15mr47452661wmi.50.1449080667954; Wed, 02 Dec 2015 10:24:27 -0800 (PST) Received: by 10.28.25.4 with HTTP; Wed, 2 Dec 2015 10:24:27 -0800 (PST) In-Reply-To: References: Date: Wed, 02 Dec 2015 18:24:00 -0000 Message-ID: Subject: Re: Always run GDB command post-hook after pre-hook has been run From: Stephen Cross To: gdb-patches@sourceware.org Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-12/txt/msg00037.txt.bz2 I was wondering if anyone has had a chance to look at this patch? (I've also CC'ed the gdb list since I'm looking for input on the approach.) Thanks, Stephen On Mon, Nov 30, 2015 at 6:17 PM, Stephen Cross wrote: > 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 -- Stephen Cross Software Engineer at Undo Software