1 //===-- SWIG Interface for SBType -------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 "Represents a member of a type in lldb.") SBTypeMember;
19 SBTypeMember (const lldb::SBTypeMember& rhs);
26 explicit operator bool() const;
44 GetBitfieldSizeInBits();
46 STRING_EXTENSION_LEVEL(SBTypeMember, lldb::eDescriptionLevelBrief)
50 name = property(GetName, None, doc='''A read only property that returns the name for this member as a string.''')
51 type = property(GetType, None, doc='''A read only property that returns an lldb object that represents the type (lldb.SBType) for this member.''')
52 byte_offset = property(GetOffsetInBytes, None, doc='''A read only property that returns offset in bytes for this member as an integer.''')
53 bit_offset = property(GetOffsetInBits, None, doc='''A read only property that returns offset in bits for this member as an integer.''')
54 is_bitfield = property(IsBitfield, None, doc='''A read only property that returns true if this member is a bitfield.''')
55 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.''')
60 std::unique_ptr<lldb_private::TypeMemberImpl> m_opaque_ap;
63 class SBTypeMemberFunction
66 SBTypeMemberFunction ();
68 SBTypeMemberFunction (const lldb::SBTypeMemberFunction& rhs);
70 ~SBTypeMemberFunction();
75 explicit operator bool() const;
93 GetNumberOfArguments ();
96 GetArgumentTypeAtIndex (uint32_t);
98 lldb::MemberFunctionKind
102 GetDescription (lldb::SBStream &description,
103 lldb::DescriptionLevel description_level);
105 STRING_EXTENSION_LEVEL(SBTypeMemberFunction, lldb::eDescriptionLevelBrief)
107 lldb::TypeMemberFunctionImplSP m_opaque_sp;
110 %feature("docstring",
111 "Represents a data type in lldb. The FindFirstType() method of SBTarget/SBModule
114 SBType supports the eq/ne operator. For example,
122 Task(int i, Task *n):
128 int main (int argc, char const *argv[])
130 Task *task_head = new Task(-1, NULL);
131 Task *task1 = new Task(1, NULL);
132 Task *task2 = new Task(2, NULL);
133 Task *task3 = new Task(3, NULL); // Orphaned.
134 Task *task4 = new Task(4, NULL);
135 Task *task5 = new Task(5, NULL);
137 task_head->next = task1;
149 printf('We have a total number of %d tasks\\n', total);
151 // This corresponds to an empty task list.
152 Task *empty_task_head = new Task(-1, NULL);
154 return 0; // Break at this line
159 # Get the type 'Task'.
160 task_type = target.FindFirstType('Task')
161 self.assertTrue(task_type)
163 # Get the variable 'task_head'.
164 frame0.FindVariable('task_head')
165 task_head_type = task_head.GetType()
166 self.assertTrue(task_head_type.IsPointerType())
168 # task_head_type is 'Task *'.
169 task_pointer_type = task_type.GetPointerType()
170 self.assertTrue(task_head_type == task_pointer_type)
172 # Get the child mmember 'id' from 'task_head'.
173 id = task_head.GetChildMemberWithName('id')
174 id_type = id.GetType()
176 # SBType.GetBasicType() takes an enum 'BasicType' (lldb-enumerations.h).
177 int_type = id_type.GetBasicType(lldb.eBasicTypeInt)
178 # id_type and int_type should be the same type!
179 self.assertTrue(id_type == int_type)
187 SBType (const lldb::SBType &rhs);
194 explicit operator bool() const;
209 IsPolymorphicClass ();
233 SBType::GetTypedefedType();
236 GetDereferencedType();
239 GetUnqualifiedType();
245 GetArrayElementType ();
248 GetArrayType (uint64_t size);
251 GetVectorElementType ();
257 GetBasicType (lldb::BasicType type);
260 GetNumberOfFields ();
263 GetNumberOfDirectBaseClasses ();
266 GetNumberOfVirtualBaseClasses ();
269 GetFieldAtIndex (uint32_t idx);
272 GetDirectBaseClassAtIndex (uint32_t idx);
275 GetVirtualBaseClassAtIndex (uint32_t idx);
277 lldb::SBTypeEnumMemberList
284 GetDisplayTypeName ();
290 GetNumberOfTemplateArguments ();
293 GetTemplateArgumentType (uint32_t idx);
295 lldb::TemplateArgumentKind
296 GetTemplateArgumentKind (uint32_t idx);
299 GetFunctionReturnType ();
302 GetFunctionArgumentTypes ();
305 GetNumberOfMemberFunctions ();
307 lldb::SBTypeMemberFunction
308 GetMemberFunctionAtIndex (uint32_t idx);
316 bool operator==(lldb::SBType &rhs);
318 bool operator!=(lldb::SBType &rhs);
320 STRING_EXTENSION_LEVEL(SBType, lldb::eDescriptionLevelBrief)
324 def template_arg_array(self):
325 num_args = self.num_template_args
328 for i in range(num_args):
329 template_args.append(self.GetTemplateArgumentType(i))
333 name = property(GetName, None, doc='''A read only property that returns the name for this type as a string.''')
334 size = property(GetByteSize, None, doc='''A read only property that returns size in bytes for this type as an integer.''')
335 is_pointer = property(IsPointerType, None, doc='''A read only property that returns a boolean value that indicates if this type is a pointer type.''')
336 is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a reference type.''')
337 is_reference = property(IsReferenceType, None, doc='''A read only property that returns a boolean value that indicates if this type is a function type.''')
338 num_fields = property(GetNumberOfFields, None, doc='''A read only property that returns number of fields in this type as an integer.''')
339 num_bases = property(GetNumberOfDirectBaseClasses, None, doc='''A read only property that returns number of direct base classes in this type as an integer.''')
340 num_vbases = property(GetNumberOfVirtualBaseClasses, None, doc='''A read only property that returns number of virtual base classes in this type as an integer.''')
341 num_template_args = property(GetNumberOfTemplateArguments, None, doc='''A read only property that returns number of template arguments in this type as an integer.''')
342 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.''')
343 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.''')
344 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).''')
346 def get_bases_array(self):
347 '''An accessor function that returns a list() that contains all direct base classes in a lldb.SBType object.'''
349 for idx in range(self.GetNumberOfDirectBaseClasses()):
350 bases.append(self.GetDirectBaseClassAtIndex(idx))
353 def get_vbases_array(self):
354 '''An accessor function that returns a list() that contains all fields in a lldb.SBType object.'''
356 for idx in range(self.GetNumberOfVirtualBaseClasses()):
357 vbases.append(self.GetVirtualBaseClassAtIndex(idx))
360 def get_fields_array(self):
361 '''An accessor function that returns a list() that contains all fields in a lldb.SBType object.'''
363 for idx in range(self.GetNumberOfFields()):
364 fields.append(self.GetFieldAtIndex(idx))
367 def get_members_array(self):
368 '''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.'''
370 bases = self.get_bases_array()
371 fields = self.get_fields_array()
372 vbases = self.get_vbases_array()
374 bit_offset = base.bit_offset
376 for idx, member in enumerate(members):
377 if member.bit_offset > bit_offset:
378 members.insert(idx, base)
384 bit_offset = vbase.bit_offset
386 for idx, member in enumerate(members):
387 if member.bit_offset > bit_offset:
388 members.insert(idx, vbase)
392 members.append(vbase)
394 bit_offset = field.bit_offset
396 for idx, member in enumerate(members):
397 if member.bit_offset > bit_offset:
398 members.insert(idx, field)
402 members.append(field)
405 def get_enum_members_array(self):
406 '''An accessor function that returns a list() that contains all enum members in an lldb.SBType object.'''
407 enum_members_list = []
408 sb_enum_members = self.GetEnumMembers()
409 for idx in range(sb_enum_members.GetSize()):
410 enum_members_list.append(sb_enum_members.GetTypeEnumMemberAtIndex(idx))
411 return enum_members_list
413 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.''')
414 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.''')
415 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.''')
416 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.''')
417 enum_members = property(get_enum_members_array, None, doc='''A read only property that returns a list() of all lldb.SBTypeEnumMember objects that represent the enum members for this type.''')
423 %feature("docstring",
424 "Represents a list of SBTypes. The FindTypes() method of SBTarget/SBModule
425 returns a SBTypeList.
427 SBTypeList supports SBType iteration. For example,
435 Task(int i, Task *n):
445 # Get the type 'Task'.
446 type_list = target.FindTypes('Task')
447 self.assertTrue(len(type_list) == 1)
448 # To illustrate the SBType iteration.
449 for type in type_list:
450 # do something with type
461 explicit operator bool() const;
464 Append (lldb::SBType type);
467 GetTypeAtIndex (uint32_t index);
477 '''Iterate over all types in a lldb.SBTypeList object.'''
478 return lldb_iter(self, 'GetSize', 'GetTypeAtIndex')
481 '''Return the number of types in a lldb.SBTypeList object.'''
482 return self.GetSize()