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

Matthew Malcomson
Fri Jan 24 14:34:00 GMT 2020


I have a plugin that requires taking the template of a command and
evaluating the result of interpolating some value into that template.(FWIW: )

An example of what it may do is if the user has written
I might replace that with
"((mystruct *)(0xff100100))->x".

I'm currently looking at modifying my plugin to use gdb.Values instead
of pointers.
The hope is that gdb.Values could give the plugin a language-agnostic
syntax and also make it's use of existing pretty_printer.children() methods
more seamless.

Unfortunately I haven't found a good way to do similar command templating
with gdb.Values.

The best I've found is to set an internal variable to the gdb.Value I
have and use that (so the user would write "$cur->x").

This means the ability to assign in the plugin is now lost (since the
`lval` type of the gdb.Value used in the command is now `lval_internalvar`
instead of that of the original value).

I have a workaround where I set one variable to the address and another
to the current object ( $addr, and $cur respectively ), but this loses some
of the language-agnostic syntax I was keen on, since I still require the
ability to access variables through their address in a gdb expression, and
adds extra complexity to my plugin interface.

I recognise that there can always be some gdb.Values whose `lval` is not
in memory and hence can never work with assignment, for these I would
just want to give an error message as is currently used when attempting
to set something that is not in memory.

Is there any way to do what I'm looking for?

If not, would it be possible to add syntax to do something that would
work in this way?


More information about the Gdb mailing list