public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: fix frame passed to gdbarch_value_to_register in value_assign
@ 2024-01-11 16:51 Simon Marchi
  2024-01-11 17:24 ` Tom de Vries
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2024-01-11 16:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom de Vries, Simon Marchi

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
---
 .../assign-variable-value-to-register.exp     | 86 +++++++++++++++++++
 gdb/valops.c                                  |  3 +-
 2 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 gdb/testsuite/gdb.dwarf2/assign-variable-value-to-register.exp

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 000000000000..770f665ca959
--- /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"
+
+# Set foo.  This used to cause an internal error.
+gdb_test_no_output "set foo = 1234"
+
+# Confirm the value.
+gdb_test "p foo" " = 1234"
diff --git a/gdb/valops.c b/gdb/valops.c
index 16cdf1f45530..147793400d90 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 ());
 	      }

base-commit: fa87f8e1958b8937047e3d5fcfd8c265745710ae
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-11 18:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-11 16:51 [PATCH] gdb: fix frame passed to gdbarch_value_to_register in value_assign Simon Marchi
2024-01-11 17:24 ` Tom de Vries
2024-01-11 18:08   ` Simon Marchi

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).