1

How do I look up overloaded methods in GDB using the python interface?

I have a class which has several methods called 'el', one of which takes two ints. GDB is stopped at a breakpoint, with a member variable called _Dr in scope in the inferior process. I do this to get a Python gdb.Value object representing _Dr:

(gdb) python _Dr = gdb.parse_and_eval('_Dr')

Now I want to get the el(int,int) method:

(gdb) python el = _Dr['el']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.error: cannot resolve overloaded method `el': no arguments supplied
Error while executing Python code.

How do I tell it the types of the arguments to resolve the overload?

I've tried this:

(gdb) python el = _Dr['el(int,int)']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.error: There is no member or method named el(int,int).
Error while executing Python code.

and this:

(gdb) python el = _Dr['el', 'int', 'int']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: Could not convert Python object: ('el', 'int', 'int').
Error while executing Python code.

and this:

(gdb) python el = _Dr['el(1,1)']
Traceback (most recent call last):
  File "<string>", line 1, in <module>
gdb.error: There is no member or method named el(1,1).
Error while executing Python code.

What's the right way of doing this?

Tom
  • 7,269
  • 1
  • 42
  • 69

1 Answers1

1

The best way to do this is to iterate over the fields of the type, looking for the one you want.

Something like:

for field in _Dr.type.fields():
  if field.name == 'el':
    ... check field.type here ...

See the node "Types in Python" in the gdb manual for more details.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
  • Yes, although the method is on a base class, so I guess I'll also have to search down through the inheritance tree. – Tom Feb 26 '15 at 15:50