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