From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8127 invoked by alias); 28 Oct 2014 13:18:22 -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 8116 invoked by uid 89); 28 Oct 2014 13:18:22 -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,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f43.google.com Received: from mail-wg0-f43.google.com (HELO mail-wg0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 28 Oct 2014 13:18:20 +0000 Received: by mail-wg0-f43.google.com with SMTP id n12so805374wgh.26 for ; Tue, 28 Oct 2014 06:18:17 -0700 (PDT) X-Received: by 10.194.189.239 with SMTP id gl15mr4248416wjc.8.1414502297007; Tue, 28 Oct 2014 06:18:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.163.34 with HTTP; Tue, 28 Oct 2014 06:17:56 -0700 (PDT) In-Reply-To: References: From: nojhan Date: Tue, 28 Oct 2014 13:18:00 -0000 Message-ID: Subject: Re: Define python hooks To: gdb Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00101.txt.bz2 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. Additionally, I did not find how to access the arguments of the command. 2) Overload the existing command with a python class binded on the same command name. Failed because of infinite recursion. 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. Should I fill a feature request/bug report for points 1 and/or 2? -- nojhan On Tue, Oct 28, 2014 at 12:22 AM, Doug Evans wrote: > gdb.execute (command, to_string=True) will return the output as a python string. > > As for what's the best way to go, I'm not sure. > > On Mon, Oct 27, 2014 at 2:17 AM, nojhan wrote: >> Thanks. >> I would want to manipulate the output of several existing commands with python. >> >> Is there a way to get the output of the command in python (something >> like a gdb.execute that would return the output)? >> Or should I use a redirection to a named pipe to communicate with gdb? >> Or maybe it would be a better option to overload existing commands >> with a python class that would execute them? >> >> -- >> nojhan >> >> On Sun, Oct 26, 2014 at 12:57 AM, Doug Evans wrote: >>> On Sat, Oct 25, 2014 at 2:08 AM, nojhan wrote: >>>> Hello, >>>> >>>> I'm currently using several of hook-* and hookpost-* functions with >>>> shell commands. >>>> I was wondering if there was a way to define such hooks in pure python. >>>> >>>> For instance, I would like to import a module at startup and use it >>>> across all the hooks to manipulate the output of the hooked commands. >>> >>> Hi. >>> >>> While one can't directly define hooks in python, one can still invoke >>> python from hooks. >>> >>> E.g. >>> >>> define hookpost-step >>> python >>> ... python code ... >>> end >>> end