* [RFA] Use new to allocate mapped_index
@ 2018-05-18 17:00 Tom Tromey
2018-05-18 20:22 ` Simon Marchi
0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2018-05-18 17:00 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes struct mapped_index to be allocated with new. This
simplifies the creation a bit (see dwarf2_read_index) and also removes
a somewhat ugly explicit destructor call from ~dwarf2_per_objfile.
Tested by the buildbot.
gdb/ChangeLog
2018-05-17 Tom Tromey <tom@tromey.com>
* dwarf2read.c (dwarf2_per_objfile): Update.
(struct mapped_index): Add initializers.
(dwarf2_read_index): Use new.
(dw2_symtab_iter_init): Update.
* dwarf2read.h (struct dwarf2_per_objfile) <index_table>: Now a
unique_ptr.
---
gdb/ChangeLog | 9 +++++++++
gdb/dwarf2read.c | 25 +++++++++----------------
gdb/dwarf2read.h | 2 +-
3 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index b2ecadf89b..1df9635137 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -195,10 +195,10 @@ struct mapped_index final : public mapped_index_base
};
/* Index data format version. */
- int version;
+ int version = 0;
/* The total length of the buffer. */
- off_t total_size;
+ off_t total_size = 0;
/* The address table data. */
gdb::array_view<const gdb_byte> address_table;
@@ -207,7 +207,7 @@ struct mapped_index final : public mapped_index_base
gdb::array_view<symbol_table_slot> symbol_table;
/* A pointer to the constant pool. */
- const char *constant_pool;
+ const char *constant_pool = nullptr;
bool symbol_name_slot_invalid (offset_type idx) const override
{
@@ -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,21 +3538,21 @@ to use the section anyway."),
static int
dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
- struct mapped_index local_map, *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;
struct objfile *objfile = dwarf2_per_objfile->objfile;
+ std::unique_ptr<struct mapped_index> map (new struct mapped_index);
if (!read_index_from_section (objfile, objfile_name (objfile),
use_deprecated_index_sections,
- &dwarf2_per_objfile->gdb_index, &local_map,
+ &dwarf2_per_objfile->gdb_index, map.get (),
&cu_list, &cu_list_elements,
&types_list, &types_list_elements))
return 0;
/* Don't use the index if it's empty. */
- if (local_map.symbol_table.empty ())
+ if (map->symbol_table.empty ())
return 0;
/* If there is a .dwz file, read it so we can get its CU list as
@@ -3599,13 +3596,9 @@ dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile)
types_list, types_list_elements);
}
- 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;
+ create_addrmap_from_index (dwarf2_per_objfile, map.get ());
- dwarf2_per_objfile->index_table = map;
+ dwarf2_per_objfile->index_table = std::move (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 +3913,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 8e6c41dc09..f36d039e7b 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.13.6
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [RFA] Use new to allocate mapped_index
2018-05-18 17:00 [RFA] Use new to allocate mapped_index Tom Tromey
@ 2018-05-18 20:22 ` Simon Marchi
0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2018-05-18 20:22 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2018-05-18 11:37, Tom Tromey wrote:
> This changes struct mapped_index to be allocated with new. This
> simplifies the creation a bit (see dwarf2_read_index) and also removes
> a somewhat ugly explicit destructor call from ~dwarf2_per_objfile.
LGTM, thanks.
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-18 19:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 17:00 [RFA] Use new to allocate mapped_index Tom Tromey
2018-05-18 20:22 ` Simon Marchi
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).