[PATCH 11/24] gdb: make put_frame_register_bytes take the next frame

Simon Marchi
2023-11-08T05:15:23Z

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

Similar to the previous patches, change put_frame_register_bytes to take
the "next frame" instead of "this frame".

Change-Id: I27bcb26573686d99b231230823cff8db6405a788
---
gdb/dwarf2/expr.c | 6 +++---
gdb/frame.c | 14 +++++---------
gdb/frame.h | 4 ++--
gdb/mips-tdep.c | 11 ++++++-----
gdb/valops.c | 32 +++++++++++++++-----------------
5 files changed, 31 insertions(+), 36 deletions(-)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index b21016eb38bb..7fc7b3abf5ca 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -272,9 +272,9 @@ rw_pieced_value (value *v, value *from, bool check_optimized)
copy_bitwise (buffer.data (), bits_to_skip % 8,
from_contents, offset,
this_size_bits, bits_big_endian);
- put_frame_register_bytes (frame, gdb_regnum,
- bits_to_skip / 8,
- buffer);
+ put_frame_register_bytes
+ (get_next_frame_sentinel_okay (frame), gdb_regnum,
+ bits_to_skip / 8, buffer);
}
}
break;
diff --git a/gdb/frame.c b/gdb/frame.c
index 753dde189814..d4e2155fdb29 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1536,11 +1536,11 @@ get_frame_register_bytes (frame_info_ptr frame, int regnum,
}

void
-put_frame_register_bytes (frame_info_ptr frame, int regnum,
+put_frame_register_bytes (frame_info_ptr next_frame, int regnum,
CORE_ADDR offset,
gdb::array_view<const gdb_byte> buffer)
{
- struct gdbarch *gdbarch = get_frame_arch (frame);
+ gdbarch *gdbarch = frame_unwind_arch (next_frame);

/* Skip registers wholly inside of OFFSET. */
while (offset >= register_size (gdbarch, regnum))
@@ -1556,19 +1556,15 @@ put_frame_register_bytes (frame_info_ptr frame, int regnum,
buffer.size ());

if (curr_len == register_size (gdbarch, regnum))
- put_frame_register (get_next_frame_sentinel_okay (frame), regnum,
- buffer.slice (0, curr_len));
+ put_frame_register (next_frame, regnum, buffer.slice (0, curr_len));
else
{
- value *value
- = frame_unwind_register_value (frame_info_ptr (frame->next),
- regnum);
+ value *value = frame_unwind_register_value (next_frame, regnum);
gdb_assert (value != nullptr);

copy (buffer.slice (0, curr_len),
value->contents_writeable ().slice (offset, curr_len));
- put_frame_register (get_next_frame_sentinel_okay (frame), regnum,
- value->contents_raw ());
+ put_frame_register (next_frame, regnum, value->contents_raw ());
release_value (value);
}

diff --git a/gdb/frame.h b/gdb/frame.h
index 7d3b8da0243d..a25f6de35f0d 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -736,8 +736,8 @@ extern bool get_frame_register_bytes (frame_info_ptr frame, int regnum,
int *optimizedp, int *unavailablep);

/* Write bytes from BUFFER to one or multiple registers starting with REGNUM
- in frame FRAME, starting at OFFSET. */
-extern void put_frame_register_bytes (frame_info_ptr frame, int regnum,
+ in NEXT_FRAME's previous frame, starting at OFFSET. */
+extern void put_frame_register_bytes (frame_info_ptr next_frame, int regnum,
CORE_ADDR offset,
gdb::array_view<const gdb_byte> buffer);

diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 941397b7ccdc..ce3eed3eb70d 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -999,7 +999,8 @@ mips_value_to_register (frame_info_ptr frame, int regnum,
{
gdb_byte fill[8];
size_t len = type->length ();
-
+ frame_info_ptr next_frame = get_next_frame_sentinel_okay (frame);
+
/* Sign extend values, irrespective of type, that are stored to
a 64-bit general purpose register. (32-bit unsigned values
are stored as signed quantities within a 64-bit register.
@@ -1012,8 +1013,8 @@ mips_value_to_register (frame_info_ptr frame, int regnum,
store_signed_integer (fill, 8, BFD_ENDIAN_BIG, -1);
else
store_signed_integer (fill, 8, BFD_ENDIAN_BIG, 0);
- put_frame_register_bytes (frame, regnum, 0, {fill, 8 - len});
- put_frame_register_bytes (frame, regnum, 8 - len, {from, len});
+ put_frame_register_bytes (next_frame, regnum, 0, {fill, 8 - len});
+ put_frame_register_bytes (next_frame, regnum, 8 - len, {from, len});
}
else
{
@@ -1021,8 +1022,8 @@ mips_value_to_register (frame_info_ptr frame, int regnum,
store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, -1);
else
store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, 0);
- put_frame_register_bytes (frame, regnum, 0, {from, len});
- put_frame_register_bytes (frame, regnum, len, {fill, 8 - len});
+ put_frame_register_bytes (next_frame, regnum, 0, {from, len});
+ put_frame_register_bytes (next_frame, regnum, len, {fill, 8 - len});
}
}
else
diff --git a/gdb/valops.c b/gdb/valops.c
index 70851cd40b4f..2530c1d6412c 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1191,10 +1191,6 @@ value_assign (struct value *toval, struct value *fromval)

case lval_register:
{
- frame_info_ptr frame;
- struct gdbarch *gdbarch;
- int value_reg;
-
/* Figure out which frame this register value is in. The value
holds the frame_id for the next frame, that is the frame this
register value was unwound from.
@@ -1202,15 +1198,14 @@ value_assign (struct value *toval, struct value *fromval)
Below we will call put_frame_register_bytes which requires that
we pass it the actual frame in which the register value is
valid, i.e. not the next frame. */
- frame = frame_find_by_id (VALUE_NEXT_FRAME_ID (toval));
- frame = get_prev_frame_always (frame);
+ frame_info_ptr next_frame = frame_find_by_id (VALUE_NEXT_FRAME_ID (toval));

- value_reg = VALUE_REGNUM (toval);
+ int value_reg = VALUE_REGNUM (toval);

- if (!frame)
+ if (next_frame == nullptr)
error (_("Value being assigned to is no longer active."));

- gdbarch = get_frame_arch (frame);
+ gdbarch *gdbarch = frame_unwind_arch (next_frame);

if (toval->bitsize ())
{
@@ -1230,9 +1225,10 @@ value_assign (struct value *toval, struct value *fromval)
"don't fit in a %d bit word."),
(int) sizeof (LONGEST) * HOST_CHAR_BIT);

- if (!get_frame_register_bytes (frame, value_reg, offset,
- {buffer, changed_len},
- &optim, &unavail))
+ if (!get_frame_register_bytes (get_prev_frame_always (next_frame),
+ value_reg, offset,
+ { buffer, changed_len }, &optim,
+ &unavail))
{
if (optim)
throw_error (OPTIMIZED_OUT_ERROR,
@@ -1245,8 +1241,8 @@ value_assign (struct value *toval, struct value *fromval)
modify_field (type, buffer, value_as_long (fromval),
toval->bitpos (), toval->bitsize ());

- put_frame_register_bytes (frame, value_reg, offset,
- {buffer, changed_len});
+ put_frame_register_bytes (next_frame, value_reg, offset,
+ { buffer, changed_len });
}
else
{
@@ -1256,17 +1252,19 @@ value_assign (struct value *toval, struct value *fromval)
/* If TOVAL is a special machine register requiring
conversion of program values to a special raw
format. */
- gdbarch_value_to_register (gdbarch, frame,
+ gdbarch_value_to_register (gdbarch,
+ get_prev_frame_always (next_frame),
VALUE_REGNUM (toval), type,
fromval->contents ().data ());
}
else
- put_frame_register_bytes (frame, value_reg,
+ put_frame_register_bytes (next_frame, value_reg,
toval->offset (),
fromval->contents ());
}

- gdb::observers::register_changed.notify (frame, value_reg);
+ gdb::observers::register_changed.notify
+ (get_prev_frame_always (next_frame), value_reg);
break;
}

--
2.42.1