* How to implement a new Python command that takes values from tty?
@ 2017-10-03 22:42 Yifei Zheng
2017-10-04 21:19 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Yifei Zheng @ 2017-10-03 22:42 UTC (permalink / raw)
To: gdb
Hi there,
I have written a few gdb pretty-printers using Python but this time I'm
trying to write a new command in Python. I want it to take arguments
from gdb and somewhat works like gdb's print. (It's a special printer
for some kind of std::vector).
I know I should start by inheriting `gdb.Command` and call `__init__`,
but I'm definitely stuck on `invoke`. The arguments passed in are in
string, which, I would like to convert them to gdb.Value, by looking
them up somehow. I have a partially working version that uses
"gdb.lookup_symbol", but it does not work for expressions (of course,
expected).
For example, say the command was called `ppack` which accepts an
argument just as native `print` do. Desired syntax would be like "pprint
some_var" or "pprint some_other_var.field1" or "pprint *some_ptr".
How can I let gdb evaluates the expression for me so that I don't have
to parse it, and then give me the value instead of the name?
Thanks,
Yifei
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to implement a new Python command that takes values from tty?
2017-10-03 22:42 How to implement a new Python command that takes values from tty? Yifei Zheng
@ 2017-10-04 21:19 ` Tom Tromey
2017-10-04 21:34 ` Yifei Zheng
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2017-10-04 21:19 UTC (permalink / raw)
To: Yifei Zheng; +Cc: gdb
>>>>> "Yifei" == Yifei Zheng <zheng432@purdue.edu> writes:
Yifei> I have written a few gdb pretty-printers using Python but this time
Yifei> I'm trying to write a new command in Python. I want it to take
Yifei> arguments from gdb and somewhat works like gdb's print. (It's a
Yifei> special printer for some kind of std::vector).
I'm curious why not write a pretty-printer for this case as well?
Yifei> How can I let gdb evaluates the expression for me so that I don't have
Yifei> to parse it, and then give me the value instead of the name?
You want gdb.parse_and_eval.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to implement a new Python command that takes values from tty?
2017-10-04 21:19 ` Tom Tromey
@ 2017-10-04 21:34 ` Yifei Zheng
0 siblings, 0 replies; 3+ messages in thread
From: Yifei Zheng @ 2017-10-04 21:34 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb
Hi Tom,
Thank you for pointing me out "parse_and_eval".
I didn't write an pretty printer because it'll be a little ambiguous on
type matching.
Say the type I wanted to print is "std::vector<Var*>" (which I call a
pack) where Var is a class and has its own printer. What I wanted to do
is to dereference all pointers in the vector and pretty-print each one.
However, some of the "std::vector<Var*>"s are packs while some are not.
It's at debugger users' discretion. I don't know if that's generally a
good practice or not. Any better idea?
Yifei
On 04/10/2017 5:19 PM, Tom Tromey wrote:
>>>>>> "Yifei" == Yifei Zheng <zheng432@purdue.edu> writes:
>
> Yifei> I have written a few gdb pretty-printers using Python but this time
> Yifei> I'm trying to write a new command in Python. I want it to take
> Yifei> arguments from gdb and somewhat works like gdb's print. (It's a
> Yifei> special printer for some kind of std::vector).
>
> I'm curious why not write a pretty-printer for this case as well?
>
> Yifei> How can I let gdb evaluates the expression for me so that I don't have
> Yifei> to parse it, and then give me the value instead of the name?
>
> You want gdb.parse_and_eval.
>
> Tom
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-04 21:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-03 22:42 How to implement a new Python command that takes values from tty? Yifei Zheng
2017-10-04 21:19 ` Tom Tromey
2017-10-04 21:34 ` Yifei Zheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox