Next: Pretty Printing, Previous: Values From Inferior, Up: Python API
gdb represents types from the inferior using the class
gdb.Type.
The following type-related functions are available in the gdb
module:
This function looks up a type by name. name is the name of the type to look up. It must be a string.
Ordinarily, this function will return an instance of
gdb.Type. If the named type cannot be found, it will throw an exception.
An instance of Type has the following attributes:
The type code for this type. The type code will be one of the
TYPE_CODE_constants defined below.
The following methods are provided:
For structure and union types, this method returns the fields. Range types have two fields, the minimum and maximum values. Enum types have one field per enum constant. Function and method types have one field per parameter. The base types of C++ classes are also represented as fields. If the type has no fields, or does not fit into one of these categories, an empty sequence will be returned.
Each field is an object, with some pre-defined attributes:
bitpos- This attribute is not available for
staticfields (as in C++ or Java). For non-staticfields, the value is the bit position of the field.name- The name of the field, or
Nonefor anonymous fields.artificial- This is
Trueif the field is artificial, usually meaning that it was provided by the compiler and not the user. This attribute is always provided, and isFalseif the field is not artificial.bitsize- If the field is packed, or is a bitfield, then this will have a non-zero value, which is the size of the field in bits. Otherwise, this will be zero; in this case the field's size is given by its type.
type- The type of the field. This is usually an instance of
Type, but it can beNonein some situations.
Return a new
gdb.Typeobject which represents aconst-qualified variant of this type.
Return a new
gdb.Typeobject which represents avolatile-qualified variant of this type.
Return a new
gdb.Typeobject which represents an unqualified variant of this type. That is, the result is neitherconstnorvolatile.
Return a new
gdb.Typethat represents the real type, after removing all layers of typedefs.
Return a new
gdb.Typeobject which represents the target type of this type.For a pointer type, the target type is the type of the pointed-to object. For an array type (meaning C-like arrays), the target type is the type of the elements of the array. For a function or method type, the target type is the type of the return value. For a complex type, the target type is the type of the elements. For a typedef, the target type is the aliased type.
If the type does not have a target, this method will throw an exception.
If this
gdb.Typeis an instantiation of a template, this will return a newgdb.Typewhich represents the type of the nth template argument.If this
gdb.Typeis not a template type, this will throw an exception. Ordinarily, only C++ code will have template types.name is searched for globally.
Each type has a code, which indicates what category this type falls
into. The available type categories are represented by constants
defined in the gdb module:
TYPE_CODE_PTRTYPE_CODE_ARRAYTYPE_CODE_STRUCTTYPE_CODE_UNIONTYPE_CODE_ENUMTYPE_CODE_FLAGSTYPE_CODE_FUNCTYPE_CODE_INTTYPE_CODE_FLTTYPE_CODE_VOIDvoid.
TYPE_CODE_SETTYPE_CODE_RANGETYPE_CODE_STRINGTYPE_CODE_BITSTRINGTYPE_CODE_ERRORTYPE_CODE_METHODTYPE_CODE_METHODPTRTYPE_CODE_MEMBERPTRTYPE_CODE_REFTYPE_CODE_CHARTYPE_CODE_BOOLTYPE_CODE_COMPLEXTYPE_CODE_TYPEDEFTYPE_CODE_NAMESPACETYPE_CODE_DECFLOATTYPE_CODE_INTERNAL_FUNCTION