Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 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 | |
| 11 | namespace lldb { |
| 12 | |
| 13 | class SBData |
| 14 | { |
| 15 | public: |
| 16 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 17 | SBData (); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 18 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 19 | SBData (const SBData &rhs); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 20 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 21 | ~SBData (); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 22 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 23 | uint8_t |
| 24 | GetAddressByteSize (); |
Greg Clayton | a6b7e32 | 2012-01-07 00:45:50 +0000 | [diff] [blame] | 25 | |
| 26 | void |
| 27 | SetAddressByteSize (uint8_t addr_byte_size); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 28 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 29 | void |
| 30 | Clear (); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 31 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 32 | bool |
| 33 | IsValid(); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 34 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 35 | size_t |
| 36 | GetByteSize (); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 37 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 38 | lldb::ByteOrder |
| 39 | GetByteOrder(); |
Greg Clayton | a6b7e32 | 2012-01-07 00:45:50 +0000 | [diff] [blame] | 40 | |
| 41 | void |
| 42 | SetByteOrder (lldb::ByteOrder endian); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 43 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 44 | float |
| 45 | GetFloat (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 46 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 47 | double |
| 48 | GetDouble (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 49 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 50 | long double |
| 51 | GetLongDouble (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 52 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 53 | lldb::addr_t |
| 54 | GetAddress (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 55 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 56 | uint8_t |
| 57 | GetUnsignedInt8 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 58 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 59 | uint16_t |
| 60 | GetUnsignedInt16 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 61 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 62 | uint32_t |
| 63 | GetUnsignedInt32 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 64 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 65 | uint64_t |
| 66 | GetUnsignedInt64 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 67 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 68 | int8_t |
| 69 | GetSignedInt8 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 70 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 71 | int16_t |
| 72 | GetSignedInt16 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 73 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 74 | int32_t |
| 75 | GetSignedInt32 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 76 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 77 | int64_t |
| 78 | GetSignedInt64 (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 79 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 80 | const char* |
| 81 | GetString (lldb::SBError& error, uint32_t offset); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 82 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 83 | bool |
Greg Clayton | 15ef51e | 2011-09-24 05:04:40 +0000 | [diff] [blame] | 84 | GetDescription (lldb::SBStream &description, lldb::addr_t base_addr); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 85 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 86 | size_t |
| 87 | ReadRawData (lldb::SBError& error, |
| 88 | uint32_t offset, |
| 89 | void *buf, |
| 90 | size_t size); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 91 | |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 92 | void |
Greg Clayton | a6b7e32 | 2012-01-07 00:45:50 +0000 | [diff] [blame] | 93 | SetData (lldb::SBError& error, const void *buf, size_t size, lldb::ByteOrder endian, uint8_t addr_size); |
Johnny Chen | 6a388c9 | 2011-09-15 22:05:38 +0000 | [diff] [blame] | 94 | |
| 95 | bool |
Greg Clayton | a6b7e32 | 2012-01-07 00:45:50 +0000 | [diff] [blame] | 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); |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 135 | |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 136 | %pythoncode %{ |
Enrico Granata | de3b25b | 2012-03-03 00:45:57 +0000 | [diff] [blame^] | 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 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 Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 289 | __swig_getmethods__["byte_order"] = GetByteOrder |
| 290 | __swig_setmethods__["byte_order"] = SetByteOrder |
Enrico Granata | de3b25b | 2012-03-03 00:45:57 +0000 | [diff] [blame^] | 291 | if _newclass: byte_order = property(GetByteOrder, SetByteOrder, doc='Allows getting and setting the endianness of this SBData object') |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 292 | |
| 293 | __swig_getmethods__["size"] = GetByteSize |
Enrico Granata | de3b25b | 2012-03-03 00:45:57 +0000 | [diff] [blame^] | 294 | if _newclass: size = property(GetByteSize, None, doc='Returns the size (in bytes) of the contents of this SBData object') |
Greg Clayton | 1b92520 | 2012-01-29 06:07:39 +0000 | [diff] [blame] | 295 | |
| 296 | %} |
| 297 | |
Enrico Granata | 9154480 | 2011-09-06 19:20:51 +0000 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | } // namespace lldb |