Is there some way to "template" commands for interpolation with gdb.Values?

Matthew Malcomson hardenedapple@gmail.com
Tue Jan 28 20:41:00 GMT 2020


On Mon, 27 Jan 2020 at 14:08, Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> "Matthew" == Matthew Malcomson <hardenedapple@gmail.com> writes:
>
> Matthew> I'm currently looking at modifying my plugin to use gdb.Values
instead
> Matthew> of pointers.
> Matthew> The hope is that gdb.Values could give the plugin a
language-agnostic
> Matthew> syntax and also make it's use of existing
pretty_printer.children() methods
> Matthew> more seamless.
> ...
> Matthew> The best I've found is to set an internal variable to the
gdb.Value I
> Matthew> have and use that (so the user would write "$cur->x").
>
> That's pretty much what I would have tried.
>
> Matthew> I have a workaround where I set one variable to the address and
another
> Matthew> to the current object ( $addr, and $cur respectively ), but this
loses some
> Matthew> of the language-agnostic syntax I was keen on, since I still
require the
> Matthew> ability to access variables through their address in a gdb
expression, and
> Matthew> adds extra complexity to my plugin interface.
>
> I didn't follow this part.  Can you just use .address in your
implementation?

The main reason I started looking at using gdb.Values was that I have a
feature
which iterates over every value coming from the `.children()` method of a
pretty printer
for a given object.

This `.children()` method can return something which produces gdb.Values
that don't have an address, and I was hoping to be able to use such
values in the same way as everything else in the plugin.
(at the moment I just error out if the user tries to use such pretty
printers).


I could just use `.address` and it would make my plugin better than it
is now, but it wouldn't help with the above.
I'm not sure which I prefer between being able to use those pretty printers
or having a more coherent syntax.


The "language-agnostic syntax" reason is more hypothetical:
I don't want to require the language being debugged to allow
direct access of something using a pointer.
As far as I can tell, all the languages for which GDB can parse an
expression *do* have the ability to use a raw address (not sure about
Ada), so it's not much of an issue.

>
> Matthew> If not, would it be possible to add syntax to do something that
would
> Matthew> work in this way?
>
> Definitely, it's just a question of deciding what would be most helpful
> and then, of course, someone actually implementing it.

Great -- I'll have a look at the gdb source to see what sort of approach
could be taken, though I'll probably take my time getting around to it.

>
> A different approach would be to parse the user's input.  This is what
> Duel did.  However I suppose that is in some conflict with your goal of
> being language-agnostic.

First off:
Wow!  I'd never heard of Duel, and it looks really cool -- thanks for
mentioning it!

But ou're right -- I really don't want to start defining my own language --
the
majority of my plugin is "find some interesting values, and then pass the
command template to GDB with each value interpolated in turn" and I
very much want to keep extra syntax to a minimum.

>
> Tom



More information about the Gdb mailing list