nds32: Abort instead of returning REG_UNKNOWN

Message ID BE486704-F964-469D-A107-731D4362E245@arm.com
State New, archived
Headers

Commit Message

Alan Hayward April 7, 2017, 8:54 a.m. UTC
  This patch is cut from "[PATCH] Remove MAX_REGISTER_SIZE from regcache.c"

When reading/writing a pseudo register, instead of returning REG_UNKNOWN on an error, assert instead.
This will make nds32 behave like all other architectures.

This is required due to some regcache refactoring (see the "Remove MAX_REGISTER_SIZE from regcache.c" thread).

Tested on a --enable-targets=all build using make check with board files
unix and native-gdbserver.

I do not have a nds32 machine to test on.

Ok to commit?

Alan.

2017-04-07  Alan Hayward  <alan.hayward@arm.com>

	* nds32-tdep.c (nds32_pseudo_register_read): Abort on errors.
        (nds32_pseudo_register_write): Likewise.


 /* Helper function for NDS32 ABI.  Return true if FPRs can be used
  

Comments

Yao Qi April 25, 2017, 3:42 p.m. UTC | #1
Alan Hayward <Alan.Hayward@arm.com> writes:

> 2017-04-07  Alan Hayward  <alan.hayward@arm.com>
>
> 	* nds32-tdep.c (nds32_pseudo_register_read): Abort on errors.
>         (nds32_pseudo_register_write): Likewise.

Patch is good to me.
  

Patch

diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index 05c48aa27d84bc0286712f0143a9447a79ae066b..804a11fb27fb0625338f1e5cda338f133b6f119d 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -445,11 +445,12 @@  nds32_pseudo_register_read (struct gdbarch *gdbarch,
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;
-  enum register_status status = REG_UNKNOWN;
+  enum register_status status;

-  /* Sanity check.  */
-  if (tdep->fpu_freg == -1 || tdep->use_pseudo_fsrs == 0)
-    return status;
+  /* This function is registered in nds32_gdbarch_init only after these are
+     set.  */
+  gdb_assert (tdep->fpu_freg != -1);
+  gdb_assert (tdep->use_pseudo_fsrs != 0);

   regnum -= gdbarch_num_regs (gdbarch);

@@ -466,9 +467,11 @@  nds32_pseudo_register_read (struct gdbarch *gdbarch,
       status = regcache_raw_read (regcache, fdr_regnum, reg_buf);
       if (status == REG_VALID)
 	memcpy (buf, reg_buf + offset, 4);
+
+      return status;
     }

-  return status;
+  gdb_assert_not_reached ("invalid pseudo register number");
 }

 /* Implement the "pseudo_register_write" gdbarch method.  */
@@ -482,9 +485,10 @@  nds32_pseudo_register_write (struct gdbarch *gdbarch,
   gdb_byte reg_buf[8];
   int offset, fdr_regnum;

-  /* Sanity check.  */
-  if (tdep->fpu_freg == -1 || tdep->use_pseudo_fsrs == 0)
-    return;
+  /* This function is registered in nds32_gdbarch_init only after these are
+     set.  */
+  gdb_assert (tdep->fpu_freg != -1);
+  gdb_assert (tdep->use_pseudo_fsrs != 0);

   regnum -= gdbarch_num_regs (gdbarch);

@@ -501,7 +505,10 @@  nds32_pseudo_register_write (struct gdbarch *gdbarch,
       regcache_raw_read (regcache, fdr_regnum, reg_buf);
       memcpy (reg_buf + offset, buf, 4);
       regcache_raw_write (regcache, fdr_regnum, reg_buf);
+      return;
     }
+
+  gdb_assert_not_reached ("invalid pseudo register number");
 }