Simplify per-BFD storage management
There's no reason that the objfile_per_bfd_storage must be allocated via bfd_alloc. This patch changes objfile_per_bfd_storage to be managed more simply, via ordinary new and delete; and moves some code into its (new) destructor. While doing this I also noticed an extra initialization of language_of_main, and removed it. gdb/ChangeLog 2019-03-15 Tom Tromey <tom@tromey.com> * objfiles.h (struct objfile_per_bfd_storage): Declare destructor. * objfiles.c (objfile_per_bfd_storage::~objfile_per_bfd_storage): New. (get_objfile_bfd_data): Use new. Don't initialize language_of_main. (free_objfile_per_bfd_storage): Remove. (objfile_bfd_data_free, objfile::~objfile): Use delete.
This commit is contained in:
parent
741d7538b7
commit
d6797f465c
|
@ -1,3 +1,14 @@
|
||||||
|
2019-03-15 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* objfiles.h (struct objfile_per_bfd_storage): Declare
|
||||||
|
destructor.
|
||||||
|
* objfiles.c (objfile_per_bfd_storage::~objfile_per_bfd_storage):
|
||||||
|
New.
|
||||||
|
(get_objfile_bfd_data): Use new. Don't initialize
|
||||||
|
language_of_main.
|
||||||
|
(free_objfile_per_bfd_storage): Remove.
|
||||||
|
(objfile_bfd_data_free, objfile::~objfile): Use delete.
|
||||||
|
|
||||||
2019-03-15 Tom Tromey <tom@tromey.com>
|
2019-03-15 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* symfile.c (reread_symbols): Update.
|
* symfile.c (reread_symbols): Update.
|
||||||
|
|
|
@ -117,13 +117,17 @@ get_objfile_pspace_data (struct program_space *pspace)
|
||||||
|
|
||||||
static const struct bfd_data *objfiles_bfd_data;
|
static const struct bfd_data *objfiles_bfd_data;
|
||||||
|
|
||||||
|
objfile_per_bfd_storage::~objfile_per_bfd_storage ()
|
||||||
|
{
|
||||||
|
if (demangled_names_hash)
|
||||||
|
htab_delete (demangled_names_hash);
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the per-BFD storage object for OBJFILE. If ABFD is not
|
/* Create the per-BFD storage object for OBJFILE. If ABFD is not
|
||||||
NULL, and it already has a per-BFD storage object, use that.
|
NULL, and it already has a per-BFD storage object, use that.
|
||||||
Otherwise, allocate a new per-BFD storage object. If ABFD is not
|
Otherwise, allocate a new per-BFD storage object. Note that it is
|
||||||
NULL, the object is allocated on the BFD; otherwise it is allocated
|
not safe to call this multiple times for a given OBJFILE -- it can
|
||||||
on OBJFILE's obstack. Note that it is not safe to call this
|
only be called when allocating or re-initializing OBJFILE. */
|
||||||
multiple times for a given OBJFILE -- it can only be called when
|
|
||||||
allocating or re-initializing OBJFILE. */
|
|
||||||
|
|
||||||
static struct objfile_per_bfd_storage *
|
static struct objfile_per_bfd_storage *
|
||||||
get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
|
get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
|
||||||
|
@ -136,50 +140,28 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
|
||||||
|
|
||||||
if (storage == NULL)
|
if (storage == NULL)
|
||||||
{
|
{
|
||||||
|
storage = new objfile_per_bfd_storage;
|
||||||
/* If the object requires gdb to do relocations, we simply fall
|
/* If the object requires gdb to do relocations, we simply fall
|
||||||
back to not sharing data across users. These cases are rare
|
back to not sharing data across users. These cases are rare
|
||||||
enough that this seems reasonable. */
|
enough that this seems reasonable. */
|
||||||
if (abfd != NULL && !gdb_bfd_requires_relocations (abfd))
|
if (abfd != NULL && !gdb_bfd_requires_relocations (abfd))
|
||||||
{
|
set_bfd_data (abfd, objfiles_bfd_data, storage);
|
||||||
storage
|
|
||||||
= ((struct objfile_per_bfd_storage *)
|
|
||||||
bfd_alloc (abfd, sizeof (struct objfile_per_bfd_storage)));
|
|
||||||
/* objfile_per_bfd_storage is not trivially constructible, must
|
|
||||||
call the ctor manually. */
|
|
||||||
storage = new (storage) objfile_per_bfd_storage ();
|
|
||||||
set_bfd_data (abfd, objfiles_bfd_data, storage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
storage
|
|
||||||
= obstack_new<objfile_per_bfd_storage> (&objfile->objfile_obstack);
|
|
||||||
|
|
||||||
/* Look up the gdbarch associated with the BFD. */
|
/* Look up the gdbarch associated with the BFD. */
|
||||||
if (abfd != NULL)
|
if (abfd != NULL)
|
||||||
storage->gdbarch = gdbarch_from_bfd (abfd);
|
storage->gdbarch = gdbarch_from_bfd (abfd);
|
||||||
|
|
||||||
storage->language_of_main = language_unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free STORAGE. */
|
/* A deleter for objfile_per_bfd_storage that can be passed as a
|
||||||
|
|
||||||
static void
|
|
||||||
free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
|
|
||||||
{
|
|
||||||
if (storage->demangled_names_hash)
|
|
||||||
htab_delete (storage->demangled_names_hash);
|
|
||||||
storage->~objfile_per_bfd_storage ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A wrapper for free_objfile_per_bfd_storage that can be passed as a
|
|
||||||
cleanup function to the BFD registry. */
|
cleanup function to the BFD registry. */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
objfile_bfd_data_free (struct bfd *unused, void *d)
|
objfile_bfd_data_free (struct bfd *unused, void *d)
|
||||||
{
|
{
|
||||||
free_objfile_per_bfd_storage ((struct objfile_per_bfd_storage *) d);
|
delete (struct objfile_per_bfd_storage *) d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See objfiles.h. */
|
/* See objfiles.h. */
|
||||||
|
@ -670,7 +652,7 @@ objfile::~objfile ()
|
||||||
if (obfd)
|
if (obfd)
|
||||||
gdb_bfd_unref (obfd);
|
gdb_bfd_unref (obfd);
|
||||||
else
|
else
|
||||||
free_objfile_per_bfd_storage (per_bfd);
|
delete per_bfd;
|
||||||
|
|
||||||
/* Remove it from the chain of all objfiles. */
|
/* Remove it from the chain of all objfiles. */
|
||||||
|
|
||||||
|
|
|
@ -235,6 +235,8 @@ struct objfile_per_bfd_storage
|
||||||
: minsyms_read (false)
|
: minsyms_read (false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
~objfile_per_bfd_storage ();
|
||||||
|
|
||||||
/* The storage has an obstack of its own. */
|
/* The storage has an obstack of its own. */
|
||||||
|
|
||||||
auto_obstack storage_obstack;
|
auto_obstack storage_obstack;
|
||||||
|
|
Loading…
Reference in New Issue