* [PATCH 2/2] Fix bug in assignment to nested packed structure
2019-04-29 18:47 [PATCH 0/2] Fix two Ada assignment bugs Tom Tromey
@ 2019-04-29 18:47 ` Tom Tromey
2019-04-29 18:47 ` [PATCH 1/2] Fix big-endian aggregate assignment in Ada Tom Tromey
2019-04-30 21:26 ` [PATCH 0/2] Fix two Ada assignment bugs Joel Brobecker
2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2019-04-29 18:47 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
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 <tromey@adacore.com>
* ada-lang.c (ada_value_primitive_field): Treat more fields as
bitfields.
gdb/testsuite/ChangeLog
2019-04-29 Tom Tromey <tromey@adacore.com>
* 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] Fix big-endian aggregate assignment in Ada
2019-04-29 18:47 [PATCH 0/2] Fix two Ada assignment bugs Tom Tromey
2019-04-29 18:47 ` [PATCH 2/2] Fix bug in assignment to nested packed structure Tom Tromey
@ 2019-04-29 18:47 ` Tom Tromey
2019-04-30 21:26 ` [PATCH 0/2] Fix two Ada assignment bugs Joel Brobecker
2 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2019-04-29 18:47 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
A bug internal to AdaCore notes that assigning a non-scalar value to
an element of a packed array will sometimes fail.
The bug turns out to be that ada_value_assign incorrectly computes the
starting point for the assignment. This patch fixes the problem.
gdb/ChangeLog
2019-04-29 Tom Tromey <tromey@adacore.com>
* ada-lang.c (ada_value_assign): Correctly compute starting offset
for big-endian copies.
gdb/testsuite/ChangeLog
2019-04-29 Tom Tromey <tromey@adacore.com>
* gdb.ada/packed_array_assign.exp: Add packed assignment
regression test.
---
gdb/ChangeLog | 5 +++++
gdb/ada-lang.c | 14 ++++++++------
gdb/testsuite/ChangeLog | 5 +++++
gdb/testsuite/gdb.ada/packed_array_assign.exp | 5 +++++
4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 250ce438b1a..422bfdb3b8d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2709,12 +2709,14 @@ ada_value_assign (struct value *toval, struct value *fromval)
from_size = value_bitsize (fromval);
if (from_size == 0)
from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
- if (gdbarch_bits_big_endian (get_type_arch (type)))
- copy_bitwise (buffer, value_bitpos (toval),
- value_contents (fromval), from_size - bits, bits, 1);
- else
- copy_bitwise (buffer, value_bitpos (toval),
- value_contents (fromval), 0, bits, 0);
+
+ const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type));
+ ULONGEST from_offset = 0;
+ if (is_big_endian && is_scalar_type (value_type (fromval)))
+ from_offset = from_size - bits;
+ copy_bitwise (buffer, value_bitpos (toval),
+ value_contents (fromval), from_offset,
+ bits, is_big_endian);
write_memory_with_notification (to_addr, buffer, len);
val = value_copy (toval);
diff --git a/gdb/testsuite/gdb.ada/packed_array_assign.exp b/gdb/testsuite/gdb.ada/packed_array_assign.exp
index 93910ac6cb4..8ed2d63ecf3 100644
--- a/gdb/testsuite/gdb.ada/packed_array_assign.exp
+++ b/gdb/testsuite/gdb.ada/packed_array_assign.exp
@@ -28,3 +28,8 @@ runto "aggregates.run_test"
gdb_test \
"print pra := ((packed_array_assign_x => 2, packed_array_assign_y => 0, packed_array_assign_w => 17), pr, (packed_array_assign_x => 7, packed_array_assign_y => 1, packed_array_assign_w => 23))" \
" = \\(\\(packed_array_assign_w => 17, packed_array_assign_x => 2, packed_array_assign_y => 0\\), \\(packed_array_assign_w => 104, packed_array_assign_x => 2, packed_array_assign_y => 3\\), \\(packed_array_assign_w => 23, packed_array_assign_x => 7, packed_array_assign_y => 1\\)\\)"
+
+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\\)"
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 0/2] Fix two Ada assignment bugs
@ 2019-04-29 18:47 Tom Tromey
2019-04-29 18:47 ` [PATCH 2/2] Fix bug in assignment to nested packed structure Tom Tromey
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Tom Tromey @ 2019-04-29 18:47 UTC (permalink / raw)
To: gdb-patches
This series fixes two bugs in the Ada code related to aggregate
assignment. They were reported internally by users at AdaCore.
I think each patch is reasonably self-explanatory.
Tested by the buildbot.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] Fix two Ada assignment bugs
2019-04-29 18:47 [PATCH 0/2] Fix two Ada assignment bugs Tom Tromey
2019-04-29 18:47 ` [PATCH 2/2] Fix bug in assignment to nested packed structure Tom Tromey
2019-04-29 18:47 ` [PATCH 1/2] Fix big-endian aggregate assignment in Ada Tom Tromey
@ 2019-04-30 21:26 ` Joel Brobecker
2 siblings, 0 replies; 4+ messages in thread
From: Joel Brobecker @ 2019-04-30 21:26 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Hi Tom,
> This series fixes two bugs in the Ada code related to aggregate
> assignment. They were reported internally by users at AdaCore.
>
> I think each patch is reasonably self-explanatory.
Thanks for those. I reviewed both patches, and they look good to me.
--
Joel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-30 21:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-29 18:47 [PATCH 0/2] Fix two Ada assignment bugs Tom Tromey
2019-04-29 18:47 ` [PATCH 2/2] Fix bug in assignment to nested packed structure Tom Tromey
2019-04-29 18:47 ` [PATCH 1/2] Fix big-endian aggregate assignment in Ada Tom Tromey
2019-04-30 21:26 ` [PATCH 0/2] Fix two Ada assignment bugs Joel Brobecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).