1061da546Spatrick //===-- SWIG Interface for SBBlock ------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9061da546Spatrick namespace lldb { 10061da546Spatrick 11061da546Spatrick %feature("docstring", 12061da546Spatrick "Represents a lexical block. SBFunction contains SBBlock(s)." 13061da546Spatrick ) SBBlock; 14061da546Spatrick class SBBlock 15061da546Spatrick { 16061da546Spatrick public: 17061da546Spatrick 18061da546Spatrick SBBlock (); 19061da546Spatrick 20061da546Spatrick SBBlock (const lldb::SBBlock &rhs); 21061da546Spatrick 22061da546Spatrick ~SBBlock (); 23061da546Spatrick 24061da546Spatrick %feature("docstring", 25*be691f3bSpatrick "Is this block contained within an inlined function?" 26061da546Spatrick ) IsInlined; 27061da546Spatrick bool 28061da546Spatrick IsInlined () const; 29061da546Spatrick 30061da546Spatrick bool 31061da546Spatrick IsValid () const; 32061da546Spatrick 33061da546Spatrick explicit operator bool() const; 34061da546Spatrick 35061da546Spatrick %feature("docstring", " 36061da546Spatrick Get the function name if this block represents an inlined function; 37061da546Spatrick otherwise, return None.") GetInlinedName; 38061da546Spatrick const char * 39061da546Spatrick GetInlinedName () const; 40061da546Spatrick 41061da546Spatrick %feature("docstring", " 42061da546Spatrick Get the call site file if this block represents an inlined function; 43061da546Spatrick otherwise, return an invalid file spec.") GetInlinedCallSiteFile; 44061da546Spatrick lldb::SBFileSpec 45061da546Spatrick GetInlinedCallSiteFile () const; 46061da546Spatrick 47061da546Spatrick %feature("docstring", " 48061da546Spatrick Get the call site line if this block represents an inlined function; 49061da546Spatrick otherwise, return 0.") GetInlinedCallSiteLine; 50061da546Spatrick uint32_t 51061da546Spatrick GetInlinedCallSiteLine () const; 52061da546Spatrick 53061da546Spatrick %feature("docstring", " 54061da546Spatrick Get the call site column if this block represents an inlined function; 55061da546Spatrick otherwise, return 0.") GetInlinedCallSiteColumn; 56061da546Spatrick uint32_t 57061da546Spatrick GetInlinedCallSiteColumn () const; 58061da546Spatrick 59061da546Spatrick %feature("docstring", "Get the parent block.") GetParent; 60061da546Spatrick lldb::SBBlock 61061da546Spatrick GetParent (); 62061da546Spatrick 63061da546Spatrick %feature("docstring", "Get the inlined block that is or contains this block.") GetContainingInlinedBlock; 64061da546Spatrick lldb::SBBlock 65061da546Spatrick GetContainingInlinedBlock (); 66061da546Spatrick 67061da546Spatrick %feature("docstring", "Get the sibling block for this block.") GetSibling; 68061da546Spatrick lldb::SBBlock 69061da546Spatrick GetSibling (); 70061da546Spatrick 71061da546Spatrick %feature("docstring", "Get the first child block.") GetFirstChild; 72061da546Spatrick lldb::SBBlock 73061da546Spatrick GetFirstChild (); 74061da546Spatrick 75061da546Spatrick uint32_t 76061da546Spatrick GetNumRanges (); 77061da546Spatrick 78061da546Spatrick lldb::SBAddress 79061da546Spatrick GetRangeStartAddress (uint32_t idx); 80061da546Spatrick 81061da546Spatrick lldb::SBAddress 82061da546Spatrick GetRangeEndAddress (uint32_t idx); 83061da546Spatrick 84061da546Spatrick uint32_t 85061da546Spatrick GetRangeIndexForBlockAddress (lldb::SBAddress block_addr); 86061da546Spatrick 87061da546Spatrick bool 88061da546Spatrick GetDescription (lldb::SBStream &description); 89061da546Spatrick 90061da546Spatrick lldb::SBValueList 91061da546Spatrick GetVariables (lldb::SBFrame& frame, 92061da546Spatrick bool arguments, 93061da546Spatrick bool locals, 94061da546Spatrick bool statics, 95061da546Spatrick lldb::DynamicValueType use_dynamic); 96061da546Spatrick 97061da546Spatrick lldb::SBValueList 98061da546Spatrick GetVariables (lldb::SBTarget& target, 99061da546Spatrick bool arguments, 100061da546Spatrick bool locals, 101061da546Spatrick bool statics); 102061da546Spatrick 103061da546Spatrick STRING_EXTENSION(SBBlock) 104061da546Spatrick 105061da546Spatrick #ifdef SWIGPYTHON 106061da546Spatrick %pythoncode %{ 107061da546Spatrick def get_range_at_index(self, idx): 108061da546Spatrick if idx < self.GetNumRanges(): 109061da546Spatrick return [self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)] 110061da546Spatrick return [] 111061da546Spatrick 112061da546Spatrick class ranges_access(object): 113061da546Spatrick '''A helper object that will lazily hand out an array of lldb.SBAddress that represent address ranges for a block.''' 114061da546Spatrick def __init__(self, sbblock): 115061da546Spatrick self.sbblock = sbblock 116061da546Spatrick 117061da546Spatrick def __len__(self): 118061da546Spatrick if self.sbblock: 119061da546Spatrick return int(self.sbblock.GetNumRanges()) 120061da546Spatrick return 0 121061da546Spatrick 122061da546Spatrick def __getitem__(self, key): 123061da546Spatrick count = len(self) 124061da546Spatrick if type(key) is int: 125061da546Spatrick return self.sbblock.get_range_at_index (key); 126061da546Spatrick if isinstance(key, SBAddress): 127061da546Spatrick range_idx = self.sbblock.GetRangeIndexForBlockAddress(key); 128061da546Spatrick if range_idx < len(self): 129061da546Spatrick return [self.sbblock.GetRangeStartAddress(range_idx), self.sbblock.GetRangeEndAddress(range_idx)] 130061da546Spatrick else: 131061da546Spatrick print("error: unsupported item type: %s" % type(key)) 132061da546Spatrick return None 133061da546Spatrick 134061da546Spatrick def get_ranges_access_object(self): 135061da546Spatrick '''An accessor function that returns a ranges_access() object which allows lazy block address ranges access.''' 136061da546Spatrick return self.ranges_access (self) 137061da546Spatrick 138061da546Spatrick def get_ranges_array(self): 139061da546Spatrick '''An accessor function that returns an array object that contains all ranges in this block object.''' 140061da546Spatrick if not hasattr(self, 'ranges_array'): 141061da546Spatrick self.ranges_array = [] 142061da546Spatrick for idx in range(self.num_ranges): 143061da546Spatrick self.ranges_array.append ([self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)]) 144061da546Spatrick return self.ranges_array 145061da546Spatrick 146061da546Spatrick def get_call_site(self): 147061da546Spatrick return declaration(self.GetInlinedCallSiteFile(), self.GetInlinedCallSiteLine(), self.GetInlinedCallSiteColumn()) 148061da546Spatrick 149061da546Spatrick parent = property(GetParent, None, doc='''A read only property that returns the same result as GetParent().''') 150061da546Spatrick first_child = property(GetFirstChild, None, doc='''A read only property that returns the same result as GetFirstChild().''') 151061da546Spatrick 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.''') 152061da546Spatrick sibling = property(GetSibling, None, doc='''A read only property that returns the same result as GetSibling().''') 153061da546Spatrick name = property(GetInlinedName, None, doc='''A read only property that returns the same result as GetInlinedName().''') 154061da546Spatrick inlined_block = property(GetContainingInlinedBlock, None, doc='''A read only property that returns the same result as GetContainingInlinedBlock().''') 155dda28197Spatrick 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]").''') 156061da546Spatrick 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.''') 157061da546Spatrick num_ranges = property(GetNumRanges, None, doc='''A read only property that returns the same result as GetNumRanges().''') 158061da546Spatrick %} 159061da546Spatrick #endif 160061da546Spatrick 161061da546Spatrick }; 162061da546Spatrick 163061da546Spatrick } // namespace lldb 164