1 //===-- SWIG Interface for SBData -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
18 SBData (const SBData &rhs);
23 GetAddressByteSize ();
26 SetAddressByteSize (uint8_t addr_byte_size);
34 explicit operator bool() const;
43 SetByteOrder (lldb::ByteOrder endian);
46 GetFloat (lldb::SBError& error, lldb::offset_t offset);
49 GetDouble (lldb::SBError& error, lldb::offset_t offset);
52 GetLongDouble (lldb::SBError& error, lldb::offset_t offset);
55 GetAddress (lldb::SBError& error, lldb::offset_t offset);
58 GetUnsignedInt8 (lldb::SBError& error, lldb::offset_t offset);
61 GetUnsignedInt16 (lldb::SBError& error, lldb::offset_t offset);
64 GetUnsignedInt32 (lldb::SBError& error, lldb::offset_t offset);
67 GetUnsignedInt64 (lldb::SBError& error, lldb::offset_t offset);
70 GetSignedInt8 (lldb::SBError& error, lldb::offset_t offset);
73 GetSignedInt16 (lldb::SBError& error, lldb::offset_t offset);
76 GetSignedInt32 (lldb::SBError& error, lldb::offset_t offset);
79 GetSignedInt64 (lldb::SBError& error, lldb::offset_t offset);
82 GetString (lldb::SBError& error, lldb::offset_t offset);
85 GetDescription (lldb::SBStream &description, lldb::addr_t base_addr);
88 ReadRawData (lldb::SBError& error,
89 lldb::offset_t offset,
94 SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
97 Append (const SBData& rhs);
100 CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data);
102 // in the following CreateData*() and SetData*() prototypes, the two parameters array and array_len
103 // should not be renamed or rearranged, because doing so will break the SWIG typemap
105 CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len);
108 CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len);
111 CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len);
114 CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len);
117 CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len);
120 SetDataFromCString (const char* data);
123 SetDataFromUInt64Array (uint64_t* array, size_t array_len);
126 SetDataFromUInt32Array (uint32_t* array, size_t array_len);
129 SetDataFromSInt64Array (int64_t* array, size_t array_len);
132 SetDataFromSInt32Array (int32_t* array, size_t array_len);
135 SetDataFromDoubleArray (double* array, size_t array_len);
137 STRING_EXTENSION(SBData)
142 class read_data_helper:
143 def __init__(self, sbdata, readerfunc, item_size):
145 self.readerfunc = readerfunc
146 self.item_size = item_size
147 def __getitem__(self,key):
148 if isinstance(key,slice):
150 for x in range(*key.indices(self.__len__())):
151 list.append(self.__getitem__(x))
153 if not (isinstance(key,six.integer_types)):
154 raise TypeError('must be int')
155 key = key * self.item_size # SBData uses byte-based indexes, but we want to use itemsize-based indexes here
157 my_data = self.readerfunc(self.sbdata,error,key)
159 raise IndexError(error.GetCString())
163 return int(self.sbdata.GetByteSize()/self.item_size)
165 return self[0:len(self)]
168 def CreateDataFromInt (cls, value, size = None, target = None, ptr_size = None, endian = None):
170 lldbmodule = sys.modules[cls.__module__]
171 lldbdict = lldbmodule.__dict__
172 if 'target' in lldbdict:
173 lldbtarget = lldbdict['target']
176 if target == None and lldbtarget != None and lldbtarget.IsValid():
179 if target and target.IsValid():
180 ptr_size = target.addr_size
184 if target and target.IsValid():
185 endian = target.byte_order
187 endian = lldbdict['eByteOrderLittle']
189 if value > 2147483647:
191 elif value < -2147483648:
193 elif value > 4294967295:
199 return SBData().CreateDataFromSInt32Array(endian, ptr_size, [value])
200 return SBData().CreateDataFromUInt32Array(endian, ptr_size, [value])
203 return SBData().CreateDataFromSInt64Array(endian, ptr_size, [value])
204 return SBData().CreateDataFromUInt64Array(endian, ptr_size, [value])
207 def _make_helper(self, sbdata, getfunc, itemsize):
208 return self.read_data_helper(sbdata, getfunc, itemsize)
210 def _make_helper_uint8(self):
211 return self._make_helper(self, SBData.GetUnsignedInt8, 1)
213 def _make_helper_uint16(self):
214 return self._make_helper(self, SBData.GetUnsignedInt16, 2)
216 def _make_helper_uint32(self):
217 return self._make_helper(self, SBData.GetUnsignedInt32, 4)
219 def _make_helper_uint64(self):
220 return self._make_helper(self, SBData.GetUnsignedInt64, 8)
222 def _make_helper_sint8(self):
223 return self._make_helper(self, SBData.GetSignedInt8, 1)
225 def _make_helper_sint16(self):
226 return self._make_helper(self, SBData.GetSignedInt16, 2)
228 def _make_helper_sint32(self):
229 return self._make_helper(self, SBData.GetSignedInt32, 4)
231 def _make_helper_sint64(self):
232 return self._make_helper(self, SBData.GetSignedInt64, 8)
234 def _make_helper_float(self):
235 return self._make_helper(self, SBData.GetFloat, 4)
237 def _make_helper_double(self):
238 return self._make_helper(self, SBData.GetDouble, 8)
240 def _read_all_uint8(self):
241 return self._make_helper_uint8().all()
243 def _read_all_uint16(self):
244 return self._make_helper_uint16().all()
246 def _read_all_uint32(self):
247 return self._make_helper_uint32().all()
249 def _read_all_uint64(self):
250 return self._make_helper_uint64().all()
252 def _read_all_sint8(self):
253 return self._make_helper_sint8().all()
255 def _read_all_sint16(self):
256 return self._make_helper_sint16().all()
258 def _read_all_sint32(self):
259 return self._make_helper_sint32().all()
261 def _read_all_sint64(self):
262 return self._make_helper_sint64().all()
264 def _read_all_float(self):
265 return self._make_helper_float().all()
267 def _read_all_double(self):
268 return self._make_helper_double().all()
270 uint8 = property(_make_helper_uint8, None, doc='''A read only property that returns an array-like object out of which you can read uint8 values.''')
271 uint16 = property(_make_helper_uint16, None, doc='''A read only property that returns an array-like object out of which you can read uint16 values.''')
272 uint32 = property(_make_helper_uint32, None, doc='''A read only property that returns an array-like object out of which you can read uint32 values.''')
273 uint64 = property(_make_helper_uint64, None, doc='''A read only property that returns an array-like object out of which you can read uint64 values.''')
274 sint8 = property(_make_helper_sint8, None, doc='''A read only property that returns an array-like object out of which you can read sint8 values.''')
275 sint16 = property(_make_helper_sint16, None, doc='''A read only property that returns an array-like object out of which you can read sint16 values.''')
276 sint32 = property(_make_helper_sint32, None, doc='''A read only property that returns an array-like object out of which you can read sint32 values.''')
277 sint64 = property(_make_helper_sint64, None, doc='''A read only property that returns an array-like object out of which you can read sint64 values.''')
278 float = property(_make_helper_float, None, doc='''A read only property that returns an array-like object out of which you can read float values.''')
279 double = property(_make_helper_double, None, doc='''A read only property that returns an array-like object out of which you can read double values.''')
280 uint8s = property(_read_all_uint8, None, doc='''A read only property that returns an array with all the contents of this SBData represented as uint8 values.''')
281 uint16s = property(_read_all_uint16, None, doc='''A read only property that returns an array with all the contents of this SBData represented as uint16 values.''')
282 uint32s = property(_read_all_uint32, None, doc='''A read only property that returns an array with all the contents of this SBData represented as uint32 values.''')
283 uint64s = property(_read_all_uint64, None, doc='''A read only property that returns an array with all the contents of this SBData represented as uint64 values.''')
284 sint8s = property(_read_all_sint8, None, doc='''A read only property that returns an array with all the contents of this SBData represented as sint8 values.''')
285 sint16s = property(_read_all_sint16, None, doc='''A read only property that returns an array with all the contents of this SBData represented as sint16 values.''')
286 sint32s = property(_read_all_sint32, None, doc='''A read only property that returns an array with all the contents of this SBData represented as sint32 values.''')
287 sint64s = property(_read_all_sint64, None, doc='''A read only property that returns an array with all the contents of this SBData represented as sint64 values.''')
288 floats = property(_read_all_float, None, doc='''A read only property that returns an array with all the contents of this SBData represented as float values.''')
289 doubles = property(_read_all_double, None, doc='''A read only property that returns an array with all the contents of this SBData represented as double values.''')
290 byte_order = property(GetByteOrder, SetByteOrder, doc='''A read/write property getting and setting the endianness of this SBData (data.byte_order = lldb.eByteOrderLittle).''')
291 size = property(GetByteSize, None, doc='''A read only property that returns the size the same result as GetByteSize().''')