Re: Python API: can I make new prefix Parameters?
Evan Driscoll <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <CAAR9PsVTMyN3Vo7y-_LaS7VBiaXNF48KidfG6j7H26+O7CtK+g@mail.gmail.com> |
On Thu, Jul 23, 2015 at 10:55 AM, Armando Miraglia <[email protected]> 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 <arg>' 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 <arg>' 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 <module> File "~/gdb/test_parameter.py", line 67, in __init__ RuntimeError: Could not find command prefix test-category Evan