Rewrite registry.h

This rewrites registry.h, removing all the macros and replacing it
with relatively ordinary template classes.  The result is less code
than the previous setup.  It replaces large macros with a relatively
straightforward C++ class, and now manages its own cleanup.

The existing type-safe "key" class is replaced with the equivalent
template class.  This approach ended up requiring relatively few
changes to the users of the registry code in gdb -- code using the key
system just required a small change to the key's declaration.

All existing users of the old C-like API are now converted to use the
type-safe API.  This mostly involved changing explicit deletion
functions to be an operator() in a deleter class.

The old "save/free" two-phase process is removed, and replaced with a
single "free" phase.  No existing code used both phases.

The old "free" callbacks took a parameter for the enclosing container
object.  However, this wasn't truly needed and is removed here as
well.
This commit is contained in:
Tom Tromey
2020-10-18 11:38:10 -06:00
parent 8f83e7b926
commit 08b8a139c9
64 changed files with 664 additions and 1052 deletions

View File

@ -43,24 +43,11 @@ static int highest_address_space_num;
/* Keep a registry of per-program_space data-pointers required by other GDB
modules. */
DEFINE_REGISTRY (program_space, REGISTRY_ACCESS_FIELD)
/* Keep a registry of per-address_space data-pointers required by other GDB
modules. */
DEFINE_REGISTRY (address_space, REGISTRY_ACCESS_FIELD)
/* Create a new address space object, and add it to the list. */
address_space::address_space ()
: m_num (++highest_address_space_num)
{
address_space_alloc_data (this);
}
/* Maybe create a new address space object, and add it to the list, or
@ -81,11 +68,6 @@ maybe_new_address_space (void)
return new address_space ();
}
address_space::~address_space ()
{
address_space_free_data (this);
}
/* Start counting over from scratch. */
static void
@ -115,8 +97,6 @@ program_space::program_space (address_space *aspace_)
: num (++last_program_space_num),
aspace (aspace_)
{
program_space_alloc_data (this);
program_spaces.push_back (this);
}
@ -140,8 +120,6 @@ program_space::~program_space ()
clear_symtab_users (SYMFILE_DEFER_BP_RESET);
if (!gdbarch_has_shared_address_space (target_gdbarch ()))
delete this->aspace;
/* Discard any data modules have associated with the PSPACE. */
program_space_free_data (this);
}
/* See progspace.h. */