/* See value.h. */
value *
-value_of_register_lazy (const frame_info_ptr &next_frame, int regnum)
+value_of_register_lazy (const frame_info_ptr &next_frame, int regnum,
+ struct type *type)
{
gdbarch *gdbarch = frame_unwind_arch (next_frame);
gdb_assert (regnum < gdbarch_num_cooked_regs (gdbarch));
gdb_assert (next_frame != nullptr);
- return value::allocate_register_lazy (next_frame, regnum);
+ return value::allocate_register_lazy (next_frame, regnum, type);
}
/* Given a pointer of type TYPE in target form in BUF, return the
frame_unwind_got_register (const frame_info_ptr &frame,
int regnum, int new_regnum)
{
+ struct gdbarch *gdbarch = frame_unwind_arch (frame);
+ struct type *regnum_type = register_type (gdbarch, regnum);
+ struct type *new_regnum_type = register_type (gdbarch, new_regnum);
+
+ /* REGNUM has been copied into NEW_REGNUM, therefore, the former
+ must be smaller or equal in size to the latter. */
+ gdb_assert (regnum_type->length () <= new_regnum_type->length ());
+
return value_of_register_lazy (get_next_frame_sentinel_okay (frame),
- new_regnum);
+ new_regnum, regnum_type);
}
/* Return a value which indicates that FRAME saved REGNUM in memory at
--- /dev/null
+/* Copyright 2025 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+volatile void dummy () {}
+
+long test_function(void)
+{
+ __asm__ volatile (
+ /* Zero d0 (64-bit vector register part of v0). */
+ "movi d0, #0\n\t"
+
+ /* Move the frame pointer (x29) to d0 using fmov. */
+ "fmov d0, x29\n\t"
+
+ /* Describe CFI: Frame pointer is now in d0. */
+ ".cfi_register x29, d0\n\t"
+
+ /* Clobber list: Specify all modified registers. */
+ : /* No output operands. */
+ : /* No input operands. */
+ : "d0"
+ );
+
+ dummy (); /* break-here */
+
+ __asm__ volatile (
+ /* Restore the frame pointer (x29) from d0 using fmov. */
+ "fmov x29, d0\n\t"
+
+ /* Describe CFI: Frame pointer is restored. */
+ ".cfi_restore x29\n\t"
+
+ /* Clobber list: Specify all modified registers. */
+ : /* No output operands. */
+ : /* No input operands. */
+ : "x29", "d0"
+ );
+
+ return 0;
+}
+
+int
+main ()
+{
+ long result = test_function ();
+ dummy ();
+ return 0;
+}
--- /dev/null
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+require is_aarch64_target
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ "${srcfile}" {debug}] } {
+ return -1
+}
+
+if {![runto_main]} {
+ return
+}
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here"
+gdb_test "with confirm off --return -1" "result = test_function \\(\\);"
+gdb_test "step" "dummy \\(\\);"
+gdb_test "print result" "= -1"
--- /dev/null
+/* Copyright 2025 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+volatile void dummy () {}
+
+long test_function(void)
+{
+ __asm__ volatile (
+ /* Clear xmm0. */
+ "vxorps %%xmm0, %%xmm0, %%xmm0\n\t"
+
+ /* Move the frame pointer (rbp) to xmm0. */
+ "movq %%rbp, %%xmm0\n\t"
+
+ /* CFI: Frame pointer is in xmm0. */
+ ".cfi_register %%rbp, %%xmm0\n\t"
+
+ /* Clobber list: Specify all modified registers */
+ : // No output operands
+ : // No input operands
+ : "xmm0"
+ );
+
+ dummy (); /* break-here */
+
+ /* Pseudo-epilogue: Restore rbp from xmm0. */
+ __asm__ volatile (
+ /* Restore rbp. */
+ "movq %%xmm0, %%rbp\n\t"
+
+ /* Describe CFI: Frame pointer is restored. */
+ ".cfi_restore %%rbp\n\t"
+
+ /* Clobber list: Specify all modified registers */
+ : /* No output operands. */
+ : /* No input operands. */
+ : /* Despite clobbering rbp, gcc doesn't let us list it here. */
+ );
+
+ return 0;
+}
+
+int
+main ()
+{
+ long result = test_function ();
+ dummy ();
+ return 0;
+}
--- /dev/null
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This test verifies that we can read and write the value of a pseudo register
+# in unwound frames. For the test, we choose one raw register, rbx, and one
+# pseudo register that is backed by rbx, ebx. We have two frames (the inner one,
+# #0 and the outer one, #1) that each set a value for rbx. We verify that we
+# can read both rbx and ebx correctly for each frame, and that when we write to
+# ebx, rbx for that frame is correctly updated.
+
+require is_x86_64_m64_target
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" ${testfile} \
+ "${srcfile}" {debug}] } {
+ return -1
+}
+
+if {![runto_main]} {
+ return
+}
+
+gdb_breakpoint [gdb_get_line_number "break-here"]
+gdb_continue_to_breakpoint "break-here"
+gdb_test "with confirm off --return -1" "result = test_function \\(\\);"
+gdb_test "step" "dummy \\(\\);"
+gdb_test "print result" "= -1"
extern value *value_of_register (int regnum, const frame_info_ptr &next_frame);
-/* Same as the above, but the value is not fetched. */
+/* Same as the above, but the value is not fetched. If TYPE is
+ non-nullptr, use it as the value type. Otherwise, 'register_type'
+ will be used to obtain the type. */
-extern value *value_of_register_lazy (const frame_info_ptr &next_frame, int regnum);
+extern value *value_of_register_lazy (const frame_info_ptr &next_frame,
+ int regnum, struct type *type = nullptr);
/* Return the symbol's reading requirement. */