diff options
author | Tom Tromey <tom@tromey.com> | 2018-03-28 15:35:46 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-03-30 13:15:58 -0600 |
commit | 263db9a1f4105b76ddf00829d50430ea0a3bcba6 (patch) | |
tree | a74d226240d6c08fbd9b8006649434338c77d99a /gdb | |
parent | 5dafb3d176ab8d9b9f0a46111d7040bb51ad8f8e (diff) | |
download | gdb-263db9a1f4105b76ddf00829d50430ea0a3bcba6.zip gdb-263db9a1f4105b76ddf00829d50430ea0a3bcba6.tar.gz gdb-263db9a1f4105b76ddf00829d50430ea0a3bcba6.tar.bz2 |
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.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/dwarf2read.c | 49 |
2 files changed, 27 insertions, 30 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 61f8131..db1c7dd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,13 @@ 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. (free_dwo_file_cleanup, free_dwo_file_from_slot): Update. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 1ab0738..fd544a7 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -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 |