forked from Imagelibrary/binutils-gdb
[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.
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
2014-10-14 Joel Brobecker <brobecker@adacore.com>
|
||||
|
||||
* ada-lang.c (ada_evaluate_subexp) <BINOP_ADD>: Add handling
|
||||
of the case where the second operand is a pointer.
|
||||
<BINOP_SUB>: Likewise.
|
||||
|
||||
2014-10-14 Sergio Durigan Junior <sergiodj@redhat.com>
|
||||
|
||||
* breakpoint.c (bkpt_probe_insert_location): Call set_semaphore
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
2014-10-14 Joel Brobecker <brobecker@adacore.com>
|
||||
|
||||
* gdb.ada/addr_arith: New testcase.
|
||||
|
||||
2014-10-14 Maciej W. Rozycki <macro@codesourcery.com>
|
||||
|
||||
* gdb.dwarf2/dw2-case-insensitive-debug.S: Handle 64-bit pointers.
|
||||
|
||||
42
gdb/testsuite/gdb.ada/addr_arith.exp
Normal file
42
gdb/testsuite/gdb.ada/addr_arith.exp
Normal file
@@ -0,0 +1,42 @@
|
||||
# Copyright 2014 Free Software Foundation, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
load_lib "ada.exp"
|
||||
|
||||
standard_ada_testfile foo_na07_019
|
||||
|
||||
if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
|
||||
return -1
|
||||
}
|
||||
|
||||
clean_restart ${testfile}
|
||||
|
||||
set bp_location [gdb_get_line_number "START" ${testdir}/foo_na07_019.adb]
|
||||
if ![runto "foo_na07_019.adb:$bp_location" ] then {
|
||||
perror "Couldn't run ${testfile}"
|
||||
return
|
||||
}
|
||||
|
||||
gdb_test "print something'address + 0" \
|
||||
"\\(system\\.address\\) $hex <pck\\.something>"
|
||||
|
||||
gdb_test "print 0 + something'address" \
|
||||
"\\(system\\.address\\) $hex <pck\\.something>"
|
||||
|
||||
gdb_test "print something'address - 0" \
|
||||
"\\(system\\.address\\) $hex <pck\\.something>"
|
||||
|
||||
gdb_test "print 0 - something'address" \
|
||||
"\\(system\\.address\\) $hex.*"
|
||||
21
gdb/testsuite/gdb.ada/addr_arith/foo_na07_019.adb
Normal file
21
gdb/testsuite/gdb.ada/addr_arith/foo_na07_019.adb
Normal file
@@ -0,0 +1,21 @@
|
||||
-- Copyright 2014 Free Software Foundation, Inc.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
with Pck; use Pck;
|
||||
|
||||
procedure Foo_NA07_019 is
|
||||
begin
|
||||
Increment (Something); -- START
|
||||
end Foo_NA07_019;
|
||||
21
gdb/testsuite/gdb.ada/addr_arith/pck.adb
Normal file
21
gdb/testsuite/gdb.ada/addr_arith/pck.adb
Normal file
@@ -0,0 +1,21 @@
|
||||
-- Copyright 2014 Free Software Foundation, Inc.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package body Pck is
|
||||
procedure Increment (I : in out Integer) is
|
||||
begin
|
||||
I := I + 1;
|
||||
end Increment;
|
||||
end Pck;
|
||||
19
gdb/testsuite/gdb.ada/addr_arith/pck.ads
Normal file
19
gdb/testsuite/gdb.ada/addr_arith/pck.ads
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Copyright 2014 Free Software Foundation, Inc.
|
||||
--
|
||||
-- This program is free software; you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation; either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package Pck is
|
||||
Something : Integer := 0;
|
||||
procedure Increment (I : in out Integer);
|
||||
end Pck;
|
||||
Reference in New Issue
Block a user