[1/3] Use register_size () instead of MAX_REGISTER_SIZE

Message ID 902F747B-B822-4629-8DB8-D6775357E6A5@arm.com
State New, archived
Headers

Commit Message

Alan Hayward Jan. 9, 2017, 10:55 a.m. UTC
  Aarch64 SVE requires a max register size of 256. The current max size in gdb
is 64. This is part of a series demonstrating the replacement of
MAX_REGISTER_SIZE.

In cases where a buffer is created to hold a single register, then
MAX_REGISTER_SIZE can be replaced with a call to register_size ().

This patch is restricted to amd64-tdep.c, remote.c and regcache.c.
Follow on patch sets will expand to other files.

Tested on x86.
Ok to commit?

Thanks,
Alan.

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

    * amd64-tdep.c (amd64_pseudo_register_read_value): remove
    MAX_REGISTER_SIZE.
    (amd64_pseudo_register_read_value): Likewise.
    * remote.c (fetch_register_using_p): Remove MAX_REGISTER_SIZE.
    (store_register_using_P): Likewise.
    * regcache.c (regcache_xfer_part): Likewise.
  

Comments

Luis Machado Jan. 9, 2017, 8:07 p.m. UTC | #1
On 01/09/2017 04:55 AM, Alan Hayward wrote:
> Aarch64 SVE requires a max register size of 256. The current max size in gdb
> is 64. This is part of a series demonstrating the replacement of
> MAX_REGISTER_SIZE.
>
> In cases where a buffer is created to hold a single register, then
> MAX_REGISTER_SIZE can be replaced with a call to register_size ().
>
> This patch is restricted to amd64-tdep.c, remote.c and regcache.c.
> Follow on patch sets will expand to other files.
>
> Tested on x86.
> Ok to commit?
>
> Thanks,
> Alan.
>
> 2017-01-09 Alan Hayward  <alan.hayward@arm.com>
>
>     * amd64-tdep.c (amd64_pseudo_register_read_value): remove
>     MAX_REGISTER_SIZE.
>     (amd64_pseudo_register_read_value): Likewise.
>     * remote.c (fetch_register_using_p): Remove MAX_REGISTER_SIZE.
>     (store_register_using_P): Likewise.
>     * regcache.c (regcache_xfer_part): Likewise.
>
>
> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
> index a6367424e75b234c89e05b2dba7490ac3e212c3c..fc1f134a18098862fab92ad45e55b05372027beb 100644
> --- a/gdb/amd64-tdep.c
> +++ b/gdb/amd64-tdep.c
> @@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
>  				  struct regcache *regcache,
>  				  int regnum)
>  {
> -  gdb_byte raw_buf[MAX_REGISTER_SIZE];
> +  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>    struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
>    enum register_status status;
>    struct value *result_value;
> @@ -414,7 +414,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
>  			     struct regcache *regcache,
>  			     int regnum, const gdb_byte *buf)
>  {
> -  gdb_byte raw_buf[MAX_REGISTER_SIZE];
> +  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>    struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
>
>    if (i386_byte_regnum_p (gdbarch, regnum))
> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index b2b9524d742a477f89195cf657085833054cbb38..9d28aa2c2114e0f1c52758bb2fbe9669a329c13e 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -988,7 +988,8 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
>  				   const gdb_byte *buf))
>  {
>    struct regcache_descr *descr = regcache->descr;
> -  gdb_byte reg[MAX_REGISTER_SIZE];
> +  struct gdbarch *gdbarch = get_regcache_arch (regcache);
> +  gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>
>    gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
>    gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
> diff --git a/gdb/remote.c b/gdb/remote.c
> index 837b9ee5124e8ac3f4e3a55279adae49c790be19..6da6eb366ae442354fd6a37741335af9a4a5a056 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -7462,9 +7462,10 @@ remote_wait (struct target_ops *ops,
>  static int
>  fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
>  {
> +  struct gdbarch *gdbarch = get_regcache_arch (regcache);
>    struct remote_state *rs = get_remote_state ();
>    char *buf, *p;
> -  char regp[MAX_REGISTER_SIZE];
> +  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
>    int i;
>
>    if (packet_support (PACKET_p) == PACKET_DISABLE)
> @@ -7769,7 +7770,7 @@ store_register_using_P (const struct regcache *regcache,
>    struct remote_state *rs = get_remote_state ();
>    /* Try storing a single register.  */
>    char *buf = rs->buf;
> -  gdb_byte regp[MAX_REGISTER_SIZE];
> +  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
>    char *p;
>
>    if (packet_support (PACKET_P) == PACKET_DISABLE)
>
>
>
>

Patch looks OK to me. Are you planning on getting rid of all/most of the 
MAX_REGISTER_SIZE in gdb?
  
Alan Hayward Jan. 10, 2017, 11:27 a.m. UTC | #2
> On 9 Jan 2017, at 20:07, Luis Machado <lgustavo@codesourcery.com> wrote:
> 
> On 01/09/2017 04:55 AM, Alan Hayward wrote:
>> Aarch64 SVE requires a max register size of 256. The current max size in gdb
>> is 64. This is part of a series demonstrating the replacement of
>> MAX_REGISTER_SIZE.
>> 
>> In cases where a buffer is created to hold a single register, then
>> MAX_REGISTER_SIZE can be replaced with a call to register_size ().
>> 
>> This patch is restricted to amd64-tdep.c, remote.c and regcache.c.
>> Follow on patch sets will expand to other files.
>> 
>> Tested on x86.
>> Ok to commit?
>> 
>> Thanks,
>> Alan.
>> 
>> 2017-01-09 Alan Hayward <alan.hayward@arm.com>
>> 
>>    * amd64-tdep.c (amd64_pseudo_register_read_value): remove
>>    MAX_REGISTER_SIZE.
>>    (amd64_pseudo_register_read_value): Likewise.
>>    * remote.c (fetch_register_using_p): Remove MAX_REGISTER_SIZE.
>>    (store_register_using_P): Likewise.
>>    * regcache.c (regcache_xfer_part): Likewise.
>> 
>> 
>> diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
>> index a6367424e75b234c89e05b2dba7490ac3e212c3c..fc1f134a18098862fab92ad45e55b05372027beb 100644
>> --- a/gdb/amd64-tdep.c
>> +++ b/gdb/amd64-tdep.c
>> @@ -353,7 +353,7 @@ amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
>> 				  struct regcache *regcache,
>> 				  int regnum)
>> {
>> -  gdb_byte raw_buf[MAX_REGISTER_SIZE];
>> +  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>>   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
>>   enum register_status status;
>>   struct value *result_value;
>> @@ -414,7 +414,7 @@ amd64_pseudo_register_write (struct gdbarch *gdbarch,
>> 			     struct regcache *regcache,
>> 			     int regnum, const gdb_byte *buf)
>> {
>> -  gdb_byte raw_buf[MAX_REGISTER_SIZE];
>> +  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>>   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
>> 
>>   if (i386_byte_regnum_p (gdbarch, regnum))
>> diff --git a/gdb/regcache.c b/gdb/regcache.c
>> index b2b9524d742a477f89195cf657085833054cbb38..9d28aa2c2114e0f1c52758bb2fbe9669a329c13e 100644
>> --- a/gdb/regcache.c
>> +++ b/gdb/regcache.c
>> @@ -988,7 +988,8 @@ regcache_xfer_part (struct regcache *regcache, int regnum,
>> 				   const gdb_byte *buf))
>> {
>>   struct regcache_descr *descr = regcache->descr;
>> -  gdb_byte reg[MAX_REGISTER_SIZE];
>> +  struct gdbarch *gdbarch = get_regcache_arch (regcache);
>> +  gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
>> 
>>   gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
>>   gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
>> diff --git a/gdb/remote.c b/gdb/remote.c
>> index 837b9ee5124e8ac3f4e3a55279adae49c790be19..6da6eb366ae442354fd6a37741335af9a4a5a056 100644
>> --- a/gdb/remote.c
>> +++ b/gdb/remote.c
>> @@ -7462,9 +7462,10 @@ remote_wait (struct target_ops *ops,
>> static int
>> fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
>> {
>> +  struct gdbarch *gdbarch = get_regcache_arch (regcache);
>>   struct remote_state *rs = get_remote_state ();
>>   char *buf, *p;
>> -  char regp[MAX_REGISTER_SIZE];
>> +  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
>>   int i;
>> 
>>   if (packet_support (PACKET_p) == PACKET_DISABLE)
>> @@ -7769,7 +7770,7 @@ store_register_using_P (const struct regcache *regcache,
>>   struct remote_state *rs = get_remote_state ();
>>   /* Try storing a single register.  */
>>   char *buf = rs->buf;
>> -  gdb_byte regp[MAX_REGISTER_SIZE];
>> +  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
>>   char *p;
>> 
>>   if (packet_support (PACKET_P) == PACKET_DISABLE)
>> 
>> 
>> 
>> 
> 
> Patch looks OK to me. Are you planning on getting rid of all/most of the MAX_REGISTER_SIZE in gdb?

Yes, I plan to remove the define completely, because Aarch64 SVE support would have required
MAX_REGISTER_SIZE to be changed from 64 to 256.

Thanks for the review.

Alan.
  
Yao Qi Jan. 18, 2017, 8:56 a.m. UTC | #3
On 17-01-09 10:55:18, Alan Hayward wrote:
> Aarch64 SVE requires a max register size of 256. The current max size in gdb
> is 64. This is part of a series demonstrating the replacement of
> MAX_REGISTER_SIZE.
> 
> In cases where a buffer is created to hold a single register, then
> MAX_REGISTER_SIZE can be replaced with a call to register_size ().
> 
> This patch is restricted to amd64-tdep.c, remote.c and regcache.c.
> Follow on patch sets will expand to other files.
> 
> Tested on x86.
> Ok to commit?
> 
> Thanks,
> Alan.
> 

Nits on ChangeLog,

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

two spaces between date and name.

> 
>     * amd64-tdep.c (amd64_pseudo_register_read_value): remove
 ^^^^^ tab rather than spaces.

>     MAX_REGISTER_SIZE.

	* amd64-tdep.c (amd64_pseudo_register_read_value): Use
	register_size instead of MAX_REGISTER_SIZE.

>     (amd64_pseudo_register_read_value): Likewise.
>     * remote.c (fetch_register_using_p): Remove MAX_REGISTER_SIZE.
>     (store_register_using_P): Likewise.
>     * regcache.c (regcache_xfer_part): Likewise.

otherwise, patch is good to me.
  

Patch

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index a6367424e75b234c89e05b2dba7490ac3e212c3c..fc1f134a18098862fab92ad45e55b05372027beb 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -353,7 +353,7 @@  amd64_pseudo_register_read_value (struct gdbarch *gdbarch,
 				  struct regcache *regcache,
 				  int regnum)
 {
-  gdb_byte raw_buf[MAX_REGISTER_SIZE];
+  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   enum register_status status;
   struct value *result_value;
@@ -414,7 +414,7 @@  amd64_pseudo_register_write (struct gdbarch *gdbarch,
 			     struct regcache *regcache,
 			     int regnum, const gdb_byte *buf)
 {
-  gdb_byte raw_buf[MAX_REGISTER_SIZE];
+  gdb_byte *raw_buf = (gdb_byte *) alloca (register_size (gdbarch, regnum));
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

   if (i386_byte_regnum_p (gdbarch, regnum))
diff --git a/gdb/regcache.c b/gdb/regcache.c
index b2b9524d742a477f89195cf657085833054cbb38..9d28aa2c2114e0f1c52758bb2fbe9669a329c13e 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -988,7 +988,8 @@  regcache_xfer_part (struct regcache *regcache, int regnum,
 				   const gdb_byte *buf))
 {
   struct regcache_descr *descr = regcache->descr;
-  gdb_byte reg[MAX_REGISTER_SIZE];
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
+  gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));

   gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
   gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
diff --git a/gdb/remote.c b/gdb/remote.c
index 837b9ee5124e8ac3f4e3a55279adae49c790be19..6da6eb366ae442354fd6a37741335af9a4a5a056 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7462,9 +7462,10 @@  remote_wait (struct target_ops *ops,
 static int
 fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
 {
+  struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct remote_state *rs = get_remote_state ();
   char *buf, *p;
-  char regp[MAX_REGISTER_SIZE];
+  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
   int i;

   if (packet_support (PACKET_p) == PACKET_DISABLE)
@@ -7769,7 +7770,7 @@  store_register_using_P (const struct regcache *regcache,
   struct remote_state *rs = get_remote_state ();
   /* Try storing a single register.  */
   char *buf = rs->buf;
-  gdb_byte regp[MAX_REGISTER_SIZE];
+  gdb_byte *regp = (gdb_byte *) alloca (register_size (gdbarch, reg->regnum));
   char *p;

   if (packet_support (PACKET_P) == PACKET_DISABLE)