aboutsummaryrefslogtreecommitdiff
path: root/gdb/frame.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2023-12-01 11:27:18 -0500
committerSimon Marchi <simon.marchi@efficios.com>2023-12-14 16:04:49 +0000
commit51e6b8cfd649013ae16a3d00f1451b2531ba6bc9 (patch)
tree7f07b62493f0ffdcfb523d57452812cf491a88f2 /gdb/frame.c
parent08d8e7ff9474a88b491d22139ace851daae1a1c6 (diff)
downloadgdb-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 'gdb/frame.c')
-rw-r--r--gdb/frame.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/gdb/frame.c b/gdb/frame.c
index 2a8a33b..529453e 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1108,9 +1108,9 @@ get_frame_func (frame_info_ptr this_frame)
std::unique_ptr<readonly_detached_regcache>
frame_save_as_regcache (frame_info_ptr this_frame)
{
- auto cooked_read = [this_frame] (int regnum, gdb_byte *buf)
+ auto cooked_read = [this_frame] (int regnum, gdb::array_view<gdb_byte> buf)
{
- if (!deprecated_frame_register_read (this_frame, regnum, buf))
+ if (!deprecated_frame_register_read (this_frame, regnum, buf.data ()))
return REG_UNAVAILABLE;
else
return REG_VALID;