[PATCH 2/4] gdbsupport: add array_view copy function
Simon Marchi
simon.marchi@polymtl.ca
Mon Nov 8 21:11:17 GMT 2021
On 2021-11-08 4:06 p.m., Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
>
> An assertion was recently added to array_view::operator[] to ensure we
> don't do out of bounds accesses. However, when the array_view is copied
> to or from using memcpy, it bypasses this safety.
>
> To address this, add a `copy` free function that copies data from an
> array view to another. It ensures that the destination and source array
> views have the same size and element size, which prevents any kind of
> overflow in the source and in the destination.
>
> I have chosen to allow the array views to have different types, because
> I am thinking we might want to copy arrays of bfd_byte into arrays of
> gdb_byte, for example.
>
> Change a few randomly selected spots to use the new function, to show
> how it can be used.
>
> Change-Id: Ibeaca04e0028410fd44ce82f72e60058d6230a03
Hi Tom,
This patch of mine causes the following test failure:
Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.ada/packed_array_assign.exp ...
FAIL: gdb.ada/packed_array_assign.exp: print pra(1) := pr (GDB internal error)
I couldn't figure out if this is a mistake on my part, or if my assert points out an
existing bug. Could you give it a quick look?
The problem is that the values we are copying from and to don't have the same length:
(top-gdb) p toval.type.length
$1 = 5
(top-gdb) p fromval.type.length
$2 = 8
... and that trips on the new assert.
The two values appear to have the same type, so I don't understand where the different
lengths come from.
Simon
More information about the Gdb-patches
mailing list