From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15900 invoked by alias); 29 Oct 2014 18:39:28 -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 15889 invoked by uid 89); 29 Oct 2014 18:39:27 -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-yh0-f44.google.com Received: from mail-yh0-f44.google.com (HELO mail-yh0-f44.google.com) (209.85.213.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 29 Oct 2014 18:39:21 +0000 Received: by mail-yh0-f44.google.com with SMTP id f10so862875yha.31 for ; Wed, 29 Oct 2014 11:39:20 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.236.66.103 with SMTP id g67mr3246745yhd.61.1414607959852; Wed, 29 Oct 2014 11:39:19 -0700 (PDT) Received: by 10.170.140.214 with HTTP; Wed, 29 Oct 2014 11:39:19 -0700 (PDT) In-Reply-To: References: Date: Wed, 29 Oct 2014 18:39: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-10/txt/msg00121.txt.bz2 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?