Call overloaded operators to perform operations on gdb.Value objects.

* NEWS: Add entry for the new feature
	* python/py-value.c (valpy_binop): Call value_x_binop for struct
	and class values.

	testsuite/
	* gdb.python/py-value-cc.cc: Improve test case to enable testing
	operations on gdb.Value objects.
	* gdb.python/py-value-cc.exp: Add new test to test operations on
	gdb.Value objects.

	doc/
	* python.texi (Values From Inferior): Add description about the
	new feature.
This commit is contained in:
Siva Chandra 2013-12-02 06:45:09 -08:00
parent 649ebbcaef
commit f7bd0f7854
8 changed files with 88 additions and 12 deletions

View file

@ -528,7 +528,26 @@ bar = some_val + 2
@noindent
As result of this, @code{bar} will also be a @code{gdb.Value} object
whose values are of the same type as those of @code{some_val}.
whose values are of the same type as those of @code{some_val}. Valid
Python operations can also be performed on @code{gdb.Value} objects
representing a @code{struct} or @code{class} object. For such cases,
the overloaded operator (if present), is used to perform the operation.
For example, if @code{val1} and @code{val2} are @code{gdb.Value} objects
representing instances of a @code{class} which overloads the @code{+}
operator, then one can use the @code{+} operator in their Python script
as follows:
@smallexample
val3 = val1 + val2
@end smallexample
@noindent
The result of the operation @code{val3} is also a @code{gdb.Value}
object corresponding to the value returned by the overloaded @code{+}
operator. In general, overloaded operators are invoked for the
following operations: @code{+} (binary addition), @code{-} (binary
subtraction), @code{*} (multiplication), @code{/}, @code{%}, @code{<<},
@code{>>}, @code{|}, @code{&}, @code{^}.
Inferior values that are structures or instances of some class can
be accessed using the Python @dfn{dictionary syntax}. For example, if