[RFA,1/3] Remove free_cached_comp_units cleanups

Message ID 20180329152757.9346-2-tom@tromey.com
State New
Headers show
Series
  • remove last cleanups from dwarf2read.c
Related show

Commit Message

Tom Tromey March 29, 2018, 3:27 p.m.
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(-)

-- 
2.13.6

Patch

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.  */