1//===-- SWIG Interface for SBType -------------------------------*- 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 10namespace lldb { 11 12 %feature("docstring", 13"Represents a member of a type in lldb. 14") SBTypeMember; 15 16class SBTypeMember 17{ 18public: 19 SBTypeMember (); 20 21 SBTypeMember (const lldb::SBTypeMember& rhs); 22 23 ~SBTypeMember(); 24 25 bool 26 IsValid() const; 27 28 const char * 29 GetName (); 30 31 lldb::SBType 32 GetType (); 33 34 uint64_t 35 GetOffsetInBytes(); 36 37 uint64_t 38 GetOffsetInBits(); 39 40 bool 41 IsBitfield(); 42 43 uint32_t 44 GetBitfieldSizeInBits(); 45 46 %pythoncode %{ 47 __swig_getmethods__["name"] = GetName 48 if _newclass: name = property(GetName, None, doc='''A read only property that returns the name for this member as a string.''') 49 50 __swig_getmethods__["type"] = GetType 51 if _newclass: type = property(GetType, None, doc='''A read only property that returns an lldb object that represents the type (lldb.SBType) for this member.''') 52 53 __swig_getmethods__["byte_offset"] = GetOffsetInBytes 54 if _newclass: byte_offset = property(GetOffsetInBytes, None, doc='''A read only property that returns offset in bytes for this member as an integer.''') 55 56 __swig_getmethods__["bit_offset"] = GetOffsetInBits 57 if _newclass: bit_offset = property(GetOffsetInBits, None, doc='''A read only property that returns offset in bits for this member as an integer.''') 58 59 __swig_getmethods__["is_bitfield"] = IsBitfield 60 if _newclass: is_bitfield = property(IsBitfield, None, doc='''A read only property that returns true if this member is a bitfield.''') 61 62 __swig_getmethods__["bitfield_bit_size"] = GetBitfieldSizeInBits 63 if _newclass: bitfield_bit_size = property(GetBitfieldSizeInBits, None, doc='''A read only property that returns the bitfield size in bits for this member as an integer, or zero if this member is not a bitfield.''') 64 65 %} 66 67protected: 68 std::unique_ptr<lldb_private::TypeMemberImpl> m_opaque_ap; 69}; 70 71%feature("docstring", 72"Represents a data type in lldb. The FindFirstType() method of SBTarget/SBModule 73returns a SBType. 74 75SBType supports the eq/ne operator. For example, 76 77main.cpp: 78 79class Task { 80public: 81 int id; 82 Task *next; 83 Task(int i, Task *n): 84 id(i), 85 next(n) 86 {} 87}; 88 89int main (int argc, char const *argv[]) 90{ 91 Task *task_head = new Task(-1, NULL); 92 Task *task1 = new Task(1, NULL); 93 Task *task2 = new Task(2, NULL); 94 Task *task3 = new Task(3, NULL); // Orphaned. 95 Task *task4 = new Task(4, NULL); 96 Task *task5 = new Task(5, NULL); 97 98 task_head->next = task1; 99 task1->next = task2; 100 task2->next = task4; 101 task4->next = task5; 102 103 int total = 0; 104 Task *t = task_head; 105 while (t != NULL) { 106 if (t->id >= 0) 107 ++total; 108 t = t->next; 109 } 110 printf('We have a total number of %d tasks\\n', total); 111 112 // This corresponds to an empty task list. 113 Task *empty_task_head = new Task(-1, NULL); 114 115 return 0; // Break at this line 116} 117 118find_type.py: 119 120 # Get the type 'Task'. 121 task_type = target.FindFirstType('Task') 122 self.assertTrue(task_type) 123 124 # Get the variable 'task_head'. 125 frame0.FindVariable('task_head') 126 task_head_type = task_head.GetType() 127 self.assertTrue(task_head_type.IsPointerType()) 128 129 # task_head_type is 'Task *'. 130 task_pointer_type = task_type.GetPointerType() 131 self.assertTrue(task_head_type == task_pointer_type) 132 133 # Get the child mmember 'id' from 'task_head'. 134 id = task_head.GetChildMemberWithName('id') 135 id_type = id.GetType() 136 137 # SBType.GetBasicType() takes an enum 'BasicType' (lldb-enumerations.h). 138 int_type = id_type.GetBasicType(lldb.eBasicTypeInt) 139 # id_type and int_type should be the same type! 140 self.assertTrue(id_type == int_type) 141 142... 143") SBType; 144class SBType 145{ 146public: 147 SBType (); 148 149 SBType (const lldb::SBType &rhs); 150 151 ~SBType (); 152 153 bool 154 IsValid(); 155 156 uint64_t 157 GetByteSize(); 158 159 bool 160 IsPointerType(); 161 162 bool 163 IsReferenceType(); 164 165 bool 166 IsFunctionType (); 167 168 bool 169 IsPolymorphicClass (); 170 171 lldb::SBType 172 GetPointerType(); 173 174 lldb::SBType 175 GetPointeeType(); 176 177 lldb::SBType 178 GetReferenceType(); 179 180 lldb::SBType 181 GetDereferencedType(); 182 183 lldb::SBType 184 GetUnqualifiedType(); 185 186 lldb::SBType 187 GetCanonicalType(); 188 189 lldb::BasicType 190 GetBasicType(); 191 192 lldb::SBType 193 GetBasicType (lldb::BasicType type); 194 195 uint32_t 196 GetNumberOfFields (); 197 198 uint32_t 199 GetNumberOfDirectBaseClasses (); 200 201 uint32_t 202 GetNumberOfVirtualBaseClasses (); 203 204 lldb::SBTypeMember 205 GetFieldAtIndex (uint32_t idx); 206 207 lldb::SBTypeMember 208 GetDirectBaseClassAtIndex (uint32_t idx); 209 210 lldb::SBTypeMember 211 GetVirtualBaseClassAtIndex (uint32_t idx); 212 213 const char* 214 GetName(); 215 216 lldb::TypeClass 217 GetTypeClass (); 218 219 uint32_t 220 GetNumberOfTemplateArguments (); 221 222 lldb::SBType 223 GetTemplateArgumentType (uint32_t idx); 224 225 lldb::TemplateArgumentKind 226 GetTemplateArgumentKind (uint32_t idx); 227 228 lldb::SBType 229 GetFunctionReturnType (); 230 231 lldb::SBTypeList 232 GetFunctionArgumentTypes (); 233 234 bool 235 IsTypeComplete (); 236 237 %pythoncode %{ 238 def template_arg_array(self): 239 num_args = self.num_template_args 240 if num_args: 241 template_args = [] 242 for i in range(num_args): 243 template_args.append(self.GetTemplateArgumentType(i)) 244 return template_args 245 return None 246 247 __swig_getmethods__["name"] = GetName 248 if _newclass: name = property(GetName, None, doc='''A read only property that returns the name for this type as a string.''') 249 250 __swig_getmethods__["size"] = GetByteSize 251 if _newclass: size = property(GetByteSize, None, doc='''A read only property that returns size in bytes for this type as an integer.''') 252 253 __swig_getmethods__["is_pointer"] = IsPointerType 254 if _newclass: is_pointer = property(IsPointerType, None, doc='''A read only property that returns a boolean value that indicates if this type is a pointer type.''') 255 256 __swig_getmethods__["is_reference"] = IsReferenceType 257 if _newclass: is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a reference type.''') 258 259 __swig_getmethods__["is_function"] = IsFunctionType 260 if _newclass: is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a function type.''') 261 262 __swig_getmethods__["num_fields"] = GetNumberOfFields 263 if _newclass: num_fields = property(GetNumberOfFields, None, doc='''A read only property that returns number of fields in this type as an integer.''') 264 265 __swig_getmethods__["num_bases"] = GetNumberOfDirectBaseClasses 266 if _newclass: num_bases = property(GetNumberOfDirectBaseClasses, None, doc='''A read only property that returns number of direct base classes in this type as an integer.''') 267 268 __swig_getmethods__["num_vbases"] = GetNumberOfVirtualBaseClasses 269 if _newclass: num_vbases = property(GetNumberOfVirtualBaseClasses, None, doc='''A read only property that returns number of virtual base classes in this type as an integer.''') 270 271 __swig_getmethods__["num_template_args"] = GetNumberOfTemplateArguments 272 if _newclass: num_template_args = property(GetNumberOfTemplateArguments, None, doc='''A read only property that returns number of template arguments in this type as an integer.''') 273 274 __swig_getmethods__["template_args"] = template_arg_array 275 if _newclass: template_args = property(template_arg_array, None, doc='''A read only property that returns a list() of lldb.SBType objects that represent all template arguments in this type.''') 276 277 __swig_getmethods__["type"] = GetTypeClass 278 if _newclass: type = property(GetTypeClass, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eTypeClass") that represents a classification for this type.''') 279 280 __swig_getmethods__["is_complete"] = IsTypeComplete 281 if _newclass: is_complete = property(IsTypeComplete, None, doc='''A read only property that returns a boolean value that indicates if this type is a complete type (True) or a forward declaration (False).''') 282 283 def get_bases_array(self): 284 '''An accessor function that returns a list() that contains all direct base classes in a lldb.SBType object.''' 285 bases = [] 286 for idx in range(self.GetNumberOfDirectBaseClasses()): 287 bases.append(self.GetDirectBaseClassAtIndex(idx)) 288 return bases 289 290 def get_vbases_array(self): 291 '''An accessor function that returns a list() that contains all fields in a lldb.SBType object.''' 292 vbases = [] 293 for idx in range(self.GetNumberOfVirtualBaseClasses()): 294 vbases.append(self.GetVirtualBaseClassAtIndex(idx)) 295 return vbases 296 297 def get_fields_array(self): 298 '''An accessor function that returns a list() that contains all fields in a lldb.SBType object.''' 299 fields = [] 300 for idx in range(self.GetNumberOfFields()): 301 fields.append(self.GetFieldAtIndex(idx)) 302 return fields 303 304 def get_members_array(self): 305 '''An accessor function that returns a list() that contains all members (base classes and fields) in a lldb.SBType object in ascending bit offset order.''' 306 members = [] 307 bases = self.get_bases_array() 308 fields = self.get_fields_array() 309 vbases = self.get_vbases_array() 310 for base in bases: 311 bit_offset = base.bit_offset 312 added = False 313 for idx, member in enumerate(members): 314 if member.bit_offset > bit_offset: 315 members.insert(idx, base) 316 added = True 317 break 318 if not added: 319 members.append(base) 320 for vbase in vbases: 321 bit_offset = vbase.bit_offset 322 added = False 323 for idx, member in enumerate(members): 324 if member.bit_offset > bit_offset: 325 members.insert(idx, vbase) 326 added = True 327 break 328 if not added: 329 members.append(vbase) 330 for field in fields: 331 bit_offset = field.bit_offset 332 added = False 333 for idx, member in enumerate(members): 334 if member.bit_offset > bit_offset: 335 members.insert(idx, field) 336 added = True 337 break 338 if not added: 339 members.append(field) 340 return members 341 342 __swig_getmethods__["bases"] = get_bases_array 343 if _newclass: bases = property(get_bases_array, None, doc='''A read only property that returns a list() of lldb.SBTypeMember objects that represent all of the direct base classes for this type.''') 344 345 __swig_getmethods__["vbases"] = get_vbases_array 346 if _newclass: vbases = property(get_vbases_array, None, doc='''A read only property that returns a list() of lldb.SBTypeMember objects that represent all of the virtual base classes for this type.''') 347 348 __swig_getmethods__["fields"] = get_fields_array 349 if _newclass: fields = property(get_fields_array, None, doc='''A read only property that returns a list() of lldb.SBTypeMember objects that represent all of the fields for this type.''') 350 351 __swig_getmethods__["members"] = get_members_array 352 if _newclass: members = property(get_members_array, None, doc='''A read only property that returns a list() of all lldb.SBTypeMember objects that represent all of the base classes, virtual base classes and fields for this type in ascending bit offset order.''') 353 354 %} 355 356}; 357 358%feature("docstring", 359"Represents a list of SBTypes. The FindTypes() method of SBTarget/SBModule 360returns a SBTypeList. 361 362SBTypeList supports SBType iteration. For example, 363 364main.cpp: 365 366class Task { 367public: 368 int id; 369 Task *next; 370 Task(int i, Task *n): 371 id(i), 372 next(n) 373 {} 374}; 375 376... 377 378find_type.py: 379 380 # Get the type 'Task'. 381 type_list = target.FindTypes('Task') 382 self.assertTrue(len(type_list) == 1) 383 # To illustrate the SBType iteration. 384 for type in type_list: 385 # do something with type 386 387... 388") SBTypeList; 389class SBTypeList 390{ 391public: 392 SBTypeList(); 393 394 bool 395 IsValid(); 396 397 void 398 Append (lldb::SBType type); 399 400 lldb::SBType 401 GetTypeAtIndex (uint32_t index); 402 403 uint32_t 404 GetSize(); 405 406 ~SBTypeList(); 407}; 408 409} // namespace lldb 410