* [PATCH 12/14] Convert linux-tdep.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (5 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 11/14] Convert auxv.c " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 04/14] Convert target dcache " Tom Tromey
` (8 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes linux-tdep.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* linux-tdep.c (struct linux_info): Add initializers.
(linux_inferior_data): Move. Change type.
(invalidate_linux_cache_inf): Update.
(linux_inferior_data_cleanup): Remove.
(get_linux_inferior_data, _initialize_linux_tdep): Update.
---
gdb/ChangeLog | 8 ++++++++
gdb/linux-tdep.c | 36 ++++++++++--------------------------
2 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 5de985def39..fe0073a5939 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -183,9 +183,6 @@ get_linux_gdbarch_data (struct gdbarch *gdbarch)
gdbarch_data (gdbarch, linux_gdbarch_data_handle));
}
-/* Per-inferior data key. */
-static const struct inferior_data *linux_inferior_data;
-
/* Linux-specific cached data. This is used by GDB for caching
purposes for each inferior. This helps reduce the overhead of
transfering data from a remote target to the local host. */
@@ -196,14 +193,17 @@ struct linux_info
at this info requires an auxv lookup (which is itself cached),
and looking through the inferior's mappings (which change
throughout execution and therefore cannot be cached). */
- struct mem_range vsyscall_range;
+ struct mem_range vsyscall_range {};
/* Zero if we haven't tried looking up the vsyscall's range before
yet. Positive if we tried looking it up, and found it. Negative
if we tried looking it up but failed. */
- int vsyscall_range_p;
+ int vsyscall_range_p = 0;
};
+/* Per-inferior data key. */
+static const struct inferior_key<linux_info> linux_inferior_data;
+
/* Frees whatever allocated space there is to be freed and sets INF's
linux cache data pointer to NULL. */
@@ -212,24 +212,14 @@ invalidate_linux_cache_inf (struct inferior *inf)
{
struct linux_info *info;
- info = (struct linux_info *) inferior_data (inf, linux_inferior_data);
+ info = linux_inferior_data.get (inf);
if (info != NULL)
{
- xfree (info);
- set_inferior_data (inf, linux_inferior_data, NULL);
+ delete info;
+ linux_inferior_data.set (inf, NULL);
}
}
-/* Handles the cleanup of the linux cache for inferior INF. ARG is
- ignored. Callback for the inferior_appeared and inferior_exit
- events. */
-
-static void
-linux_inferior_data_cleanup (struct inferior *inf, void *arg)
-{
- invalidate_linux_cache_inf (inf);
-}
-
/* Fetch the linux cache info for INF. This function always returns a
valid INFO pointer. */
@@ -239,12 +229,9 @@ get_linux_inferior_data (void)
struct linux_info *info;
struct inferior *inf = current_inferior ();
- info = (struct linux_info *) inferior_data (inf, linux_inferior_data);
+ info = linux_inferior_data.get (inf);
if (info == NULL)
- {
- info = XCNEW (struct linux_info);
- set_inferior_data (inf, linux_inferior_data, info);
- }
+ info = linux_inferior_data.emplace (inf);
return info;
}
@@ -2535,9 +2522,6 @@ _initialize_linux_tdep (void)
linux_gdbarch_data_handle =
gdbarch_data_register_post_init (init_linux_gdbarch_data);
- /* Set a cache per-inferior. */
- linux_inferior_data
- = register_inferior_data_with_cleanup (NULL, linux_inferior_data_cleanup);
/* Observers used to invalidate the cache when needed. */
gdb::observers::inferior_exit.attach (invalidate_linux_cache_inf);
gdb::observers::inferior_appeared.attach (invalidate_linux_cache_inf);
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 14/14] Convert remote.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
2019-04-23 2:10 ` [PATCH 06/14] Convert break-catch-syscall.c to type-safe registry API Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 01/14] Add a type-safe C++ interface to a registry Tom Tromey
` (13 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes remote.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* remote.c (remote_pspace_data): Change type.
(remote_pspace_data_cleanup): Remove.
(get_remote_exec_file, set_pspace_remote_exec_file)
(_initialize_remote): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/remote.c | 28 ++++++----------------------
2 files changed, 13 insertions(+), 22 deletions(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index 5e5fbbf8c34..dd129b3407a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -969,7 +969,8 @@ public:
};
/* Per-program-space data key. */
-static const struct program_space_data *remote_pspace_data;
+static const struct program_space_key<char, gdb::xfree_deleter<char>>
+ remote_pspace_data;
/* The variable registered as the control variable used by the
remote exec-file commands. While the remote exec-file setting is
@@ -1229,16 +1230,6 @@ remote_target::get_remote_state ()
return &m_remote_state;
}
-/* Cleanup routine for the remote module's pspace data. */
-
-static void
-remote_pspace_data_cleanup (struct program_space *pspace, void *arg)
-{
- char *remote_exec_file = (char *) arg;
-
- xfree (remote_exec_file);
-}
-
/* Fetch the remote exec-file from the current program space. */
static const char *
@@ -1246,9 +1237,7 @@ get_remote_exec_file (void)
{
char *remote_exec_file;
- remote_exec_file
- = (char *) program_space_data (current_program_space,
- remote_pspace_data);
+ remote_exec_file = remote_pspace_data.get (current_program_space);
if (remote_exec_file == NULL)
return "";
@@ -1259,13 +1248,12 @@ get_remote_exec_file (void)
static void
set_pspace_remote_exec_file (struct program_space *pspace,
- char *remote_exec_file)
+ const char *remote_exec_file)
{
- char *old_file = (char *) program_space_data (pspace, remote_pspace_data);
+ char *old_file = remote_pspace_data.get (pspace);
xfree (old_file);
- set_program_space_data (pspace, remote_pspace_data,
- xstrdup (remote_exec_file));
+ remote_pspace_data.set (pspace, xstrdup (remote_exec_file));
}
/* The "set/show remote exec-file" set command hook. */
@@ -14263,10 +14251,6 @@ _initialize_remote (void)
remote_g_packet_data_handle =
gdbarch_data_register_pre_init (remote_g_packet_data_init);
- remote_pspace_data
- = register_program_space_data_with_cleanup (NULL,
- remote_pspace_data_cleanup);
-
add_target (remote_target_info, remote_target::open);
add_target (extended_remote_target_info, extended_remote_target::open);
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 10/14] Convert symfile-debug.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (8 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 13/14] Convert breakpoint.c " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 05/14] Convert inflow " Tom Tromey
` (5 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes symfile-debug.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* symfile-debug.c (struct debug_sym_fns_data): Add initializers.
(symfile_debug_objfile_data_key): Change type.
(symfile_debug_installed, debug_qf_has_symbols)
(debug_qf_find_last_source_symtab)
(debug_qf_forget_cached_source_info)
(debug_qf_map_symtabs_matching_filename, debug_qf_lookup_symbol)
(debug_qf_print_stats, debug_qf_dump)
(debug_qf_expand_symtabs_for_function)
(debug_qf_expand_all_symtabs)
(debug_qf_expand_symtabs_with_fullname)
(debug_qf_map_matching_symbols)
(debug_qf_expand_symtabs_matching)
(debug_qf_find_pc_sect_compunit_symtab)
(debug_qf_map_symbol_filenames)
(debug_qf_find_compunit_symtab_by_address, debug_sym_get_probes)
(debug_sym_new_init, debug_sym_init, debug_sym_read)
(debug_sym_read_psymbols, debug_sym_finish, debug_sym_offsets)
(debug_sym_read_linetable, debug_sym_relocate): Update.
(symfile_debug_free_objfile): Remove.
(install_symfile_debug_logging, _initialize_symfile_debug):
Update.
---
gdb/ChangeLog | 24 +++++++++++
gdb/symfile-debug.c | 103 +++++++++++++++-----------------------------
2 files changed, 58 insertions(+), 69 deletions(-)
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 5b3ae926504..47117b14959 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -39,13 +39,14 @@
struct debug_sym_fns_data
{
- const struct sym_fns *real_sf;
- struct sym_fns debug_sf;
+ const struct sym_fns *real_sf = nullptr;
+ struct sym_fns debug_sf {};
};
/* We need to record a pointer to the real set of functions for each
objfile. */
-static const struct objfile_data *symfile_debug_objfile_data_key;
+static const struct objfile_key<debug_sym_fns_data>
+ symfile_debug_objfile_data_key;
/* If non-zero all calls to the symfile functions are logged. */
static int debug_symfile = 0;
@@ -56,7 +57,7 @@ static int
symfile_debug_installed (struct objfile *objfile)
{
return (objfile->sf != NULL
- && objfile_data (objfile, symfile_debug_objfile_data_key) != NULL);
+ && symfile_debug_objfile_data_key.get (objfile) != NULL);
}
/* Utility return the name to print for SYMTAB. */
@@ -73,8 +74,7 @@ static int
debug_qf_has_symbols (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
int retval;
retval = debug_data->real_sf->qf->has_symbols (objfile);
@@ -89,8 +89,7 @@ static struct symtab *
debug_qf_find_last_source_symtab (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
struct symtab *retval;
fprintf_filtered (gdb_stdlog, "qf->find_last_source_symtab (%s)\n",
@@ -108,8 +107,7 @@ static void
debug_qf_forget_cached_source_info (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "qf->forget_cached_source_info (%s)\n",
objfile_debug_name (objfile));
@@ -123,8 +121,7 @@ debug_qf_map_symtabs_matching_filename
gdb::function_view<bool (symtab *)> callback)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->map_symtabs_matching_filename (%s, \"%s\", \"%s\", %s)\n",
@@ -147,8 +144,7 @@ debug_qf_lookup_symbol (struct objfile *objfile, int kind, const char *name,
domain_enum domain)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
struct compunit_symtab *retval;
fprintf_filtered (gdb_stdlog,
@@ -171,8 +167,7 @@ static void
debug_qf_print_stats (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "qf->print_stats (%s)\n",
objfile_debug_name (objfile));
@@ -184,8 +179,7 @@ static void
debug_qf_dump (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "qf->dump (%s)\n",
objfile_debug_name (objfile));
@@ -198,8 +192,7 @@ debug_qf_expand_symtabs_for_function (struct objfile *objfile,
const char *func_name)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->expand_symtabs_for_function (%s, \"%s\")\n",
@@ -212,8 +205,7 @@ static void
debug_qf_expand_all_symtabs (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "qf->expand_all_symtabs (%s)\n",
objfile_debug_name (objfile));
@@ -226,8 +218,7 @@ debug_qf_expand_symtabs_with_fullname (struct objfile *objfile,
const char *fullname)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->expand_symtabs_with_fullname (%s, \"%s\")\n",
@@ -247,8 +238,7 @@ debug_qf_map_matching_symbols (struct objfile *objfile,
symbol_compare_ftype *ordered_compare)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->map_matching_symbols (%s, \"%s\", %s, %d, %s, %s, %s, %s)\n",
@@ -276,8 +266,7 @@ debug_qf_expand_symtabs_matching
enum search_domain kind)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->expand_symtabs_matching (%s, %s, %s, %s, %s)\n",
@@ -303,8 +292,7 @@ debug_qf_find_pc_sect_compunit_symtab (struct objfile *objfile,
int warn_if_readin)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
struct compunit_symtab *retval;
fprintf_filtered (gdb_stdlog,
@@ -335,8 +323,7 @@ debug_qf_map_symbol_filenames (struct objfile *objfile,
int need_fullname)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->map_symbol_filenames (%s, %s, %s, %d)\n",
objfile_debug_name (objfile),
@@ -353,8 +340,7 @@ debug_qf_find_compunit_symtab_by_address (struct objfile *objfile,
CORE_ADDR address)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog,
"qf->find_compunit_symtab_by_address (%s, %s)\n",
objfile_debug_name (objfile),
@@ -400,8 +386,7 @@ static const std::vector<probe *> &
debug_sym_get_probes (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
const std::vector<probe *> &retval
= debug_data->real_sf->sym_probe_fns->sym_get_probes (objfile);
@@ -425,8 +410,7 @@ static void
debug_sym_new_init (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_new_init (%s)\n",
objfile_debug_name (objfile));
@@ -438,8 +422,7 @@ static void
debug_sym_init (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_init (%s)\n",
objfile_debug_name (objfile));
@@ -451,8 +434,7 @@ static void
debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
objfile_debug_name (objfile), (unsigned) symfile_flags);
@@ -464,8 +446,7 @@ static void
debug_sym_read_psymbols (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_read_psymbols (%s)\n",
objfile_debug_name (objfile));
@@ -477,8 +458,7 @@ static void
debug_sym_finish (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_finish (%s)\n",
objfile_debug_name (objfile));
@@ -491,8 +471,7 @@ debug_sym_offsets (struct objfile *objfile,
const section_addr_info &info)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_offsets (%s, %s)\n",
objfile_debug_name (objfile),
@@ -514,8 +493,7 @@ static void
debug_sym_read_linetable (struct objfile *objfile)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
fprintf_filtered (gdb_stdlog, "sf->sym_read_linetable (%s)\n",
objfile_debug_name (objfile));
@@ -527,8 +505,7 @@ static bfd_byte *
debug_sym_relocate (struct objfile *objfile, asection *sectp, bfd_byte *buf)
{
const struct debug_sym_fns_data *debug_data
- = ((const struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ = symfile_debug_objfile_data_key.get (objfile);
bfd_byte *retval;
retval = debug_data->real_sf->sym_relocate (objfile, sectp, buf);
@@ -563,14 +540,6 @@ static const struct sym_fns debug_sym_fns =
&debug_sym_quick_functions
};
\f
-/* Free the copy of sym_fns recorded in the registry. */
-
-static void
-symfile_debug_free_objfile (struct objfile *objfile, void *datum)
-{
- xfree (datum);
-}
-
/* Install the debugging versions of the symfile functions for OBJFILE.
Do not call this if the debug versions are already installed. */
@@ -586,7 +555,7 @@ install_symfile_debug_logging (struct objfile *objfile)
real_sf = objfile->sf;
/* Alas we have to preserve NULL entries in REAL_SF. */
- debug_data = XCNEW (struct debug_sym_fns_data);
+ debug_data = new struct debug_sym_fns_data;
#define COPY_SF_PTR(from, to, name, func) \
do { \
@@ -612,7 +581,7 @@ install_symfile_debug_logging (struct objfile *objfile)
#undef COPY_SF_PTR
debug_data->real_sf = real_sf;
- set_objfile_data (objfile, symfile_debug_objfile_data_key, debug_data);
+ symfile_debug_objfile_data_key.set (objfile, debug_data);
objfile->sf = &debug_data->debug_sf;
}
@@ -627,12 +596,11 @@ uninstall_symfile_debug_logging (struct objfile *objfile)
/* The debug versions should be currently installed. */
gdb_assert (symfile_debug_installed (objfile));
- debug_data = ((struct debug_sym_fns_data *)
- objfile_data (objfile, symfile_debug_objfile_data_key));
+ debug_data = symfile_debug_objfile_data_key.get (objfile);
objfile->sf = debug_data->real_sf;
- xfree (debug_data);
- set_objfile_data (objfile, symfile_debug_objfile_data_key, NULL);
+ delete debug_data;
+ symfile_debug_objfile_data_key.set (objfile, nullptr);
}
/* Call this function to set OBJFILE->SF.
@@ -687,9 +655,6 @@ show_debug_symfile (struct ui_file *file, int from_tty,
void
_initialize_symfile_debug (void)
{
- symfile_debug_objfile_data_key
- = register_objfile_data_with_cleanup (NULL, symfile_debug_free_objfile);
-
add_setshow_boolean_cmd ("symfile", no_class, &debug_symfile, _("\
Set debugging of the symfile functions."), _("\
Show debugging of the symfile functions."), _("\
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 08/14] Convert auto-load.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (11 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 09/14] Convert dwarf2_per_objfile " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:13 ` [PATCH 07/14] Convert objfiles.c " Tom Tromey
` (2 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes auto-load.c to use the type-safe registry API. It also
changes a couple of types to "bool", removing uses of "FALSE".
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* auto-load.c (struct auto_load_pspace_info): Add destructor and
initializers.
<unsupported_script_warning_printed,
script_not_found_warning_printed>: Now bool.
(auto_load_pspace_data): Change type.
(~auto_load_pspace_info): Rename from
auto_load_pspace_data_cleanup.
(get_auto_load_pspace_data, init_loaded_scripts_info)
(clear_section_scripts, maybe_print_unsupported_script_warning)
(maybe_print_script_not_found_warning, _initialize_auto_load):
Update.
---
gdb/ChangeLog | 14 ++++++++++++
gdb/auto-load.c | 59 +++++++++++++++++++------------------------------
2 files changed, 37 insertions(+), 36 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index ae7a189dc04..634cc924903 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -527,18 +527,21 @@ For more information about this security protection see the\n\
struct auto_load_pspace_info
{
+ auto_load_pspace_info () = default;
+ ~auto_load_pspace_info ();
+
/* For each program space we keep track of loaded scripts, both when
specified as file names and as scripts to be executed directly. */
- struct htab *loaded_script_files;
- struct htab *loaded_script_texts;
+ struct htab *loaded_script_files = nullptr;
+ struct htab *loaded_script_texts = nullptr;
/* Non-zero if we've issued the warning about an auto-load script not being
supported. We only want to issue this warning once. */
- int unsupported_script_warning_printed;
+ bool unsupported_script_warning_printed = false;
/* Non-zero if we've issued the warning about an auto-load script not being
found. We only want to issue this warning once. */
- int script_not_found_warning_printed;
+ bool script_not_found_warning_printed = false;
};
/* Objects of this type are stored in the loaded_script hash table. */
@@ -559,18 +562,15 @@ struct loaded_script
};
/* Per-program-space data key. */
-static const struct program_space_data *auto_load_pspace_data;
+static const struct program_space_key<struct auto_load_pspace_info>
+ auto_load_pspace_data;
-static void
-auto_load_pspace_data_cleanup (struct program_space *pspace, void *arg)
+auto_load_pspace_info::~auto_load_pspace_info ()
{
- struct auto_load_pspace_info *info = (struct auto_load_pspace_info *) arg;
-
- if (info->loaded_script_files)
- htab_delete (info->loaded_script_files);
- if (info->loaded_script_texts)
- htab_delete (info->loaded_script_texts);
- xfree (info);
+ if (loaded_script_files)
+ htab_delete (loaded_script_files);
+ if (loaded_script_texts)
+ htab_delete (loaded_script_texts);
}
/* Get the current autoload data. If none is found yet, add it now. This
@@ -581,13 +581,9 @@ get_auto_load_pspace_data (struct program_space *pspace)
{
struct auto_load_pspace_info *info;
- info = ((struct auto_load_pspace_info *)
- program_space_data (pspace, auto_load_pspace_data));
+ info = auto_load_pspace_data.get (pspace);
if (info == NULL)
- {
- info = XCNEW (struct auto_load_pspace_info);
- set_program_space_data (pspace, auto_load_pspace_data, info);
- }
+ info = auto_load_pspace_data.emplace (pspace);
return info;
}
@@ -632,8 +628,8 @@ init_loaded_scripts_info (struct auto_load_pspace_info *pspace_info)
eq_loaded_script_entry,
xfree);
- pspace_info->unsupported_script_warning_printed = FALSE;
- pspace_info->script_not_found_warning_printed = FALSE;
+ pspace_info->unsupported_script_warning_printed = false;
+ pspace_info->script_not_found_warning_printed = false;
}
/* Wrapper on get_auto_load_pspace_data to also allocate the hash table
@@ -747,16 +743,11 @@ clear_section_scripts (void)
struct program_space *pspace = current_program_space;
struct auto_load_pspace_info *info;
- info = ((struct auto_load_pspace_info *)
- program_space_data (pspace, auto_load_pspace_data));
+ info = auto_load_pspace_data.get (pspace);
if (info != NULL && info->loaded_script_files != NULL)
{
- htab_delete (info->loaded_script_files);
- htab_delete (info->loaded_script_texts);
- info->loaded_script_files = NULL;
- info->loaded_script_texts = NULL;
- info->unsupported_script_warning_printed = FALSE;
- info->script_not_found_warning_printed = FALSE;
+ delete info;
+ auto_load_pspace_data.emplace (pspace);
}
}
@@ -1386,7 +1377,7 @@ of file %s.\n\
Use `info auto-load %s-scripts [REGEXP]' to list them."),
offset, section_name, objfile_name (objfile),
ext_lang_name (language));
- pspace_info->unsupported_script_warning_printed = 1;
+ pspace_info->unsupported_script_warning_printed = true;
}
}
@@ -1408,7 +1399,7 @@ of file %s.\n\
Use `info auto-load %s-scripts [REGEXP]' to list them."),
offset, section_name, objfile_name (objfile),
ext_lang_name (language));
- pspace_info->script_not_found_warning_printed = 1;
+ pspace_info->script_not_found_warning_printed = true;
}
}
@@ -1538,10 +1529,6 @@ _initialize_auto_load (void)
char *guile_name_help;
const char *suffix;
- auto_load_pspace_data
- = register_program_space_data_with_cleanup (NULL,
- auto_load_pspace_data_cleanup);
-
gdb::observers::new_objfile.attach (auto_load_new_objfile);
add_setshow_boolean_cmd ("gdb-scripts", class_support,
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 02/14] Convert main_info to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (3 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 03/14] Convert symbol_cache to type-safe registry API Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 11/14] Convert auxv.c " Tom Tromey
` (10 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes main_info to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* symtab.c (struct main_info): Add destructor and initializers.
(main_progspace_key): Move. Change type.
(get_main_info): Update.
(main_info_cleanup): Remove.
(_initialize_symtab): Update.
---
gdb/ChangeLog | 8 ++++++++
gdb/symtab.c | 44 +++++++++++++++-----------------------------
2 files changed, 23 insertions(+), 29 deletions(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 16e641a830b..cf97a1d18e2 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -95,23 +95,30 @@ static struct block_symbol
lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
const char *name, const domain_enum domain);
-/* Program space key for finding name and language of "main". */
-
-static const struct program_space_data *main_progspace_key;
-
/* Type of the data stored on the program space. */
struct main_info
{
+ main_info () = default;
+
+ ~main_info ()
+ {
+ xfree (name_of_main);
+ }
+
/* Name of "main". */
- char *name_of_main;
+ char *name_of_main = nullptr;
/* Language of "main". */
- enum language language_of_main;
+ enum language language_of_main = language_unknown;
};
+/* Program space key for finding name and language of "main". */
+
+static const program_space_key<main_info> main_progspace_key;
+
/* Program space key for finding its symbol cache. */
static const struct program_space_data *symbol_cache_key;
@@ -5665,9 +5672,7 @@ make_source_files_completion_list (const char *text, const char *word)
static struct main_info *
get_main_info (void)
{
- struct main_info *info
- = (struct main_info *) program_space_data (current_program_space,
- main_progspace_key);
+ struct main_info *info = main_progspace_key.get (current_program_space);
if (info == NULL)
{
@@ -5677,28 +5682,12 @@ get_main_info (void)
gdb returned "main" as the name even if no function named
"main" was defined the program; and this approach lets us
keep compatibility. */
- info = XCNEW (struct main_info);
- info->language_of_main = language_unknown;
- set_program_space_data (current_program_space, main_progspace_key,
- info);
+ info = main_progspace_key.emplace (current_program_space);
}
return info;
}
-/* A cleanup to destroy a struct main_info when a progspace is
- destroyed. */
-
-static void
-main_info_cleanup (struct program_space *pspace, void *data)
-{
- struct main_info *info = (struct main_info *) data;
-
- if (info != NULL)
- xfree (info->name_of_main);
- xfree (info);
-}
-
static void
set_main_name (const char *name, enum language lang)
{
@@ -6048,9 +6037,6 @@ _initialize_symtab (void)
{
initialize_ordinary_address_classes ();
- main_progspace_key
- = register_program_space_data_with_cleanup (NULL, main_info_cleanup);
-
symbol_cache_key
= register_program_space_data_with_cleanup (NULL, symbol_cache_cleanup);
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 09/14] Convert dwarf2_per_objfile to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (10 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 05/14] Convert inflow " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 08/14] Convert auto-load.c " Tom Tromey
` (3 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes dwarf2_per_objfile to use the type-safe registry API.
This also changes dwarf2_per_objfile not to be allocated on an
obstack. It seemed clearer to me to simply allocate it on the heap;
and I didn't see a drawback from doing so.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* dwarf2read.h (struct dwarf2_per_objfile): Don't inherit from
allocate_on_obstack.
* dwarf2read.c (dwarf2_objfile_data_key): Change type.
(get_dwarf2_per_objfile): Update.
(set_dwarf2_per_objfile): Remove.
(dwarf2_has_info, dwarf2_get_section_info): Update.
(dwarf2_free_objfile): Remove.
(_initialize_dwarf2_read): Update.
---
gdb/ChangeLog | 11 +++++++++++
gdb/dwarf2read.c | 43 ++++++-------------------------------------
gdb/dwarf2read.h | 2 +-
3 files changed, 18 insertions(+), 38 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 829b07f01ac..e9449cc571a 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -108,7 +108,7 @@ static int check_physname = 0;
/* When non-zero, do not reject deprecated .gdb_index sections. */
static int use_deprecated_index_sections = 0;
-static const struct objfile_data *dwarf2_objfile_data_key;
+static const struct objfile_key<dwarf2_per_objfile> dwarf2_objfile_data_key;
/* The "aclass" indices for various kinds of computed DWARF symbols. */
@@ -281,18 +281,7 @@ struct mapped_debug_names final : public mapped_index_base
dwarf2_per_objfile *
get_dwarf2_per_objfile (struct objfile *objfile)
{
- return ((struct dwarf2_per_objfile *)
- objfile_data (objfile, dwarf2_objfile_data_key));
-}
-
-/* Set the dwarf2_per_objfile associated to OBJFILE. */
-
-void
-set_dwarf2_per_objfile (struct objfile *objfile,
- struct dwarf2_per_objfile *dwarf2_per_objfile)
-{
- gdb_assert (get_dwarf2_per_objfile (objfile) == NULL);
- set_objfile_data (objfile, dwarf2_objfile_data_key, dwarf2_per_objfile);
+ return dwarf2_objfile_data_key.get (objfile);
}
/* Default names of the debugging sections. */
@@ -2256,13 +2245,9 @@ dwarf2_has_info (struct objfile *objfile,
= get_dwarf2_per_objfile (objfile);
if (dwarf2_per_objfile == NULL)
- {
- /* Initialize per-objfile state. */
- dwarf2_per_objfile
- = new (&objfile->objfile_obstack) struct dwarf2_per_objfile (objfile,
- names);
- set_dwarf2_per_objfile (objfile, dwarf2_per_objfile);
- }
+ dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile,
+ names);
+
return (!dwarf2_per_objfile->info.is_virtual
&& dwarf2_per_objfile->info.s.section != NULL
&& !dwarf2_per_objfile->abbrev.is_virtual
@@ -2594,9 +2579,7 @@ dwarf2_get_section_info (struct objfile *objfile,
asection **sectp, const gdb_byte **bufp,
bfd_size_type *sizep)
{
- struct dwarf2_per_objfile *data
- = (struct dwarf2_per_objfile *) objfile_data (objfile,
- dwarf2_objfile_data_key);
+ struct dwarf2_per_objfile *data = dwarf2_objfile_data_key.get (objfile);
struct dwarf2_section_info *info;
/* We may see an objfile without any DWARF, in which case we just
@@ -25351,17 +25334,6 @@ free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu)
}
}
-/* Cleanup function for the dwarf2_per_objfile data. */
-
-static void
-dwarf2_free_objfile (struct objfile *objfile, void *datum)
-{
- struct dwarf2_per_objfile *dwarf2_per_objfile
- = static_cast<struct dwarf2_per_objfile *> (datum);
-
- delete dwarf2_per_objfile;
-}
-
/* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
We store these in a hash table separate from the DIEs, and preserve them
when the DIEs are flushed out of cache.
@@ -25679,9 +25651,6 @@ show_check_physname (struct ui_file *file, int from_tty,
void
_initialize_dwarf2_read (void)
{
- dwarf2_objfile_data_key
- = register_objfile_data_with_cleanup (nullptr, dwarf2_free_objfile);
-
add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\
Set DWARF specific variables.\n\
Configure DWARF variables such as the cache size"),
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 34c66167b5b..9a316260be4 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -102,7 +102,7 @@ typedef struct die_info *die_info_ptr;
/* Collection of data recorded per objfile.
This hangs off of dwarf2_objfile_data_key. */
-struct dwarf2_per_objfile : public allocate_on_obstack
+struct dwarf2_per_objfile
{
/* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
dwarf2 section names, or is NULL if the standard ELF names are
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 01/14] Add a type-safe C++ interface to a registry
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
2019-04-23 2:10 ` [PATCH 06/14] Convert break-catch-syscall.c to type-safe registry API Tom Tromey
2019-04-23 2:10 ` [PATCH 14/14] Convert remote.c " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 03/14] Convert symbol_cache to type-safe registry API Tom Tromey
` (12 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes DECLARE_REGISTRY to add a type-safe interface. This
interface is a C++ class that handles the details of registering a
key, and provides various useful methods, including policy-based
cleanup.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* registry.h (DECLARE_REGISTRY): Define the _key class.
---
gdb/ChangeLog | 4 ++++
gdb/registry.h | 53 ++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/gdb/registry.h b/gdb/registry.h
index 3881e29b54f..5890147681d 100644
--- a/gdb/registry.h
+++ b/gdb/registry.h
@@ -243,11 +243,52 @@ typedef void (*registry_ ## TAG ## _callback) (struct TAG *, void *); \
extern const struct TAG ## _data *register_ ## TAG ## _data (void); \
extern const struct TAG ## _data *register_ ## TAG ## _data_with_cleanup \
(registry_ ## TAG ## _callback save, registry_ ## TAG ## _callback free); \
-extern void clear_ ## TAG ## _data (struct TAG *); \
-extern void set_ ## TAG ## _data (struct TAG *, \
- const struct TAG ## _data *data, \
- void *value); \
-extern void *TAG ## _data (struct TAG *, \
- const struct TAG ## _data *data);
+extern void clear_ ## TAG ## _data (struct TAG *); \
+extern void set_ ## TAG ## _data (struct TAG *, \
+ const struct TAG ## _data *data, \
+ void *value); \
+extern void *TAG ## _data (struct TAG *, \
+ const struct TAG ## _data *data); \
+ \
+template<typename DATA, typename Deleter = std::default_delete<DATA>> \
+class TAG ## _key \
+{ \
+public: \
+ \
+ TAG ## _key () \
+ : m_key (register_ ## TAG ## _data_with_cleanup (nullptr, \
+ cleanup)) \
+ { \
+ } \
+ \
+ DATA *get (struct TAG *obj) const \
+ { \
+ return (DATA *) TAG ## _data (obj, m_key); \
+ } \
+ \
+ void set (struct TAG *obj, DATA *data) const \
+ { \
+ set_ ## TAG ## _data (obj, m_key, data); \
+ } \
+ \
+ template<typename... Args> \
+ DATA *emplace (struct TAG *obj, Args &&...args) const \
+ { \
+ DATA *result = new DATA (std::forward<Args> (args)...); \
+ set (obj, result); \
+ return result; \
+ } \
+ \
+private: \
+ \
+ static void cleanup (struct TAG *obj, void *arg) \
+ { \
+ DATA *datum = (DATA *) arg; \
+ Deleter d; \
+ d (datum); \
+ } \
+ \
+ const struct TAG ## _data *m_key; \
+};
#endif /* REGISTRY_H */
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 04/14] Convert target dcache to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (6 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 12/14] Convert linux-tdep.c " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 13/14] Convert breakpoint.c " Tom Tromey
` (7 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes the target dcache to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* target-dcache.c (target_dcache_cleanup): Remove.
(target_dcache_aspace_key): Change type.
(target_dcache_init_p, target_dcache_invalidate)
(target_dcache_get, target_dcache_get_or_init)
(_initialize_target_dcache): Update.
* dcache.h (struct dcache_deleter): New.
---
gdb/ChangeLog | 9 +++++++++
gdb/dcache.h | 9 +++++++++
gdb/target-dcache.c | 34 +++++++---------------------------
3 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/gdb/dcache.h b/gdb/dcache.h
index 9c29074c919..a58ac840d12 100644
--- a/gdb/dcache.h
+++ b/gdb/dcache.h
@@ -34,6 +34,15 @@ DCACHE *dcache_init (void);
/* Free a DCACHE. */
void dcache_free (DCACHE *);
+/* A deletion adapter that calls dcache_free. */
+struct dcache_deleter
+{
+ void operator() (DCACHE *d) const
+ {
+ dcache_free (d);
+ }
+};
+
enum target_xfer_status
dcache_read_memory_partial (struct target_ops *ops, DCACHE *dcache,
CORE_ADDR memaddr, gdb_byte *myaddr,
diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c
index 3fab9845bc3..98d5c1f83b6 100644
--- a/gdb/target-dcache.c
+++ b/gdb/target-dcache.c
@@ -23,16 +23,8 @@
/* The target dcache is kept per-address-space. This key lets us
associate the cache with the address space. */
-static const struct address_space_data *target_dcache_aspace_key;
-
-/* Clean up dcache, represented by ARG, which is associated with
- ASPACE. */
-
-static void
-target_dcache_cleanup (struct address_space *aspace, void *arg)
-{
- dcache_free ((DCACHE *) arg);
-}
+static const struct address_space_key<DCACHE, dcache_deleter>
+ target_dcache_aspace_key;
/* Target dcache is initialized or not. */
@@ -40,8 +32,7 @@ int
target_dcache_init_p (void)
{
DCACHE *dcache
- = (DCACHE *) address_space_data (current_program_space->aspace,
- target_dcache_aspace_key);
+ = target_dcache_aspace_key.get (current_program_space->aspace);
return (dcache != NULL);
}
@@ -52,8 +43,7 @@ void
target_dcache_invalidate (void)
{
DCACHE *dcache
- = (DCACHE *) address_space_data (current_program_space->aspace,
- target_dcache_aspace_key);
+ = target_dcache_aspace_key.get (current_program_space->aspace);
if (dcache != NULL)
dcache_invalidate (dcache);
@@ -65,11 +55,7 @@ target_dcache_invalidate (void)
DCACHE *
target_dcache_get (void)
{
- DCACHE *dcache
- = (DCACHE *) address_space_data (current_program_space->aspace,
- target_dcache_aspace_key);
-
- return dcache;
+ return target_dcache_aspace_key.get (current_program_space->aspace);
}
/* Return the target dcache. If it is not initialized yet, initialize
@@ -79,14 +65,12 @@ DCACHE *
target_dcache_get_or_init (void)
{
DCACHE *dcache
- = (DCACHE *) address_space_data (current_program_space->aspace,
- target_dcache_aspace_key);
+ = target_dcache_aspace_key.get (current_program_space->aspace);
if (dcache == NULL)
{
dcache = dcache_init ();
- set_address_space_data (current_program_space->aspace,
- target_dcache_aspace_key, dcache);
+ target_dcache_aspace_key.set (current_program_space->aspace, dcache);
}
return dcache;
@@ -193,8 +177,4 @@ access is on."),
set_code_cache,
show_code_cache,
&setlist, &showlist);
-
- target_dcache_aspace_key
- = register_address_space_data_with_cleanup (NULL,
- target_dcache_cleanup);
}
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 05/14] Convert inflow to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (9 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 10/14] Convert symfile-debug.c " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 09/14] Convert dwarf2_per_objfile " Tom Tromey
` (4 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes inflow.c to use the type-safe registry API. This fixes a
latent bug in swap_terminal_info, which previously said:
terminal_info *info_a
= (terminal_info *) inferior_data (a, inflow_inferior_data);
terminal_info *info_b
= (terminal_info *) inferior_data (a, inflow_inferior_data);
... both of which examine 'a'.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* inflow.c (struct terminal_info): Add destructor and
initializers.
(inflow_inferior_data): Change type.
(~terminal_info): Rename from inflow_inferior_data_cleanup.
(get_inflow_inferior_data, inflow_inferior_exit)
(swap_terminal_info, _initialize_inflow): Update.
---
gdb/ChangeLog | 9 +++++++++
gdb/inflow.c | 51 ++++++++++++++++++++-------------------------------
2 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/gdb/inflow.c b/gdb/inflow.c
index b71511308b3..beca25ab1df 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -58,13 +58,16 @@ static struct serial *stdin_serial;
the inferior is resumed in the foreground. */
struct terminal_info
{
+ terminal_info () = default;
+ ~terminal_info ();
+
/* The name of the tty (from the `tty' command) that we gave to the
inferior when it was started. */
- char *run_terminal;
+ char *run_terminal = nullptr;
/* TTY state. We save it whenever the inferior stops, and restore
it when it resumes in the foreground. */
- serial_ttystate ttystate;
+ serial_ttystate ttystate {};
#ifdef HAVE_TERMIOS_H
/* The terminal's foreground process group. Saved whenever the
@@ -80,11 +83,11 @@ struct terminal_info
inf2's pgrp in the foreground instead of inf1's (which would be
problematic since it would be left stopped: Ctrl-C wouldn't work,
for example). */
- pid_t process_group;
+ pid_t process_group = 0;
#endif
/* fcntl flags. Saved and restored just like ttystate. */
- int tflags;
+ int tflags = 0;
};
/* Our own tty state, which we restore every time we need to deal with
@@ -623,16 +626,12 @@ child_pass_ctrlc (struct target_ops *self)
}
/* Per-inferior data key. */
-static const struct inferior_data *inflow_inferior_data;
+static const struct inferior_key<terminal_info> inflow_inferior_data;
-static void
-inflow_inferior_data_cleanup (struct inferior *inf, void *arg)
+terminal_info::~terminal_info ()
{
- struct terminal_info *info = (struct terminal_info *) arg;
-
- xfree (info->run_terminal);
- xfree (info->ttystate);
- xfree (info);
+ xfree (run_terminal);
+ xfree (ttystate);
}
/* Get the current svr4 data. If none is found yet, add it now. This
@@ -643,12 +642,9 @@ get_inflow_inferior_data (struct inferior *inf)
{
struct terminal_info *info;
- info = (struct terminal_info *) inferior_data (inf, inflow_inferior_data);
+ info = inflow_inferior_data.get (inf);
if (info == NULL)
- {
- info = XCNEW (struct terminal_info);
- set_inferior_data (inf, inflow_inferior_data, info);
- }
+ info = inflow_inferior_data.emplace (inf);
return info;
}
@@ -666,13 +662,11 @@ inflow_inferior_exit (struct inferior *inf)
inf->terminal_state = target_terminal_state::is_ours;
- info = (struct terminal_info *) inferior_data (inf, inflow_inferior_data);
+ info = inflow_inferior_data.get (inf);
if (info != NULL)
{
- xfree (info->run_terminal);
- xfree (info->ttystate);
- xfree (info);
- set_inferior_data (inf, inflow_inferior_data, NULL);
+ delete info;
+ inflow_inferior_data.set (inf, nullptr);
}
}
@@ -705,13 +699,11 @@ copy_terminal_info (struct inferior *to, struct inferior *from)
void
swap_terminal_info (inferior *a, inferior *b)
{
- terminal_info *info_a
- = (terminal_info *) inferior_data (a, inflow_inferior_data);
- terminal_info *info_b
- = (terminal_info *) inferior_data (a, inflow_inferior_data);
+ terminal_info *info_a = inflow_inferior_data.get (a);
+ terminal_info *info_b = inflow_inferior_data.get (b);
- set_inferior_data (a, inflow_inferior_data, info_b);
- set_inferior_data (b, inflow_inferior_data, info_a);
+ inflow_inferior_data.set (a, info_b);
+ inflow_inferior_data.set (b, info_a);
std::swap (a->terminal_state, b->terminal_state);
}
@@ -1006,7 +998,4 @@ _initialize_inflow (void)
have_job_control ();
gdb::observers::inferior_exit.attach (inflow_inferior_exit);
-
- inflow_inferior_data
- = register_inferior_data_with_cleanup (NULL, inflow_inferior_data_cleanup);
}
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 03/14] Convert symbol_cache to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (2 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 01/14] Add a type-safe C++ interface to a registry Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 02/14] Convert main_info " Tom Tromey
` (11 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes the symbol_cache to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* symtab.c (struct symbol_cache): Add destructor and
initializers.
(symbol_cache_key): Move. Change type.
(make_symbol_cache, free_symbol_cache): Remove.
(get_symbol_cache): Update.
(symbol_cache_cleanup): Remove.
(ALL_PSPACES, symbol_cache_flush)
(maintenance_print_symbol_cache)
(maintenance_print_symbol_cache_statistics, _initialize_symtab):
Update.
---
gdb/ChangeLog | 13 +++++++++
gdb/symtab.c | 75 +++++++++++++++------------------------------------
2 files changed, 34 insertions(+), 54 deletions(-)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index cf97a1d18e2..2e5fbbedde2 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -119,10 +119,6 @@ struct main_info
static const program_space_key<main_info> main_progspace_key;
-/* Program space key for finding its symbol cache. */
-
-static const struct program_space_data *symbol_cache_key;
-
/* The default symbol cache size.
There is no extra cpu cost for large N (except when flushing the cache,
which is rare). The value here is just a first attempt. A better default
@@ -214,10 +210,22 @@ struct block_symbol_cache
struct symbol_cache
{
- struct block_symbol_cache *global_symbols;
- struct block_symbol_cache *static_symbols;
+ symbol_cache () = default;
+
+ ~symbol_cache ()
+ {
+ xfree (global_symbols);
+ xfree (static_symbols);
+ }
+
+ struct block_symbol_cache *global_symbols = nullptr;
+ struct block_symbol_cache *static_symbols = nullptr;
};
+/* Program space key for finding its symbol cache. */
+
+static const program_space_key<symbol_cache> symbol_cache_key;
+
/* When non-zero, print debugging messages related to symtab creation. */
unsigned int symtab_create_debug = 0;
@@ -1226,57 +1234,23 @@ resize_symbol_cache (struct symbol_cache *cache, unsigned int new_size)
}
}
-/* Make a symbol cache of size SIZE. */
-
-static struct symbol_cache *
-make_symbol_cache (unsigned int size)
-{
- struct symbol_cache *cache;
-
- cache = XCNEW (struct symbol_cache);
- resize_symbol_cache (cache, symbol_cache_size);
- return cache;
-}
-
-/* Free the space used by CACHE. */
-
-static void
-free_symbol_cache (struct symbol_cache *cache)
-{
- xfree (cache->global_symbols);
- xfree (cache->static_symbols);
- xfree (cache);
-}
-
/* Return the symbol cache of PSPACE.
Create one if it doesn't exist yet. */
static struct symbol_cache *
get_symbol_cache (struct program_space *pspace)
{
- struct symbol_cache *cache
- = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key);
+ struct symbol_cache *cache = symbol_cache_key.get (pspace);
if (cache == NULL)
{
- cache = make_symbol_cache (symbol_cache_size);
- set_program_space_data (pspace, symbol_cache_key, cache);
+ cache = symbol_cache_key.emplace (pspace);
+ resize_symbol_cache (cache, symbol_cache_size);
}
return cache;
}
-/* Delete the symbol cache of PSPACE.
- Called when PSPACE is destroyed. */
-
-static void
-symbol_cache_cleanup (struct program_space *pspace, void *data)
-{
- struct symbol_cache *cache = (struct symbol_cache *) data;
-
- free_symbol_cache (cache);
-}
-
/* Set the size of the symbol cache in all program spaces. */
static void
@@ -1286,8 +1260,7 @@ set_symbol_cache_size (unsigned int new_size)
ALL_PSPACES (pspace)
{
- struct symbol_cache *cache
- = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key);
+ struct symbol_cache *cache = symbol_cache_key.get (pspace);
/* The pspace could have been created but not have a cache yet. */
if (cache != NULL)
@@ -1443,8 +1416,7 @@ symbol_cache_mark_not_found (struct block_symbol_cache *bsc,
static void
symbol_cache_flush (struct program_space *pspace)
{
- struct symbol_cache *cache
- = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key);
+ struct symbol_cache *cache = symbol_cache_key.get (pspace);
int pass;
if (cache == NULL)
@@ -1558,8 +1530,7 @@ maintenance_print_symbol_cache (const char *args, int from_tty)
: "(no object file)");
/* If the cache hasn't been created yet, avoid creating one. */
- cache
- = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key);
+ cache = symbol_cache_key.get (pspace);
if (cache == NULL)
printf_filtered (" <empty>\n");
else
@@ -1630,8 +1601,7 @@ maintenance_print_symbol_cache_statistics (const char *args, int from_tty)
: "(no object file)");
/* If the cache hasn't been created yet, avoid creating one. */
- cache
- = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key);
+ cache = symbol_cache_key.get (pspace);
if (cache == NULL)
printf_filtered (" empty, no stats available\n");
else
@@ -6037,9 +6007,6 @@ _initialize_symtab (void)
{
initialize_ordinary_address_classes ();
- symbol_cache_key
- = register_program_space_data_with_cleanup (NULL, symbol_cache_cleanup);
-
add_info ("variables", info_variables_command,
info_print_args_help (_("\
All global and static variable names or those matching REGEXPs.\n\
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 13/14] Convert breakpoint.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (7 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 04/14] Convert target dcache " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 10/14] Convert symfile-debug.c " Tom Tromey
` (6 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes breakpoint.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* breakpoint.c (breakpoint_objfile_key): Change type.
(get_breakpoint_objfile_data): Update.
(free_breakpoint_objfile_data): Remove.
(_initialize_breakpoint): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/breakpoint.c | 23 ++++-------------------
2 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 3047ef3827d..6097b62e81f 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3156,7 +3156,8 @@ struct breakpoint_objfile_data
std::vector<probe *> exception_probes;
};
-static const struct objfile_data *breakpoint_objfile_key;
+static const struct objfile_key<breakpoint_objfile_data>
+ breakpoint_objfile_key;
/* Minimal symbol not found sentinel. */
static struct minimal_symbol msym_not_found;
@@ -3177,25 +3178,12 @@ get_breakpoint_objfile_data (struct objfile *objfile)
{
struct breakpoint_objfile_data *bp_objfile_data;
- bp_objfile_data = ((struct breakpoint_objfile_data *)
- objfile_data (objfile, breakpoint_objfile_key));
+ bp_objfile_data = breakpoint_objfile_key.get (objfile);
if (bp_objfile_data == NULL)
- {
- bp_objfile_data = new breakpoint_objfile_data ();
- set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data);
- }
+ bp_objfile_data = breakpoint_objfile_key.emplace (objfile);
return bp_objfile_data;
}
-static void
-free_breakpoint_objfile_data (struct objfile *obj, void *data)
-{
- struct breakpoint_objfile_data *bp_objfile_data
- = (struct breakpoint_objfile_data *) data;
-
- delete bp_objfile_data;
-}
-
static void
create_overlay_event_breakpoint (void)
{
@@ -15448,9 +15436,6 @@ _initialize_breakpoint (void)
gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile);
gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change);
- breakpoint_objfile_key
- = register_objfile_data_with_cleanup (NULL, free_breakpoint_objfile_data);
-
breakpoint_chain = 0;
/* Don't bother to call set_breakpoint_count. $bpnum isn't useful
before a breakpoint is set. */
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 11/14] Convert auxv.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (4 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 02/14] Convert main_info " Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 12/14] Convert linux-tdep.c " Tom Tromey
` (9 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes auxv.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* auxv.c (auxv_inferior_data): Move. Change type.
(auxv_inferior_data_cleanup): Remove.
(invalidate_auxv_cache_inf): Rewrite.
(get_auxv_inferior_data, _initialize_auxv): Update.
---
gdb/ChangeLog | 7 +++++++
gdb/auxv.c | 36 ++++++++----------------------------
2 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/gdb/auxv.c b/gdb/auxv.c
index 13caa936651..d861d9319a1 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -293,9 +293,6 @@ target_auxv_parse (gdb_byte **readptr,
}
-/* Per-inferior data key for auxv. */
-static const struct inferior_data *auxv_inferior_data;
-
/* Auxiliary Vector information structure. This is used by GDB
for caching purposes for each inferior. This helps reduce the
overhead of transfering data from a remote target to the local host. */
@@ -304,34 +301,22 @@ struct auxv_info
gdb::optional<gdb::byte_vector> data;
};
-/* Handles the cleanup of the auxv cache for inferior INF. ARG is ignored.
- Frees whatever allocated space there is to be freed and sets INF's auxv cache
- data pointer to NULL.
+/* Per-inferior data key for auxv. */
+static const struct inferior_key<auxv_info> auxv_inferior_data;
- This function is called when the following events occur: inferior_appeared,
- inferior_exit and executable_changed. */
+/* Invalidate INF's auxv cache. */
static void
-auxv_inferior_data_cleanup (struct inferior *inf, void *arg)
+invalidate_auxv_cache_inf (struct inferior *inf)
{
- struct auxv_info *info;
-
- info = (struct auxv_info *) inferior_data (inf, auxv_inferior_data);
+ struct auxv_info *info = auxv_inferior_data.get (inf);
if (info != NULL)
{
delete info;
- set_inferior_data (inf, auxv_inferior_data, NULL);
+ auxv_inferior_data.set (inf, NULL);
}
}
-/* Invalidate INF's auxv cache. */
-
-static void
-invalidate_auxv_cache_inf (struct inferior *inf)
-{
- auxv_inferior_data_cleanup (inf, NULL);
-}
-
/* Invalidate current inferior's auxv cache. */
static void
@@ -350,12 +335,11 @@ get_auxv_inferior_data (struct target_ops *ops)
struct auxv_info *info;
struct inferior *inf = current_inferior ();
- info = (struct auxv_info *) inferior_data (inf, auxv_inferior_data);
+ info = auxv_inferior_data.get (inf);
if (info == NULL)
{
- info = new auxv_info;
+ info = auxv_inferior_data.emplace (inf);
info->data = target_read_alloc (ops, TARGET_OBJECT_AUXV, NULL);
- set_inferior_data (inf, auxv_inferior_data, info);
}
return info;
@@ -574,10 +558,6 @@ _initialize_auxv (void)
_("Display the inferior's auxiliary vector.\n\
This is information provided by the operating system at program startup."));
- /* Set an auxv cache per-inferior. */
- auxv_inferior_data
- = register_inferior_data_with_cleanup (NULL, auxv_inferior_data_cleanup);
-
/* Observers used to invalidate the auxv cache when needed. */
gdb::observers::inferior_exit.attach (invalidate_auxv_cache_inf);
gdb::observers::inferior_appeared.attach (invalidate_auxv_cache_inf);
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 06/14] Convert break-catch-syscall.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
@ 2019-04-23 2:10 ` Tom Tromey
2019-04-23 2:10 ` [PATCH 14/14] Convert remote.c " Tom Tromey
` (14 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes break-catch-syscall.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* break-catch-syscall.c (catch_syscall_inferior_data): Move.
Change type.
(get_catch_syscall_inferior_data): Update.
(catch_syscall_inferior_data_cleanup): Remove.
(_initialize_break_catch_syscall): Update.
---
gdb/ChangeLog | 8 ++++++++
gdb/break-catch-syscall.c | 25 +++++--------------------
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 6a911fbc2a3..cd4870f7f51 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -42,8 +42,6 @@ struct syscall_catchpoint : public breakpoint
std::vector<int> syscalls_to_be_caught;
};
-static const struct inferior_data *catch_syscall_inferior_data = NULL;
-
struct catch_syscall_inferior_data
{
/* We keep a count of the number of times the user has requested a
@@ -61,31 +59,21 @@ struct catch_syscall_inferior_data
int total_syscalls_count;
};
+static const struct inferior_key<struct catch_syscall_inferior_data>
+ catch_syscall_inferior_data;
+
static struct catch_syscall_inferior_data *
get_catch_syscall_inferior_data (struct inferior *inf)
{
struct catch_syscall_inferior_data *inf_data;
- inf_data = ((struct catch_syscall_inferior_data *)
- inferior_data (inf, catch_syscall_inferior_data));
+ inf_data = catch_syscall_inferior_data.get (inf);
if (inf_data == NULL)
- {
- inf_data = new struct catch_syscall_inferior_data ();
- set_inferior_data (inf, catch_syscall_inferior_data, inf_data);
- }
+ inf_data = catch_syscall_inferior_data.emplace (inf);
return inf_data;
}
-static void
-catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg)
-{
- struct catch_syscall_inferior_data *inf_data
- = (struct catch_syscall_inferior_data *) arg;
- delete inf_data;
-}
-
-
/* Implement the "insert" breakpoint_ops method for syscall
catchpoints. */
@@ -617,9 +605,6 @@ _initialize_break_catch_syscall (void)
initialize_syscall_catchpoint_ops ();
gdb::observers::inferior_exit.attach (clear_syscall_counts);
- catch_syscall_inferior_data
- = register_inferior_data_with_cleanup (NULL,
- catch_syscall_inferior_data_cleanup);
add_catch_command ("syscall", _("\
Catch system calls by their names, groups and/or numbers.\n\
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 00/14] Add a type-safe API to registries
@ 2019-04-23 2:10 Tom Tromey
2019-04-23 2:10 ` [PATCH 06/14] Convert break-catch-syscall.c to type-safe registry API Tom Tromey
` (15 more replies)
0 siblings, 16 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:10 UTC (permalink / raw)
To: gdb-patches
This series adds an optional type-safe API to the gdb registry
feature, and converts various modules to use it.
I don't think this is the final form for registries -- in the long run
I suppose I'd like to turn them into a CRTP mixin class. However,
this series seems like a reasonable step along the way, providing type
safety and using policy classes for destruction.
Let me know what you think.
Regression tested by the buildbot.
Tom
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 07/14] Convert objfiles.c to type-safe registry API
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (12 preceding siblings ...)
2019-04-23 2:10 ` [PATCH 08/14] Convert auto-load.c " Tom Tromey
@ 2019-04-23 2:13 ` Tom Tromey
2019-04-23 23:11 ` [PATCH 00/14] Add a type-safe API to registries John Baldwin
2019-06-18 13:41 ` Pedro Alves
15 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-23 2:13 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes objfiles.c to use the type-safe registry API.
gdb/ChangeLog
2019-04-22 Tom Tromey <tom@tromey.com>
* objfiles.c (objfile_pspace_info): Add destructor and
initializers.
(objfiles_pspace_data): Change type.
(~objfile_pspace_info): Rename from objfiles_pspace_data_cleanup.
(get_objfile_pspace_data): Update.
(objfiles_bfd_data): Change type.
(get_objfile_bfd_data): Update.
(objfile_bfd_data_free, _initialize_objfiles): Remove.
---
gdb/ChangeLog | 11 ++++++++++
gdb/objfiles.c | 59 +++++++++++++++-----------------------------------
2 files changed, 28 insertions(+), 42 deletions(-)
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 1b0ea29980d..0f5c7381aa6 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -66,30 +66,30 @@ DEFINE_REGISTRY (objfile, REGISTRY_ACCESS_FIELD)
struct objfile_pspace_info
{
- struct obj_section **sections;
- int num_sections;
+ objfile_pspace_info () = default;
+ ~objfile_pspace_info ();
+
+ struct obj_section **sections = nullptr;
+ int num_sections = 0;
/* Nonzero if object files have been added since the section map
was last updated. */
- int new_objfiles_available;
+ int new_objfiles_available = 0;
/* Nonzero if the section map MUST be updated before use. */
- int section_map_dirty;
+ int section_map_dirty = 0;
/* Nonzero if section map updates should be inhibited if possible. */
- int inhibit_updates;
+ int inhibit_updates = 0;
};
/* Per-program-space data key. */
-static const struct program_space_data *objfiles_pspace_data;
+static const struct program_space_key<objfile_pspace_info>
+ objfiles_pspace_data;
-static void
-objfiles_pspace_data_cleanup (struct program_space *pspace, void *arg)
+objfile_pspace_info::~objfile_pspace_info ()
{
- struct objfile_pspace_info *info = (struct objfile_pspace_info *) arg;
-
- xfree (info->sections);
- xfree (info);
+ xfree (sections);
}
/* Get the current svr4 data. If none is found yet, add it now. This
@@ -100,13 +100,9 @@ get_objfile_pspace_data (struct program_space *pspace)
{
struct objfile_pspace_info *info;
- info = ((struct objfile_pspace_info *)
- program_space_data (pspace, objfiles_pspace_data));
+ info = objfiles_pspace_data.get (pspace);
if (info == NULL)
- {
- info = XCNEW (struct objfile_pspace_info);
- set_program_space_data (pspace, objfiles_pspace_data, info);
- }
+ info = objfiles_pspace_data.emplace (pspace);
return info;
}
@@ -115,7 +111,7 @@ get_objfile_pspace_data (struct program_space *pspace)
/* Per-BFD data key. */
-static const struct bfd_data *objfiles_bfd_data;
+static const struct bfd_key<objfile_per_bfd_storage> objfiles_bfd_data;
objfile_per_bfd_storage::~objfile_per_bfd_storage ()
{
@@ -133,8 +129,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
struct objfile_per_bfd_storage *storage = NULL;
if (abfd != NULL)
- storage = ((struct objfile_per_bfd_storage *)
- bfd_data (abfd, objfiles_bfd_data));
+ storage = objfiles_bfd_data.get (abfd);
if (storage == NULL)
{
@@ -143,7 +138,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
back to not sharing data across users. These cases are rare
enough that this seems reasonable. */
if (abfd != NULL && !gdb_bfd_requires_relocations (abfd))
- set_bfd_data (abfd, objfiles_bfd_data, storage);
+ objfiles_bfd_data.set (abfd, storage);
/* Look up the gdbarch associated with the BFD. */
if (abfd != NULL)
@@ -153,15 +148,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
return storage;
}
-/* A deleter for objfile_per_bfd_storage that can be passed as a
- cleanup function to the BFD registry. */
-
-static void
-objfile_bfd_data_free (struct bfd *unused, void *d)
-{
- delete (struct objfile_per_bfd_storage *) d;
-}
-
/* See objfiles.h. */
void
@@ -1511,14 +1497,3 @@ objfile_flavour_name (struct objfile *objfile)
return bfd_flavour_name (bfd_get_flavour (objfile->obfd));
return NULL;
}
-
-void
-_initialize_objfiles (void)
-{
- objfiles_pspace_data
- = register_program_space_data_with_cleanup (NULL,
- objfiles_pspace_data_cleanup);
-
- objfiles_bfd_data = register_bfd_data_with_cleanup (NULL,
- objfile_bfd_data_free);
-}
--
2.17.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 00/14] Add a type-safe API to registries
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (13 preceding siblings ...)
2019-04-23 2:13 ` [PATCH 07/14] Convert objfiles.c " Tom Tromey
@ 2019-04-23 23:11 ` John Baldwin
2019-04-24 0:57 ` Tom Tromey
2019-06-18 13:41 ` Pedro Alves
15 siblings, 1 reply; 18+ messages in thread
From: John Baldwin @ 2019-04-23 23:11 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 4/22/19 7:09 PM, Tom Tromey wrote:
> This series adds an optional type-safe API to the gdb registry
> feature, and converts various modules to use it.
>
> I don't think this is the final form for registries -- in the long run
> I suppose I'd like to turn them into a CRTP mixin class. However,
> this series seems like a reasonable step along the way, providing type
> safety and using policy classes for destruction.
>
> Let me know what you think.
>
> Regression tested by the buildbot.
I looked a few of these over and think it's an improvement. Do existing
keys still work btw? I know fbsd-tdep.c has a progspace key to cache
info needed to resolve TLS variables. It also has gdbarch data used to
cache the generated type for $_siginfo. I don't mind converting them
myself if the changes support both the old and new styles for now.
--
John Baldwin
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 00/14] Add a type-safe API to registries
2019-04-23 23:11 ` [PATCH 00/14] Add a type-safe API to registries John Baldwin
@ 2019-04-24 0:57 ` Tom Tromey
0 siblings, 0 replies; 18+ messages in thread
From: Tom Tromey @ 2019-04-24 0:57 UTC (permalink / raw)
To: John Baldwin; +Cc: Tom Tromey, gdb-patches
>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:
John> I looked a few of these over and think it's an improvement. Do existing
John> keys still work btw? I know fbsd-tdep.c has a progspace key to cache
John> info needed to resolve TLS variables. It also has gdbarch data used to
John> cache the generated type for $_siginfo. I don't mind converting them
John> myself if the changes support both the old and new styles for now.
Yes, this is implemented by adding a new type-safe wrapper for the
existing functions. I think it would be good to convert everything but
I haven't done so yet.
Tom
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 00/14] Add a type-safe API to registries
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
` (14 preceding siblings ...)
2019-04-23 23:11 ` [PATCH 00/14] Add a type-safe API to registries John Baldwin
@ 2019-06-18 13:41 ` Pedro Alves
15 siblings, 0 replies; 18+ messages in thread
From: Pedro Alves @ 2019-06-18 13:41 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 4/23/19 3:09 AM, Tom Tromey wrote:
> This series adds an optional type-safe API to the gdb registry
> feature, and converts various modules to use it.
>
> I don't think this is the final form for registries -- in the long run
> I suppose I'd like to turn them into a CRTP mixin class. However,
> this series seems like a reasonable step along the way, providing type
> safety and using policy classes for destruction.
>
> Let me know what you think.
I only managed to read this now, but I'd still like to say thanks
for doing this.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2019-06-18 13:41 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 2:10 [PATCH 00/14] Add a type-safe API to registries Tom Tromey
2019-04-23 2:10 ` [PATCH 06/14] Convert break-catch-syscall.c to type-safe registry API Tom Tromey
2019-04-23 2:10 ` [PATCH 14/14] Convert remote.c " Tom Tromey
2019-04-23 2:10 ` [PATCH 01/14] Add a type-safe C++ interface to a registry Tom Tromey
2019-04-23 2:10 ` [PATCH 03/14] Convert symbol_cache to type-safe registry API Tom Tromey
2019-04-23 2:10 ` [PATCH 02/14] Convert main_info " Tom Tromey
2019-04-23 2:10 ` [PATCH 11/14] Convert auxv.c " Tom Tromey
2019-04-23 2:10 ` [PATCH 12/14] Convert linux-tdep.c " Tom Tromey
2019-04-23 2:10 ` [PATCH 04/14] Convert target dcache " Tom Tromey
2019-04-23 2:10 ` [PATCH 13/14] Convert breakpoint.c " Tom Tromey
2019-04-23 2:10 ` [PATCH 10/14] Convert symfile-debug.c " Tom Tromey
2019-04-23 2:10 ` [PATCH 05/14] Convert inflow " Tom Tromey
2019-04-23 2:10 ` [PATCH 09/14] Convert dwarf2_per_objfile " Tom Tromey
2019-04-23 2:10 ` [PATCH 08/14] Convert auto-load.c " Tom Tromey
2019-04-23 2:13 ` [PATCH 07/14] Convert objfiles.c " Tom Tromey
2019-04-23 23:11 ` [PATCH 00/14] Add a type-safe API to registries John Baldwin
2019-04-24 0:57 ` Tom Tromey
2019-06-18 13:41 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).