[PATCH 1/2] gdb: remove uses of VLA

Simon Marchi simon.marchi@efficios.com
Wed Jul 31 17:07:35 GMT 2024


On 7/31/24 12:25 PM, Keith Seitz wrote:
> On 7/30/24 12:43 PM, Simon Marchi wrote:
>> Remove uses of VLAs, replace with gdb::byte_vector.  There might be more
>> in files that I can't compile, but it's difficult to tell without
>> actually compiling on all platforms.
> 
> Hi, Simon, nice to see you around here again.
> 
> This series LGTM, I just have one comment.
> 
>> diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
>> index a1296a8f0c7e..e019d6bfc59a 100644
>> --- a/gdb/aarch64-linux-tdep.c
>> +++ b/gdb/aarch64-linux-tdep.c
>> @@ -1297,8 +1297,8 @@ aarch64_linux_supply_za_regset (const struct regset *regset,
>>       }
>>     else
>>       {
>> -      gdb_byte za_zeroed[za_bytes];
>> -      memset (za_zeroed, 0, za_bytes);
>> +      gdb::byte_vector za_zeroed (za_bytes);
>> +      memset (za_zeroed.data (), 0, za_bytes);
>>         regcache->raw_supply (tdep->sme_za_regnum, za_zeroed);
>>       }
>>   }
> 
> This decl/memset paradigm is used in several places. IIUC from
> gdbsupport/byte-vector.h, if initialization of the data is
> desired, one can simply use a std::vector or use an override:
> 
> gdb::byte_vector za_zeroed (za_bytes, 0);

That makes sense.  I could also use an std::vector<gdb_byte>, which has
default initialization (the point of gdb::byte_vector is to not
default-initialize).  Two ways of achieving the same thing.  I'll use
what you suggested, because I think it makes it a bit more explicit that
we rely on the bytes being 0.

> 
> Feel free to add my Reviewed-by, and thank you for the
> patch!

The Linaro pre-commit CI told me that this patch broke something on
arm/aarch64, so I need to check that first.  I will send a v2 anyway, so
that you can double-check my changes for the zero-initialization thing.

Thanks!

Simon


More information about the Gdb-patches mailing list