[PATCH 2/2] gdb/riscv: remove csr aliases created with DECLARE_CSR_ALIAS

Andrew Burgess andrew.burgess@embecosm.com
Thu Nov 26 13:09:44 GMT 2020


In this commit:

  commit 767a879e31ce31179e6135c2f991f670a35709fa
  Date:   Tue Jun 9 17:38:30 2020 +0100

      gdb/riscv: Improved register alias name creation

RISC-V GDB was changed to make use of the DECLARE_CSR_ALIAS macro to
define register aliases for some CSRs.  Actually, only one alias was
created 'dscratch' as an alias for 'dscratch0'.  All of the other
DECLARE_CSR_ALIAS lines (from include/opcode/riscv-opc.h) were
filtered out.

In this commit:

  commit 08ccfccf0ed825be9be2972594d4be4a2207ef13
  Date:   Mon Jun 8 10:54:53 2020 +0800

      RISC-V: Support debug and float CSR as the unprivileged ones.

Changes were made to include/opcode/riscv-opc.h so that GDB no longer
created even the dscratch alias.

This caused a test failure in gdb.arch/riscv-tdesc-regs.exp.

In looking at how to address this failure I think that the best
strategy is, for now at least, to just remove the code that tries to
create aliases with DECLARE_CSR_ALIAS.

My thoughts are that:

  1. At least some of the aliases are for CSRs where the register now
  has a completely different use.  Being able to reference the CSR
  using a completely inappropriate name just seems confusing.  This
  was solved by the filtering added in the first commit referenced
  above.  But we certainly don't want to blindly add all aliases.

  2. Names presented in a target description are always honoured, so
  if a user has a legacy target then they should just start sending a
  target description with their legacy register names in, this problem
  is then solved.

  3. It's easy enough to figure out which CSRs a target has with the
  info registers command, so missing an alias shouldn't be a big
  issue.

  4.  Allowing users to use names for registers that differ from the
  names the target announces doesn't feel like a critical feature.  If
  in the future targets want multiple names for a register then maybe
  we could/should extend target descriptions to allow the target to
  send aliases as well as the primary name.... but that can wait for
  another day.

So in this commit I remove the use of DECLARE_CSR_ALIAS, and remove
the test that was failing.

gdb/ChangeLog:

	* riscv-tdep.c (riscv_create_csr_aliases): Remove use of
	DECLARE_CSR_ALIAS.

gdb/testsuite/ChangeLog:

	* gdb.arch/riscv-tdesc-regs.exp: Remove unwanted test.
---
 gdb/ChangeLog                               |  5 +++++
 gdb/riscv-tdep.c                            | 10 ----------
 gdb/testsuite/ChangeLog                     |  4 ++++
 gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp |  4 ----
 4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 437e8f847ae..2f182e8ba8c 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -376,16 +376,6 @@ riscv_create_csr_aliases ()
       int csr_num = reg.regnum - RISCV_FIRST_CSR_REGNUM;
       const char *alias = xstrprintf ("csr%d", csr_num);
       reg.names.push_back (alias);
-
-      /* Setup the other csr aliases.  We don't use a switch table here in
-	 case there are multiple aliases with the same value.  Also filter
-	 based on ABRT_VER in order to avoid a very old alias for misa that
-	 duplicates the name "misa" but at a different CSR address.  */
-#define DECLARE_CSR_ALIAS(NAME,VALUE,CLASS,DEF_VER,ABRT_VER)	 \
-      if (csr_num == VALUE && ABRT_VER >= PRIV_SPEC_CLASS_1P11)  \
-	reg.names.push_back ( # NAME );
-#include "opcode/riscv-opc.h"
-#undef DECLARE_CSR_ALIAS
     }
 }
 
diff --git a/gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp b/gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp
index e35d6181b7f..6ee2bb7cb16 100644
--- a/gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp
+++ b/gdb/testsuite/gdb.arch/riscv-tdesc-regs.exp
@@ -76,10 +76,6 @@ gdb_test_no_output "set tdesc filename $remote_file" \
 # Check that an alias for an unknown CSR will give a suitable error.
 gdb_test "info registers \$csr0" "Invalid register `csr0'"
 
-# Check we can access the dscratch register using either of its names.
-gdb_test "info registers \$dscratch0" "dscratch0\[ \t\]+.*"
-gdb_test "info registers \$dscratch" "dscratch\[ \t\]+.*"
-
 # Return the number of times REGISTER should appear in GROUP, this
 # will either be 0 or 1.
 proc get_expected_result { register group } {
-- 
2.25.4



More information about the Gdb-patches mailing list