[PATCH 03/24] gdb: make store_integer take an array_view

Simon Marchi
2023-11-08T05:13:07Z

From: Simon Marchi <simon.marchi@efficios.com>

Change store_integer, store_signed_integer and store_unsigned_integer to
accept an array_view. Add some backwards compatibility overloads to
avoid changing all callers at once.

Change-Id: Ibb1381228ab1cb65fc7e2e4b92cf9ab1047cdc03
---
gdb/defs.h | 39 +++++++++++++++++++++++++++++++--------
gdb/findvar.c | 16 +++++++---------
2 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/gdb/defs.h b/gdb/defs.h
index b8612e1ac6d3..8170ec53c87c 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -501,21 +501,44 @@ extern CORE_ADDR extract_typed_address (const gdb_byte *buf,
target-format integer at ADDR which is LEN bytes long. */

template<typename T, typename = RequireLongest<T>>
-extern void store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order,
- T val);
+extern void store_integer (gdb::array_view<gdb_byte> dst,
+ bfd_endian byte_order, T val);
+
+template<typename T>
+static inline void
+store_integer (gdb_byte *addr, int len, bfd_endian byte_order, T val)
+{
+ return store_integer (gdb::make_array_view (addr, len), byte_order, val);
+}
+
+static inline void
+store_signed_integer (gdb::array_view<gdb_byte> dst, bfd_endian byte_order,
+ LONGEST val)
+{
+ return store_integer (dst, byte_order, val);
+}
+
+static inline void
+store_signed_integer (gdb_byte *addr, int len, bfd_endian byte_order,
+ LONGEST val)
+{
+ return store_signed_integer (gdb::make_array_view (addr, len), byte_order,
+ val);
+}

static inline void
-store_signed_integer (gdb_byte *addr, int len,
- enum bfd_endian byte_order, LONGEST val)
+store_unsigned_integer (gdb::array_view<gdb_byte> dst, bfd_endian byte_order,
+ ULONGEST val)
{
- return store_integer (addr, len, byte_order, val);
+ return store_integer (dst, byte_order, val);
}

static inline void
-store_unsigned_integer (gdb_byte *addr, int len,
- enum bfd_endian byte_order, ULONGEST val)
+store_unsigned_integer (gdb_byte *addr, int len, bfd_endian byte_order,
+ LONGEST val)
{
- return store_integer (addr, len, byte_order, val);
+ return store_unsigned_integer (gdb::make_array_view (addr, len), byte_order,
+ val);
}

extern void store_typed_address (gdb_byte *buf, struct type *type,
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 4e992ecdcc73..edb61fb27317 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -160,12 +160,12 @@ extract_typed_address (const gdb_byte *buf, struct type *type)
target-format integer at ADDR which is LEN bytes long. */
template<typename T, typename>
void
-store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order,
+store_integer (gdb::array_view<gdb_byte> dst, enum bfd_endian byte_order,
T val)
{
gdb_byte *p;
- gdb_byte *startaddr = addr;
- gdb_byte *endaddr = startaddr + len;
+ gdb_byte *startaddr = dst.data ();
+ gdb_byte *endaddr = startaddr + dst.size ();

/* Start at the least significant end of the integer, and work towards
the most significant. */
@@ -188,13 +188,11 @@ store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order,
}

/* Explicit instantiations. */
-template void store_integer (gdb_byte *addr, int len,
- enum bfd_endian byte_order,
- LONGEST val);
+template void store_integer (gdb::array_view<gdb_byte> dst,
+ bfd_endian byte_order, LONGEST val);

-template void store_integer (gdb_byte *addr, int len,
- enum bfd_endian byte_order,
- ULONGEST val);
+template void store_integer (gdb::array_view<gdb_byte> dst,
+ bfd_endian byte_order, ULONGEST val);

/* Store the address ADDR as a pointer of type TYPE at BUF, in target
form. */
--
2.42.1