From 268e4f09144c48e02f01d82ab3aab359457df214 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 1 Nov 2019 16:21:04 -0600 Subject: Make the objfile destructor private The idea behind this is that, in the long run, some code will need to be able to hold onto an objfile after it is unlinked from the program space. In particular, this is needed for some functionality to be moved to worker threads -- otherwise the objfile can be deleted while still in use. So, this makes ~objfile private, replacing it with an "unlink" method, making it more obvious which operation is intended at the calling points. gdb/ChangeLog 2019-12-12 Tom Tromey * symfile.c (syms_from_objfile_1): Use objfile_up. (syms_from_objfile_1, remove_symbol_file_command): Call unlink method. (reread_symbols): Use objfile_up. * solib.c (update_solib_list, reload_shared_libraries_1): Call unlink method. * objfiles.h (struct objfile) <~objfile>: Now private. : New method. (struct objfile_deleter): New. (objfile_up): New typedef. * objfiles.c (objfile::unlink): New method. (free_objfile_separate_debug, free_all_objfiles) (objfile_purge_solibs): Use it. * jit.c (jit_unregister_code): Remove. (jit_inferior_exit_hook, jit_event_handler): Call unlink on objfile. * compile/compile-object-run.c (do_module_cleanup): Call unlink on objfile. * compile/compile-object-load.c (compile_object_load): Use objfile_up. Change-Id: I934bee70b26b8b24e1735828fb1e60fe8a05714f --- gdb/objfiles.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'gdb/objfiles.h') diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 663e639..49b4627 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -399,13 +399,18 @@ private: /* The only way to create an objfile is to call objfile::make. */ objfile (bfd *, const char *, objfile_flags); + /* The only way to free an objfile is via 'unlink'. */ + ~objfile (); + public: /* Create an objfile. */ static objfile *make (bfd *bfd_, const char *name_, objfile_flags flags_, objfile *parent = nullptr); - ~objfile (); + /* Remove an objfile from the current program space, and free + it. */ + void unlink (); DISABLE_COPY_AND_ASSIGN (objfile); @@ -637,6 +642,20 @@ public: htab_up static_links; }; +/* A deleter for objfile. */ + +struct objfile_deleter +{ + void operator() (objfile *ptr) const + { + ptr->unlink (); + } +}; + +/* A unique pointer that holds an objfile. */ + +typedef std::unique_ptr objfile_up; + /* Declarations for functions defined in objfiles.c */ extern struct gdbarch *get_objfile_arch (const struct objfile *); -- cgit v1.1