From patchwork Tue Oct 14 21:06:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 3225 Received: (qmail 26465 invoked by alias); 14 Oct 2014 21:06:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 26386 invoked by uid 89); 14 Oct 2014 21:06:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 14 Oct 2014 21:06:19 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C5C8A1162BB for ; Tue, 14 Oct 2014 17:06:17 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id A9L69YP9Z3g9 for ; Tue, 14 Oct 2014 17:06:17 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 926C01162B6 for ; Tue, 14 Oct 2014 17:06:17 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id BF8B940DC3; Tue, 14 Oct 2014 14:06:17 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [pushed/Ada] Error adding/subtracting pointer value to/from integral. Date: Tue, 14 Oct 2014 14:06:15 -0700 Message-Id: <1413320775-16024-1-git-send-email-brobecker@adacore.com> Hello, 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 (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 (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) : Add handling of the case where the second operand is a pointer. : Likewise. gdb/testsuite/ChangeLog: * gdb.ada/addr_arith: New testcase. Tested on x86_64-linux and pushed. Thank you, diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 57ddd7b..9423d69 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2014-10-14 Joel Brobecker + + * ada-lang.c (ada_evaluate_subexp) : Add handling + of the case where the second operand is a pointer. + : Likewise. + 2014-10-14 Sergio Durigan Junior * breakpoint.c (bkpt_probe_insert_location): Call set_semaphore 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)) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e780db3..1029e32 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2014-10-14 Joel Brobecker + + * gdb.ada/addr_arith: New testcase. + 2014-10-14 Maciej W. Rozycki * gdb.dwarf2/dw2-case-insensitive-debug.S: Handle 64-bit pointers. diff --git a/gdb/testsuite/gdb.ada/addr_arith.exp b/gdb/testsuite/gdb.ada/addr_arith.exp new file mode 100644 index 0000000..daba638 --- /dev/null +++ b/gdb/testsuite/gdb.ada/addr_arith.exp @@ -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 . + +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 " + +gdb_test "print 0 + something'address" \ + "\\(system\\.address\\) $hex " + +gdb_test "print something'address - 0" \ + "\\(system\\.address\\) $hex " + +gdb_test "print 0 - something'address" \ + "\\(system\\.address\\) $hex.*" diff --git a/gdb/testsuite/gdb.ada/addr_arith/foo_na07_019.adb b/gdb/testsuite/gdb.ada/addr_arith/foo_na07_019.adb new file mode 100644 index 0000000..a4d70df --- /dev/null +++ b/gdb/testsuite/gdb.ada/addr_arith/foo_na07_019.adb @@ -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 . + +with Pck; use Pck; + +procedure Foo_NA07_019 is +begin + Increment (Something); -- START +end Foo_NA07_019; diff --git a/gdb/testsuite/gdb.ada/addr_arith/pck.adb b/gdb/testsuite/gdb.ada/addr_arith/pck.adb new file mode 100644 index 0000000..fbb43e1 --- /dev/null +++ b/gdb/testsuite/gdb.ada/addr_arith/pck.adb @@ -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 . + +package body Pck is + procedure Increment (I : in out Integer) is + begin + I := I + 1; + end Increment; +end Pck; diff --git a/gdb/testsuite/gdb.ada/addr_arith/pck.ads b/gdb/testsuite/gdb.ada/addr_arith/pck.ads new file mode 100644 index 0000000..f49e321 --- /dev/null +++ b/gdb/testsuite/gdb.ada/addr_arith/pck.ads @@ -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 . + +package Pck is + Something : Integer := 0; + procedure Increment (I : in out Integer); +end Pck;