aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-value.c
diff options
context:
space:
mode:
authorSiva Chandra <sivachandra@chromium.org>2013-12-02 06:45:09 -0800
committerSiva Chandra <sivachandra@chromium.org>2014-02-19 15:47:45 -0800
commitf7bd0f7854f2fd0dfeddafd073b007d91bea79e8 (patch)
tree38d3ca9d46e619b3f4a371a0b50158563a3af60d /gdb/python/py-value.c
parent649ebbcaef0f8e58146e62be0d3f22da5f82446c (diff)
downloadgdb-f7bd0f7854f2fd0dfeddafd073b007d91bea79e8.zip
gdb-f7bd0f7854f2fd0dfeddafd073b007d91bea79e8.tar.gz
gdb-f7bd0f7854f2fd0dfeddafd073b007d91bea79e8.tar.bz2
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.
Diffstat (limited to 'gdb/python/py-value.c')
-rw-r--r--gdb/python/py-value.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index f8a8a98..75aa642 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -933,6 +933,8 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
struct value *arg1, *arg2;
struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ());
struct value *res_val = NULL;
+ enum exp_opcode op = OP_NULL;
+ int handled = 0;
/* If the gdb.Value object is the second operand, then it will be passed
to us as the OTHER argument, and SELF will be an entirely different
@@ -964,6 +966,7 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
CHECK_TYPEDEF (rtype);
rtype = STRIP_REFERENCE (rtype);
+ handled = 1;
if (TYPE_CODE (ltype) == TYPE_CODE_PTR
&& is_integral_type (rtype))
res_val = value_ptradd (arg1, value_as_long (arg2));
@@ -971,7 +974,10 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
&& is_integral_type (ltype))
res_val = value_ptradd (arg2, value_as_long (arg1));
else
- res_val = value_binop (arg1, arg2, BINOP_ADD);
+ {
+ handled = 0;
+ op = BINOP_ADD;
+ }
}
break;
case VALPY_SUB:
@@ -984,6 +990,7 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
CHECK_TYPEDEF (rtype);
rtype = STRIP_REFERENCE (rtype);
+ handled = 1;
if (TYPE_CODE (ltype) == TYPE_CODE_PTR
&& TYPE_CODE (rtype) == TYPE_CODE_PTR)
/* A ptrdiff_t for the target would be preferable here. */
@@ -993,38 +1000,49 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
&& is_integral_type (rtype))
res_val = value_ptradd (arg1, - value_as_long (arg2));
else
- res_val = value_binop (arg1, arg2, BINOP_SUB);
+ {
+ handled = 0;
+ op = BINOP_SUB;
+ }
}
break;
case VALPY_MUL:
- res_val = value_binop (arg1, arg2, BINOP_MUL);
+ op = BINOP_MUL;
break;
case VALPY_DIV:
- res_val = value_binop (arg1, arg2, BINOP_DIV);
+ op = BINOP_DIV;
break;
case VALPY_REM:
- res_val = value_binop (arg1, arg2, BINOP_REM);
+ op = BINOP_REM;
break;
case VALPY_POW:
- res_val = value_binop (arg1, arg2, BINOP_EXP);
+ op = BINOP_EXP;
break;
case VALPY_LSH:
- res_val = value_binop (arg1, arg2, BINOP_LSH);
+ op = BINOP_LSH;
break;
case VALPY_RSH:
- res_val = value_binop (arg1, arg2, BINOP_RSH);
+ op = BINOP_RSH;
break;
case VALPY_BITAND:
- res_val = value_binop (arg1, arg2, BINOP_BITWISE_AND);
+ op = BINOP_BITWISE_AND;
break;
case VALPY_BITOR:
- res_val = value_binop (arg1, arg2, BINOP_BITWISE_IOR);
+ op = BINOP_BITWISE_IOR;
break;
case VALPY_BITXOR:
- res_val = value_binop (arg1, arg2, BINOP_BITWISE_XOR);
+ op = BINOP_BITWISE_XOR;
break;
}
+ if (!handled)
+ {
+ if (binop_user_defined_p (op, arg1, arg2))
+ res_val = value_x_binop (arg1, arg2, op, OP_NULL, EVAL_NORMAL);
+ else
+ res_val = value_binop (arg1, arg2, op);
+ }
+
if (res_val)
result = value_to_value_object (res_val);