From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6230 invoked by alias); 7 Dec 2014 19:59:15 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 6219 invoked by uid 89); 7 Dec 2014 19:59:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f179.google.com Received: from mail-wi0-f179.google.com (HELO mail-wi0-f179.google.com) (209.85.212.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 07 Dec 2014 19:59:12 +0000 Received: by mail-wi0-f179.google.com with SMTP id ex7so3024443wid.12 for ; Sun, 07 Dec 2014 11:59:09 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.180.90.16 with SMTP id bs16mr11050820wib.4.1417982349783; Sun, 07 Dec 2014 11:59:09 -0800 (PST) Received: by 10.27.132.70 with HTTP; Sun, 7 Dec 2014 11:59:09 -0800 (PST) In-Reply-To: References: Date: Sun, 07 Dec 2014 19:59:00 -0000 Message-ID: Subject: Re: Define python hooks From: Doug Evans To: nojhan Cc: gdb Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-12/txt/msg00008.txt.bz2 On Wed, Nov 5, 2014 at 8:50 AM, nojhan wrote: > Here are the three complete examples, I hope this will be more clear. > > Or in a gist: > https://gist.github.com/nojhan/c3bc28e2fa0608f21551 Hi. I looked at examples 1 and 2. Re: #1: The command is executed twice, as expected, but the hook isn't executed twice, also as expected Re: #2: We currently don't provide a way to access the "previous" version of a command if it is overridden. That would be a good enhancement alright. I didn't have time to look at #3. > On Wed, Oct 29, 2014 at 7:39 PM, Doug Evans wrote: >> On Tue, Oct 28, 2014 at 6:17 AM, nojhan wrote: >>> The documentation states that "It is valid for a hook to call the >>> command which it hooks. If this occurs, the hook is not re-executed, >>> thereby avoiding infinite recursion." >>> But this does not seems to be true for the python API. >>> >>> Here what I tried: >>> 1) Defining the hook as a python function that would gdb.execute the >>> same command. Failed, because then the command is executed twice. >> >> You mean the hook is executed twice, right? >> The docs say the hook won't be executed twice, but executing the >> command twice is ok. >> >> I tried a trivial example and couldn't reproduce symptoms of the hook >> being executed twice. >> This is with current sources and 7.8 (release and branch). >> >> (gdb) define foo >> echo Hi there.\n >> end >> (gdb) define hookpost-foo >> echo Me again.\n >> python gdb.execute("foo") >> end >> (gdb) foo >> Hi there. >> Me again. >> Hi there. >> (gdb) >> >>> Additionally, I did not find how to access the arguments of the >>> command. >> >> I'm not sure what you mean here. >> Access the arguments of the command from the hook? >> I don't think we support that. >> >>> 2) Overload the existing command with a python class binded on the >>> same command name. Failed because of infinite recursion. >> >> Infinite recursion because command -> hook -> command -> hook -> ... >> or something else? >> Just trying to understand if and how this is different from (1). >> >> If it's easy, providing an example so that we can see it for ourselves >> will help. >> >>> 3) Use a named pipe to communicate. Failed (sort of) because one >>> should sleep a variable amount of time waiting for the pipe to be >>> consumed before returning to the prompt. >> >> I don't understand how this relates to (1) and (2). >> Communicate what between whom?