This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 2/3] Allocate data in cached_reg_t
- From: Yao Qi <qiyaoltc at gmail dot com>
- To: Luis Machado <lgustavo at codesourcery dot com>
- Cc: Alan Hayward <Alan dot Hayward at arm dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, nd <nd at arm dot com>
- Date: Tue, 10 Jan 2017 12:59:05 +0000
- Subject: Re: [PATCH 2/3] Allocate data in cached_reg_t
- Authentication-results: sourceware.org; auth=none
- References: <3BD71BF1-BD32-4952-9E54-8FD14EB54987@arm.com> <29912fac-24a9-afb3-d65e-6d1796fedd14@codesourcery.com>
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.
class cached_reg
{
public:
cached_reg (struct gdbarch *gdbarch, int num_)
: num (num_)
{
this->data = (gdb_byte *) xmalloc (register_size (gdbarch, num_));
}
~cached_reg ()
{
xfree (this->data);
}
private:
int num;
gdb_byte *data;
};
--
Yao (齐尧)