Re: [PATCH] Removal of uses of MAX_REGISTER_SIZE

Alan Hayward
2017-02-03T11:25:58Z

> On 3 Feb 2017, at 10:59, Pedro Alves <palves@redhat.com> wrote:
>
> On 02/03/2017 10:28 AM, Yao Qi wrote:
>
>> I don't think we have to replace all MAX_REGISTER_SIZE with std::vector.
>> MAX_REGISTER_SIZE is mostly used in arch-dependent code (*-tdep.c
>> and *-nat.c), where the register size or max register size is known. For
>> example, MAX_REGISTER_SIZE is used only once in arm-tdep.c, and
>> it can be replaced with FP_REGISTER_SIZE, because 'buf' is to get the
>> contents for FPA register. Similarly, MAX_REGISTER_SIZE is used three
>> times in aarch64-tdep.c, all of them can be repalced by V_REGISTER_SIZE.
>> Also, MAX_REGISTER_SIZE can be replaced by
>> I386_MAX_REGISTER_SIZE in i386-tdep.c. I would like to examine the
>> usages of MAX_REGISTER_SIZE in each target-dependent code, and
>> replace MAX_REGISTER_SIZE with known constants as much as we can.
>> I don't think anyone has objections on replacing one constant
>> MAX_REGISTER_SIZE with other smaller constants :)
>>
>> Then, let us discuss how to remove MAX_REGISTER_SIZE from
>> arch-independent code after all above is done.
>>
>
> +1.
>
> Thanks,
> Pedro Alves
>

If someone can ok the common patch, then I’ll make a second patch with the
replacement of all remaining uses of MAX_REGISTER_SIZE in common code.
Ensuring it’s not used in common code will allow me to continue moving with the
aarch64 SVE code.

There are quite a lot of arch specific functions where we have a register number
from which the register size could be extracted. Eg:

void
SOMEARCH_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, const gdb_byte *buf)
{
gdb_byte raw_buf[MAX_REGISTER_SIZE];

This could become:

void
SOMEARCH_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, const gdb_byte *buf)
{
gdb_byte buf[SOMEARCH_MAX_REGISTER_SIZE];

Or:

void
SOMEARCH_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
int regnum, const gdb_byte *buf)
{
std::vector<gdb_byte> buf (register_size (gdbarch, regnum));

I suspect people will want the first approach? It will result in quite a few new
defines - ALPHA_MAX_REGISTER_SIZE, PPC_MAX_REGISTER_SIZE etc etc.

Alan.