GDB Python解决了重载方法

时间:2015-02-26 03:56:05

标签: python c++ gdb gdb-python

如何使用python接口在GDB中查找重载方法?

我有一个类有几个名为'el'的方法,其中一个方法需要两个int s。 GDB在断点处停止,在下级进程的范围内有一个名为_Dr的成员变量。我这样做是为了获得一个代表gdb.Value的Python _Dr对象:

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

现在我想获得el(int,int)方法:

(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.

如何告诉它解决重载的参数类型?

我试过这个:

(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.

和此:

(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.

和此:

(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.

这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

执行此操作的最佳方法是迭代该类型的字段,查找所需的字段。

类似的东西:

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

有关详细信息,请参阅gdb手册中的“Python中的类型”节点。