I have following 2 functions defined in a library:
void print_root(topo *root){
int i;
for (i=0; i<10; i++) {
print_topo_arr(i,root);
}
}
int add(int x, int y)
{
return (x+y);
}
我可以从 gdb 的 Python 脚本调用 add() 而不会出现任何问题。但是,我在打电话时得到
Python Exception <class 'ctypes.ArgumentError'> argument 1: <type 'exceptions.TypeError'>: wrong type:
lib = cdll.LoadLibrary('./libshow.so')
try1 = gdb.parse_and_eval ("i")
print(type(try1)) # output is: <type 'gdb.Value'>
print(try1.type.code) # output is: 8 TYPE_CODE_INT
print('NEW Val of i={0}'.format(try1))
lib.add.argtypes = [c_int, c_int]
print lib.add(try1, 4) # works without issues
#try to get root and call print_root()
root_py = gdb.parse_and_eval ("root")
print(type(root_py)) # output is: <type 'gdb.Value'>
print(root_py.type.code) # output is: 14 TYPE_CODE_PTR
lib.print_root.argtypes = [c_void_p]
print lib.print_root(root_py) # wrong type error here
如何print_root
使用 gdb 变量调用root
?
根存在于 gdb 中:
(gdb) p root
$1 = (topo *) 0x7fffffffd620