Re: Python API: can I make new prefix Parameters?

Armando Miraglia <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CAOcbMd3t1xcXjHEM9qQvHkYmHDox5Uj_7VMEO0t1cXjdOzWxKQ@mail.gmail.com>
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 <[email protected]> wrote:
> On Thu, Jul 23, 2015 at 6:03 AM, Armando Miraglia <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.