binutils-gdb/gdbsupport
Simon Marchi 51e6b8cfd6 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>
2023-12-14 16:04:49 +00:00
..
.dir-locals.el
.gitattributes
acinclude.m4
aclocal.m4 Finalized intl-update patches 2023-11-15 12:53:04 +00:00
agent.cc Do not cast away const in agent_run_command 2023-02-14 09:01:18 -07:00
agent.h Do not cast away const in agent_run_command 2023-02-14 09:01:18 -07:00
alt-stack.h
array-view.h Enable some C++14 code in array-view.h 2023-11-29 14:29:44 -07:00
ax.def
block-signals.h
break-common.h
btrace-common.cc Use C++17 [[fallthrough]] attribute 2023-11-29 14:29:43 -07:00
btrace-common.h gdb: c++ify btrace_target_info 2023-09-11 06:15:52 +00:00
buildargv.h
byte-vector.h
ChangeLog-2020-2021
check-defines.el
cleanups.cc
cleanups.h
common-debug.cc
common-debug.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
common-defs.h Remove EXTERN_C and related defines 2023-11-06 20:31:12 -07:00
common-exceptions.cc [gdb] Fix typos 2023-06-03 22:43:57 +02:00
common-exceptions.h [gdb/build, c++20] Fix Wdeprecated-enum-enum-conversion 2023-08-17 10:41:34 +02:00
common-gdbthread.h
common-inferior.cc
common-inferior.h
common-regcache.cc gdb: use reg_buffer_common throughout gdbsupport/common-regcache.h 2023-12-14 16:04:49 +00:00
common-regcache.h gdb: change regcache interface to use array_view 2023-12-14 16:04:49 +00:00
common-types.h Move unrelocated_addr to common-types.h 2023-06-05 09:59:18 -06:00
common-utils.cc gdb: Fix building with latest libc++ 2023-04-29 00:35:11 -07:00
common-utils.h gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
common.m4 Move -lsocket check to common.m4 2023-10-12 18:23:13 -06:00
compiler-type.m4
config.in Finalized intl-update patches 2023-11-15 12:53:04 +00:00
configure Switch to -Wimplicit-fallthrough=5 2023-11-29 14:29:43 -07:00
configure.ac gdb/gdbsupport/gdbserver: Require c++17 2023-10-28 19:25:34 +00:00
create-version.sh
def-vector.h
default-init-alloc.h [gdb/build, c++20] Handle deprecated std::allocator::construct 2023-08-17 10:41:34 +02:00
eintr.h
enum-flags.h [gdb] Fix typos 2023-06-03 22:43:57 +02:00
environ.cc
environ.h
errors.cc Introduce throw_winerror_with_name 2023-11-27 12:55:14 -07:00
errors.h Introduce throw_winerror_with_name 2023-11-27 12:55:14 -07:00
event-loop.cc gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
event-loop.h
event-pipe.cc
event-pipe.h
fileio.cc
fileio.h gdb, gdbserver, gdbsupport: fix whitespace issues 2023-03-09 16:32:00 -05:00
filestuff.cc gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
filestuff.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
filtered-iterator.h gdbsupport: Replace gdb::invoke_result with std::invoke_result 2023-11-21 11:52:36 +00:00
format.cc Use C++17 [[fallthrough]] attribute 2023-11-29 14:29:43 -07:00
format.h gdb: Use std::string_view instead of gdb::string_view 2023-11-21 11:52:36 +00:00
forward-scope-exit.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
function-view.h gdbsupport: Replace gdb::invoke_result with std::invoke_result 2023-11-21 11:52:36 +00:00
gdb_assert.h Remove gdb_static_assert 2023-11-29 14:29:44 -07:00
gdb_binary_search.h
gdb_file.h
gdb_locale.h
gdb_obstack.cc
gdb_obstack.h
gdb_proc_service.h Remove EXTERN_C and related defines 2023-11-06 20:31:12 -07:00
gdb_ref_ptr.h
gdb_regex.cc
gdb_regex.h
gdb_select.h
gdb_setjmp.h
gdb_signals.h [gdb] Fix typos 2023-06-03 22:43:57 +02:00
gdb_splay_tree.h
gdb_sys_time.h
gdb_tilde_expand.cc gdb, gdbserver, gdbsupport: fix whitespace issues 2023-03-09 16:32:00 -05:00
gdb_tilde_expand.h
gdb_unique_ptr.h gdb: Use C++17's std::make_unique instead of gdb::make_unique 2023-11-21 11:52:35 +00:00
gdb_unlinker.h
gdb_vecs.cc
gdb_vecs.h
gdb_wait.cc
gdb_wait.h Remove explanatory comments from includes 2023-09-20 11:45:16 -06:00
gdb-checked-static-cast.h gdbsupport: add support for references to checked_static_cast 2023-05-24 14:53:53 -04:00
gdb-dlfcn.cc
gdb-dlfcn.h
gdb-hashtab.cc
gdb-hashtab.h
gdb-safe-ctype.h gdb: Fix building with latest libc++ 2023-04-29 00:35:11 -07:00
gdb-sigmask.h
gdb-xfree.h
hash_enum.h
host-defs.h
intrusive_list.h gdbsupport: use "reference" and "pointer" type aliases in intrusive_list 2023-10-19 10:57:51 -04:00
iterator-range.h
job-control.cc
job-control.h
Makefile.am Finalized intl-update patches 2023-11-15 12:53:04 +00:00
Makefile.in Finalized intl-update patches 2023-11-15 12:53:04 +00:00
netstuff.cc
netstuff.h
new-op.cc Rely on C++17 <new> in new-op.cc 2023-11-29 14:29:44 -07:00
next-iterator.h
observable.h gdb, gdbserver, gdbsupport: fix whitespace issues 2023-03-09 16:32:00 -05:00
offset-type.h
packed.h Remove gdb_static_assert 2023-11-29 14:29:44 -07:00
parallel-for.h gdbsupport: Replace gdb::invoke_result with std::invoke_result 2023-11-21 11:52:36 +00:00
pathstuff.cc [gdb] Fix typos 2023-06-03 22:43:57 +02:00
pathstuff.h Remove gdb_static_assert 2023-11-29 14:29:44 -07:00
poison.h [gdb/build, c++20] Stop using deprecated is_pod 2023-08-17 10:41:34 +02:00
preprocessor.h
print-utils.cc
print-utils.h
ptid.cc
ptid.h Fix build failure with GCC 4.8 2023-09-15 10:36:15 -06:00
ptrace.m4
range-chain.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
README
refcounted-object.h [gdb] Fix segfault in for_each_block, part 1 2023-11-28 10:31:25 +01:00
reference-to-pointer-iterator.h [gdb] Fix typos 2023-06-03 22:43:57 +02:00
rsp-low.cc gdb: change regcache interface to use array_view 2023-12-14 16:04:49 +00:00
rsp-low.h gdb: change regcache interface to use array_view 2023-12-14 16:04:49 +00:00
run-time-clock.cc
run-time-clock.h
safe-iterator.h gdbsupport: Replace gdb::invoke_result with std::invoke_result 2023-11-21 11:52:36 +00:00
safe-strerror.cc
scope-exit.h Rely on copy elision in scope-exit.h 2023-11-29 14:29:44 -07:00
scoped_fd.h
scoped_ignore_signal.h
scoped_ignore_sigttou.h gdb: Replace gdb::optional with std::optional 2023-11-21 11:52:35 +00:00
scoped_mmap.cc
scoped_mmap.h
scoped_restore.h
search.cc
search.h
selftest.cc gdbsupport: record and print failed selftest names 2023-11-03 14:25:59 -04:00
selftest.h
selftest.m4
signals-state-save-restore.cc
signals-state-save-restore.h
signals.cc [gdb] Fix typos 2023-06-03 22:43:57 +02:00
symbol.h
tdesc.cc
tdesc.h
thread-pool.cc gdb: Enable early init of thread pool size 2023-12-04 14:23:17 +00:00
thread-pool.h gdb: Enable early init of thread pool size 2023-12-04 14:23:17 +00:00
traits.h Use C++17 void_t 2023-11-29 14:29:44 -07:00
underlying.h
valid-expr.h
version.h
warning.m4 Switch to -Wimplicit-fallthrough=5 2023-11-29 14:29:43 -07:00
x86-xstate.h x86: Remove X86_XSTATE_SIZE and related constants. 2023-08-28 14:18:19 -07:00
xml-utils.cc
xml-utils.h

This is a helper library that is used by gdb and gdbserver.

To send patches, follow the gdb patch submission instructions in
../gdb/CONTRIBUTE.  For maintainers, see ../gdb/MAINTAINERS.