xref: /freebsd/contrib/llvm-project/lldb/bindings/interface/SBFrameExtensions.i (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 STRING_EXTENSION_OUTSIDE(SBFrame)
2 
3 %extend lldb::SBFrame {
4 #ifdef SWIGPYTHON
5     %pythoncode %{
6         # operator== is a free function, which swig does not handle, so we inject
7         # our own equality operator here
8         def __eq__(self, other):
9             return not self.__ne__(other)
10 
11         def __int__(self):
12             return self.GetFrameID()
13 
14         def __hex__(self):
15             return self.GetPC()
16 
17         def get_all_variables(self):
18             return self.GetVariables(True,True,True,True)
19 
20         def get_parent_frame(self):
21             parent_idx = self.idx + 1
22             if parent_idx >= 0 and parent_idx < len(self.thread.frame):
23                 return self.thread.frame[parent_idx]
24             else:
25                 return SBFrame()
26 
27         def get_arguments(self):
28             return self.GetVariables(True,False,False,False)
29 
30         def get_locals(self):
31             return self.GetVariables(False,True,False,False)
32 
33         def get_statics(self):
34             return self.GetVariables(False,False,True,False)
35 
36         def var(self, var_expr_path):
37             '''Calls through to lldb.SBFrame.GetValueForVariablePath() and returns
38             a value that represents the variable expression path'''
39             return self.GetValueForVariablePath(var_expr_path)
40 
41         def get_registers_access(self):
42             class registers_access(object):
43                 '''A helper object that exposes a flattened view of registers, masking away the notion of register sets for easy scripting.'''
44                 def __init__(self, regs):
45                     self.regs = regs
46 
47                 def __iter__(self):
48                     return self.get_registers()
49 
50                 def get_registers(self):
51                     for i in range(0,len(self.regs)):
52                         rs = self.regs[i]
53                         for j in range (0,rs.num_children):
54                             reg = rs.GetChildAtIndex(j)
55                             yield reg
56 
57                 def __getitem__(self, key):
58                     if type(key) is str:
59                         for i in range(0,len(self.regs)):
60                             rs = self.regs[i]
61                             for j in range (0,rs.num_children):
62                                 reg = rs.GetChildAtIndex(j)
63                                 if reg.name == key: return reg
64                     else:
65                         return SBValue()
66 
67             return registers_access(self.registers)
68 
69         pc = property(GetPC, SetPC)
70         addr = property(GetPCAddress, None, doc='''A read only property that returns the program counter (PC) as a section offset address (lldb.SBAddress).''')
71         fp = property(GetFP, None, doc='''A read only property that returns the frame pointer (FP) as an unsigned integer.''')
72         sp = property(GetSP, None, doc='''A read only property that returns the stack pointer (SP) as an unsigned integer.''')
73         module = property(GetModule, None, doc='''A read only property that returns an lldb object that represents the module (lldb.SBModule) for this stack frame.''')
74         compile_unit = property(GetCompileUnit, None, doc='''A read only property that returns an lldb object that represents the compile unit (lldb.SBCompileUnit) for this stack frame.''')
75         function = property(GetFunction, None, doc='''A read only property that returns an lldb object that represents the function (lldb.SBFunction) for this stack frame.''')
76         symbol = property(GetSymbol, None, doc='''A read only property that returns an lldb object that represents the symbol (lldb.SBSymbol) for this stack frame.''')
77         block = property(GetBlock, None, doc='''A read only property that returns an lldb object that represents the block (lldb.SBBlock) for this stack frame.''')
78         is_inlined = property(IsInlined, None, doc='''A read only property that returns an boolean that indicates if the block frame is an inlined function.''')
79         name = property(GetFunctionName, None, doc='''A read only property that retuns the name for the function that this frame represents. Inlined stack frame might have a concrete function that differs from the name of the inlined function (a named lldb.SBBlock).''')
80         line_entry = property(GetLineEntry, None, doc='''A read only property that returns an lldb object that represents the line table entry (lldb.SBLineEntry) for this stack frame.''')
81         thread = property(GetThread, None, doc='''A read only property that returns an lldb object that represents the thread (lldb.SBThread) for this stack frame.''')
82         disassembly = property(Disassemble, None, doc='''A read only property that returns the disassembly for this stack frame as a python string.''')
83         idx = property(GetFrameID, None, doc='''A read only property that returns the zero based stack frame index.''')
84         variables = property(get_all_variables, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the variables in this stack frame.''')
85         vars = property(get_all_variables, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the variables in this stack frame.''')
86         locals = property(get_locals, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the local variables in this stack frame.''')
87         args = property(get_arguments, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the argument variables in this stack frame.''')
88         arguments = property(get_arguments, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the argument variables in this stack frame.''')
89         statics = property(get_statics, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the static variables in this stack frame.''')
90         registers = property(GetRegisters, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the CPU registers for this stack frame.''')
91         regs = property(GetRegisters, None, doc='''A read only property that returns a list() that contains a collection of lldb.SBValue objects that represent the CPU registers for this stack frame.''')
92         register = property(get_registers_access, None, doc='''A read only property that returns an helper object providing a flattened indexable view of the CPU registers for this stack frame.''')
93         reg = property(get_registers_access, None, doc='''A read only property that returns an helper object providing a flattened indexable view of the CPU registers for this stack frame''')
94         parent = property(get_parent_frame, None, doc='''A read only property that returns the parent (caller) frame of the current frame.''')
95     %}
96 #endif
97 }
98