From: Evan Driscoll <evaned@gmail.com>
To: Armando Miraglia <arma2ff0@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: Python API: can I make new prefix Parameters?
Date: Thu, 23 Jul 2015 16:09:00 -0000 [thread overview]
Message-ID: <CAAR9PsVTMyN3Vo7y-_LaS7VBiaXNF48KidfG6j7H26+O7CtK+g@mail.gmail.com> (raw)
In-Reply-To: <CAOcbMd3t1xcXjHEM9qQvHkYmHDox5Uj_7VMEO0t1cXjdOzWxKQ@mail.gmail.com>
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
next prev parent reply other threads:[~2015-07-23 16:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAAR9PsX2CMoAF7PThZd3R-FSsUtu-UQMQ1Rr-1yfasb7w==JnQ@mail.gmail.com>
[not found] ` <CAOcbMd3sqfrJogM4jd3=vtvYbZM-QkWCJ8W5inUuJ15ow9sOJQ@mail.gmail.com>
2015-07-23 14:26 ` Evan Driscoll
2015-07-23 15:55 ` Armando Miraglia
2015-07-23 16:09 ` Evan Driscoll [this message]
2015-07-23 16:17 ` Evan Driscoll
[not found] ` <CAOcbMd1ULBBHSsM-b2HEuZhfZFSu95mjSRvEhyMwtaU9Y2DEgg@mail.gmail.com>
2015-07-23 17:55 ` Evan Driscoll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAR9PsVTMyN3Vo7y-_LaS7VBiaXNF48KidfG6j7H26+O7CtK+g@mail.gmail.com \
--to=evaned@gmail.com \
--cc=arma2ff0@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox