-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_method.py
28 lines (21 loc) · 1013 Bytes
/
call_method.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gdb
#********************************************************************************
class CallMethod(gdb.Function):
'''Call C++ method or function and return its return value.
usage from GDB CLI:
print $call_method(obj.methodName(...))
usage from Pythone-code:
CallMethod.invoke("obj.methodName(...)")'''
def __init__(self):
super(CallMethod, self).__init__("call_method")
@classmethod
def invoke(cls, argument):
# Convenience function call_method(...) was called from GDB CLI
retval = argument # argument is already computed expr, argument is gdb.Value
if isinstance(argument, str):
# Convenience function CallMethod.invoke('...') was called from Python-code
gdb.execute(f'set $tmp_retval = {argument}')
retval = gdb.convenience_variable('tmp_retval') # retval is gdb.Value
return retval
CallMethod()
#********************************************************************************