blob: f90dd3e1ba23b8f93022fde58524fe04821b1764 [file] [log] [blame]
Enrico Granata91544802011-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 Chen6a388c92011-09-15 22:05:38 +000017 SBData ();
Enrico Granata91544802011-09-06 19:20:51 +000018
Johnny Chen6a388c92011-09-15 22:05:38 +000019 SBData (const SBData &rhs);
Enrico Granata91544802011-09-06 19:20:51 +000020
Johnny Chen6a388c92011-09-15 22:05:38 +000021 ~SBData ();
Enrico Granata91544802011-09-06 19:20:51 +000022
Johnny Chen6a388c92011-09-15 22:05:38 +000023 uint8_t
24 GetAddressByteSize ();
Greg Claytona6b7e322012-01-07 00:45:50 +000025
26 void
27 SetAddressByteSize (uint8_t addr_byte_size);
Enrico Granata91544802011-09-06 19:20:51 +000028
Johnny Chen6a388c92011-09-15 22:05:38 +000029 void
30 Clear ();
Enrico Granata91544802011-09-06 19:20:51 +000031
Johnny Chen6a388c92011-09-15 22:05:38 +000032 bool
33 IsValid();
Enrico Granata91544802011-09-06 19:20:51 +000034
Johnny Chen6a388c92011-09-15 22:05:38 +000035 size_t
36 GetByteSize ();
Enrico Granata91544802011-09-06 19:20:51 +000037
Johnny Chen6a388c92011-09-15 22:05:38 +000038 lldb::ByteOrder
39 GetByteOrder();
Greg Claytona6b7e322012-01-07 00:45:50 +000040
41 void
42 SetByteOrder (lldb::ByteOrder endian);
Enrico Granata91544802011-09-06 19:20:51 +000043
Johnny Chen6a388c92011-09-15 22:05:38 +000044 float
45 GetFloat (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000046
Johnny Chen6a388c92011-09-15 22:05:38 +000047 double
48 GetDouble (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000049
Johnny Chen6a388c92011-09-15 22:05:38 +000050 long double
51 GetLongDouble (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000052
Johnny Chen6a388c92011-09-15 22:05:38 +000053 lldb::addr_t
54 GetAddress (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000055
Johnny Chen6a388c92011-09-15 22:05:38 +000056 uint8_t
57 GetUnsignedInt8 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000058
Johnny Chen6a388c92011-09-15 22:05:38 +000059 uint16_t
60 GetUnsignedInt16 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000061
Johnny Chen6a388c92011-09-15 22:05:38 +000062 uint32_t
63 GetUnsignedInt32 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000064
Johnny Chen6a388c92011-09-15 22:05:38 +000065 uint64_t
66 GetUnsignedInt64 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000067
Johnny Chen6a388c92011-09-15 22:05:38 +000068 int8_t
69 GetSignedInt8 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000070
Johnny Chen6a388c92011-09-15 22:05:38 +000071 int16_t
72 GetSignedInt16 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000073
Johnny Chen6a388c92011-09-15 22:05:38 +000074 int32_t
75 GetSignedInt32 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000076
Johnny Chen6a388c92011-09-15 22:05:38 +000077 int64_t
78 GetSignedInt64 (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000079
Johnny Chen6a388c92011-09-15 22:05:38 +000080 const char*
81 GetString (lldb::SBError& error, uint32_t offset);
Enrico Granata91544802011-09-06 19:20:51 +000082
Johnny Chen6a388c92011-09-15 22:05:38 +000083 bool
Greg Clayton15ef51e2011-09-24 05:04:40 +000084 GetDescription (lldb::SBStream &description, lldb::addr_t base_addr);
Enrico Granata91544802011-09-06 19:20:51 +000085
Johnny Chen6a388c92011-09-15 22:05:38 +000086 size_t
87 ReadRawData (lldb::SBError& error,
88 uint32_t offset,
89 void *buf,
90 size_t size);
Enrico Granata91544802011-09-06 19:20:51 +000091
Johnny Chen6a388c92011-09-15 22:05:38 +000092 void
Greg Claytona6b7e322012-01-07 00:45:50 +000093 SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size);
Johnny Chen6a388c92011-09-15 22:05:38 +000094
95 bool
Greg Claytona6b7e322012-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 Granata91544802011-09-06 19:20:51 +0000135
Greg Clayton1b925202012-01-29 06:07:39 +0000136 %pythoncode %{
Enrico Granatade3b25b2012-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):
159 return self.sbdata.GetByteSize()/self.item_size
160 def all(self):
161 return self[0:len(self)]
162
163 def _make_helper(self, sbdata, getfunc, itemsize):
164 return self.read_data_helper(sbdata, getfunc, itemsize)
165
166 def _make_helper_uint8(self):
167 return self._make_helper(self, SBData.GetUnsignedInt8, 1)
168
169 def _make_helper_uint16(self):
170 return self._make_helper(self, SBData.GetUnsignedInt16, 2)
171
172 def _make_helper_uint32(self):
173 return self._make_helper(self, SBData.GetUnsignedInt32, 4)
174
175 def _make_helper_uint64(self):
176 return self._make_helper(self, SBData.GetUnsignedInt64, 8)
177
178 def _make_helper_sint8(self):
179 return self._make_helper(self, SBData.GetSignedInt8, 1)
180
181 def _make_helper_sint16(self):
182 return self._make_helper(self, SBData.GetSignedInt16, 2)
183
184 def _make_helper_sint32(self):
185 return self._make_helper(self, SBData.GetSignedInt32, 4)
186
187 def _make_helper_sint64(self):
188 return self._make_helper(self, SBData.GetSignedInt64, 8)
189
190 def _make_helper_float(self):
191 return self._make_helper(self, SBData.GetFloat, 4)
192
193 def _make_helper_double(self):
194 return self._make_helper(self, SBData.GetDouble, 8)
195
196 def _read_all_uint8(self):
197 return self._make_helper_uint8().all()
198
199 def _read_all_uint16(self):
200 return self._make_helper_uint16().all()
201
202 def _read_all_uint32(self):
203 return self._make_helper_uint32().all()
204
205 def _read_all_uint64(self):
206 return self._make_helper_uint64().all()
207
208 def _read_all_sint8(self):
209 return self._make_helper_sint8().all()
210
211 def _read_all_sint16(self):
212 return self._make_helper_sint16().all()
213
214 def _read_all_sint32(self):
215 return self._make_helper_sint32().all()
216
217 def _read_all_sint64(self):
218 return self._make_helper_sint64().all()
219
220 def _read_all_float(self):
221 return self._make_helper_float().all()
222
223 def _read_all_double(self):
224 return self._make_helper_double().all()
225
226 __swig_getmethods__["uint8"] = _make_helper_uint8
227 if _newclass: uint8 = property(_make_helper_uint8, None, doc='Returns an array-like object out of which you can read uint8 values')
228
229 __swig_getmethods__["uint16"] = _make_helper_uint16
230 if _newclass: uint16 = property(_make_helper_uint16, None, doc='Returns an array-like object out of which you can read uint16 values')
231
232 __swig_getmethods__["uint32"] = _make_helper_uint32
233 if _newclass: uint32 = property(_make_helper_uint32, None, doc='Returns an array-like object out of which you can read uint32 values')
234
235 __swig_getmethods__["uint64"] = _make_helper_uint64
236 if _newclass: uint64 = property(_make_helper_uint64, None, doc='Returns an array-like object out of which you can read uint64 values')
237
238 __swig_getmethods__["sint8"] = _make_helper_sint8
239 if _newclass: sint8 = property(_make_helper_sint8, None, doc='Returns an array-like object out of which you can read sint8 values')
240
241 __swig_getmethods__["sint16"] = _make_helper_sint16
242 if _newclass: sint16 = property(_make_helper_sint16, None, doc='Returns an array-like object out of which you can read sint16 values')
243
244 __swig_getmethods__["sint32"] = _make_helper_sint32
245 if _newclass: sint32 = property(_make_helper_sint32, None, doc='Returns an array-like object out of which you can read sint32 values')
246
247 __swig_getmethods__["sint64"] = _make_helper_sint64
248 if _newclass: sint64 = property(_make_helper_sint64, None, doc='Returns an array-like object out of which you can read sint64 values')
249
250 __swig_getmethods__["float"] = _make_helper_float
251 if _newclass: float = property(_make_helper_float, None, doc='Returns an array-like object out of which you can read float values')
252
253 __swig_getmethods__["double"] = _make_helper_double
254 if _newclass: double = property(_make_helper_double, None, doc='Returns an array-like object out of which you can read double values')
255
256 __swig_getmethods__["uint8s"] = _read_all_uint8
257 if _newclass: uint8s = property(_read_all_uint8, None, doc='Returns an array with all the contents of this SBData represented as uint8 values')
258
259 __swig_getmethods__["uint16s"] = _read_all_uint16
260 if _newclass: uint16s = property(_read_all_uint16, None, doc='Returns an array with all the contents of this SBData represented as uint16 values')
261
262 __swig_getmethods__["uint32s"] = _read_all_uint32
263 if _newclass: uint32s = property(_read_all_uint32, None, doc='Returns an array with all the contents of this SBData represented as uint32 values')
264
265 __swig_getmethods__["uint64s"] = _read_all_uint64
266 if _newclass: uint64s = property(_read_all_uint64, None, doc='Returns an array with all the contents of this SBData represented as uint64 values')
267
268 __swig_getmethods__["sint8s"] = _read_all_sint8
269 if _newclass: sint8s = property(_read_all_sint8, None, doc='Returns an array with all the contents of this SBData represented as sint8 values')
270
271 __swig_getmethods__["sint16s"] = _read_all_sint16
272 if _newclass: sint16s = property(_read_all_sint16, None, doc='Returns an array with all the contents of this SBData represented as sint16 values')
273
274 __swig_getmethods__["sint32s"] = _read_all_sint32
275 if _newclass: sint32s = property(_read_all_sint32, None, doc='Returns an array with all the contents of this SBData represented as sint32 values')
276
277 __swig_getmethods__["sint64s"] = _read_all_sint64
278 if _newclass: sint64s = property(_read_all_sint64, None, doc='Returns an array with all the contents of this SBData represented as sint64 values')
279
280 __swig_getmethods__["floats"] = _read_all_float
281 if _newclass: floats = property(_read_all_float, None, doc='Returns an array with all the contents of this SBData represented as float values')
282
283 __swig_getmethods__["doubles"] = _read_all_double
284 if _newclass: doubles = property(_read_all_double, None, doc='Returns an array with all the contents of this SBData represented as double values')
285
286 %}
287
288 %pythoncode %{
Greg Clayton1b925202012-01-29 06:07:39 +0000289 __swig_getmethods__["byte_order"] = GetByteOrder
290 __swig_setmethods__["byte_order"] = SetByteOrder
Enrico Granatade3b25b2012-03-03 00:45:57 +0000291 if _newclass: byte_order = property(GetByteOrder, SetByteOrder, doc='Allows getting and setting the endianness of this SBData object')
Greg Clayton1b925202012-01-29 06:07:39 +0000292
293 __swig_getmethods__["size"] = GetByteSize
Enrico Granatade3b25b2012-03-03 00:45:57 +0000294 if _newclass: size = property(GetByteSize, None, doc='Returns the size (in bytes) of the contents of this SBData object')
Greg Clayton1b925202012-01-29 06:07:39 +0000295
296 %}
297
Enrico Granata91544802011-09-06 19:20:51 +0000298};
299
300} // namespace lldb