220.127.116.11 Values From Inferior
gdb provides values it obtains from the inferior program in
an object of type
gdb.Value. gdb uses this object
for its internal bookkeeping of the inferior's values, and for
fetching values when necessary.
Inferior values that are simple scalars can be used directly in
Python expressions that are valid for the value's data type. Here's
an example for an integer or floating-point value
bar = some_val + 2
As result of this,
bar will also be a
whose values are of the same type as those of
Inferior values that are structures or instances of some class can
be accessed using the Python dictionary syntax. For example, if
some_val is a
gdb.Value instance holding a structure, you
can access its
foo element with:
bar = some_val['foo']
bar will also be a
The following attributes are provided:
If this object is addressable, this read-only attribute holds a
gdb.Valueobject representing the address. Otherwise, this attribute holds
This read-only boolean attribute is true if the compiler optimized out this value, thus it is not available for fetching from the inferior.
The following methods are provided:
Return a new instance of
gdb.Valuethat is the result of casting this instance to the type described by type, which must be a
gdb.Typeobject. If the cast cannot be performed for some reason, this method throws an exception.
For pointer data types, this method returns a new
gdb.Valueobject whose contents is the object pointed to by the pointer. For example, if
foois a C pointer to an
int, declared in your C program asint *foo;
then you can use the corresponding
gdb.Valueto access what
foopoints to like this:bar = foo.dereference ()
barwill be a
gdb.Valueobject holding the value pointed to by
gdb.Valuerepresents a string, then this method converts the contents to a Python string. Otherwise, this method will throw an exception.
Strings are recognized in a language-specific way; whether a given
gdb.Valuerepresents a string is determined by the current language.
For C-like languages, a value is a string if it is a pointer to or an array of characters or ints. The string is assumed to be terminated by a zero of the appropriate width. However if the optional length argument is given, the string will be converted to that given length, ignoring any embedded zeros that the string may contain.
If the optional encoding argument is given, it must be a string naming the encoding of the string in the
gdb.Value, such as
"utf-8". It accepts the same encodings as the corresponding argument to Python's
string.decodemethod, and the Python codec machinery will be used to convert the string. If encoding is not given, or if encoding is the empty string, then either the
target-charset(see Character Sets) will be used, or a language-specific encoding will be used, if the current language is able to supply one.
The optional errors argument is the same as the corresponding argument to Python's
If the optional length argument is given, the string will be fetched and converted to the given length.
gdb.Valuerepresents a string, then this method converts the contents to a
gdb.LazyString(see Lazy Strings In Python). Otherwise, this method will throw an exception.
If the optional encoding argument is given, it must be a string naming the encoding of the
gdb.LazyString. Some examples are: ascii, iso-8859-6 or utf-8. If the encoding argument is an encoding that gdb does recognize, gdb will raise an error.
When a lazy string is printed, the gdb encoding machinery is used to convert the string during printing. If the optional encoding argument is not provided, or is an empty string, gdb will automatically select the encoding most suitable for the string type. For further information on encoding in gdb please see Character Sets.
If the optional length argument is given, the string will be fetched and encoded to the length of characters specified. If the length argument is not provided, the string will be fetched and encoded until a null of appropriate width is found.