Re: [PATCH 5/7] jit: make gdb_object::symtabs a vector of unique_ptr

Simon Marchi
2019-12-13T18:45:36Z

On 2019-12-13 12:54 p.m., Pedro Alves wrote:
> On 12/13/19 6:03 AM, Simon Marchi wrote:
>> struct gdb_object
>> {
>> - std::vector<gdb_symtab *> symtabs;
>> + std::vector<std::unique_ptr<gdb_symtab>> symtabs;
>> };
>
> Could this be a vector or objects instead of a vector or pointers?
>
> Like:
>
> std::vector<gdb_symtab> symtabs;

I don't think so. We return these pointers to the JIT debug readers, which then pass
it back to the block_open and symtab_close callbacks. It's important that the objects
don't move during their lifetime. If we had a vector of objects, the pointers we return
to the user would get invalidated the moment the vector is resized.

>
>> + object->symtabs.emplace_back (new gdb_symtab (file_name));
>> + return object->symtabs.back ().get ();
>> }
>
> and:
>
> object->symtabs.emplace_back (file_name);
> return &object->symtabs.back ();
>
> Thanks,
> Pedro Alves
>