From patchwork Sat Sep 8 21:55:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 29259 Received: (qmail 55598 invoked by alias); 8 Sep 2018 21:56:09 -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 55471 invoked by uid 89); 8 Sep 2018 21:56:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=formula, D*adacore.com, U*brobecker, brobeckeradacorecom 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 ESMTP; Sat, 08 Sep 2018 21:56:04 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6148F117191 for ; Sat, 8 Sep 2018 17:56:03 -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 Z7RR6eXqO8JQ for ; Sat, 8 Sep 2018 17:56:03 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 4F18F1170ED for ; Sat, 8 Sep 2018 17:56:03 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4233) id 4E338489; Sat, 8 Sep 2018 17:56:03 -0400 (EDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [PATCH 1/8] (Ada) assigning packed array aggregate with variable as component Date: Sat, 8 Sep 2018 17:55:53 -0400 Message-Id: <1536443760-78016-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1536443760-78016-1-git-send-email-brobecker@adacore.com> References: <1536443760-78016-1-git-send-email-brobecker@adacore.com> Consider a variable "PRA" defined as a packed array of packed records as follow: subtype Int is Integer range 0 .. 7; type Packed_Rec is record X, Y : Int; W : Integer; end record; pragma Pack (Packed_Rec); type Packed_RecArr is array (Integer range <>) of Packed_Rec; pragma Pack (Packed_RecArr); PRA : Packed_RecArr (1 .. 3); Consider also a variable "PR", which is a Packed_Rec record, declared as follow: PR : Packed_Rec := (2, 2, 2); Trying to assign a new value to PRA using an aggregate expression where one of the components is our variable PR yields the wrong result on big-endian machines (e.g. on ppc-linux): (gdb) p pra := (pr, (2,2,2), (2,2,2)) $6 = ((x => 1, y => 0, w => 8), [...] On the other hand, replacing "pr" by "(2,2,2)" does work. I tracked the issue down to the bit offset we use to extract the value of "PR" and copy it inside PRA. in value_assign_to_component, we have: if (gdbarch_bits_big_endian (get_type_arch (value_type (container)))) move_bits ([target buffer], [bit offset in target buffer], [source buffer where PR is stored], TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits, bits, 1); The issue is with the third-to-last argument, which provides the bit offset where the value of PR is stored relative to its start address, and therefore the bit offset relative to the start of the source buffer passed as the previous argument. In our case, component is a 38bit packed record whose TYPE_LENGTH is 5 bytes, so the bit-offset that gets calculated is 2 (bits). However, that formula only really applies to scalars, whereas in our case, we have a record (struct). The offset in the non-scalar case should be zero. gdb/ChangeLog: * ada-lang.c (value_assign_to_component): In the case of big-endian targets, extract the bits of the given VAL using an src_offset of zero if container is not a scalar. gdb/testsuite/ChangeLog: * gdb.ada/packed_array_assign: New testcase. --- gdb/ChangeLog | 6 ++++ gdb/ada-lang.c | 17 +++++++---- gdb/testsuite/ChangeLog | 4 +++ gdb/testsuite/gdb.ada/packed_array_assign.exp | 30 ++++++++++++++++++++ .../gdb.ada/packed_array_assign/aggregates.adb | 25 ++++++++++++++++ .../gdb.ada/packed_array_assign/aggregates.ads | 33 ++++++++++++++++++++++ gdb/testsuite/gdb.ada/packed_array_assign/pck.adb | 23 +++++++++++++++ gdb/testsuite/gdb.ada/packed_array_assign/pck.ads | 22 +++++++++++++++ .../gdb.ada/packed_array_assign/tester.adb | 20 +++++++++++++ 9 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/packed_array_assign.exp create mode 100644 gdb/testsuite/gdb.ada/packed_array_assign/aggregates.adb create mode 100644 gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads create mode 100644 gdb/testsuite/gdb.ada/packed_array_assign/pck.adb create mode 100644 gdb/testsuite/gdb.ada/packed_array_assign/pck.ads create mode 100644 gdb/testsuite/gdb.ada/packed_array_assign/tester.adb diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e6f44a3..0d87f83 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-09-08 Joel Brobecker + + * ada-lang.c (value_assign_to_component): In the case of + big-endian targets, extract the bits of the given VAL + using an src_offset of zero if container is not a scalar. + 2018-09-06 Simon Ser PR gdb/23105 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index ef87164..3618e1d 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2809,11 +2809,18 @@ value_assign_to_component (struct value *container, struct value *component, bits = value_bitsize (component); if (gdbarch_bits_big_endian (get_type_arch (value_type (container)))) - move_bits (value_contents_writeable (container) + offset_in_container, - value_bitpos (container) + bit_offset_in_container, - value_contents (val), - TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits, - bits, 1); + { + int src_offset; + + if (is_scalar_type (check_typedef (value_type (component)))) + src_offset + = TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits; + else + src_offset = 0; + move_bits (value_contents_writeable (container) + offset_in_container, + value_bitpos (container) + bit_offset_in_container, + value_contents (val), src_offset, bits, 1); + } else move_bits (value_contents_writeable (container) + offset_in_container, value_bitpos (container) + bit_offset_in_container, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d808d8b..e667471 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-09-08 Joel Brobecker + + * gdb.ada/packed_array_assign: New testcase. + 2018-09-07 Andrew Burgess * gdb.base/watchpoint.exp (test_complex_watchpoint): Extend test diff --git a/gdb/testsuite/gdb.ada/packed_array_assign.exp b/gdb/testsuite/gdb.ada/packed_array_assign.exp new file mode 100644 index 0000000..25b20dd --- /dev/null +++ b/gdb/testsuite/gdb.ada/packed_array_assign.exp @@ -0,0 +1,30 @@ +# Copyright 2018 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 tester + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } { + return -1 +} + +clean_restart ${testfile} + +runto "aggregates.run_test" + +gdb_test \ + "print pra := ((x => 2, y => 0, w => 17), pr, (x => 7, y => 1, w => 23))" \ + " = \\(\\(w => 17, x => 2, y => 0\\), \\(w => 104, x => 2, y => 3\\), \\(w => 23, x => 7, y => 1\\)\\)" diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.adb b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.adb new file mode 100644 index 0000000..c44bc0e --- /dev/null +++ b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.adb @@ -0,0 +1,25 @@ +-- Copyright 2018 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; + +package body Aggregates is + procedure Run_Test is + begin + -- Fake the use of PRA to prevent the AIX linker from optimizing + -- the following symbols away. + Do_Nothing (PRA'Address); + end; +end Aggregates; diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads new file mode 100644 index 0000000..b43f70a --- /dev/null +++ b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads @@ -0,0 +1,33 @@ +-- Copyright 2018 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 Aggregates is + subtype Int is Integer range 0 .. 7; + + type Packed_Rec is record + X, Y : Int; + W : Integer; + end record; + pragma Pack (Packed_Rec); + + type Packed_RecArr is array (Integer range <>) of Packed_Rec; + pragma Pack (Packed_RecArr); + + procedure Run_Test; + +private + PR : Packed_Rec := (y => 3, w => 104, x => 2); + PRA : Packed_RecArr (1 .. 3); +end Aggregates; diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/pck.adb b/gdb/testsuite/gdb.ada/packed_array_assign/pck.adb new file mode 100644 index 0000000..3b03c00 --- /dev/null +++ b/gdb/testsuite/gdb.ada/packed_array_assign/pck.adb @@ -0,0 +1,23 @@ +-- Copyright 2018 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 Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/pck.ads b/gdb/testsuite/gdb.ada/packed_array_assign/pck.ads new file mode 100644 index 0000000..c3400c2 --- /dev/null +++ b/gdb/testsuite/gdb.ada/packed_array_assign/pck.ads @@ -0,0 +1,22 @@ +-- Copyright 2018 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 System; + +package Pck is + + procedure Do_Nothing (A : System.Address); + +end Pck; diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/tester.adb b/gdb/testsuite/gdb.ada/packed_array_assign/tester.adb new file mode 100644 index 0000000..dd61509 --- /dev/null +++ b/gdb/testsuite/gdb.ada/packed_array_assign/tester.adb @@ -0,0 +1,20 @@ +-- Copyright 2018 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 Aggregates; +procedure Tester is +begin + Aggregates.Run_Test; +end Tester;