Remove free_dwo_file_cleanup

This removes free_dwo_file_cleanup, the last cleanup in dwarf2read.c.
This is replaced with a unique_ptr; which, despite the fact that a
dwo_file is obstack-allocated, seemed like the best fit.

gdb/ChangeLog
2018-03-30  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct free_dwo_file_cleanup_data): Remove.
	(struct dwo_file_deleter): New.
	(dwo_file_up): New typedef.
	(open_and_init_dwo_file): Use dwo_file_up.
	(free_dwo_file_cleanup): Remove.
This commit is contained in:
Tom Tromey 2018-03-28 15:35:46 -06:00
parent 5dafb3d176
commit 263db9a1f4
2 changed files with 27 additions and 30 deletions

View File

@ -1,3 +1,11 @@
2018-03-30 Tom Tromey <tom@tromey.com>
* dwarf2read.c (struct free_dwo_file_cleanup_data): Remove.
(struct dwo_file_deleter): New.
(dwo_file_up): New typedef.
(open_and_init_dwo_file): Use dwo_file_up.
(free_dwo_file_cleanup): Remove.
2018-03-30 Tom Tromey <tom@tromey.com>
* dwarf2read.c (free_dwo_file): Remove "objfile" parameter.

View File

@ -1959,14 +1959,22 @@ static struct dwo_unit *lookup_dwo_type_unit
static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *);
static void free_dwo_file_cleanup (void *);
static void free_dwo_file (struct dwo_file *);
struct free_dwo_file_cleanup_data
/* A unique_ptr helper to free a dwo_file. */
struct dwo_file_deleter
{
struct dwo_file *dwo_file;
struct dwarf2_per_objfile *dwarf2_per_objfile;
void operator() (struct dwo_file *df) const
{
free_dwo_file (df);
}
};
/* A unique pointer to a dwo_file. */
typedef std::unique_ptr<struct dwo_file, dwo_file_deleter> dwo_file_up;
static void process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile);
static void check_producer (struct dwarf2_cu *cu);
@ -12983,8 +12991,6 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
{
struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
struct objfile *objfile = dwarf2_per_objfile->objfile;
struct dwo_file *dwo_file;
struct cleanup *cleanups;
gdb_bfd_ref_ptr dbfd (open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir));
if (dbfd == NULL)
@ -12993,32 +12999,28 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name);
return NULL;
}
dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
/* We use a unique pointer here, despite the obstack allocation,
because a dwo_file needs some cleanup if it is abandoned. */
dwo_file_up dwo_file (OBSTACK_ZALLOC (&objfile->objfile_obstack,
struct dwo_file));
dwo_file->dwo_name = dwo_name;
dwo_file->comp_dir = comp_dir;
dwo_file->dbfd = dbfd.release ();
free_dwo_file_cleanup_data *cleanup_data = XNEW (free_dwo_file_cleanup_data);
cleanup_data->dwo_file = dwo_file;
cleanup_data->dwarf2_per_objfile = dwarf2_per_objfile;
cleanups = make_cleanup (free_dwo_file_cleanup, cleanup_data);
bfd_map_over_sections (dwo_file->dbfd, dwarf2_locate_dwo_sections,
&dwo_file->sections);
create_cus_hash_table (dwarf2_per_objfile, *dwo_file, dwo_file->sections.info,
dwo_file->cus);
create_debug_types_hash_table (dwarf2_per_objfile, dwo_file,
create_debug_types_hash_table (dwarf2_per_objfile, dwo_file.get (),
dwo_file->sections.types, dwo_file->tus);
discard_cleanups (cleanups);
if (dwarf_read_debug)
fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name);
return dwo_file;
return dwo_file.release ();
}
/* This function is mapped across the sections and remembers the offset and
@ -13524,19 +13526,6 @@ free_dwo_file (struct dwo_file *dwo_file)
VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
}
/* Wrapper for free_dwo_file for use in cleanups. */
static void
free_dwo_file_cleanup (void *arg)
{
struct free_dwo_file_cleanup_data *data
= (struct free_dwo_file_cleanup_data *) arg;
free_dwo_file (data->dwo_file);
xfree (data);
}
/* Traversal function for free_dwo_files. */
static int