1//===-- 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 17 SBData (); 18 19 SBData (const SBData &rhs); 20 21 ~SBData (); 22 23 uint8_t 24 GetAddressByteSize (); 25 26 void 27 SetAddressByteSize (uint8_t addr_byte_size); 28 29 void 30 Clear (); 31 32 bool 33 IsValid(); 34 35 size_t 36 GetByteSize (); 37 38 lldb::ByteOrder 39 GetByteOrder(); 40 41 void 42 SetByteOrder (lldb::ByteOrder endian); 43 44 float 45 GetFloat (lldb::SBError& error, lldb::offset_t offset); 46 47 double 48 GetDouble (lldb::SBError& error, lldb::offset_t offset); 49 50 long double 51 GetLongDouble (lldb::SBError& error, lldb::offset_t offset); 52 53 lldb::addr_t 54 GetAddress (lldb::SBError& error, lldb::offset_t offset); 55 56 uint8_t 57 GetUnsignedInt8 (lldb::SBError& error, lldb::offset_t offset); 58 59 uint16_t 60 GetUnsignedInt16 (lldb::SBError& error, lldb::offset_t offset); 61 62 uint32_t 63 GetUnsignedInt32 (lldb::SBError& error, lldb::offset_t offset); 64 65 uint64_t 66 GetUnsignedInt64 (lldb::SBError& error, lldb::offset_t offset); 67 68 int8_t 69 GetSignedInt8 (lldb::SBError& error, lldb::offset_t offset); 70 71 int16_t 72 GetSignedInt16 (lldb::SBError& error, lldb::offset_t offset); 73 74 int32_t 75 GetSignedInt32 (lldb::SBError& error, lldb::offset_t offset); 76 77 int64_t 78 GetSignedInt64 (lldb::SBError& error, lldb::offset_t offset); 79 80 const char* 81 GetString (lldb::SBError& error, lldb::offset_t offset); 82 83 bool 84 GetDescription (lldb::SBStream &description, lldb::addr_t base_addr); 85 86 size_t 87 ReadRawData (lldb::SBError& error, 88 lldb::offset_t offset, 89 void *buf, 90 size_t size); 91 92 void 93 SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size); 94 95 bool 96 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); 135 136 %pythoncode %{ 137 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 int(self.sbdata.GetByteSize()/self.item_size) 160 def all(self): 161 return self[0:len(self)] 162 163 @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 203 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 267 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.''') 268 269 __swig_getmethods__["uint16"] = _make_helper_uint16 270 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.''') 271 272 __swig_getmethods__["uint32"] = _make_helper_uint32 273 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.''') 274 275 __swig_getmethods__["uint64"] = _make_helper_uint64 276 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.''') 277 278 __swig_getmethods__["sint8"] = _make_helper_sint8 279 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.''') 280 281 __swig_getmethods__["sint16"] = _make_helper_sint16 282 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.''') 283 284 __swig_getmethods__["sint32"] = _make_helper_sint32 285 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.''') 286 287 __swig_getmethods__["sint64"] = _make_helper_sint64 288 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.''') 289 290 __swig_getmethods__["float"] = _make_helper_float 291 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.''') 292 293 __swig_getmethods__["double"] = _make_helper_double 294 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.''') 295 296 __swig_getmethods__["uint8s"] = _read_all_uint8 297 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.''') 298 299 __swig_getmethods__["uint16s"] = _read_all_uint16 300 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.''') 301 302 __swig_getmethods__["uint32s"] = _read_all_uint32 303 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.''') 304 305 __swig_getmethods__["uint64s"] = _read_all_uint64 306 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.''') 307 308 __swig_getmethods__["sint8s"] = _read_all_sint8 309 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.''') 310 311 __swig_getmethods__["sint16s"] = _read_all_sint16 312 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.''') 313 314 __swig_getmethods__["sint32s"] = _read_all_sint32 315 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.''') 316 317 __swig_getmethods__["sint64s"] = _read_all_sint64 318 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.''') 319 320 __swig_getmethods__["floats"] = _read_all_float 321 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.''') 322 323 __swig_getmethods__["doubles"] = _read_all_double 324 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.''') 325 326 %} 327 328 %pythoncode %{ 329 __swig_getmethods__["byte_order"] = GetByteOrder 330 __swig_setmethods__["byte_order"] = SetByteOrder 331 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).''') 332 333 __swig_getmethods__["size"] = GetByteSize 334 if _newclass: size = property(GetByteSize, None, doc='''A read only property that returns the size the same result as GetByteSize().''') 335 336 %} 337 338}; 339 340} // namespace lldb 341