blob: 3972b939b18b967cf375d0deaa6f82dc0d8a6eaf [file] [log] [blame]
Johnny Chen5de6a792011-07-18 21:30:21 +00001//===-- SWIG Interface for SBBlock ------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Chen5de6a792011-07-18 21:30:21 +00006//
7//===----------------------------------------------------------------------===//
8
9namespace lldb {
10
11%feature("docstring",
12"Represents a lexical block. SBFunction contains SBBlock(s)."
13) SBBlock;
14class SBBlock
15{
16public:
17
18 SBBlock ();
19
20 SBBlock (const lldb::SBBlock &rhs);
21
22 ~SBBlock ();
23
24 %feature("docstring",
Vedant Kumar4926a5e2020-09-17 16:53:17 -070025 "Is this block contained within an inlined function?"
Johnny Chen5de6a792011-07-18 21:30:21 +000026 ) IsInlined;
27 bool
28 IsInlined () const;
29
30 bool
31 IsValid () const;
32
Pavel Labath7f5237b2019-03-11 13:58:46 +000033 explicit operator bool() const;
34
Johnny Chen5de6a792011-07-18 21:30:21 +000035 %feature("docstring", "
36 Get the function name if this block represents an inlined function;
Pavel Labatheba97422019-04-18 16:23:33 +000037 otherwise, return None.") GetInlinedName;
Johnny Chen5de6a792011-07-18 21:30:21 +000038 const char *
39 GetInlinedName () const;
40
41 %feature("docstring", "
42 Get the call site file if this block represents an inlined function;
Pavel Labatheba97422019-04-18 16:23:33 +000043 otherwise, return an invalid file spec.") GetInlinedCallSiteFile;
Johnny Chen5de6a792011-07-18 21:30:21 +000044 lldb::SBFileSpec
45 GetInlinedCallSiteFile () const;
46
47 %feature("docstring", "
48 Get the call site line if this block represents an inlined function;
Pavel Labatheba97422019-04-18 16:23:33 +000049 otherwise, return 0.") GetInlinedCallSiteLine;
50 uint32_t
Johnny Chen5de6a792011-07-18 21:30:21 +000051 GetInlinedCallSiteLine () const;
52
53 %feature("docstring", "
54 Get the call site column if this block represents an inlined function;
Pavel Labatheba97422019-04-18 16:23:33 +000055 otherwise, return 0.") GetInlinedCallSiteColumn;
Johnny Chen5de6a792011-07-18 21:30:21 +000056 uint32_t
57 GetInlinedCallSiteColumn () const;
58
59 %feature("docstring", "Get the parent block.") GetParent;
60 lldb::SBBlock
61 GetParent ();
Pavel Labatheba97422019-04-18 16:23:33 +000062
Greg Clayton8f7180b2011-09-26 07:11:27 +000063 %feature("docstring", "Get the inlined block that is or contains this block.") GetContainingInlinedBlock;
64 lldb::SBBlock
65 GetContainingInlinedBlock ();
66
Johnny Chen5de6a792011-07-18 21:30:21 +000067 %feature("docstring", "Get the sibling block for this block.") GetSibling;
68 lldb::SBBlock
69 GetSibling ();
Pavel Labatheba97422019-04-18 16:23:33 +000070
Johnny Chen5de6a792011-07-18 21:30:21 +000071 %feature("docstring", "Get the first child block.") GetFirstChild;
72 lldb::SBBlock
73 GetFirstChild ();
Pavel Labatheba97422019-04-18 16:23:33 +000074
Greg Clayton8f7180b2011-09-26 07:11:27 +000075 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 Chen5de6a792011-07-18 21:30:21 +000086
87 bool
88 GetDescription (lldb::SBStream &description);
Greg Clayton5569e642012-02-06 01:44:54 +000089
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 Devlieghereae47a3d2020-01-08 16:13:03 -0800103 STRING_EXTENSION(SBBlock)
104
Jonas Devlieghere0a570342019-12-08 14:46:48 -0800105#ifdef SWIGPYTHON
Greg Clayton5569e642012-02-06 01:44:54 +0000106 %pythoncode %{
107 def get_range_at_index(self, idx):
108 if idx < self.GetNumRanges():
Greg Clayton006c1d12013-02-25 21:53:07 +0000109 return [self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)]
Greg Clayton5569e642012-02-06 01:44:54 +0000110 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 Labatheba97422019-04-18 16:23:33 +0000116
Greg Clayton5569e642012-02-06 01:44:54 +0000117 def __len__(self):
118 if self.sbblock:
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +0000119 return int(self.sbblock.GetNumRanges())
Greg Clayton5569e642012-02-06 01:44:54 +0000120 return 0
Pavel Labatheba97422019-04-18 16:23:33 +0000121
Greg Clayton5569e642012-02-06 01:44:54 +0000122 def __getitem__(self, key):
123 count = len(self)
124 if type(key) is int:
125 return self.sbblock.get_range_at_index (key);
Greg Clayton85673552012-06-27 20:23:09 +0000126 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 Clayton5569e642012-02-06 01:44:54 +0000130 else:
Zachary Turner5f3fd802015-10-16 17:52:32 +0000131 print("error: unsupported item type: %s" % type(key))
Greg Clayton5569e642012-02-06 01:44:54 +0000132 return None
Pavel Labatheba97422019-04-18 16:23:33 +0000133
Greg Clayton5569e642012-02-06 01:44:54 +0000134 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 Labatheba97422019-04-18 16:23:33 +0000137
Greg Clayton5569e642012-02-06 01:44:54 +0000138 def get_ranges_array(self):
139 '''An accessor function that returns an array object that contains all ranges in this block object.'''
Greg Clayton006c1d12013-02-25 21:53:07 +0000140 if not hasattr(self, 'ranges_array'):
141 self.ranges_array = []
Greg Clayton5569e642012-02-06 01:44:54 +0000142 for idx in range(self.num_ranges):
Greg Clayton006c1d12013-02-25 21:53:07 +0000143 self.ranges_array.append ([self.GetRangeStartAddress(idx), self.GetRangeEndAddress(idx)])
144 return self.ranges_array
Pavel Labatheba97422019-04-18 16:23:33 +0000145
Greg Clayton5569e642012-02-06 01:44:54 +0000146 def get_call_site(self):
147 return declaration(self.GetInlinedCallSiteFile(), self.GetInlinedCallSiteLine(), self.GetInlinedCallSiteColumn())
148
Jonas Devlieghere89b65842019-07-02 22:18:35 +0000149 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 Ishizakie9264b72020-04-07 01:06:02 +0900155 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 Devlieghere89b65842019-07-02 22:18:35 +0000156 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 Devlieghere97316ff2019-07-02 18:04:55 +0000158 %}
Jonas Devlieghere0a570342019-12-08 14:46:48 -0800159#endif
Jonas Devlieghere97316ff2019-07-02 18:04:55 +0000160
161};
Jonas Devliegheref9b91a52019-07-02 17:25:20 +0000162
Johnny Chen5de6a792011-07-18 21:30:21 +0000163} // namespace lldb