Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 1 | //===-- SWIG Interface for SBBlock ------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | namespace lldb { |
| 10 | |
| 11 | %feature("docstring", |
| 12 | "Represents a lexical block. SBFunction contains SBBlock(s)." |
| 13 | ) SBBlock; |
| 14 | class SBBlock |
| 15 | { |
| 16 | public: |
| 17 | |
| 18 | SBBlock (); |
| 19 | |
| 20 | SBBlock (const lldb::SBBlock &rhs); |
| 21 | |
| 22 | ~SBBlock (); |
| 23 | |
| 24 | %feature("docstring", |
Vedant Kumar | 4926a5e | 2020-09-17 16:53:17 -0700 | [diff] [blame] | 25 | "Is this block contained within an inlined function?" |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 26 | ) IsInlined; |
| 27 | bool |
| 28 | IsInlined () const; |
| 29 | |
| 30 | bool |
| 31 | IsValid () const; |
| 32 | |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 33 | explicit operator bool() const; |
| 34 | |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 35 | %feature("docstring", " |
| 36 | Get the function name if this block represents an inlined function; |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 37 | otherwise, return None.") GetInlinedName; |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 38 | const char * |
| 39 | GetInlinedName () const; |
| 40 | |
| 41 | %feature("docstring", " |
| 42 | Get the call site file if this block represents an inlined function; |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 43 | otherwise, return an invalid file spec.") GetInlinedCallSiteFile; |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 44 | lldb::SBFileSpec |
| 45 | GetInlinedCallSiteFile () const; |
| 46 | |
| 47 | %feature("docstring", " |
| 48 | Get the call site line if this block represents an inlined function; |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 49 | otherwise, return 0.") GetInlinedCallSiteLine; |
| 50 | uint32_t |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 51 | GetInlinedCallSiteLine () const; |
| 52 | |
| 53 | %feature("docstring", " |
| 54 | Get the call site column if this block represents an inlined function; |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 55 | otherwise, return 0.") GetInlinedCallSiteColumn; |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 56 | uint32_t |
| 57 | GetInlinedCallSiteColumn () const; |
| 58 | |
| 59 | %feature("docstring", "Get the parent block.") GetParent; |
| 60 | lldb::SBBlock |
| 61 | GetParent (); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 62 | |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 63 | %feature("docstring", "Get the inlined block that is or contains this block.") GetContainingInlinedBlock; |
| 64 | lldb::SBBlock |
| 65 | GetContainingInlinedBlock (); |
| 66 | |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 67 | %feature("docstring", "Get the sibling block for this block.") GetSibling; |
| 68 | lldb::SBBlock |
| 69 | GetSibling (); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 70 | |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 71 | %feature("docstring", "Get the first child block.") GetFirstChild; |
| 72 | lldb::SBBlock |
| 73 | GetFirstChild (); |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 74 | |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 75 | uint32_t |
| 76 | GetNumRanges (); |
| 77 | |
| 78 | lldb::SBAddress |
| 79 | GetRangeStartAddress (uint32_t idx); |
| 80 | |
| 81 | lldb::SBAddress |
| 82 | GetRangeEndAddress (uint32_t idx); |
| 83 | |
| 84 | uint32_t |
| 85 | GetRangeIndexForBlockAddress (lldb::SBAddress block_addr); |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 86 | |
| 87 | bool |
| 88 | GetDescription (lldb::SBStream &description); |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 89 | |
| 90 | lldb::SBValueList |
| 91 | GetVariables (lldb::SBFrame& frame, |
| 92 | bool arguments, |
| 93 | bool locals, |
| 94 | bool statics, |
| 95 | lldb::DynamicValueType use_dynamic); |
| 96 | |
| 97 | lldb::SBValueList |
| 98 | GetVariables (lldb::SBTarget& target, |
| 99 | bool arguments, |
| 100 | bool locals, |
| 101 | bool statics); |
| 102 | |
Jonas Devlieghere | ae47a3d | 2020-01-08 16:13:03 -0800 | [diff] [blame] | 103 | STRING_EXTENSION(SBBlock) |
| 104 | |
Jonas Devlieghere | 0a57034 | 2019-12-08 14:46:48 -0800 | [diff] [blame] | 105 | #ifdef SWIGPYTHON |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 106 | %pythoncode %{ |
| 107 | def get_range_at_index(self, idx): |
| 108 | if idx < self.GetNumRanges(): |
Greg Clayton | 006c1d1 | 2013-02-25 21:53:07 +0000 | [diff] [blame] | 109 | return [self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)] |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 110 | return [] |
| 111 | |
| 112 | class ranges_access(object): |
| 113 | '''A helper object that will lazily hand out an array of lldb.SBAddress that represent address ranges for a block.''' |
| 114 | def __init__(self, sbblock): |
| 115 | self.sbblock = sbblock |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 116 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 117 | def __len__(self): |
| 118 | if self.sbblock: |
Filipe Cabecinhas | 1a96ef8 | 2012-05-11 20:39:42 +0000 | [diff] [blame] | 119 | return int(self.sbblock.GetNumRanges()) |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 120 | return 0 |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 121 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 122 | def __getitem__(self, key): |
| 123 | count = len(self) |
| 124 | if type(key) is int: |
| 125 | return self.sbblock.get_range_at_index (key); |
Greg Clayton | 8567355 | 2012-06-27 20:23:09 +0000 | [diff] [blame] | 126 | if isinstance(key, SBAddress): |
| 127 | range_idx = self.sbblock.GetRangeIndexForBlockAddress(key); |
| 128 | if range_idx < len(self): |
| 129 | return [self.sbblock.GetRangeStartAddress(range_idx), self.sbblock.GetRangeEndAddress(range_idx)] |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 130 | else: |
Zachary Turner | 5f3fd80 | 2015-10-16 17:52:32 +0000 | [diff] [blame] | 131 | print("error: unsupported item type: %s" % type(key)) |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 132 | return None |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 133 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 134 | def get_ranges_access_object(self): |
| 135 | '''An accessor function that returns a ranges_access() object which allows lazy block address ranges access.''' |
| 136 | return self.ranges_access (self) |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 137 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 138 | def get_ranges_array(self): |
| 139 | '''An accessor function that returns an array object that contains all ranges in this block object.''' |
Greg Clayton | 006c1d1 | 2013-02-25 21:53:07 +0000 | [diff] [blame] | 140 | if not hasattr(self, 'ranges_array'): |
| 141 | self.ranges_array = [] |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 142 | for idx in range(self.num_ranges): |
Greg Clayton | 006c1d1 | 2013-02-25 21:53:07 +0000 | [diff] [blame] | 143 | self.ranges_array.append ([self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)]) |
| 144 | return self.ranges_array |
Pavel Labath | eba9742 | 2019-04-18 16:23:33 +0000 | [diff] [blame] | 145 | |
Greg Clayton | 5569e64 | 2012-02-06 01:44:54 +0000 | [diff] [blame] | 146 | def get_call_site(self): |
| 147 | return declaration(self.GetInlinedCallSiteFile(), self.GetInlinedCallSiteLine(), self.GetInlinedCallSiteColumn()) |
| 148 | |
Jonas Devlieghere | 89b6584 | 2019-07-02 22:18:35 +0000 | [diff] [blame] | 149 | parent = property(GetParent, None, doc='''A read only property that returns the same result as GetParent().''') |
| 150 | first_child = property(GetFirstChild, None, doc='''A read only property that returns the same result as GetFirstChild().''') |
| 151 | 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.''') |
| 152 | sibling = property(GetSibling, None, doc='''A read only property that returns the same result as GetSibling().''') |
| 153 | name = property(GetInlinedName, None, doc='''A read only property that returns the same result as GetInlinedName().''') |
| 154 | inlined_block = property(GetContainingInlinedBlock, None, doc='''A read only property that returns the same result as GetContainingInlinedBlock().''') |
Kazuaki Ishizaki | e9264b7 | 2020-04-07 01:06:02 +0900 | [diff] [blame] | 155 | 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]").''') |
Jonas Devlieghere | 89b6584 | 2019-07-02 22:18:35 +0000 | [diff] [blame] | 156 | 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.''') |
| 157 | num_ranges = property(GetNumRanges, None, doc='''A read only property that returns the same result as GetNumRanges().''') |
Jonas Devlieghere | 97316ff | 2019-07-02 18:04:55 +0000 | [diff] [blame] | 158 | %} |
Jonas Devlieghere | 0a57034 | 2019-12-08 14:46:48 -0800 | [diff] [blame] | 159 | #endif |
Jonas Devlieghere | 97316ff | 2019-07-02 18:04:55 +0000 | [diff] [blame] | 160 | |
| 161 | }; |
Jonas Devlieghere | f9b91a5 | 2019-07-02 17:25:20 +0000 | [diff] [blame] | 162 | |
Johnny Chen | 5de6a79 | 2011-07-18 21:30:21 +0000 | [diff] [blame] | 163 | } // namespace lldb |