diff mbox

[8/11] Add FRV_MAX_REGISTER_SIZE

Message ID 3B3BD949-1C9D-44FF-AB6A-03091ECA49D0@arm.com
State New
Headers show

Commit Message

Alan Hayward April 4, 2017, 10:14 a.m. UTC
Max size set to 64bits, which I determined using frv_register_type()

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

I do not have a FRV machine to test on.

Ok to commit?

Alan.

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

	* frv-linux-tdep.c (frv_linux_supply_gregset): Use FRV_MAX_REGISTER_SIZE.
	* frv-tdep.h (FRV_MAX_REGISTER_SIZE): Add.

Comments

Yao Qi April 11, 2017, 10:02 a.m. UTC | #1
Alan Hayward <Alan.Hayward@arm.com> writes:

> -  char zerobuf[MAX_REGISTER_SIZE];
> +  char zerobuf[FRV_MAX_REGISTER_SIZE];
>
> -  memset (zerobuf, 0, MAX_REGISTER_SIZE);
> +  memset (zerobuf, 0, FRV_MAX_REGISTER_SIZE);
>
>    /* gr0 always contains 0.  Also, the kernel passes the TBR value in
>       this slot.  */

The code here fills some gr registers with zeros,

  /* gr0 always contains 0.  Also, the kernel passes the TBR value in
     this slot.  */
  regcache_raw_supply (regcache, first_gpr_regnum, zerobuf);

  /* Fill gr32, ..., gr63 with zeros. */
  for (regi = first_gpr_regnum + 32; regi <= last_gpr_regnum; regi++)
    regcache_raw_supply (regcache, regi, zerobuf);

the size of these gr registers are know, 8 bytes.  It won't be changed.
We can do,

 gdb_byte zerobuf[8] = { 0 };

the code is still easy to read.  If you really dislike magic number (IMO, 8
is not a magic number in this context), you can define FRR_GR_REGISTER_SIZE.

Alternatively, you can add a new regache api, regcache_raw_supply_zero.
Many places can use this api, and some uses of MAX_REGISTER_SIZE can be
removed too, for example,

  regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf);
diff mbox

Patch

diff --git a/gdb/frv-linux-tdep.c b/gdb/frv-linux-tdep.c
index eb87f93058b0287e8f05c585d1b6aa1ff2bffb78..6f5585e774c86afe7e271f90df1bf3db93340421 100644
--- a/gdb/frv-linux-tdep.c
+++ b/gdb/frv-linux-tdep.c
@@ -413,9 +413,9 @@  frv_linux_supply_gregset (const struct regset *regset,
 			  int regnum, const void *gregs, size_t len)
 {
   int regi;
-  char zerobuf[MAX_REGISTER_SIZE];
+  char zerobuf[FRV_MAX_REGISTER_SIZE];

-  memset (zerobuf, 0, MAX_REGISTER_SIZE);
+  memset (zerobuf, 0, FRV_MAX_REGISTER_SIZE);

   /* gr0 always contains 0.  Also, the kernel passes the TBR value in
      this slot.  */
diff --git a/gdb/frv-tdep.h b/gdb/frv-tdep.h
index c1a0f35456c879c655198820f5319bf0ab42b9f7..9c8c32eb08b6e4b4d87139b201008c1ee419f6a9 100644
--- a/gdb/frv-tdep.h
+++ b/gdb/frv-tdep.h
@@ -92,6 +92,9 @@  enum {
   frv_num_pseudo_regs = last_pseudo_regnum - first_pseudo_regnum + 1,
 };

+/* Big enough to hold the size of the largest register in bytes.  */
+#define FRV_MAX_REGISTER_SIZE	8
+
 /* Return the FR-V ABI associated with GDBARCH.  */
 enum frv_abi frv_abi (struct gdbarch *gdbarch);