blob: 5f22bd81b23688a0b924f58bb97550c7feb8e0f3 [file] [log] [blame]
Enrico Granata9128ee22011-09-06 19:20:51 +00001//===-- SWIG Interface for SBData -------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11namespace lldb {
12
13class SBData
14{
15public:
16
Johnny Chen55114c22011-09-15 22:05:38 +000017 SBData ();
Enrico Granata9128ee22011-09-06 19:20:51 +000018
Johnny Chen55114c22011-09-15 22:05:38 +000019 SBData (const SBData &rhs);
Enrico Granata9128ee22011-09-06 19:20:51 +000020
Johnny Chen55114c22011-09-15 22:05:38 +000021 ~SBData ();
Enrico Granata9128ee22011-09-06 19:20:51 +000022
Johnny Chen55114c22011-09-15 22:05:38 +000023 uint8_t
24 GetAddressByteSize ();
Greg Clayton0f289862012-01-07 00:45:50 +000025
26 void
27 SetAddressByteSize (uint8_t addr_byte_size);
Enrico Granata9128ee22011-09-06 19:20:51 +000028
Johnny Chen55114c22011-09-15 22:05:38 +000029 void
30 Clear ();
Enrico Granata9128ee22011-09-06 19:20:51 +000031
Johnny Chen55114c22011-09-15 22:05:38 +000032 bool
33 IsValid();
Enrico Granata9128ee22011-09-06 19:20:51 +000034
Johnny Chen55114c22011-09-15 22:05:38 +000035 size_t
36 GetByteSize ();
Enrico Granata9128ee22011-09-06 19:20:51 +000037
Johnny Chen55114c22011-09-15 22:05:38 +000038 lldb::ByteOrder
39 GetByteOrder();
Greg Clayton0f289862012-01-07 00:45:50 +000040
41 void
42 SetByteOrder (lldb::ByteOrder endian);
Enrico Granata9128ee22011-09-06 19:20:51 +000043
Johnny Chen55114c22011-09-15 22:05:38 +000044 float
Greg Claytonc7bece562013-01-25 18:06:21 +000045 GetFloat (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000046
Johnny Chen55114c22011-09-15 22:05:38 +000047 double
Greg Claytonc7bece562013-01-25 18:06:21 +000048 GetDouble (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000049
Johnny Chen55114c22011-09-15 22:05:38 +000050 long double
Greg Claytonc7bece562013-01-25 18:06:21 +000051 GetLongDouble (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000052
Johnny Chen55114c22011-09-15 22:05:38 +000053 lldb::addr_t
Greg Claytonc7bece562013-01-25 18:06:21 +000054 GetAddress (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000055
Johnny Chen55114c22011-09-15 22:05:38 +000056 uint8_t
Greg Claytonc7bece562013-01-25 18:06:21 +000057 GetUnsignedInt8 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000058
Johnny Chen55114c22011-09-15 22:05:38 +000059 uint16_t
Greg Claytonc7bece562013-01-25 18:06:21 +000060 GetUnsignedInt16 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000061
Johnny Chen55114c22011-09-15 22:05:38 +000062 uint32_t
Greg Claytonc7bece562013-01-25 18:06:21 +000063 GetUnsignedInt32 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000064
Johnny Chen55114c22011-09-15 22:05:38 +000065 uint64_t
Greg Claytonc7bece562013-01-25 18:06:21 +000066 GetUnsignedInt64 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000067
Johnny Chen55114c22011-09-15 22:05:38 +000068 int8_t
Greg Claytonc7bece562013-01-25 18:06:21 +000069 GetSignedInt8 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000070
Johnny Chen55114c22011-09-15 22:05:38 +000071 int16_t
Greg Claytonc7bece562013-01-25 18:06:21 +000072 GetSignedInt16 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000073
Johnny Chen55114c22011-09-15 22:05:38 +000074 int32_t
Greg Claytonc7bece562013-01-25 18:06:21 +000075 GetSignedInt32 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000076
Johnny Chen55114c22011-09-15 22:05:38 +000077 int64_t
Greg Claytonc7bece562013-01-25 18:06:21 +000078 GetSignedInt64 (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000079
Johnny Chen55114c22011-09-15 22:05:38 +000080 const char*
Greg Claytonc7bece562013-01-25 18:06:21 +000081 GetString (lldb::SBError& error, lldb::offset_t offset);
Enrico Granata9128ee22011-09-06 19:20:51 +000082
Johnny Chen55114c22011-09-15 22:05:38 +000083 bool
Greg Claytond9dc52d2011-09-24 05:04:40 +000084 GetDescription (lldb::SBStream &description, lldb::addr_t base_addr);
Enrico Granata9128ee22011-09-06 19:20:51 +000085
Johnny Chen55114c22011-09-15 22:05:38 +000086 size_t
87 ReadRawData (lldb::SBError& error,
Greg Claytonc7bece562013-01-25 18:06:21 +000088 lldb::offset_t offset,
Johnny Chen55114c22011-09-15 22:05:38 +000089 void *buf,
90 size_t size);
Enrico Granata9128ee22011-09-06 19:20:51 +000091
Johnny Chen55114c22011-09-15 22:05:38 +000092 void
Greg Clayton0f289862012-01-07 00:45:50 +000093 SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
Johnny Chen55114c22011-09-15 22:05:38 +000094
95 bool
Greg Clayton0f289862012-01-07 00:45:50 +000096 Append (const SBData& rhs);
97
98 static lldb::SBData
99 CreateDataFromCString (lldb::ByteOrder endian, uint32_t addr_byte_size, const char* data);
100
101 // in the following CreateData*() and SetData*() prototypes, the two parameters array and array_len
102 // should not be renamed or rearranged, because doing so will break the SWIG typemap
103 static lldb::SBData
104 CreateDataFromUInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint64_t* array, size_t array_len);
105
106 static lldb::SBData
107 CreateDataFromUInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, uint32_t* array, size_t array_len);
108
109 static lldb::SBData
110 CreateDataFromSInt64Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int64_t* array, size_t array_len);
111
112 static lldb::SBData
113 CreateDataFromSInt32Array (lldb::ByteOrder endian, uint32_t addr_byte_size, int32_t* array, size_t array_len);
114
115 static lldb::SBData
116 CreateDataFromDoubleArray (lldb::ByteOrder endian, uint32_t addr_byte_size, double* array, size_t array_len);
117
118 bool
119 SetDataFromCString (const char* data);
120
121 bool
122 SetDataFromUInt64Array (uint64_t* array, size_t array_len);
123
124 bool
125 SetDataFromUInt32Array (uint32_t* array, size_t array_len);
126
127 bool
128 SetDataFromSInt64Array (int64_t* array, size_t array_len);
129
130 bool
131 SetDataFromSInt32Array (int32_t* array, size_t array_len);
132
133 bool
134 SetDataFromDoubleArray (double* array, size_t array_len);
Enrico Granata9128ee22011-09-06 19:20:51 +0000135
Greg Clayton13d19502012-01-29 06:07:39 +0000136 %pythoncode %{
Enrico Granata385ad4e2012-03-03 00:45:57 +0000137
138 class read_data_helper:
139 def __init__(self, sbdata, readerfunc, item_size):
140 self.sbdata = sbdata
141 self.readerfunc = readerfunc
142 self.item_size = item_size
143 def __getitem__(self,key):
144 if isinstance(key,slice):
145 list = []
146 for x in range(*key.indices(self.__len__())):
147 list.append(self.__getitem__(x))
148 return list
149 if not (isinstance(key,(int,long))):
150 raise TypeError('must be int')
151 key = key * self.item_size # SBData uses byte-based indexes, but we want to use itemsize-based indexes here
152 error = SBError()
153 my_data = self.readerfunc(self.sbdata,error,key)
154 if error.Fail():
155 raise IndexError(error.GetCString())
156 else:
157 return my_data
158 def __len__(self):
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +0000159 return int(self.sbdata.GetByteSize()/self.item_size)
Enrico Granata385ad4e2012-03-03 00:45:57 +0000160 def all(self):
161 return self[0:len(self)]
162
Enrico Granatab0c72d92013-06-11 22:06:06 +0000163 @classmethod
164 def CreateDataFromInt (cls, value, size = None, target = None, ptr_size = None, endian = None):
165 import sys
166 lldbmodule = sys.modules[cls.__module__]
167 lldbdict = lldbmodule.__dict__
168 if 'target' in lldbdict:
169 lldbtarget = lldbdict['target']
170 else:
171 lldbtarget = None
172 if target == None and lldbtarget != None and lldbtarget.IsValid():
173 target = lldbtarget
174 if ptr_size == None:
175 if target and target.IsValid():
176 ptr_size = target.addr_size
177 else:
178 ptr_size = 8
179 if endian == None:
180 if target and target.IsValid():
181 endian = target.byte_order
182 else:
183 endian = lldbdict['eByteOrderLittle']
184 if size == None:
185 if value > 2147483647:
186 size = 8
187 elif value < -2147483648:
188 size = 8
189 elif value > 4294967295:
190 size = 8
191 else:
192 size = 4
193 if size == 4:
194 if value < 0:
195 return SBData().CreateDataFromSInt32Array(endian, ptr_size, [value])
196 return SBData().CreateDataFromUInt32Array(endian, ptr_size, [value])
197 if size == 8:
198 if value < 0:
199 return SBData().CreateDataFromSInt64Array(endian, ptr_size, [value])
200 return SBData().CreateDataFromUInt64Array(endian, ptr_size, [value])
201 return None
202
Enrico Granata385ad4e2012-03-03 00:45:57 +0000203 def _make_helper(self, sbdata, getfunc, itemsize):
204 return self.read_data_helper(sbdata, getfunc, itemsize)
205
206 def _make_helper_uint8(self):
207 return self._make_helper(self, SBData.GetUnsignedInt8, 1)
208
209 def _make_helper_uint16(self):
210 return self._make_helper(self, SBData.GetUnsignedInt16, 2)
211
212 def _make_helper_uint32(self):
213 return self._make_helper(self, SBData.GetUnsignedInt32, 4)
214
215 def _make_helper_uint64(self):
216 return self._make_helper(self, SBData.GetUnsignedInt64, 8)
217
218 def _make_helper_sint8(self):
219 return self._make_helper(self, SBData.GetSignedInt8, 1)
220
221 def _make_helper_sint16(self):
222 return self._make_helper(self, SBData.GetSignedInt16, 2)
223
224 def _make_helper_sint32(self):
225 return self._make_helper(self, SBData.GetSignedInt32, 4)
226
227 def _make_helper_sint64(self):
228 return self._make_helper(self, SBData.GetSignedInt64, 8)
229
230 def _make_helper_float(self):
231 return self._make_helper(self, SBData.GetFloat, 4)
232
233 def _make_helper_double(self):
234 return self._make_helper(self, SBData.GetDouble, 8)
235
236 def _read_all_uint8(self):
237 return self._make_helper_uint8().all()
238
239 def _read_all_uint16(self):
240 return self._make_helper_uint16().all()
241
242 def _read_all_uint32(self):
243 return self._make_helper_uint32().all()
244
245 def _read_all_uint64(self):
246 return self._make_helper_uint64().all()
247
248 def _read_all_sint8(self):
249 return self._make_helper_sint8().all()
250
251 def _read_all_sint16(self):
252 return self._make_helper_sint16().all()
253
254 def _read_all_sint32(self):
255 return self._make_helper_sint32().all()
256
257 def _read_all_sint64(self):
258 return self._make_helper_sint64().all()
259
260 def _read_all_float(self):
261 return self._make_helper_float().all()
262
263 def _read_all_double(self):
264 return self._make_helper_double().all()
265
266 __swig_getmethods__["uint8"] = _make_helper_uint8
Greg Clayton5ef31a92012-06-29 22:00:42 +0000267 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000268
269 __swig_getmethods__["uint16"] = _make_helper_uint16
Greg Clayton5ef31a92012-06-29 22:00:42 +0000270 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000271
272 __swig_getmethods__["uint32"] = _make_helper_uint32
Greg Clayton5ef31a92012-06-29 22:00:42 +0000273 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000274
275 __swig_getmethods__["uint64"] = _make_helper_uint64
Greg Clayton5ef31a92012-06-29 22:00:42 +0000276 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000277
278 __swig_getmethods__["sint8"] = _make_helper_sint8
Greg Clayton5ef31a92012-06-29 22:00:42 +0000279 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000280
281 __swig_getmethods__["sint16"] = _make_helper_sint16
Greg Clayton5ef31a92012-06-29 22:00:42 +0000282 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000283
284 __swig_getmethods__["sint32"] = _make_helper_sint32
Greg Clayton5ef31a92012-06-29 22:00:42 +0000285 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000286
287 __swig_getmethods__["sint64"] = _make_helper_sint64
Greg Clayton5ef31a92012-06-29 22:00:42 +0000288 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000289
290 __swig_getmethods__["float"] = _make_helper_float
Greg Clayton5ef31a92012-06-29 22:00:42 +0000291 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000292
293 __swig_getmethods__["double"] = _make_helper_double
Greg Clayton5ef31a92012-06-29 22:00:42 +0000294 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000295
296 __swig_getmethods__["uint8s"] = _read_all_uint8
Greg Clayton5ef31a92012-06-29 22:00:42 +0000297 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000298
299 __swig_getmethods__["uint16s"] = _read_all_uint16
Greg Clayton5ef31a92012-06-29 22:00:42 +0000300 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000301
302 __swig_getmethods__["uint32s"] = _read_all_uint32
Greg Clayton5ef31a92012-06-29 22:00:42 +0000303 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000304
305 __swig_getmethods__["uint64s"] = _read_all_uint64
Greg Clayton5ef31a92012-06-29 22:00:42 +0000306 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000307
308 __swig_getmethods__["sint8s"] = _read_all_sint8
Greg Clayton5ef31a92012-06-29 22:00:42 +0000309 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000310
311 __swig_getmethods__["sint16s"] = _read_all_sint16
Greg Clayton5ef31a92012-06-29 22:00:42 +0000312 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000313
314 __swig_getmethods__["sint32s"] = _read_all_sint32
Greg Clayton5ef31a92012-06-29 22:00:42 +0000315 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000316
317 __swig_getmethods__["sint64s"] = _read_all_sint64
Greg Clayton5ef31a92012-06-29 22:00:42 +0000318 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000319
320 __swig_getmethods__["floats"] = _read_all_float
Greg Clayton5ef31a92012-06-29 22:00:42 +0000321 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000322
323 __swig_getmethods__["doubles"] = _read_all_double
Greg Clayton5ef31a92012-06-29 22:00:42 +0000324 if _newclass: 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.''')
Enrico Granata385ad4e2012-03-03 00:45:57 +0000325
326 %}
327
328 %pythoncode %{
Greg Clayton13d19502012-01-29 06:07:39 +0000329 __swig_getmethods__["byte_order"] = GetByteOrder
330 __swig_setmethods__["byte_order"] = SetByteOrder
Greg Clayton5ef31a92012-06-29 22:00:42 +0000331 if _newclass: byte_order = property(GetByteOrder, SetByteOrder, doc='''A read/write property getting and setting the endianness of this SBData (data.byte_order = lldb.eByteOrderLittle).''')
Greg Clayton13d19502012-01-29 06:07:39 +0000332
333 __swig_getmethods__["size"] = GetByteSize
Greg Clayton5ef31a92012-06-29 22:00:42 +0000334 if _newclass: size = property(GetByteSize, None, doc='''A read only property that returns the size the same result as GetByteSize().''')
Greg Clayton13d19502012-01-29 06:07:39 +0000335
336 %}
337
Enrico Granata9128ee22011-09-06 19:20:51 +0000338};
339
340} // namespace lldb