[PATCH] Removal of uses of MAX_REGISTER_SIZE

Pedro Alves palves@redhat.com
Wed Feb 1 15:49:00 GMT 2017


On 01/27/2017 04:46 PM, Alan Hayward wrote:

> --- a/gdb/xtensa-tdep.c
> +++ b/gdb/xtensa-tdep.c
> @@ -370,7 +370,10 @@ static void
>  xtensa_register_write_masked (struct regcache *regcache,
>  			      xtensa_register_t *reg, const gdb_byte *buffer)
>  {
> -  unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
> +  struct gdbarch *gdbarch = get_regcache_arch (regcache);
> +  unsigned int *value = (unsigned int *) alloca (max_register_size (gdbarch)
> +						 + 1);

I don't think I understand this +1.

AFAICS, the previous code was creating an array of ints
such that sizeof(value) is as big as MAX_REGISTER_SIZE, rounded up
to sizeof int.  Seems like a replacement would be:

 alloca (align_up (max_register_size (gdbarch), 4));
or better:
 alloca (align_up (max_register_size (gdbarch), sizeof (int)));

?

> +
>    const xtensa_mask_t *mask = reg->mask;
> 
>    int shift = 0;		/* Shift for next mask (mod 32).  */
> @@ -454,7 +457,9 @@ static enum register_status
>  xtensa_register_read_masked (struct regcache *regcache,
>  			     xtensa_register_t *reg, gdb_byte *buffer)
>  {
> -  unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
> +  struct gdbarch *gdbarch = get_regcache_arch (regcache);
> +  unsigned int *value = (unsigned int *) alloca (max_register_size (gdbarch)
> +						 + 1);

Ditto.

Thanks,
Pedro Alves



More information about the Gdb-patches mailing list