[PATCH v2 1/3] Don't allocate mapped_index on the objfile obstack
Simon Marchi
simon.marchi@polymtl.ca
Sat Apr 28 03:31:00 GMT 2018
To make things simpler, allocate it with new and manage its lifetime
using a unique_ptr (just like mapped_debug_names). We can also
std::move the temporary local_map in the permanent map.
gdb/ChangeLog;
* dwarf2read.h (struct dwarf2_per_objfile) <index_table>: Change
type to std::unique_ptr.
* dwarf2read.c (dwarf2_per_objfile::~dwarf2_per_objfile): Don't
manually destroy mapped_index.
(dwarf2_read_index): Adjust for unique_ptr, use std::move.
(dw2_symtab_iter_init): Adjust for unique_ptr.
---
gdb/dwarf2read.c | 14 ++++----------
gdb/dwarf2read.h | 2 +-
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9eb98b2eab8e..b3bcb43a519b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2153,9 +2153,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
if (dwz_file != NULL && dwz_file->dwz_bfd)
gdb_bfd_unref (dwz_file->dwz_bfd);
- if (index_table != NULL)
- index_table->~mapped_index ();
-
/* Everything else should be on the objfile obstack. */
}
@@ -3541,7 +3538,7 @@ to use the section anyway."),
static int
dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- struct mapped_index local_map, *map;
+ struct mapped_index local_map;
const gdb_byte *cu_list, *types_list, *dwz_list = NULL;
offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0;
struct dwz_file *dwz;
@@ -3601,11 +3598,8 @@ dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
create_addrmap_from_index (dwarf2_per_objfile, &local_map);
- map = XOBNEW (&objfile->objfile_obstack, struct mapped_index);
- map = new (map) mapped_index ();
- *map = local_map;
-
- dwarf2_per_objfile->index_table = map;
+ dwarf2_per_objfile->index_table.reset (new mapped_index);
+ *dwarf2_per_objfile->index_table = std::move (local_map);
dwarf2_per_objfile->using_index = 1;
dwarf2_per_objfile->quick_file_names_table =
create_quick_file_names_table (dwarf2_per_objfile->all_comp_units.size ());
@@ -3920,7 +3914,7 @@ dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
iter->next = 0;
iter->global_seen = 0;
- mapped_index *index = dwarf2_per_objfile->index_table;
+ mapped_index *index = dwarf2_per_objfile->index_table.get ();
/* index is NULL if OBJF_READNOW. */
if (index != NULL && find_slot_in_mapped_hash (index, name, &iter->vec))
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 8e6c41dc09ef..f36d039e7bea 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -209,7 +209,7 @@ public:
bool using_index = false;
/* The mapped index, or NULL if .gdb_index is missing or not being used. */
- mapped_index *index_table = NULL;
+ std::unique_ptr<mapped_index> index_table;
/* The mapped index, or NULL if .debug_names is missing or not being used. */
std::unique_ptr<mapped_debug_names> debug_names_table;
--
2.17.0
More information about the Gdb-patches
mailing list