From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 92540 invoked by alias); 23 Jul 2015 16:09:29 -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 92525 invoked by uid 89); 23 Jul 2015 16:09:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS,WEIRD_QUOTING autolearn=ham version=3.3.2 X-HELO: mail-yk0-f180.google.com Received: from mail-yk0-f180.google.com (HELO mail-yk0-f180.google.com) (209.85.160.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 23 Jul 2015 16:09:26 +0000 Received: by ykdu72 with SMTP id u72so223640238ykd.2 for ; Thu, 23 Jul 2015 09:09:24 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.129.75.214 with SMTP id y205mr9548480ywa.65.1437667764415; Thu, 23 Jul 2015 09:09:24 -0700 (PDT) Received: by 10.107.154.199 with HTTP; Thu, 23 Jul 2015 09:09:24 -0700 (PDT) In-Reply-To: References: Date: Thu, 23 Jul 2015 16:09:00 -0000 Message-ID: Subject: Re: Python API: can I make new prefix Parameters? From: Evan Driscoll To: Armando Miraglia Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2015-07/txt/msg00035.txt.bz2 On Thu, Jul 23, 2015 at 10:55 AM, Armando Miraglia wrote: > To have your own type of "set history" you should do something > like this: > > class MyHistory(gdb.Command): > def __init__(self): > super(MyHistory, self).__init__("set myhistory", COMMAND_DATA) > > def invoke(self, arg, from_tty): > # use arg to extract the parameter name and check > # if it maches your TestParameter name for example, and > # act on it accordingly. In can also simply use your command > # as a proxy using parse_and_eval or execute, hence eventually > # executing "set testparam" instead of "set myhistory testparam" > pass > > I hope this was helpful. I appreciate your responses, but I feel we may be talking past each other. :-) Let's see if I can describe this better. Forgetting about Python-level Commands vs Parameters, what I want is, from the user's perspective, for 'set my-category my-setting ' and 'show my-category my-setting' to work. Now, I can achieve this in the following manner using gdb.Command: 1. Define a prefix command "set my-category" 2. Define a prefix command "show my-category" 3. Define a non-prefix command "set my-category my-setting" 4. Define a non-prefix command "show my-category my-setting" But #3 especially is a bit annoying in comparison to using gdb.Parameter, because I have to take care of a fair bit of stuff myself. For example, with a Parameter I could use gdb.PARAM_ENUM and that will automatically provide validation and completion for the set of permissible values, but I'd have to do that myself if 'set my-category my-setting ' is a gdb.Command. I also have to define twice as many Commands as I would if I could say "make a 'my-category' prefix Parameter" then "make a 'my-category my-setting'" Parameter. So I'm wondering if there's a better way to do it with gdb.Parameter. Does that make it clearer what I'm trying to do? Inspired by your previous email, I also tried the following hybrid approach: import gdb class SetPrefixCommand (gdb.Command): """Dummy""" def __init__(self): super(SetPrefixCommand, self).__init__( "set my-category", gdb.COMMAND_SUPPORT, gdb.COMPLETE_NONE, True) SetPrefixCommand() class ShowPrefixCommand (gdb.Command): """Dummy""" def __init__(self): super(ShowPrefixCommand, self).__init__( "show my-category", gdb.COMMAND_SUPPORT, gdb.COMPLETE_NONE, True) ShowPrefixCommand() class TestParameter(gdb.Parameter): """The Parameter""" def __init__(self): super(TestParameter, self).__init__( "test-category test-param", gdb.COMMAND_SUPPORT, gdb.PARAM_ENUM, ["one", "two", "three"]) self.value = "one" self.set_doc = "Test doc (set)" self.show_doc = "Test doc (show)" param = TestParameter() but that still gives the same error: (gdb) source ~/gdb/test_parameter.py Traceback (most recent call last): File "~/gdb/test_parameter.py", line 72, in File "~/gdb/test_parameter.py", line 67, in __init__ RuntimeError: Could not find command prefix test-category Evan