static struct ada_inferior_data *
get_ada_inferior_data (struct inferior *inf)
{
- struct ada_inferior_data *data;
-
- data = ada_inferior_data.get (inf);
- if (data == NULL)
- data = &ada_inferior_data.emplace (inf);
-
- return data;
+ return &ada_inferior_data.try_emplace (inf);
}
/* Perform all necessary cleanups regarding our module's inferior data
static cache_entry_set &
get_ada_pspace_data (struct program_space *pspace)
{
- cache_entry_set *data = ada_pspace_data_handle.get (pspace);
- if (data == nullptr)
- data = &ada_pspace_data_handle.emplace (pspace);
-
- return *data;
+ return ada_pspace_data_handle.try_emplace (pspace);
}
/* Utilities */
static struct ada_tasks_pspace_data *
get_ada_tasks_pspace_data (struct program_space *pspace)
{
- struct ada_tasks_pspace_data *data;
-
- data = ada_tasks_pspace_data_handle.get (pspace);
- if (data == NULL)
- data = &ada_tasks_pspace_data_handle.emplace (pspace);
-
- return data;
+ return &ada_tasks_pspace_data_handle.try_emplace (pspace);
}
/* Return the ada-tasks module's data for the given inferior (INF).
static struct ada_tasks_inferior_data *
get_ada_tasks_inferior_data (struct inferior *inf)
{
- struct ada_tasks_inferior_data *data;
-
- data = ada_tasks_inferior_data_handle.get (inf);
- if (data == NULL)
- data = &ada_tasks_inferior_data_handle.emplace (inf);
-
- return data;
+ return &ada_tasks_inferior_data_handle.try_emplace (inf);
}
/* Return the task number of the task whose thread is THREAD, or zero
if (inf == NULL)
return NULL;
- struct aix_thread_variables* data;
-
- data = aix_thread_variables_handle.get (inf);
- if (data == NULL)
- data = &aix_thread_variables_handle.emplace (inf);
-
- return data;
+ return &aix_thread_variables_handle.try_emplace (inf);
}
/* Helper to get data for ptid in a function. */
static amd_dbgapi_inferior_info &
get_amd_dbgapi_inferior_info (inferior *inferior)
{
- amd_dbgapi_inferior_info *info = amd_dbgapi_inferior_data.get (inferior);
-
- if (info == nullptr)
- info = &amd_dbgapi_inferior_data.emplace (inferior, inferior);
-
- return *info;
+ return amd_dbgapi_inferior_data.try_emplace (inferior, inferior);
}
/* The async event handler registered with the event loop, indicating that we
if (name[1] != 'a' && name[1] != 't' && name[1] != 'd')
return;
- data = arm_bfd_data_key.get (objfile->obfd.get ());
- if (data == NULL)
- data = &arm_bfd_data_key.emplace (objfile->obfd.get (),
- objfile->obfd->section_count);
+ data = &arm_bfd_data_key.try_emplace (objfile->obfd.get (),
+ objfile->obfd->section_count);
arm_mapping_symbol_vec &map
= data->section_maps[bfd_asymbol_section (sym)->index];
static struct auto_load_pspace_info *
get_auto_load_pspace_data (struct program_space *pspace)
{
- struct auto_load_pspace_info *info;
-
- info = auto_load_pspace_data.get (pspace);
- if (info == NULL)
- info = &auto_load_pspace_data.emplace (pspace);
-
- return info;
+ return &auto_load_pspace_data.try_emplace (pspace);
}
/* Hash function for the loaded script hash. */
static struct catch_syscall_inferior_data *
get_catch_syscall_inferior_data (struct inferior *inf)
{
- struct catch_syscall_inferior_data *inf_data;
-
- inf_data = catch_syscall_inferior_data.get (inf);
- if (inf_data == NULL)
- inf_data = &catch_syscall_inferior_data.emplace (inf);
-
- return inf_data;
+ return &catch_syscall_inferior_data.try_emplace (inf);
}
/* Implement the "insert" method for syscall catchpoints. */
static struct breakpoint_objfile_data *
get_breakpoint_objfile_data (struct objfile *objfile)
{
- struct breakpoint_objfile_data *bp_objfile_data;
-
- bp_objfile_data = breakpoint_objfile_key.get (objfile);
- if (bp_objfile_data == NULL)
- bp_objfile_data = &breakpoint_objfile_key.emplace (objfile);
- return bp_objfile_data;
+ return &breakpoint_objfile_key.try_emplace (objfile);
}
static void
static struct bsd_uthread_ops *
get_bsd_uthread (struct gdbarch *gdbarch)
{
- struct bsd_uthread_ops *ops = bsd_uthread_data.get (gdbarch);
- if (ops == nullptr)
- ops = &bsd_uthread_data.emplace (gdbarch);
- return ops;
+ return &bsd_uthread_data.try_emplace (gdbarch);
}
/* Set the function that supplies registers from an inactive thread
dwarf_expr_context::address_type () const
{
gdbarch *arch = this->m_per_objfile->objfile->arch ();
- dwarf_gdbarch_types *types = dwarf_arch_cookie.get (arch);
- if (types == nullptr)
- types = &dwarf_arch_cookie.emplace (arch);
+ dwarf_gdbarch_types *types = &dwarf_arch_cookie.try_emplace (arch);
int ndx;
if (this->m_addr_size == 2)
static dwarf2_frame_ops *
get_frame_ops (struct gdbarch *gdbarch)
{
- dwarf2_frame_ops *result = dwarf2_frame_data.get (gdbarch);
- if (result == nullptr)
- result = &dwarf2_frame_data.emplace (gdbarch);
- return result;
+ return &dwarf2_frame_data.try_emplace (gdbarch);
}
/* Default architecture-specific register state initialization
static struct fbsd_gdbarch_data *
get_fbsd_gdbarch_data (struct gdbarch *gdbarch)
{
- struct fbsd_gdbarch_data *result = fbsd_gdbarch_data_handle.get (gdbarch);
- if (result == nullptr)
- result = &fbsd_gdbarch_data_handle.emplace (gdbarch);
- return result;
+ return &fbsd_gdbarch_data_handle.try_emplace (gdbarch);
}
struct fbsd_pspace_data
static struct fbsd_pspace_data *
get_fbsd_pspace_data (struct program_space *pspace)
{
- struct fbsd_pspace_data *data;
-
- data = fbsd_pspace_data_handle.get (pspace);
- if (data == NULL)
- data = &fbsd_pspace_data_handle.emplace (pspace);
-
- return data;
+ return &fbsd_pspace_data_handle.try_emplace (pspace);
}
/* This is how we want PTIDs from core files to be printed. */
static struct frame_base_table *
get_frame_base_table (struct gdbarch *gdbarch)
{
- struct frame_base_table *table = frame_base_data.get (gdbarch);
- if (table == nullptr)
- table = &frame_base_data.emplace (gdbarch);
- return table;
+ return &frame_base_data.try_emplace (gdbarch);
}
void
static std::vector<const frame_unwind *> &
get_frame_unwind_table (struct gdbarch *gdbarch)
{
- std::vector<const frame_unwind *> *table = frame_unwind_data.get (gdbarch);
- if (table == nullptr)
- table = &frame_unwind_data.emplace (gdbarch,
+ return frame_unwind_data.try_emplace (gdbarch,
standard_unwinders.begin (),
standard_unwinders.end ());
- return *table;
}
static const char *
static struct bfd_inferior_data *
get_bfd_inferior_data (struct inferior *inf)
{
- struct bfd_inferior_data *data;
-
- data = bfd_inferior_data_key.get (inf);
- if (data == nullptr)
- data = &bfd_inferior_data_key.emplace (inf);
-
- return data;
+ return &bfd_inferior_data_key.try_emplace (inf);
}
/* Increment the BFD error count for STR and return the updated
static struct libunwind_descr *
libunwind_descr (struct gdbarch *gdbarch)
{
- struct libunwind_descr *result = libunwind_descr_handle.get (gdbarch);
- if (result == nullptr)
- result = &libunwind_descr_handle.emplace (gdbarch);
- return result;
+ return &libunwind_descr_handle.try_emplace (gdbarch);
}
void
static struct terminal_info *
get_inflow_inferior_data (struct inferior *inf)
{
- struct terminal_info *info;
-
- info = inflow_inferior_data.get (inf);
- if (info == NULL)
- info = &inflow_inferior_data.emplace (inf);
-
- return info;
+ return &inflow_inferior_data.try_emplace (inf);
}
/* This is a "inferior_exit" observer. Releases the TERMINAL_INFO member
static void
jit_prepend_unwinder (struct gdbarch *gdbarch)
{
- struct jit_gdbarch_data_type *data = jit_gdbarch_data.get (gdbarch);
- if (data == nullptr)
- data = &jit_gdbarch_data.emplace (gdbarch);
+ struct jit_gdbarch_data_type *data = &jit_gdbarch_data.try_emplace (gdbarch);
if (!data->unwinder_registered)
{
static struct checkpoint_inferior_data *
get_checkpoint_inferior_data (struct inferior *inf)
{
- struct checkpoint_inferior_data *data;
-
- data = checkpoint_inferior_data_key.get (inf);
- if (data == nullptr)
- data = &checkpoint_inferior_data_key.emplace (inf);
-
- return data;
+ return &checkpoint_inferior_data_key.try_emplace (inf);
}
/* Return a reference to the per-inferior fork list. */
static struct linux_gdbarch_data *
get_linux_gdbarch_data (struct gdbarch *gdbarch)
{
- struct linux_gdbarch_data *result = linux_gdbarch_data_handle.get (gdbarch);
- if (result == nullptr)
- result = &linux_gdbarch_data_handle.emplace (gdbarch);
- return result;
+ return &linux_gdbarch_data_handle.try_emplace (gdbarch);
}
/* Linux-specific cached data. This is used by GDB for caching
static struct linux_info *
get_linux_inferior_data (inferior *inf)
{
- linux_info *info = linux_inferior_data.get (inf);
-
- if (info == nullptr)
- info = &linux_inferior_data.emplace (inf);
-
- return info;
+ return &linux_inferior_data.try_emplace (inf);
}
/* See linux-tdep.h. */
static struct nbsd_gdbarch_data *
get_nbsd_gdbarch_data (struct gdbarch *gdbarch)
{
- struct nbsd_gdbarch_data *result = nbsd_gdbarch_data_handle.get (gdbarch);
- if (result == nullptr)
- result = &nbsd_gdbarch_data_handle.emplace (gdbarch);
- return result;
+ return &nbsd_gdbarch_data_handle.try_emplace (gdbarch);
}
/* Implement the "get_siginfo_type" gdbarch method. */
static struct objfile_pspace_info *
get_objfile_pspace_data (struct program_space *pspace)
{
- struct objfile_pspace_info *info;
-
- info = objfiles_pspace_data.get (pspace);
- if (info == NULL)
- info = &objfiles_pspace_data.emplace (pspace);
-
- return info;
+ return &objfiles_pspace_data.try_emplace (pspace);
}
\f
gdbpy_get_register_descriptor (struct gdbarch *gdbarch,
int regnum)
{
- gdbpy_register_type *vecp = gdbpy_register_object_data.get (gdbarch);
- if (vecp == nullptr)
- vecp = &gdbpy_register_object_data.emplace (gdbarch);
- gdbpy_register_type &vec = *vecp;
+ gdbpy_register_type &vec = gdbpy_register_object_data.try_emplace (gdbarch);
/* Ensure that we have enough entries in the vector. */
if (vec.size () <= regnum)
static void
pyuw_on_new_gdbarch (gdbarch *newarch)
{
- struct pyuw_gdbarch_data_type *data = pyuw_gdbarch_data.get (newarch);
- if (data == nullptr)
- data = &pyuw_gdbarch_data.emplace (newarch);
+ struct pyuw_gdbarch_data_type *data = &pyuw_gdbarch_data.try_emplace (newarch);
if (!data->unwinder_registered)
{
template<typename O>
Storage *get_storage (O *owner, const StorageKey<O> &key) const
{
- Storage *r = key.get (owner);
- if (r == nullptr)
- {
- r = new Storage();
- key.set (owner, r);
- }
- return r;
+ return &key.try_emplace (owner);
}
Storage *get_storage (struct objfile* objf) const
static reggroups *
get_reggroups (struct gdbarch *gdbarch)
{
- struct reggroups *groups = reggroups_data.get (gdbarch);
- if (groups == nullptr)
- groups = ®groups_data.emplace (gdbarch);
- return groups;
+ return ®groups_data.try_emplace (gdbarch);
}
/* See reggroups.h. */
return *result;
}
+ /* If this key uses the default deleter, then this method is
+ available. It returns the data associated with OBJ and this
+ key. If no such data has been attached, a new instance is
+ constructed using ARGS and attached to OBJ. */
+ template<typename... Args>
+ DATA &
+ try_emplace (T *obj, Args &&...args) const
+ {
+ DATA *result = get (obj);
+ if (result == nullptr)
+ result = &emplace (obj, std::forward<Args> (args)...);
+ return *result;
+ }
+
/* Clear the data attached to OBJ that is associated with this KEY.
Any existing data is destroyed using the deleter, and the data is
reset to nullptr. */
static remote_per_progspace &
get_remote_progspace_info (program_space *pspace)
{
- remote_per_progspace *info = remote_pspace_data.get (pspace);
- if (info == nullptr)
- info = &remote_pspace_data.emplace (pspace);
- gdb_assert (info != nullptr);
- return *info;
+ return remote_pspace_data.try_emplace (pspace);
}
/* The size to align memory write packets, when practical. The protocol
static struct remote_g_packet_data *
get_g_packet_data (struct gdbarch *gdbarch)
{
- struct remote_g_packet_data *data
- = remote_g_packet_data_handle.get (gdbarch);
- if (data == nullptr)
- data = &remote_g_packet_data_handle.emplace (gdbarch);
- return data;
+ return &remote_g_packet_data_handle.try_emplace (gdbarch);
}
void
ppc_inferior_data *
get_ppc_per_inferior (inferior *inf)
{
- ppc_inferior_data *per_inf = ppc_inferior_data_key.get (inf);
-
- if (per_inf == nullptr)
- per_inf = &ppc_inferior_data_key.emplace (inf);
-
- return per_inf;
+ return &ppc_inferior_data_key.try_emplace (inf);
}
/* To be used by skip_prologue. */
static struct solib_aix_inferior_data *
get_solib_aix_inferior_data (struct inferior *inf)
{
- struct solib_aix_inferior_data *data;
-
- data = solib_aix_inferior_data_handle.get (inf);
- if (data == NULL)
- data = &solib_aix_inferior_data_handle.emplace (inf);
-
- return data;
+ return &solib_aix_inferior_data_handle.try_emplace (inf);
}
#if !defined(HAVE_LIBEXPAT)
static darwin_info *
get_darwin_info (program_space *pspace)
{
- darwin_info *info = solib_darwin_pspace_data.get (pspace);
- if (info != nullptr)
- return info;
-
- return &solib_darwin_pspace_data.emplace (pspace);
+ return &solib_darwin_pspace_data.try_emplace (pspace);
}
/* Return non-zero if the version in dyld_all_image is known. */
static dsbt_info *
get_dsbt_info (program_space *pspace)
{
- dsbt_info *info = solib_dsbt_pspace_data.get (pspace);
- if (info != nullptr)
- return info;
-
- return &solib_dsbt_pspace_data.emplace (pspace);
+ return &solib_dsbt_pspace_data.try_emplace (pspace);
}
static struct solib_info *
get_solib_info (inferior *inf)
{
- solib_info *info = rocm_solib_data.get (inf);
-
- if (info == nullptr)
- info = &rocm_solib_data.emplace (inf, inf);
-
- return info;
+ return &rocm_solib_data.try_emplace (inf, inf);
}
/* Relocate section addresses. */
static struct svr4_info *
get_svr4_info (program_space *pspace)
{
- struct svr4_info *info = solib_svr4_pspace_data.get (pspace);
-
- if (info == NULL)
- info = &solib_svr4_pspace_data.emplace (pspace);
-
- return info;
+ return &solib_svr4_pspace_data.try_emplace (pspace);
}
/* Local function prototypes */
static current_source_location *
get_source_location (program_space *pspace)
{
- current_source_location *loc
- = current_source_key.get (pspace);
- if (loc == nullptr)
- loc = ¤t_source_key.emplace (pspace);
- return loc;
+ return ¤t_source_key.try_emplace (pspace);
}
/* See source.h. */
static struct svr4_tls_gdbarch_data *
get_svr4_tls_gdbarch_data (struct gdbarch *gdbarch)
{
- struct svr4_tls_gdbarch_data *result = svr4_tls_gdbarch_data_handle.get (gdbarch);
- if (result == nullptr)
- result = &svr4_tls_gdbarch_data_handle.emplace (gdbarch);
- return result;
+ return &svr4_tls_gdbarch_data_handle.try_emplace (gdbarch);
}
/* When true, force internal TLS address lookup instead of lookup via
static main_info *
get_main_info (program_space *pspace)
{
- main_info *info = main_progspace_key.get (pspace);
-
- if (info == NULL)
- {
- /* It may seem strange to store the main name in the progspace
- and also in whatever objfile happens to see a main name in
- its debug info. The reason for this is mainly historical:
- gdb returned "main" as the name even if no function named
- "main" was defined the program; and this approach lets us
- keep compatibility. */
- info = &main_progspace_key.emplace (pspace);
- }
-
- return info;
+ /* It may seem strange to store the main name in the progspace
+ and also in whatever objfile happens to see a main name in
+ its debug info. The reason for this is mainly historical:
+ gdb returned "main" as the name even if no function named
+ "main" was defined the program; and this approach lets us
+ keep compatibility. */
+ return &main_progspace_key.try_emplace (pspace);
}
static void
static tdesc_arch_data *
get_arch_data (struct gdbarch *gdbarch)
{
- tdesc_arch_data *result = tdesc_data.get (gdbarch);
- if (result == nullptr)
- result = &tdesc_data.emplace (gdbarch);
- return result;
+ return &tdesc_data.try_emplace (gdbarch);
}
/* Fetch the current target's description, and switch the current
static struct windows_gdbarch_data *
get_windows_gdbarch_data (struct gdbarch *gdbarch)
{
- windows_gdbarch_data *result = windows_gdbarch_data_handle.get (gdbarch);
- if (result == nullptr)
- result = &windows_gdbarch_data_handle.emplace (gdbarch);
- return result;
+ return &windows_gdbarch_data_handle.try_emplace (gdbarch);
}
/* Define Thread Local Base pointer type. */