1

I'm trying to find a way to get a list of members of a c++ class object from the python api in GDB.

So far, the only solution I've been able to find has been to use the ptype <value> and then try to parse it for the members, and I was wondering if there's a better way that I haven't been able to find.

anirudh
  • 4,116
  • 2
  • 20
  • 35
  • Member variables or functions? Member variables can be listed with [Type.fields()](https://sourceware.org/gdb/current/onlinedocs/gdb/Types-In-Python.html#index-Type_002efields). – ssbssa Aug 16 '21 at 10:32
  • I was actually thinking of both, but right now my interest is in checking the member functions. – anirudh Aug 16 '21 at 12:20

1 Answers1

0

if you have a value called my_name you can get the member variables by

val = gdb.parse_and_eval('my_name') #converts it to a gdb value 

for field in val.type.fields():
        return field.name, val[field.name]
# this gives you the member name and the gdb value.

more information on gdb.Types here

If it is member functions i am not sure how to get that

Ezike Ebuka
  • 137
  • 2
  • 8