1 //===-- SWIG Interface for SBBlock ------------------------------*- C++ -*-===//
2 //
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
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",
25     "Is this block contained within an inlined function?"
26     ) IsInlined;
27     bool
28     IsInlined () const;
29 
30     bool
31     IsValid () const;
32 
33     explicit operator bool() const;
34 
35     %feature("docstring", "
36     Get the function name if this block represents an inlined function;
37     otherwise, return None.") GetInlinedName;
38     const char *
39     GetInlinedName () const;
40 
41     %feature("docstring", "
42     Get the call site file if this block represents an inlined function;
43     otherwise, return an invalid file spec.") GetInlinedCallSiteFile;
44     lldb::SBFileSpec
45     GetInlinedCallSiteFile () const;
46 
47     %feature("docstring", "
48     Get the call site line if this block represents an inlined function;
49     otherwise, return 0.") GetInlinedCallSiteLine;
50     uint32_t
51     GetInlinedCallSiteLine () const;
52 
53     %feature("docstring", "
54     Get the call site column if this block represents an inlined function;
55     otherwise, return 0.") GetInlinedCallSiteColumn;
56     uint32_t
57     GetInlinedCallSiteColumn () const;
58 
59     %feature("docstring", "Get the parent block.") GetParent;
60     lldb::SBBlock
61     GetParent ();
62 
63     %feature("docstring", "Get the inlined block that is or contains this block.") GetContainingInlinedBlock;
64     lldb::SBBlock
65     GetContainingInlinedBlock ();
66 
67     %feature("docstring", "Get the sibling block for this block.") GetSibling;
68     lldb::SBBlock
69     GetSibling ();
70 
71     %feature("docstring", "Get the first child block.") GetFirstChild;
72     lldb::SBBlock
73     GetFirstChild ();
74 
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);
86 
87     bool
88     GetDescription (lldb::SBStream &description);
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 
103     STRING_EXTENSION(SBBlock)
104 
105 #ifdef SWIGPYTHON
106     %pythoncode %{
107         def get_range_at_index(self, idx):
108             if idx < self.GetNumRanges():
109                 return [self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)]
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
116 
117             def __len__(self):
118                 if self.sbblock:
119                     return int(self.sbblock.GetNumRanges())
120                 return 0
121 
122             def __getitem__(self, key):
123                 count = len(self)
124                 if type(key) is int:
125                     return self.sbblock.get_range_at_index (key);
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)]
130                 else:
131                     print("error: unsupported item type: %s" % type(key))
132                 return None
133 
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)
137 
138         def get_ranges_array(self):
139             '''An accessor function that returns an array object that contains all ranges in this block object.'''
140             if not hasattr(self, 'ranges_array'):
141                 self.ranges_array = []
142                 for idx in range(self.num_ranges):
143                     self.ranges_array.append ([self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)])
144             return self.ranges_array
145 
146         def get_call_site(self):
147             return declaration(self.GetInlinedCallSiteFile(), self.GetInlinedCallSiteLine(), self.GetInlinedCallSiteColumn())
148 
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().''')
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]").''')
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().''')
158     %}
159 #endif
160 
161 };
162 
163 } // namespace lldb
164