diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-12-01 11:27:18 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-12-14 16:04:49 +0000 |
commit | 51e6b8cfd649013ae16a3d00f1451b2531ba6bc9 (patch) | |
tree | 7f07b62493f0ffdcfb523d57452812cf491a88f2 /gdbsupport/rsp-low.h | |
parent | 08d8e7ff9474a88b491d22139ace851daae1a1c6 (diff) | |
download | gdb-51e6b8cfd649013ae16a3d00f1451b2531ba6bc9.zip gdb-51e6b8cfd649013ae16a3d00f1451b2531ba6bc9.tar.gz gdb-51e6b8cfd649013ae16a3d00f1451b2531ba6bc9.tar.bz2 |
gdb: change regcache interface to use array_view
Change most of regcache (and base classes) to use array_view when
possible, instead of raw pointers. By propagating the use of array_view
further, it enables having some runtime checks to make sure the what we
read from or write to regcaches has the expected length (such as the one
in the `copy(array_view, array_view)` function. It also integrates well
when connecting with other APIs already using gdb::array_view.
Add some overloads of the methods using raw pointers to avoid having to
change all call sites at once (which is both a lot of work and risky).
I tried to do this change in small increments, but since many of these
functions use each other, it ended up simpler to do it in one shot than
having a lot of intermediary / transient changes.
This change extends into gdbserver as well, because there is some part
of the regcache interface that is shared.
Changing the reg_buffer_common interface to use array_view caused some
build failures in nat/aarch64-scalable-linux-ptrace.c. That file
currently "takes advantage" of the fact that
reg_buffer_common::{raw_supply,raw_collect} operates on `void *`, which
IMO is dangerous. It uses raw_supply/raw_collect directly on
uint64_t's, which I guess is fine because it is expected that native
code will have the same endianness as the debugged process. To
accomodate that, add some overloads of raw_collect and raw_supply that
work on uint64_t.
This file also uses raw_collect and raw_supply on `char` pointers.
Change it to use `gdb_byte` pointers instead. Add overloads of
raw_collect and raw_supply that work on `gdb_byte *` and make an
array_view on the fly using the register's size. Those call sites could
be converted to use array_view with not much work, in which case these
overloads could be removed, but I didn't want to do it in this patch, to
avoid starting to dig in arch-specific code.
During development, I inadvertently changed reg_buffer::raw_compare's
behavior to not accept an offset equal to the register size. This
behavior (effectively comparing 0 bytes, returning true) change was
caught by the AArch64 SME core tests. Add a selftest to make sure that
this raw_compare behavior is preserved in the future.
Change-Id: I9005f04114543ddff738949e12d85a31855304c2
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Diffstat (limited to 'gdbsupport/rsp-low.h')
-rw-r--r-- | gdbsupport/rsp-low.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/gdbsupport/rsp-low.h b/gdbsupport/rsp-low.h index 327d5f3..1fc2572 100644 --- a/gdbsupport/rsp-low.h +++ b/gdbsupport/rsp-low.h @@ -54,6 +54,8 @@ extern std::string hex2str (const char *hex, int count); extern int bin2hex (const gdb_byte *bin, char *hex, int count); +extern int bin2hex (gdb::array_view<gdb_byte> bin, char *hex); + /* Overloaded version of bin2hex that returns a std::string. */ extern std::string bin2hex (const gdb_byte *bin, int count); |