xref: /llvm-project/lldb/bindings/interface/SBBlockExtensions.i (revision 380c5da98efa62920e9fbf3aa9a4fa8add236fb9)
1*662548c8SAlex Langford STRING_EXTENSION_OUTSIDE(SBBlock)
2*662548c8SAlex Langford 
3*662548c8SAlex Langford %extend lldb::SBBlock {
4*662548c8SAlex Langford #ifdef SWIGPYTHON
5*662548c8SAlex Langford     %pythoncode %{
6*662548c8SAlex Langford         def get_range_at_index(self, idx):
7*662548c8SAlex Langford             if idx < self.GetNumRanges():
8*662548c8SAlex Langford                 return [self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)]
9*662548c8SAlex Langford             return []
10*662548c8SAlex Langford 
11*662548c8SAlex Langford         class ranges_access(object):
12*662548c8SAlex Langford             '''A helper object that will lazily hand out an array of lldb.SBAddress that represent address ranges for a block.'''
13*662548c8SAlex Langford             def __init__(self, sbblock):
14*662548c8SAlex Langford                 self.sbblock = sbblock
15*662548c8SAlex Langford 
16*662548c8SAlex Langford             def __len__(self):
17*662548c8SAlex Langford                 if self.sbblock:
18*662548c8SAlex Langford                     return int(self.sbblock.GetNumRanges())
19*662548c8SAlex Langford                 return 0
20*662548c8SAlex Langford 
21*662548c8SAlex Langford             def __getitem__(self, key):
22*662548c8SAlex Langford                 count = len(self)
23*662548c8SAlex Langford                 if type(key) is int:
24*662548c8SAlex Langford                     return self.sbblock.get_range_at_index (key);
25*662548c8SAlex Langford                 if isinstance(key, SBAddress):
26*662548c8SAlex Langford                     range_idx = self.sbblock.GetRangeIndexForBlockAddress(key);
27*662548c8SAlex Langford                     if range_idx < len(self):
28*662548c8SAlex Langford                         return [self.sbblock.GetRangeStartAddress(range_idx), self.sbblock.GetRangeEndAddress(range_idx)]
29*662548c8SAlex Langford                 else:
30*662548c8SAlex Langford                     print("error: unsupported item type: %s" % type(key))
31*662548c8SAlex Langford                 return None
32*662548c8SAlex Langford 
33*662548c8SAlex Langford         def get_ranges_access_object(self):
34*662548c8SAlex Langford             '''An accessor function that returns a ranges_access() object which allows lazy block address ranges access.'''
35*662548c8SAlex Langford             return self.ranges_access (self)
36*662548c8SAlex Langford 
37*662548c8SAlex Langford         def get_ranges_array(self):
38*662548c8SAlex Langford             '''An accessor function that returns an array object that contains all ranges in this block object.'''
39*662548c8SAlex Langford             if not hasattr(self, 'ranges_array'):
40*662548c8SAlex Langford                 self.ranges_array = []
41*662548c8SAlex Langford                 for idx in range(self.num_ranges):
42*662548c8SAlex Langford                     self.ranges_array.append ([self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)])
43*662548c8SAlex Langford             return self.ranges_array
44*662548c8SAlex Langford 
45*662548c8SAlex Langford         def get_call_site(self):
46*662548c8SAlex Langford             return declaration(self.GetInlinedCallSiteFile(), self.GetInlinedCallSiteLine(), self.GetInlinedCallSiteColumn())
47*662548c8SAlex Langford 
48*662548c8SAlex Langford         parent = property(GetParent, None, doc='''A read only property that returns the same result as GetParent().''')
49*662548c8SAlex Langford         first_child = property(GetFirstChild, None, doc='''A read only property that returns the same result as GetFirstChild().''')
50*662548c8SAlex Langford         call_site = property(get_call_site, None, doc='''A read only property that returns a lldb.declaration object that contains the inlined call site file, line and column.''')
51*662548c8SAlex Langford         sibling = property(GetSibling, None, doc='''A read only property that returns the same result as GetSibling().''')
52*662548c8SAlex Langford         name = property(GetInlinedName, None, doc='''A read only property that returns the same result as GetInlinedName().''')
53*662548c8SAlex Langford         inlined_block = property(GetContainingInlinedBlock, None, doc='''A read only property that returns the same result as GetContainingInlinedBlock().''')
54*662548c8SAlex Langford         range = property(get_ranges_access_object, None, doc='''A read only property that allows item access to the address ranges for a block by integer (range = block.range[0]) and by lldb.SBAddress (find the range that contains the specified lldb.SBAddress like "pc_range = lldb.frame.block.range[frame.addr]").''')
55*662548c8SAlex Langford         ranges = property(get_ranges_array, None, doc='''A read only property that returns a list() object that contains all of the address ranges for the block.''')
56*662548c8SAlex Langford         num_ranges = property(GetNumRanges, None, doc='''A read only property that returns the same result as GetNumRanges().''')
57*662548c8SAlex Langford     %}
58*662548c8SAlex Langford #endif
59*662548c8SAlex Langford }
60