On Sun, 8 May 2022 at 15:09, Paul Smith <paul@xxxxxxxxxxxxxxxxx> wrote: > > On Sun, 2022-05-08 at 09:16 +0100, Jonathan Wakely wrote: > > > > xmethods don't help me (IIUC) because I'm in the middle of some > > > > Python function and the value I want to retrieve is in a Python > > > > variable, not in a GDB variable, so I can't easily access it with > > > > parse_and_eval(). > > > > > > gdb.set_convenience_variable('mgr', val['mgr']) > > > init = gdb.parse_and_eval('$mgr->initialized') > > > > > > This will use the xmethod to evaluate the expression. > > > > And then: > > > > if init: > > return gdb.parse_and_eval('*$mgr') > > Yes... this is why I qualified my statement with "easily" :). > > Also if I'm doing this as I search through a 700,000 element container, > which is already not super-speedy, the performance is likely not going > to be great. > > I imagine the cleanest solution is to have a Python API for STL that > works with and returns gdb.Values, then have the pretty-printers call > that API and format the result. Then others can use that API as well. > > I get that the current suite of Python functions are geared > specifically towards using STL objects directly from the GDB UI: both > pretty-printing and accessing them. As someone who's writing my own > Python functions for a complex C++ program, however, an API as above > would be more helpful; we have lots of methods that grovel through > complex structures looking for specific elements, etc. Then you are the perfect person to scratch this itch :-) > > And, I understand the answer "patches welcome" :). I'm just putting > this out there for people to consider.