From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57758 invoked by alias); 29 Apr 2019 18:47:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 57686 invoked by uid 89); 29 Apr 2019 18:47:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=pra, HContent-Transfer-Encoding:8bit 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; Mon, 29 Apr 2019 18:47:48 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id AEEB8117192; Mon, 29 Apr 2019 14:47:46 -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 Z4-9mur+FneK; Mon, 29 Apr 2019 14:47:46 -0400 (EDT) Received: from murgatroyd.Home (97-122-168-123.hlrn.qwest.net [97.122.168.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 5A4EA11716F; Mon, 29 Apr 2019 14:47:46 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Fix bug in assignment to nested packed structure Date: Mon, 29 Apr 2019 18:47:00 -0000 Message-Id: <20190429184744.2239-3-tromey@adacore.com> In-Reply-To: <20190429184744.2239-1-tromey@adacore.com> References: <20190429184744.2239-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2019-04/txt/msg00632.txt.bz2 A user at AdaCore found a case where assignment to a nested packed structure would fail. The bug is that ada_value_primitive_field doesn't account for the situation where a field is not packed relative to its containing structure, but where the structure itself is packed in its parent. 2019-04-29 Tom Tromey * ada-lang.c (ada_value_primitive_field): Treat more fields as bitfields. gdb/testsuite/ChangeLog 2019-04-29 Tom Tromey * gdb.ada/packed_array_assign/aggregates.ads (Nested_Packed): New record. (NPR): New variable. * gdb.ada/packed_array_assign.exp: Add nested packed assignment test. --- gdb/ChangeLog | 5 +++++ gdb/ada-lang.c | 7 ++++--- gdb/testsuite/ChangeLog | 8 ++++++++ gdb/testsuite/gdb.ada/packed_array_assign.exp | 3 +++ gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads | 7 +++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 422bfdb3b8d..3744ae27f56 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -7158,9 +7158,10 @@ ada_value_primitive_field (struct value *arg1, int offset, int fieldno, arg_type = ada_check_typedef (arg_type); type = TYPE_FIELD_TYPE (arg_type, fieldno); - /* Handle packed fields. */ - - if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0) + /* Handle packed fields. It might be that the field is not packed + relative to its containing structure, but the structure itself is + packed; in this case we must take the bit-field path. */ + if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0 || value_bitpos (arg1) != 0) { int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno); int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno); diff --git a/gdb/testsuite/gdb.ada/packed_array_assign.exp b/gdb/testsuite/gdb.ada/packed_array_assign.exp index 8ed2d63ecf3..407ea9cecbb 100644 --- a/gdb/testsuite/gdb.ada/packed_array_assign.exp +++ b/gdb/testsuite/gdb.ada/packed_array_assign.exp @@ -33,3 +33,6 @@ gdb_test "print pra(1) := pr" \ " = \\(packed_array_assign_w => 104, packed_array_assign_x => 2, packed_array_assign_y => 3\\)" gdb_test "print pra(1)" \ " = \\(packed_array_assign_w => 104, packed_array_assign_x => 2, packed_array_assign_y => 3\\)" + +gdb_test "print npr := (q000 => 3, r000 => (packed_array_assign_x => 6, packed_array_assign_y => 1, packed_array_assign_w => 117))" \ + " = \\(q000 => 3, r000 => \\(packed_array_assign_w => 117, packed_array_assign_x => 6, packed_array_assign_y => 1\\)\\)" diff --git a/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads index f0d052510e4..d1b0552bbd1 100644 --- a/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads +++ b/gdb/testsuite/gdb.ada/packed_array_assign/aggregates.ads @@ -25,6 +25,12 @@ package Aggregates is type Packed_RecArr is array (Integer range <>) of Packed_Rec; pragma Pack (Packed_RecArr); + type Nested_Packed is record + Q000 : Int; + R000 : Packed_Rec; + end record; + pragma Pack (Nested_Packed); + procedure Run_Test; private @@ -32,4 +38,5 @@ private Packed_Array_Assign_W => 104, Packed_Array_Assign_X => 2); PRA : Packed_RecArr (1 .. 3); + NPR : Nested_Packed := (q000 => 3, r000 => (packed_array_assign_x => 6, packed_array_assign_y => 1, packed_array_assign_w => 117)); end Aggregates; -- 2.20.1