diff mbox

[11/11] Add SH_MAX_REGISTER_SIZE and SH64_MAX_REGISTER_SIZE

Message ID 44AA3E84-BCF8-4A36-ADF5-83C0DE7771BE@arm.com
State New
Headers show

Commit Message

Alan Hayward June 5, 2017, 4:30 p.m. UTC
> On 12 Apr 2017, at 09:34, Alan Hayward <Alan.Hayward@arm.com> wrote:

> 

> 

>> On 11 Apr 2017, at 12:23, Yao Qi <qiyaoltc@gmail.com> wrote:

>> 

>> Alan Hayward <Alan.Hayward@arm.com> writes:

>> 



I’ve rebased this patch due to Yao’s unit test changes.


I don't have a SH machine to test on.
Tested on a --enable-targets=all and --enable-libsanitizer build using
make check with board files unix and native-gdbserver.


Ok to commit?

Alan.


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

	* gdb/sh-tdep.c (sh_pseudo_register_read): Remove MAX_REGISTER_SIZE.
	(sh_pseudo_register_write): Likewise.
	* gdb/sh64-tdep.c (SH64_MAX_REGISTER_SIZE): Add.
        (sh64_pseudo_register_read): Use SH64_MAX_REGISTER_SIZE.
	(sh64_pseudo_register_write): Likewise

Comments

Yao Qi June 6, 2017, 2:31 p.m. UTC | #1
Alan Hayward <Alan.Hayward@arm.com> writes:

> @@ -1528,7 +1531,7 @@ sh64_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
>    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>    int base_regnum;
>    int offset = 0;
> -  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
> +  gdb_byte temp_buffer[SH64_MAX_REGISTER_SIZE];
>    enum register_status status;
>
>    if (reg_nr >= DR0_REGNUM
> @@ -1704,7 +1707,7 @@ sh64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
>    enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
>    int base_regnum, portion;
>    int offset;
> -  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
> +  gdb_byte temp_buffer[SH64_MAX_REGISTER_SIZE];

Could you define temp_buffer in each block where it is used?  The size
of register is known at each place.  In some places, we don't need to
use temp_buffer, instead, we can use regcache_raw_read_unsigned to
replace regcache_raw_read+extract_unsigned_integer.  Then, we don't need
SH64_MAX_REGISTER_SIZE at all.
diff mbox

Patch

diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index 2c2b26847d58808ef912ed4969bc28c799ad9bbd..a87547d4ceda1b6db4157d181ae1b982444a867c 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -1648,13 +1648,14 @@  sh_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
 			 int reg_nr, gdb_byte *buffer)
 {
   int base_regnum;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
   enum register_status status;

   if (reg_nr == PSEUDO_BANK_REGNUM)
     return regcache_raw_read (regcache, BANK_REGNUM, buffer);
   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
     {
+      /* Enough space for two float registers.  */
+      gdb_byte temp_buffer[4 * 2];
       base_regnum = dr_reg_base_num (gdbarch, reg_nr);

       /* Build the value in the provided buffer.  */
@@ -1687,7 +1688,6 @@  sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
 			  int reg_nr, const gdb_byte *buffer)
 {
   int base_regnum, portion;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];

   if (reg_nr == PSEUDO_BANK_REGNUM)
     {
@@ -1703,6 +1703,8 @@  sh_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
     }
   else if (reg_nr >= DR0_REGNUM && reg_nr <= DR_LAST_REGNUM)
     {
+      /* Enough space for two float registers.  */
+      gdb_byte temp_buffer[4 * 2];
       base_regnum = dr_reg_base_num (gdbarch, reg_nr);

       /* We must pay attention to the endiannes.  */
diff --git a/gdb/sh64-tdep.c b/gdb/sh64-tdep.c
index 06ae04e9da1eff6e2b9e3e977e4f52fa398f69f2..244029501aed1837097f5eb73e6a141cf928d009 100644
--- a/gdb/sh64-tdep.c
+++ b/gdb/sh64-tdep.c
@@ -122,6 +122,9 @@  enum
     FP_LAST_REGNUM = SIM_SH64_FR0_REGNUM + SIM_SH64_NR_FP_REGS - 1
   };

+/* Big enough to hold the size of the largest register in bytes.  */
+#define SH64_MAX_REGISTER_SIZE	12
+
 static const char *
 sh64_register_name (struct gdbarch *gdbarch, int reg_nr)
 {
@@ -1528,7 +1531,7 @@  sh64_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int base_regnum;
   int offset = 0;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
+  gdb_byte temp_buffer[SH64_MAX_REGISTER_SIZE];
   enum register_status status;

   if (reg_nr >= DR0_REGNUM
@@ -1704,7 +1707,7 @@  sh64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   int base_regnum, portion;
   int offset;
-  gdb_byte temp_buffer[MAX_REGISTER_SIZE];
+  gdb_byte temp_buffer[SH64_MAX_REGISTER_SIZE];

   if (reg_nr >= DR0_REGNUM
       && reg_nr <= DR_LAST_REGNUM)