From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74324 invoked by alias); 23 Jul 2015 15:55: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 74309 invoked by uid 89); 23 Jul 2015 15:55:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 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-f172.google.com Received: from mail-wi0-f172.google.com (HELO mail-wi0-f172.google.com) (209.85.212.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 23 Jul 2015 15:55:20 +0000 Received: by wicmv11 with SMTP id mv11so30204951wic.0 for ; Thu, 23 Jul 2015 08:55:16 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.194.58.130 with SMTP id r2mr17256063wjq.72.1437666916595; Thu, 23 Jul 2015 08:55:16 -0700 (PDT) Received: by 10.27.170.142 with HTTP; Thu, 23 Jul 2015 08:55:16 -0700 (PDT) In-Reply-To: References: Date: Thu, 23 Jul 2015 15:55:00 -0000 Message-ID: Subject: Re: Python API: can I make new prefix Parameters? From: Armando Miraglia To: Evan Driscoll Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-07/txt/msg00034.txt.bz2 Sorry, I did not reply to the list as well, hence I am writing this again. On Thu, Jul 23, 2015 at 4:26 PM, Evan Driscoll wrote: > On Thu, Jul 23, 2015 at 6:03 AM, Armando Miraglia wrote: >> Hi all, hi Evan. > > Hello; thanks for the response. I'll answer a little out of order. > >> However, I am not >> complete sure what you need to achieve. >> >> Additionally, I think parameters are meant to work with commands like "set", >> "print" & co out of the box, but if you define your own commands, you can >> associate prefix to group of commands and whatever action to the command you >> want the to perform. > > This is indeed what I want to do. I have prefix commands working (e.g. > I can make "foo bar baz on" and "foo bar baz off" work), but I figured > it would be nice for commands that are really just defining settings > to go through Parameters to get things like PARAM_ENUM checking and > registering both set/show implicitly. (I can define set and show > Commands explicitly it seems that would have the same interface to the > user as a Parameter.) > > >> I believe that the main reason for "print test-param" to work is that >> "print" is actually a command, not a parameter. > > That was probably a bad choice of prefix to use; I think that's a red > herring, because there's also a "print" category of settings (e.g. > 'set print object' or 'set print pretty'). For example, with the > Parameter below, I can do this: > > (gdb) show history test-param > Test doc (show) one > (gdb) set history test-param three > Test doc (set) > (gdb) show history test-param > Test doc (show) three > > but again, I can't figure out how to define my own equivalent to "history". Again, this is a command :) try "help show" and "help show history" and you will see that history is, in fact a command with its own subcommands (expansion, filename, save, size), and not a parameter. If you do the same with the variations of "set print" you provided above, you can see that "set print" is also a command, namely print, in this case, is a sub command of set. 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. My 2 cents :) Armando