aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-04-21 12:32:47 -0600
committerTom Tromey <tom@tromey.com>2019-05-08 16:01:48 -0600
commit5bfd760d66c816d53a930635a84990c8536bb545 (patch)
tree46b9f5765730b9ae35a80f562c1a81606bfe2ea3
parente85e19b4d7d9b3b322f27684f8c0a3a9ac0e57ab (diff)
downloadgdb-5bfd760d66c816d53a930635a84990c8536bb545.zip
gdb-5bfd760d66c816d53a930635a84990c8536bb545.tar.gz
gdb-5bfd760d66c816d53a930635a84990c8536bb545.tar.bz2
Convert dwarf2_per_objfile to type-safe registry API
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-05-08 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.
-rw-r--r--gdb/ChangeLog11
-rw-r--r--gdb/dwarf2read.c43
-rw-r--r--gdb/dwarf2read.h2
3 files changed, 18 insertions, 38 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 82e55e9..cb763b7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,16 @@
2019-05-08 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.
+
+2019-05-08 Tom Tromey <tom@tromey.com>
+
* auto-load.c (struct auto_load_pspace_info): Add destructor and
initializers.
<unsupported_script_warning_printed,
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index b5ea9e3..b29c089 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. */
@@ -2251,13 +2240,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
@@ -2589,9 +2574,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
@@ -25433,17 +25416,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.
@@ -25761,9 +25733,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 82bf639..7326543 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