aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2014-10-09 12:37:17 -0400
committerJoel Brobecker <brobecker@adacore.com>2014-10-14 14:05:11 -0700
commitc40cc657bcc930b83ec42e071fe419073bd199f5 (patch)
tree5bbf82ebaeae8c4787a1ffa35b2011cacaa07dd2 /gdb/ada-lang.c
parent2abf49e11e603ecc002fa27704a978733c601386 (diff)
downloadgdb-c40cc657bcc930b83ec42e071fe419073bd199f5.zip
gdb-c40cc657bcc930b83ec42e071fe419073bd199f5.tar.gz
gdb-c40cc657bcc930b83ec42e071fe419073bd199f5.tar.bz2
[Ada] Error adding/subtracting pointer value to/from integral.
When trying to evaluate an expression which adds a pointer and an integral, the evaluation succeeds if the pointer is on the left handside of the operator, but not when it is on the right handside: (gdb) p something'address + 0 $1 = (system.address) 0x613418 <pck.something> (gdb) p 0 + something'address Argument to arithmetic operation not a number or boolean. Same issue when doing subtractions: (gdb) p something'address - 0 $2 = (system.address) 0x613418 <pck.something> (gdb) p 0 - something'address Argument to arithmetic operation not a number or boolean. This patch enhances the Ada expression evaluator to handle these two situations. gdb/ChangeLog: * ada-lang.c (ada_evaluate_subexp) <BINOP_ADD>: Add handling of the case where the second operand is a pointer. <BINOP_SUB>: Likewise. gdb/testsuite/ChangeLog: * gdb.ada/addr_arith: New testcase. Tested on x86_64-linux.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 36a2f24..5793cd2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10004,6 +10004,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
return (value_from_longest
(value_type (arg1),
value_as_long (arg1) + value_as_long (arg2)));
+ if (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR)
+ return (value_from_longest
+ (value_type (arg2),
+ value_as_long (arg1) + value_as_long (arg2)));
if ((ada_is_fixed_point_type (value_type (arg1))
|| ada_is_fixed_point_type (value_type (arg2)))
&& value_type (arg1) != value_type (arg2))
@@ -10026,6 +10030,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
return (value_from_longest
(value_type (arg1),
value_as_long (arg1) - value_as_long (arg2)));
+ if (TYPE_CODE (value_type (arg2)) == TYPE_CODE_PTR)
+ return (value_from_longest
+ (value_type (arg2),
+ value_as_long (arg1) - value_as_long (arg2)));
if ((ada_is_fixed_point_type (value_type (arg1))
|| ada_is_fixed_point_type (value_type (arg2)))
&& value_type (arg1) != value_type (arg2))