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

Simon Marchi
2019-12-13T06:03:34Z

This makes the gdb_object hold everything. When it gets destroyed, all
contained symtabs and contained blocks get destroyed.

gdb/ChangeLog:

* jit.c (struct gdb_object) <symtabs>: Change type to
std::vector<std::unique_ptr<gdb_symtab>>.
(jit_symtab_open_impl): Adjust.
(jit_object_close_impl): Adjust.
---
gdb/jit.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/gdb/jit.c b/gdb/jit.c
index bb855e09f59b..1f6de6796e10 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -476,7 +476,7 @@ struct gdb_symtab

struct gdb_object
{
- std::vector<gdb_symtab *> symtabs;
+ std::vector<std::unique_ptr<gdb_symtab>> symtabs;
};

/* The type of the `private' data passed around by the callback
@@ -521,9 +521,8 @@ jit_symtab_open_impl (struct gdb_symbol_callbacks *cb,
{
/* CB stays unused. See comment in jit_object_open_impl. */

- gdb_symtab *symtab = new gdb_symtab (file_name);
- object->symtabs.push_back (symtab);
- return symtab;
+ object->symtabs.emplace_back (new gdb_symtab (file_name));
+ return object->symtabs.back ().get ();
}

/* Called by readers to open a new gdb_block. This function also
@@ -722,8 +721,6 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
}
}
-
- delete stab;
}

/* Called when closing a gdb_objfile. Converts OBJ to a proper
@@ -742,8 +739,8 @@ jit_object_close_impl (struct gdb_symbol_callbacks *cb,
OBJF_NOT_FILENAME);
objfile->per_bfd->gdbarch = target_gdbarch ();

- for (gdb_symtab *symtab : obj->symtabs)
- finalize_symtab (symtab, objfile);
+ for (const std::unique_ptr<gdb_symtab> &symtab : obj->symtabs)
+ finalize_symtab (symtab.get (), objfile);

add_objfile_entry (objfile, *priv_data);

--
2.24.1