diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2018-10-16 22:40:09 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2018-10-23 10:32:34 +0100 |
commit | 0dbfcfffe9abbc5198bce95eb8c66b6bc9b364be (patch) | |
tree | 389fd6bdc0b2f58914bfbdf59b28ea798ae5be33 /gdb/testsuite/gdb.arch | |
parent | Automatic date update in version.in (diff) | |
download | binutils-gdb-0dbfcfffe9abbc5198bce95eb8c66b6bc9b364be.tar.gz binutils-gdb-0dbfcfffe9abbc5198bce95eb8c66b6bc9b364be.tar.bz2 binutils-gdb-0dbfcfffe9abbc5198bce95eb8c66b6bc9b364be.zip |
gdb/riscv: Fix register access for register aliases
Some confusion over how the register names and aliases are setup in
riscv means that we currently can't access registers through their
architectural name.
This commit fixes this issue, and moves some of the csr register
handling out of the alias handling code and deals with it separately.
This has the benefit that we can now directly access some arrays
rather than having to iterate over them.
A new test is added to ensure that register aliases now work
correctly.
gdb/ChangeLog:
* riscv-tdep.c (riscv_gdb_reg_names): Update comment, and all
register names.
(struct register_alias): Rename to...
(struct riscv_register_alias): ...this, and update comment.
(riscv_register_aliases): Update type, and alias names. Remove
CSR names from this list.
(riscv_register_name): Use riscv_gdb_reg_names for int and float
register names. Add an extra assertion.
(riscv_is_regnum_a_named_csr): New function.
(riscv_register_reggroup_p): Use riscv_is_regnum_a_named_csr.
gdb/testsuite/ChangeLog:
* gdb.arch/riscv-reg-aliases.c: New file.
* gdb.arch/riscv-reg-aliases.exp: New file.
Diffstat (limited to 'gdb/testsuite/gdb.arch')
-rw-r--r-- | gdb/testsuite/gdb.arch/riscv-reg-aliases.c | 22 | ||||
-rw-r--r-- | gdb/testsuite/gdb.arch/riscv-reg-aliases.exp | 130 |
2 files changed, 152 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.arch/riscv-reg-aliases.c b/gdb/testsuite/gdb.arch/riscv-reg-aliases.c new file mode 100644 index 00000000000..f6341e30a1e --- /dev/null +++ b/gdb/testsuite/gdb.arch/riscv-reg-aliases.c @@ -0,0 +1,22 @@ +/* This file is part of GDB, the GNU debugger. + + Copyright 2018 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/>. */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.arch/riscv-reg-aliases.exp b/gdb/testsuite/gdb.arch/riscv-reg-aliases.exp new file mode 100644 index 00000000000..0b54723d8bc --- /dev/null +++ b/gdb/testsuite/gdb.arch/riscv-reg-aliases.exp @@ -0,0 +1,130 @@ +# Copyright 2018 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/>. + +if {![istarget "riscv*-*-*"]} { + verbose "Skipping ${gdb_test_file_name}." + return +} + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +if ![runto_main] then { + fail "can't run to main" + return 0 +} + +# A list, each entry is itself a list, the first item being the +# primary name of a register (the name GDB uses by default), and the +# second entry being a list of register aliases. +set register_names \ +{ { ra {x1} } { sp {x2} } { gp {x3} } { tp {x4} } { t0 {x5} } \ + { t1 {x6} } { t2 {x7} } { fp {x8 s0} } { s1 {x9} } { a0 {x10} } \ + { a1 {x11} } { a2 {x12} } { a3 {x13} } { a4 {x14} } { a5 {x15} } \ + { a6 {x16} } { a7 {x17} } { s2 {x18} } { s3 {x19} } { s4 {x20} } \ + { s5 {x21} } { s6 {x22} } { s7 {x23} } { s8 {x24} } { s9 {x25} } \ + { s10 {x26} } { s11 {x27} } { t3 {x28} } { t4 {x29} } { t5 {x30} } \ + { t6 {x31} } { ft0 {f0} } { ft1 {f1} } { ft2 {f2} } { ft3 {f3} } \ + { ft4 {f4} } { ft5 {f5} } { ft6 {f6} } { ft7 {f7} } { fs0 {f8} } \ + { fs1 {f9} } { fa0 {f10} } { fa1 {f11} } { fa2 {f12} } { fa3 {f13} } \ + { fa4 {f14} } { fa5 {f15} } { fa6 {f16} } { fa7 {f17} } { fs2 {f18} } \ + { fs3 {f19} } { fs4 {f20} } { fs5 {f21} } { fs6 {f22} } { fs7 {f23} } \ + { fs8 {f24} } { fs9 {f25} } { fs10 {f26} } { fs11 {f27} } { ft8 {f28} } \ + { ft9 {f29} } { ft10 {f30} } { ft11 {f31} } } + +# Check that the zero register (and its x0 alias) both contain the +# value 0. + +proc check_zero_register_value {testname} { + gdb_test "p/d \$zero" " = 0" "check \$zero: ${testname}" + gdb_test "p/d \$x0" " = 0" "check \$x0: ${testname}" +} + +# First, some testing of the zero register. This register should +# always read as zero, and should swallow any attempt to write a +# non-zero value to the register. + +check_zero_register_value "before any writes" + +gdb_test_no_output "set \$zero = 123" \ + "write to the \$zero register" + +check_zero_register_value "after write to \$zero" + +gdb_test_no_output "set \$x0 = 123" \ + "write to the \$x0 register" + +check_zero_register_value "after write to \$x0" + +# Set all of the general registers to zero. Confirm that the value of +# zero can be read back from the primary name, and from all of the +# alias names. + +foreach reg_desc ${register_names} { + set primary_name [lindex ${reg_desc} 0] + set alias_names [lindex ${reg_desc} 1] + + gdb_test_no_output "set \$${primary_name} = 0" \ + "set register ${primary_name} to an initial value of zero" + gdb_test "p/d \$${primary_name}" " = 0" \ + "check the initial value of ${primary_name} is now zero" + + foreach reg_alias ${alias_names} { + gdb_test "p/d \$${reg_alias}" " = 0" \ + "check the initial value of ${reg_alias} is now zero" + } +} + +# Set each register in turn to a new value, and confirm that the new +# value can be read back from the primary name, and from all of the +# alias names. + +set reg_value 100 +foreach reg_desc ${register_names} { + set primary_name [lindex ${reg_desc} 0] + set alias_names [lindex ${reg_desc} 1] + + # Set value through the primary register name, and check that all + # the aliases see the same value. + set reg_value [incr reg_value] + gdb_test_no_output "set \$${primary_name} = $reg_value" \ + "write non-zero value to ${primary_name}" + gdb_test "p/d \$${primary_name}" " = $reg_value" \ + "read ${primary_name} after non-zero write to ${primary_name}" + foreach reg_alias ${alias_names} { + gdb_test "p/d \$${reg_alias}" " = $reg_value" \ + "read ${reg_alias} after non-zero write to ${primary_name}" + } + + # For each alias, set a new value, and check that the primary + # register name, and all the other aliases, see the new value. + foreach reg_alias ${alias_names} { + set reg_value [incr reg_value] + + gdb_test_no_output "set \$${reg_alias} = $reg_value" \ + "write non-zero value to ${reg_alias}" + + gdb_test "p/d \$${primary_name}" " = $reg_value" \ + "read ${primary_name} after non-zero write to ${reg_alias}" + + foreach other_reg_alias ${alias_names} { + gdb_test "p/d \$${other_reg_alias}" " = $reg_value" \ + "read ${other_reg_alias} after non-zero write to ${reg_alias}" + } + } +} |