From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32345 invoked by alias); 3 Jun 2010 00:11:38 -0000 Received: (qmail 32308 invoked by uid 22791); 3 Jun 2010 00:11:28 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 Jun 2010 00:11:23 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D75102BAC61; Wed, 2 Jun 2010 20:11:20 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id s75PJpPgLN+0; Wed, 2 Jun 2010 20:11:20 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id A56ED2BAC60; Wed, 2 Jun 2010 20:11:20 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id B85B9F58FA; Wed, 2 Jun 2010 17:11:15 -0700 (PDT) Date: Thu, 03 Jun 2010 00:11:00 -0000 From: Joel Brobecker To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA/python:2/2] First script in GDB python library - command/pahole.py Message-ID: <20100603001115.GJ3019@adacore.com> References: <1274918921-23200-1-git-send-email-brobecker@adacore.com> <1274918921-23200-3-git-send-email-brobecker@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) 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 X-SW-Source: 2010-06/txt/msg00092.txt.bz2 > There is no sensible way for a user to activate such a command. With > this patch a user would have to know the name of the command's file and > invoke "python import gdb.command.pahole". [...] > One idea would be to allow some kind of auto-loading when a command is > not found. That is, load pahole.py the first time the "pahole" command > is used. Or even better, scan the install tree first so that command > completion still works. (This is not ideal, though, since there is not > actually a way to discover command names without loading the file.) Here is an approach that should work. The idea is to rely on the convention that the command name is the name of the python script. Subcommands are stored inside subdirectories. For instance, let's imagine that we're trying to execute the following command: (gdb) prefix1 prefix2 pycommand arg1 arg2 What I propose we do is that, if a python script provides an implementation of command "prefix1 prefix2 pycommand", then it should be stored in GDB_PYTHON_DIR/command/prefix1/prefix2/pycommand.py (Doug asked whether we wanted the .py extension or not; either of us don't seem to have a strong opinion on it, although I do like it, and most editors will likely also appreciate having it to automatically activate the python edit mode). pycommand.py is a python *script* (it is not expected to be a module file) which will be executed when the "prefix1 prefix2 pycommand" command is actually used. I am not sure that we should search for Python commands only after we failed to find a command. I'm thinking of the various prefix commands that we already have such as the set command. The current semantics of the "set" command is that it treats the arguments as an expression if no subcommand was found. So if we looked at python commands only after we failed to find a regular command, then it would not allow us to add a set subcommand, at least not automatically. That's why I suggest we scan the GDB_PYTHON_DIR/command directory for all scripts, and create stub commands - the commands exist, but their implementation is only loaded on-demand. The loading would be performed using the execfile command (or its C equivalent if there is one). WDYT? (note that having the stub command should also allow us to have command completion) -- Joel