Next: Pretty Printing API, 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.
If block is given, then name is looked up in that scope. Otherwise, it is searched for globally.
Ordinarily, this function will return an instance of
gdb.Type
. If the named type cannot be found, it will throw an exception.
If the type is a structure or class type, or an enum type, the fields
of that type can be accessed using the Python dictionary syntax.
For example, if some_type
is a gdb.Type
instance holding
a structure type, you can access its foo
field with:
bar = some_type['foo']
bar
will be a gdb.Field
object; see below under the
description of the Type.fields
method for a description of the
gdb.Field
class.
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 a
gdb.Field
object, with some pre-defined attributes:
bitpos
- This attribute is not available for
static
fields (as in C++ or Java). For non-static
fields, the value is the bit position of the field. Forenum
fields, the value is the enumeration member's integer representation.name
- The name of the field, or
None
for anonymous fields.artificial
- This is
True
if the field is artificial, usually meaning that it was provided by the compiler and not the user. This attribute is always provided, and isFalse
if the field is not artificial.is_base_class
- This is
True
if the field represents a base class of a C++ structure. This attribute is always provided, and isFalse
if the field is not a base class of the type that is the argument offields
, or if that type was not a C++ class.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 beNone
in some situations.
Return a new
gdb.Type
object which represents an array of this type. If one argument is given, it is the inclusive upper bound of the array; in this case the lower bound is zero. If two arguments are given, the first argument is the lower bound of the array, and the second argument is the upper bound of the array. An array's length must not be negative, but the bounds can be.
Return a new
gdb.Type
object which represents aconst
-qualified variant of this type.
Return a new
gdb.Type
object which represents avolatile
-qualified variant of this type.
Return a new
gdb.Type
object which represents an unqualified variant of this type. That is, the result is neitherconst
norvolatile
.
Return a Python
Tuple
object that contains two elements: the low bound of the argument type and the high bound of that type. If the type does not have a range, gdb will raise agdb.error
exception (see Exception Handling).
Return a new
gdb.Type
object which represents a reference to this type.
Return a new
gdb.Type
that represents the real type, after removing all layers of typedefs.
Return a new
gdb.Type
object 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.Type
is an instantiation of a template, this will return a newgdb.Type
which represents the type of the nth template argument.If this
gdb.Type
is not a template type, this will throw an exception. Ordinarily, only C++ code will have template types.If block is given, then name is looked up in that scope. Otherwise, it 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:
gdb.TYPE_CODE_PTR
gdb.TYPE_CODE_ARRAY
gdb.TYPE_CODE_STRUCT
gdb.TYPE_CODE_UNION
gdb.TYPE_CODE_ENUM
gdb.TYPE_CODE_FLAGS
gdb.TYPE_CODE_FUNC
gdb.TYPE_CODE_INT
gdb.TYPE_CODE_FLT
gdb.TYPE_CODE_VOID
void
.
gdb.TYPE_CODE_SET
gdb.TYPE_CODE_RANGE
gdb.TYPE_CODE_STRING
gdb.TYPE_CODE_BITSTRING
gdb.TYPE_CODE_ERROR
gdb.TYPE_CODE_METHOD
gdb.TYPE_CODE_METHODPTR
gdb.TYPE_CODE_MEMBERPTR
gdb.TYPE_CODE_REF
gdb.TYPE_CODE_CHAR
gdb.TYPE_CODE_BOOL
gdb.TYPE_CODE_COMPLEX
gdb.TYPE_CODE_TYPEDEF
gdb.TYPE_CODE_NAMESPACE
gdb.TYPE_CODE_DECFLOAT
gdb.TYPE_CODE_INTERNAL_FUNCTION
Further support for types is provided in the gdb.types
Python module (see gdb.types).