This is the mail archive of the
mailing list for the GDB project.
Re: [PATCH 2/3] Allocate data in cached_reg_t
- From: Alan Hayward <Alan dot Hayward at arm dot com>
- To: Luis Machado <lgustavo at codesourcery dot com>
- Cc: Yao Qi <qiyaoltc at gmail dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, nd <nd at arm dot com>
- Date: Wed, 11 Jan 2017 10:53:45 +0000
- Subject: Re: [PATCH 2/3] Allocate data in cached_reg_t
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan dot Hayward at arm dot com;
- Nodisclaimer: True
- References: <3BD71BF1-BD32-4952-9E54-8FD14EB54987@arm.com> <email@example.com> <20170110125905.GF9518@E107787-LIN> <firstname.lastname@example.org>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
> On 10 Jan 2017, at 17:42, Luis Machado <email@example.com> wrote:
> On 01/10/2017 06:59 AM, Yao Qi wrote:
>> On 17-01-09 14:11:13, Luis Machado wrote:
>>>> @@ -6306,7 +6306,7 @@ remote_console_output (char *msg)
>>>> typedef struct cached_reg
>>>> int num;
>>>> - gdb_byte data[MAX_REGISTER_SIZE];
>>>> + gdb_byte *data;
>>> Would it make sense to go C++ and use a data structure that can take
>>> care of variable sizes? Just thinking if that would be easier than
>>> handling allocation/deallocation of the data.
>> Do you suggest std::vector? We still need to allocate/deallocate it
>> if we change "gdb_byte *data" to "std::vector<gdb_byte> *data", or we
>> have to convert cached_reg to class, and do RAII.
> Something like std::vector, yes. But it is true we will still need to allocate the vector itself.
> I was pondering about the benefits of not being limited to a specific register size. Then we wouldn't need to worry about adjusting things as we have to do now.
> As i see it, data[register_size(register_size (gdbarch, num)] wouldn't be much different than data[MAX_REGISTER_SIZE]. The only thing is that we're setting the max register size dynamically.
> We may or may not need this flexibility right now, but who knows what weird architectures we may have in the future.
I avoided using data[register_size(gdbarch, num)] as dynamically sized arrays are a gcc extension - it’s not something we can expect to work on other compilers.
Plus there is a danger of it using up all the stack. Aarch64 SVE will have a max register size of 256, potentially this could grow further in the future.
This is why I used alloca in patches 1/3 and 2/3.
I know that gcc avoid using std::vector because it’s fairly slow. I think gcc also have newer c++ like replacements for VEC, but am not sure what they have that’s suitable. However, I’d suggest that’s something that should be done as part of the work to move gdb to c++, and not this patch.