* Re: Python API: can I make new prefix Parameters? [not found] ` <CAOcbMd3sqfrJogM4jd3=vtvYbZM-QkWCJ8W5inUuJ15ow9sOJQ@mail.gmail.com> @ 2015-07-23 14:26 ` Evan Driscoll 2015-07-23 15:55 ` Armando Miraglia 0 siblings, 1 reply; 5+ messages in thread From: Evan Driscoll @ 2015-07-23 14:26 UTC (permalink / raw) To: Armando Miraglia; +Cc: gdb On Thu, Jul 23, 2015 at 6:03 AM, Armando Miraglia <arma2ff0@gmail.com> 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". Here's that Parameter: class TestParameter(gdb.Parameter): """The Parameter""" def __init__(self): super(TestParameter, self).__init__( "history test-param", gdb.COMMAND_DATA, gdb.PARAM_ENUM, ["one", "two", "three"]) self.value = "one" self.set_doc = "Test doc (set)" self.show_doc = "Test doc (show)" param = TestParameter() Evan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Python API: can I make new prefix Parameters? 2015-07-23 14:26 ` Python API: can I make new prefix Parameters? Evan Driscoll @ 2015-07-23 15:55 ` Armando Miraglia 2015-07-23 16:09 ` Evan Driscoll 0 siblings, 1 reply; 5+ messages in thread From: Armando Miraglia @ 2015-07-23 15:55 UTC (permalink / raw) To: Evan Driscoll; +Cc: gdb 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 <evaned@gmail.com> wrote: > On Thu, Jul 23, 2015 at 6:03 AM, Armando Miraglia <arma2ff0@gmail.com> 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Python API: can I make new prefix Parameters? 2015-07-23 15:55 ` Armando Miraglia @ 2015-07-23 16:09 ` Evan Driscoll 2015-07-23 16:17 ` Evan Driscoll 0 siblings, 1 reply; 5+ messages in thread From: Evan Driscoll @ 2015-07-23 16:09 UTC (permalink / raw) To: Armando Miraglia; +Cc: gdb On Thu, Jul 23, 2015 at 10:55 AM, Armando Miraglia <arma2ff0@gmail.com> 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Python API: can I make new prefix Parameters? 2015-07-23 16:09 ` Evan Driscoll @ 2015-07-23 16:17 ` Evan Driscoll [not found] ` <CAOcbMd1ULBBHSsM-b2HEuZhfZFSu95mjSRvEhyMwtaU9Y2DEgg@mail.gmail.com> 0 siblings, 1 reply; 5+ messages in thread From: Evan Driscoll @ 2015-07-23 16:17 UTC (permalink / raw) To: Armando Miraglia; +Cc: gdb On Thu, Jul 23, 2015 at 11:09 AM, Evan Driscoll <evaned@gmail.com> wrote: > 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 This is still true, by the way, if I fix 'test-category' by changing it to 'my-category' in TestParameter.__init__. (That mostly just showed up during my double check and transcription to the email.) Evan ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <CAOcbMd1ULBBHSsM-b2HEuZhfZFSu95mjSRvEhyMwtaU9Y2DEgg@mail.gmail.com>]
* Re: Python API: can I make new prefix Parameters? [not found] ` <CAOcbMd1ULBBHSsM-b2HEuZhfZFSu95mjSRvEhyMwtaU9Y2DEgg@mail.gmail.com> @ 2015-07-23 17:55 ` Evan Driscoll 0 siblings, 0 replies; 5+ messages in thread From: Evan Driscoll @ 2015-07-23 17:55 UTC (permalink / raw) To: Armando Miraglia; +Cc: gdb On Thu, Jul 23, 2015 at 11:22 AM, Armando Miraglia <arma2ff0@gmail.com> wrote: > Fixing what you just said, namely renaming "test-category" to "my-category" > it worked for me: Oh shoot, I see that now too. I was messing with some other stuff and didn't completely put it back. I guess I *didn't* try exactly that permuation before, or made some other similar error. I think that this might suggest a documentation improvement; if people are open to the idea, I can write up a proposed change later. Anyway, thanks for your help! Evan ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-07-23 17:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CAAR9PsX2CMoAF7PThZd3R-FSsUtu-UQMQ1Rr-1yfasb7w==JnQ@mail.gmail.com>
[not found] ` <CAOcbMd3sqfrJogM4jd3=vtvYbZM-QkWCJ8W5inUuJ15ow9sOJQ@mail.gmail.com>
2015-07-23 14:26 ` Python API: can I make new prefix Parameters? Evan Driscoll
2015-07-23 15:55 ` Armando Miraglia
2015-07-23 16:09 ` Evan Driscoll
2015-07-23 16:17 ` Evan Driscoll
[not found] ` <CAOcbMd1ULBBHSsM-b2HEuZhfZFSu95mjSRvEhyMwtaU9Y2DEgg@mail.gmail.com>
2015-07-23 17:55 ` Evan Driscoll
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox