aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-05-01 15:18:31 -0600
committerTom Tromey <tom@tromey.com>2019-05-08 16:01:52 -0600
commitf37b313d5cafbed4e724db4724d1ab567b373be4 (patch)
treea2e223f5e83ec9568e306541408b3529df32ae8d /gdb/ada-lang.c
parent246994051b6659bf9f4c89b5d5ede86717c5bbef (diff)
downloadgdb-f37b313d5cafbed4e724db4724d1ab567b373be4.zip
gdb-f37b313d5cafbed4e724db4724d1ab567b373be4.tar.gz
gdb-f37b313d5cafbed4e724db4724d1ab567b373be4.tar.bz2
Convert ada-lang.c to type-safe registry API
This changes ada-lang.c to use the type-safe registry API. gdb/ChangeLog 2019-05-08 Tom Tromey <tom@tromey.com> * ada-lang.c (struct ada_inferior_data): Add initializers. (ada_inferior_data): Change type. (ada_inferior_data_cleanup): Remove. (get_ada_inferior_data, ada_inferior_exit) (struct ada_pspace_data): Add initializers, destructor. (ada_pspace_data_handle): Change type. (get_ada_pspace_data): Update. (ada_pspace_data_cleanup): Remove.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c63
1 files changed, 16 insertions, 47 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 20fb349..e513280 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -378,27 +378,16 @@ struct ada_inferior_data
tagged types. With older versions of GNAT, this type was directly
accessible through a component ("tsd") in the object tag. But this
is no longer the case, so we cache it for each inferior. */
- struct type *tsd_type;
+ struct type *tsd_type = nullptr;
/* The exception_support_info data. This data is used to determine
how to implement support for Ada exception catchpoints in a given
inferior. */
- const struct exception_support_info *exception_info;
+ const struct exception_support_info *exception_info = nullptr;
};
/* Our key to this module's inferior data. */
-static const struct inferior_data *ada_inferior_data;
-
-/* A cleanup routine for our inferior data. */
-static void
-ada_inferior_data_cleanup (struct inferior *inf, void *arg)
-{
- struct ada_inferior_data *data;
-
- data = (struct ada_inferior_data *) inferior_data (inf, ada_inferior_data);
- if (data != NULL)
- xfree (data);
-}
+static const struct inferior_key<ada_inferior_data> ada_inferior_data;
/* Return our inferior data for the given inferior (INF).
@@ -413,12 +402,9 @@ get_ada_inferior_data (struct inferior *inf)
{
struct ada_inferior_data *data;
- data = (struct ada_inferior_data *) inferior_data (inf, ada_inferior_data);
+ data = ada_inferior_data.get (inf);
if (data == NULL)
- {
- data = XCNEW (struct ada_inferior_data);
- set_inferior_data (inf, ada_inferior_data, data);
- }
+ data = ada_inferior_data.emplace (inf);
return data;
}
@@ -429,8 +415,7 @@ get_ada_inferior_data (struct inferior *inf)
static void
ada_inferior_exit (struct inferior *inf)
{
- ada_inferior_data_cleanup (inf, NULL);
- set_inferior_data (inf, ada_inferior_data, NULL);
+ ada_inferior_data.clear (inf);
}
@@ -439,12 +424,18 @@ ada_inferior_exit (struct inferior *inf)
/* This module's per-program-space data. */
struct ada_pspace_data
{
+ ~ada_pspace_data ()
+ {
+ if (sym_cache != NULL)
+ ada_free_symbol_cache (sym_cache);
+ }
+
/* The Ada symbol cache. */
- struct ada_symbol_cache *sym_cache;
+ struct ada_symbol_cache *sym_cache = nullptr;
};
/* Key to our per-program-space data. */
-static const struct program_space_data *ada_pspace_data_handle;
+static const struct program_space_key<ada_pspace_data> ada_pspace_data_handle;
/* Return this module's data for the given program space (PSPACE).
If not is found, add a zero'ed one now.
@@ -456,29 +447,13 @@ get_ada_pspace_data (struct program_space *pspace)
{
struct ada_pspace_data *data;
- data = ((struct ada_pspace_data *)
- program_space_data (pspace, ada_pspace_data_handle));
+ data = ada_pspace_data_handle.get (pspace);
if (data == NULL)
- {
- data = XCNEW (struct ada_pspace_data);
- set_program_space_data (pspace, ada_pspace_data_handle, data);
- }
+ data = ada_pspace_data_handle.emplace (pspace);
return data;
}
-/* The cleanup callback for this module's per-program-space data. */
-
-static void
-ada_pspace_data_cleanup (struct program_space *pspace, void *data)
-{
- struct ada_pspace_data *pspace_data = (struct ada_pspace_data *) data;
-
- if (pspace_data->sym_cache != NULL)
- ada_free_symbol_cache (pspace_data->sym_cache);
- xfree (pspace_data);
-}
-
/* Utilities */
/* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
@@ -14648,10 +14623,4 @@ DWARF attribute."),
gdb::observers::new_objfile.attach (ada_new_objfile_observer);
gdb::observers::free_objfile.attach (ada_free_objfile_observer);
gdb::observers::inferior_exit.attach (ada_inferior_exit);
-
- /* Setup various context-specific data. */
- ada_inferior_data
- = register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup);
- ada_pspace_data_handle
- = register_program_space_data_with_cleanup (NULL, ada_pspace_data_cleanup);
}