From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 07/24] gdb: make put_frame_register take an array_view
Date: Wed, 8 Nov 2023 00:00:51 -0500 [thread overview]
Message-ID: <20231108051222.1275306-8-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20231108051222.1275306-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@efficios.com>
Change put_frame_register to take an array_view instead of a raw
pointer.
Add an assertion to verify that the number of bytes we try to write
matches the length of the register.
Change-Id: Ib75a9c8a12b47e203097621643eaa2c1830591ae
---
gdb/alpha-tdep.c | 12 ++++++------
gdb/frame.c | 13 ++++++++-----
gdb/frame.h | 2 +-
gdb/i386-tdep.c | 3 ++-
gdb/i387-tdep.c | 6 ++++--
gdb/ia64-tdep.c | 6 ++++--
gdb/m68k-tdep.c | 7 ++++---
gdb/mips-tdep.c | 5 +++--
gdb/rs6000-tdep.c | 7 ++++---
9 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index 9fb973597fc4..1901b9449e6c 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -263,14 +263,14 @@ static void
alpha_value_to_register (frame_info_ptr frame, int regnum,
struct type *valtype, const gdb_byte *in)
{
- gdb_byte out[ALPHA_REGISTER_SIZE];
-
+ int reg_size = register_size (get_frame_arch (frame), regnum);
gdb_assert (valtype->length () == 4);
- gdb_assert (register_size (get_frame_arch (frame), regnum)
- <= ALPHA_REGISTER_SIZE);
- alpha_lds (get_frame_arch (frame), out, in);
+ gdb_assert (reg_size <= ALPHA_REGISTER_SIZE);
- put_frame_register (frame, regnum, out);
+ gdb_byte out[ALPHA_REGISTER_SIZE];
+ alpha_lds (get_frame_arch (frame), out, in);
+ auto out_view = gdb::make_array_view (out, reg_size);
+ put_frame_register (frame, regnum, out_view);
}
\f
diff --git a/gdb/frame.c b/gdb/frame.c
index b3d99163b4dc..84ef8461b835 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1423,7 +1423,7 @@ read_frame_register_unsigned (frame_info_ptr frame, int regnum,
void
put_frame_register (frame_info_ptr frame, int regnum,
- const gdb_byte *buf)
+ gdb::array_view<const gdb_byte> buf)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
int realnum;
@@ -1431,6 +1431,9 @@ put_frame_register (frame_info_ptr frame, int regnum,
int unavail;
enum lval_type lval;
CORE_ADDR addr;
+ int size = register_size (gdbarch, regnum);
+
+ gdb_assert (buf.size () == size);
frame_register (frame, regnum, &optim, &unavail,
&lval, &addr, &realnum, NULL);
@@ -1440,11 +1443,11 @@ put_frame_register (frame_info_ptr frame, int regnum,
{
case lval_memory:
{
- write_memory (addr, buf, register_size (gdbarch, regnum));
+ write_memory (addr, buf.data (), size);
break;
}
case lval_register:
- get_current_regcache ()->cooked_write (realnum, buf);
+ get_current_regcache ()->cooked_write (realnum, buf, 1.0f);
break;
default:
error (_("Attempt to assign to an unmodifiable value."));
@@ -1576,7 +1579,7 @@ put_frame_register_bytes (frame_info_ptr frame, int regnum,
buffer.size ());
if (curr_len == register_size (gdbarch, regnum))
- put_frame_register (frame, regnum, buffer.data ());
+ put_frame_register (frame, regnum, buffer.slice (0, curr_len));
else
{
value *value
@@ -1586,7 +1589,7 @@ put_frame_register_bytes (frame_info_ptr frame, int regnum,
copy (buffer.slice (0, curr_len),
value->contents_writeable ().slice (offset, curr_len));
- put_frame_register (frame, regnum, value->contents_raw ().data ());
+ put_frame_register (frame, regnum, value->contents_raw ());
release_value (value);
}
diff --git a/gdb/frame.h b/gdb/frame.h
index 1d7422cac32b..e3393cdd972c 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -724,7 +724,7 @@ extern bool read_frame_register_unsigned (frame_info_ptr frame,
frame. Note: this call makes the frame's state undefined. The
register and frame caches must be flushed. */
extern void put_frame_register (frame_info_ptr frame, int regnum,
- const gdb_byte *buf);
+ gdb::array_view<const gdb_byte> buf);
/* Read LEN bytes from one or multiple registers starting with REGNUM
in frame FRAME, starting at OFFSET, into BUF. If the register
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 2759c1a558c5..7f6ea5ba06ec 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3917,7 +3917,8 @@ i386_value_to_register (frame_info_ptr frame, int regnum,
gdb_assert (regnum != -1);
gdb_assert (register_size (get_frame_arch (frame), regnum) == 4);
- put_frame_register (frame, regnum, from);
+ auto from_view = gdb::make_array_view (from, 4);
+ put_frame_register (frame, regnum, from_view);
regnum = i386_next_regnum (regnum);
len -= 4;
from += 4;
diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c
index 47667da21c7d..74481f5aeb3c 100644
--- a/gdb/i387-tdep.c
+++ b/gdb/i387-tdep.c
@@ -397,8 +397,10 @@ i387_value_to_register (frame_info_ptr frame, int regnum,
}
/* Convert from TYPE. */
- target_float_convert (from, type, to, i387_ext_type (gdbarch));
- put_frame_register (frame, regnum, to);
+ struct type *to_type = i387_ext_type (gdbarch);
+ target_float_convert (from, type, to, to_type);
+ auto to_view = gdb::make_array_view (to, to_type->length ());
+ put_frame_register (frame, regnum, to_view);
}
\f
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index cdd5553cf5d3..113d384e8649 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -1245,8 +1245,10 @@ ia64_value_to_register (frame_info_ptr frame, int regnum,
{
struct gdbarch *gdbarch = get_frame_arch (frame);
gdb_byte out[IA64_FP_REGISTER_SIZE];
- target_float_convert (in, valtype, out, ia64_ext_type (gdbarch));
- put_frame_register (frame, regnum, out);
+ type *to_type = ia64_ext_type (gdbarch);
+ target_float_convert (in, valtype, out, to_type);
+ auto out_view = gdb::make_array_view (out, to_type->length ());
+ put_frame_register (frame, regnum, out_view);
}
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 5b2a29a350e5..5a80ecb94390 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -236,8 +236,8 @@ m68k_value_to_register (frame_info_ptr frame, int regnum,
struct type *type, const gdb_byte *from)
{
gdb_byte to[M68K_MAX_REGISTER_SIZE];
- struct type *fpreg_type = register_type (get_frame_arch (frame),
- M68K_FP0_REGNUM);
+ gdbarch *arch = get_frame_arch (frame);
+ struct type *fpreg_type = register_type (arch, M68K_FP0_REGNUM);
/* We only support floating-point values. */
if (type->code () != TYPE_CODE_FLT)
@@ -249,7 +249,8 @@ m68k_value_to_register (frame_info_ptr frame, int regnum,
/* Convert from TYPE. */
target_float_convert (from, type, to, fpreg_type);
- put_frame_register (frame, regnum, to);
+ auto to_view = gdb::make_array_view (to, fpreg_type->length ());
+ put_frame_register (frame, regnum, to_view);
}
\f
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index d40d28e85de5..6bd0a66a6284 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -990,8 +990,9 @@ mips_value_to_register (frame_info_ptr frame, int regnum,
if (mips_convert_register_float_case_p (gdbarch, regnum, type))
{
- put_frame_register (frame, regnum + 0, from + 4);
- put_frame_register (frame, regnum + 1, from + 0);
+ auto from_view = gdb::make_array_view (from, 8);
+ put_frame_register (frame, regnum, from_view.slice (4));
+ put_frame_register (frame, regnum + 1, from_view.slice (0, 4));
}
else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type))
{
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index bae6737852d8..9fb3f326bd07 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -2715,9 +2715,10 @@ rs6000_value_to_register (frame_info_ptr frame,
gdb_assert (type->code () == TYPE_CODE_FLT);
- target_float_convert (from, type,
- to, builtin_type (gdbarch)->builtin_double);
- put_frame_register (frame, regnum, to);
+ struct type *to_type = builtin_type (gdbarch)->builtin_double;
+ target_float_convert (from, type, to, to_type);
+ auto to_view = gdb::make_array_view (to, to_type->length ());
+ put_frame_register (frame, regnum, to_view);
}
/* The type of a function that moves the value of REG between CACHE
--
2.42.1
next prev parent reply other threads:[~2023-11-08 5:21 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 5:00 [PATCH 00/24] Fix reading and writing pseudo registers in non-current frames Simon Marchi
2023-11-08 5:00 ` [PATCH 01/24] gdb: don't handle i386 k registers as pseudo registers Simon Marchi
2023-11-11 19:29 ` John Baldwin
2023-11-08 5:00 ` [PATCH 02/24] gdb: use reg_buffer_common throughout gdbsupport/common-regcache.h Simon Marchi
2023-11-11 19:42 ` John Baldwin
2023-11-08 5:00 ` [PATCH 03/24] gdb: make store_integer take an array_view Simon Marchi
2023-11-08 5:00 ` [PATCH 04/24] gdb: simplify conditions in regcache::{read,write,raw_collect,raw_supply}_part Simon Marchi
2023-11-08 5:00 ` [PATCH 05/24] gdb: change regcache interface to use array_view Simon Marchi
2023-11-13 13:43 ` Andrew Burgess
2023-11-13 14:00 ` Andrew Burgess
2023-11-13 16:47 ` Simon Marchi
2023-11-08 5:00 ` [PATCH 06/24] gdb: fix bugs in {get,put}_frame_register_bytes Simon Marchi
2023-11-13 15:00 ` Andrew Burgess
2023-11-13 19:51 ` Simon Marchi
2023-11-08 5:00 ` Simon Marchi [this message]
2023-11-08 5:00 ` [PATCH 08/24] gdb: change value_of_register and value_of_register_lazy to take the next frame Simon Marchi
2023-11-08 5:00 ` [PATCH 09/24] gdb: remove frame_register Simon Marchi
2023-11-08 5:00 ` [PATCH 10/24] gdb: make put_frame_register take the next frame Simon Marchi
2023-11-08 5:00 ` [PATCH 11/24] gdb: make put_frame_register_bytes " Simon Marchi
2023-11-08 5:00 ` [PATCH 12/24] gdb: make get_frame_register_bytes " Simon Marchi
2023-11-08 5:00 ` [PATCH 13/24] gdb: add value::allocate_register Simon Marchi
2023-11-08 5:00 ` [PATCH 14/24] gdb: read pseudo register through frame Simon Marchi
2023-11-11 20:11 ` John Baldwin
2023-11-08 5:00 ` [PATCH 15/24] gdb: change parameter name in frame_unwind_register_unsigned declaration Simon Marchi
2023-11-08 5:01 ` [PATCH 16/24] gdb: rename gdbarch_pseudo_register_write to gdbarch_deprecated_pseudo_register_write Simon Marchi
2023-11-14 12:12 ` Andrew Burgess
2023-11-14 15:16 ` Simon Marchi
2023-11-08 5:01 ` [PATCH 17/24] gdb: add gdbarch_pseudo_register_write that takes a frame Simon Marchi
2023-11-14 12:20 ` Andrew Burgess
2023-11-14 15:20 ` Simon Marchi
2023-11-08 5:01 ` [PATCH 18/24] gdb: migrate i386 and amd64 to the new gdbarch_pseudo_register_write Simon Marchi
2023-11-11 20:16 ` John Baldwin
2023-11-13 2:59 ` Simon Marchi
2023-11-08 5:01 ` [PATCH 19/24] gdb: make aarch64_za_offsets_from_regnum return za_offsets Simon Marchi
2023-11-08 5:01 ` [PATCH 20/24] gdb: add missing raw register read in aarch64_sme_pseudo_register_write Simon Marchi
2023-11-08 5:01 ` [PATCH 21/24] gdb: migrate aarch64 to new gdbarch_pseudo_register_write Simon Marchi
2023-11-08 5:01 ` [PATCH 22/24] gdb: migrate arm to gdbarch_pseudo_register_read_value Simon Marchi
2023-11-08 5:01 ` [PATCH 23/24] gdb: migrate arm to new gdbarch_pseudo_register_write Simon Marchi
2023-11-08 5:01 ` [PATCH 24/24] gdb/testsuite: add tests for unwinding of pseudo registers Simon Marchi
2023-11-08 5:16 ` [PATCH 00/24] Fix reading and writing pseudo registers in non-current frames Simon Marchi
2023-11-09 3:05 ` Simon Marchi
2023-11-08 11:57 ` Luis Machado
2023-11-08 15:47 ` Simon Marchi
2023-11-08 17:08 ` Luis Machado
2023-11-08 19:34 ` Simon Marchi
2023-11-09 19:04 ` Simon Marchi
2023-11-13 13:10 ` Luis Machado
2023-11-13 15:08 ` Luis Machado
2023-11-11 20:26 ` John Baldwin
2023-11-13 3:03 ` Simon Marchi
2023-12-01 16:27 Simon Marchi
2023-12-01 16:27 ` [PATCH 07/24] gdb: make put_frame_register take an array_view Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231108051222.1275306-8-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).