aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2024-01-11 11:41:04 -0500
committerSimon Marchi <simon.marchi@efficios.com>2024-01-11 13:11:19 -0500
commit47ff07a6c283a39fa3b8c92d823c8851678dfc0f (patch)
tree6197067697917b5a2a6685c66ce9d961d270296f /gdb
parentfa87f8e1958b8937047e3d5fcfd8c265745710ae (diff)
downloadfsf-binutils-gdb-47ff07a6c283a39fa3b8c92d823c8851678dfc0f.zip
fsf-binutils-gdb-47ff07a6c283a39fa3b8c92d823c8851678dfc0f.tar.gz
fsf-binutils-gdb-47ff07a6c283a39fa3b8c92d823c8851678dfc0f.tar.bz2
gdb: fix frame passed to gdbarch_value_to_register in value_assign
Commit 78f2fd84e83 ("gdb: remove VALUE_REGNUM, add value::regnum") introduced an unexpected change in value_assign. It replaced `get_prev_frame_always (next_frame)` with `next_frame`in the call to gdbarch_value_to_register. This is the result of a merge error, since I previously had a patch to change gdbarch_value_to_register to take the next frame, and later decided to drop it. Revert that change. Add a test based on the DWARF assembler to expose the problem and test the fix. I also tested on ppc64le to make sure the problem reported in PR 31231 was fixed. Change-Id: Ib8b851287ac27a4b2e386f7b680cf65865e6aee6 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31231
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.dwarf2/assign-variable-value-to-register.exp86
-rw-r--r--gdb/valops.c3
2 files changed, 88 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.dwarf2/assign-variable-value-to-register.exp b/gdb/testsuite/gdb.dwarf2/assign-variable-value-to-register.exp
new file mode 100644
index 0000000..14f6b90
--- /dev/null
+++ b/gdb/testsuite/gdb.dwarf2/assign-variable-value-to-register.exp
@@ -0,0 +1,86 @@
+# Copyright 2024 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/>.
+
+# Test writing to a variable that is in a register that causes
+# gdbarch_value_to_register to be called. This was introduced to test
+# PR 31231 (https://sourceware.org/bugzilla/show_bug.cgi?id=31231).
+
+# This test uses a hard-coded x86-64 DWARF register number, so restrict it to
+# x86-64.
+if { ![is_x86_64_m64_target] } {
+ unsupported "unsupported architecture"
+}
+
+load_lib dwarf.exp
+
+standard_testfile main.c -dw.S
+set dwarf_file [standard_output_file $srcfile2]
+
+set st0_dwarf_regnum 33
+
+Dwarf::assemble $dwarf_file {
+ get_func_info main
+
+ cu {} {
+ DW_TAG_compile_unit {} {
+ declare_labels int_label float_label
+
+ int_label: DW_TAG_base_type {
+ { DW_AT_name int }
+ { DW_AT_byte_size 4 DW_FORM_udata }
+ { DW_AT_encoding @DW_ATE_signed }
+ }
+
+ float_label: DW_TAG_base_type {
+ { DW_AT_name float }
+ { DW_AT_byte_size 4 DW_FORM_udata }
+ { DW_AT_encoding @DW_ATE_float }
+ }
+
+ DW_TAG_subprogram {
+ { DW_AT_name main }
+ { DW_AT_low_pc $main_start DW_FORM_addr }
+ { DW_AT_high_pc $main_end DW_FORM_addr }
+ { DW_AT_type :$int_label }
+ } {
+ DW_TAG_variable {
+ { DW_AT_name foo }
+ { DW_AT_type :$float_label }
+ { DW_AT_location {
+ DW_OP_regx $::st0_dwarf_regnum
+ } SPECIAL_expr }
+ }
+ }
+ }
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" $testfile \
+ [list $srcfile $dwarf_file] {nodebug}] } {
+ return
+}
+
+if { ![runto_main] } {
+ return
+}
+
+# st0 is expected to be initialized to 0.
+gdb_test "p foo" " = 0" "print foo before"
+
+# Set foo. This used to cause an internal error.
+gdb_test_no_output "set foo = 1234"
+
+# Confirm the value.
+gdb_test "p foo" " = 1234" "print foo after"
diff --git a/gdb/valops.c b/gdb/valops.c
index 16cdf1f..1477934 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1244,7 +1244,8 @@ 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, next_frame,
+ gdbarch_value_to_register (gdbarch,
+ get_prev_frame_always (next_frame),
toval->regnum (), type,
fromval->contents ().data ());
}