public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA 2/3] Remove parameter from free_dwo_file
  2018-03-29 15:28 [RFA 0/3] remove last cleanups from dwarf2read.c Tom Tromey
  2018-03-29 15:28 ` [RFA 3/3] Remvoe free_dwo_file_cleanup Tom Tromey
@ 2018-03-29 15:28 ` Tom Tromey
  2018-03-29 15:34 ` [RFA 1/3] Remove free_cached_comp_units cleanups Tom Tromey
  2 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2018-03-29 15:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The objfile parameter to free_dwo_file is unused, so remove it.

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

	* dwarf2read.c (free_dwo_file): Remove "objfile" parameter.
	(free_dwo_file_cleanup, free_dwo_file_from_slot): Update.
---
 gdb/ChangeLog    |  5 +++++
 gdb/dwarf2read.c | 12 ++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 7840496738..1ab073804d 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13513,13 +13513,11 @@ queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu)
 }
 
 /* Free all resources associated with DWO_FILE.
-   Close the DWO file and munmap the sections.
-   All memory should be on the objfile obstack.  */
+   Close the DWO file and munmap the sections.  */
 
 static void
-free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile)
+free_dwo_file (struct dwo_file *dwo_file)
 {
-
   /* Note: dbfd is NULL for virtual DWO files.  */
   gdb_bfd_unref (dwo_file->dbfd);
 
@@ -13533,9 +13531,8 @@ free_dwo_file_cleanup (void *arg)
 {
   struct free_dwo_file_cleanup_data *data
     = (struct free_dwo_file_cleanup_data *) arg;
-  struct objfile *objfile = data->dwarf2_per_objfile->objfile;
 
-  free_dwo_file (data->dwo_file, objfile);
+  free_dwo_file (data->dwo_file);
 
   xfree (data);
 }
@@ -13546,9 +13543,8 @@ static int
 free_dwo_file_from_slot (void **slot, void *info)
 {
   struct dwo_file *dwo_file = (struct dwo_file *) *slot;
-  struct objfile *objfile = (struct objfile *) info;
 
-  free_dwo_file (dwo_file, objfile);
+  free_dwo_file (dwo_file);
 
   return 1;
 }
-- 
2.13.6

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFA 0/3] remove last cleanups from dwarf2read.c
@ 2018-03-29 15:28 Tom Tromey
  2018-03-29 15:28 ` [RFA 3/3] Remvoe free_dwo_file_cleanup Tom Tromey
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tom Tromey @ 2018-03-29 15:28 UTC (permalink / raw)
  To: gdb-patches

This short series removes the last cleanups from dwarf2read.c.

Regression tested by the buildbot.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFA 3/3] Remvoe free_dwo_file_cleanup
  2018-03-29 15:28 [RFA 0/3] remove last cleanups from dwarf2read.c Tom Tromey
@ 2018-03-29 15:28 ` Tom Tromey
  2018-03-30 16:30   ` Simon Marchi
  2018-03-29 15:28 ` [RFA 2/3] Remove parameter from free_dwo_file Tom Tromey
  2018-03-29 15:34 ` [RFA 1/3] Remove free_cached_comp_units cleanups Tom Tromey
  2 siblings, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2018-03-29 15:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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-29  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.
---
 gdb/ChangeLog    |  8 ++++++++
 gdb/dwarf2read.c | 49 +++++++++++++++++++------------------------------
 2 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1ab073804d..fd544a7f9b 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
-- 
2.13.6

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFA 1/3] Remove free_cached_comp_units cleanups
  2018-03-29 15:28 [RFA 0/3] remove last cleanups from dwarf2read.c Tom Tromey
  2018-03-29 15:28 ` [RFA 3/3] Remvoe free_dwo_file_cleanup Tom Tromey
  2018-03-29 15:28 ` [RFA 2/3] Remove parameter from free_dwo_file Tom Tromey
@ 2018-03-29 15:34 ` Tom Tromey
  2 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2018-03-29 15:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes free_cached_comp_units from a cleanup function to an RAII
class.

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

	* dwarf2read.c (class free_cached_comp_units): New class.
	(dw2_instantiate_symtab, dwarf2_build_psymtabs_hard): Use it.
	(free_cached_comp_units): Remove function.
---
 gdb/ChangeLog    |  6 ++++++
 gdb/dwarf2read.c | 46 ++++++++++++++++++++++++++--------------------
 2 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index dfa69d1dbb..7840496738 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1821,8 +1821,6 @@ static void prepare_one_comp_unit (struct dwarf2_cu *cu,
 				   struct die_info *comp_unit_die,
 				   enum language pretend_language);
 
-static void free_cached_comp_units (void *);
-
 static void age_cached_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *);
@@ -2172,6 +2170,30 @@ dwarf2_per_objfile::free_cached_comp_units ()
     }
 }
 
+/* A helper class that calls free_cached_comp_units on
+   destruction.  */
+
+class free_cached_comp_units
+{
+public:
+
+  explicit free_cached_comp_units (dwarf2_per_objfile *per_objfile)
+    : m_per_objfile (per_objfile)
+  {
+  }
+
+  ~free_cached_comp_units ()
+  {
+    m_per_objfile->free_cached_comp_units ();
+  }
+
+  DISABLE_COPY_AND_ASSIGN (free_cached_comp_units);
+
+private:
+
+  dwarf2_per_objfile *m_per_objfile;
+};
+
 /* Try to locate the sections we need for DWARF 2 debugging
    information and return true if we have enough to do something.
    NAMES points to the dwarf2 section names, or is NULL if the standard
@@ -2876,12 +2898,10 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu)
   gdb_assert (dwarf2_per_objfile->using_index);
   if (!per_cu->v.quick->compunit_symtab)
     {
-      struct cleanup *back_to = make_cleanup (free_cached_comp_units,
-					      dwarf2_per_objfile);
+      free_cached_comp_units freer (dwarf2_per_objfile);
       scoped_restore decrementer = increment_reading_symtab ();
       dw2_do_instantiate_symtab (per_cu);
       process_cu_includes (dwarf2_per_objfile);
-      do_cleanups (back_to);
     }
 
   return per_cu->v.quick->compunit_symtab;
@@ -8434,7 +8454,6 @@ set_partial_user (struct dwarf2_per_objfile *dwarf2_per_objfile)
 static void
 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
 {
-  struct cleanup *back_to;
   int i;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
 
@@ -8450,7 +8469,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* Any cached compilation units will be linked by the per-objfile
      read_in_chain.  Make sure to free them when we're done.  */
-  back_to = make_cleanup (free_cached_comp_units, dwarf2_per_objfile);
+  free_cached_comp_units freer (dwarf2_per_objfile);
 
   build_type_psymtabs (dwarf2_per_objfile);
 
@@ -8491,8 +8510,6 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
   /* At this point we want to keep the address map.  */
   save_psymtabs_addrmap.release ();
 
-  do_cleanups (back_to);
-
   if (dwarf_read_debug)
     fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n",
 			objfile_name (objfile));
@@ -25072,17 +25089,6 @@ prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die,
   cu->producer = dwarf2_string_attr (comp_unit_die, DW_AT_producer, cu);
 }
 
-/* Free all cached compilation units.  */
-
-static void
-free_cached_comp_units (void *data)
-{
-  struct dwarf2_per_objfile *dwarf2_per_objfile
-    = (struct dwarf2_per_objfile *) data;
-
-  dwarf2_per_objfile->free_cached_comp_units ();
-}
-
 /* Increase the age counter on each cached compilation unit, and free
    any that are too old.  */
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA 3/3] Remvoe free_dwo_file_cleanup
  2018-03-29 15:28 ` [RFA 3/3] Remvoe free_dwo_file_cleanup Tom Tromey
@ 2018-03-30 16:30   ` Simon Marchi
  2018-03-30 16:31     ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2018-03-30 16:30 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

"Remvoe" in the title.

Otherwise LGTM.  That's a nice milestone!

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFA 3/3] Remvoe free_dwo_file_cleanup
  2018-03-30 16:30   ` Simon Marchi
@ 2018-03-30 16:31     ` Simon Marchi
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2018-03-30 16:31 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2018-03-30 12:29, Simon Marchi wrote:
> "Remvoe" in the title.
> 
> Otherwise LGTM.  That's a nice milestone!
> 
> Simon

To be clear, all three patches LGTM.

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-03-30 16:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-29 15:28 [RFA 0/3] remove last cleanups from dwarf2read.c Tom Tromey
2018-03-29 15:28 ` [RFA 3/3] Remvoe free_dwo_file_cleanup Tom Tromey
2018-03-30 16:30   ` Simon Marchi
2018-03-30 16:31     ` Simon Marchi
2018-03-29 15:28 ` [RFA 2/3] Remove parameter from free_dwo_file Tom Tromey
2018-03-29 15:34 ` [RFA 1/3] Remove free_cached_comp_units cleanups Tom Tromey

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).