Remove make_cleanup_discard_psymtabs
authorTom Tromey <tom@tromey.com>
Mon, 21 Nov 2016 23:50:20 +0000 (16:50 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 11 Jan 2017 02:14:12 +0000 (19:14 -0700)
This removes make_cleanup_discard_psymtabs in favor of a new class.

2017-01-10  Tom Tromey  <tom@tromey.com>

* dwarf2read.c (dwarf2_build_psymtabs): Use psymtab_discarder.
* psympriv.h (make_cleanup_discard_psymtabs): Don't declare.
* psymtab.c (discard_psymtabs_upto): Remove.
(make_cleanup_discard_psymtabs): Remove.
(struct psymtab_state): Remove.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/psympriv.h
gdb/psymtab.c

index f1e6458..ba3af7a 100644 (file)
@@ -1,5 +1,13 @@
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
+       * dwarf2read.c (dwarf2_build_psymtabs): Use psymtab_discarder.
+       * psympriv.h (make_cleanup_discard_psymtabs): Don't declare.
+       * psymtab.c (discard_psymtabs_upto): Remove.
+       (make_cleanup_discard_psymtabs): Remove.
+       (struct psymtab_state): Remove.
+
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
        * record-full.c (record_full_save_cleanups): Remove.
        (record_full_save): Use gdb::unlinker.
        * gcore.c (do_bfd_delete_cleanup): Remove.
index dfb79c9..b5dc510 100644 (file)
@@ -4271,10 +4271,9 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       /* This isn't really ideal: all the data we allocate on the
         objfile's obstack is still uselessly kept around.  However,
         freeing it seems unsafe.  */
-      struct cleanup *cleanups = make_cleanup_discard_psymtabs (objfile);
-
+      psymtab_discarder psymtabs (objfile);
       dwarf2_build_psymtabs_hard (objfile);
-      discard_cleanups (cleanups);
+      psymtabs.keep ();
     }
   CATCH (except, RETURN_MASK_ERROR)
     {
index 36ce1d2..c4d2bb9 100644 (file)
@@ -21,6 +21,7 @@
 #define PSYMPRIV_H
 
 #include "psymtab.h"
+#include "objfiles.h"
 
 struct psymbol_allocation_list;
 
@@ -225,7 +226,40 @@ extern struct partial_symtab *allocate_psymtab (const char *,
 
 extern void discard_psymtab (struct objfile *, struct partial_symtab *);
 
-extern struct cleanup *make_cleanup_discard_psymtabs (struct objfile *);
+/* Used when recording partial symbol tables.  On destruction,
+   discards any partial symbol tables that have been built.  However,
+   the tables can be kept by calling the "keep" method.  */
+class psymtab_discarder
+{
+ public:
+
+  psymtab_discarder (struct objfile *objfile)
+    : m_objfile (objfile),
+      m_psymtab (objfile->psymtabs)
+  {
+  }
+
+  ~psymtab_discarder ()
+  {
+    if (m_objfile != NULL)
+      while (m_objfile->psymtabs != m_psymtab)
+       discard_psymtab (m_objfile, m_objfile->psymtabs);
+  }
+
+  /* Keep any partial symbol tables that were built.  */
+  void keep ()
+  {
+    m_objfile = NULL;
+  }
+
+ private:
+
+  /* The objfile.  If NULL this serves as a sentinel to indicate that
+     the psymtabs should be kept.  */
+  struct objfile *m_objfile;
+  /* How far back to free.  */
+  struct partial_symtab *m_psymtab;
+};
 
 /* Traverse all psymtabs in one objfile.  */
 
index e895828..3acc226 100644 (file)
@@ -1832,44 +1832,6 @@ discard_psymtab (struct objfile *objfile, struct partial_symtab *pst)
   objfile->free_psymtabs = pst;
 }
 
-/* An object of this type is passed to discard_psymtabs_upto.  */
-
-struct psymtab_state
-{
-  /* The objfile where psymtabs are discarded.  */
-
-  struct objfile *objfile;
-
-  /* The first psymtab to save.  */
-
-  struct partial_symtab *save;
-};
-
-/* A cleanup function used by make_cleanup_discard_psymtabs.  */
-
-static void
-discard_psymtabs_upto (void *arg)
-{
-  struct psymtab_state *state = (struct psymtab_state *) arg;
-
-  while (state->objfile->psymtabs != state->save)
-    discard_psymtab (state->objfile, state->objfile->psymtabs);
-}
-
-/* Return a new cleanup that discards all psymtabs created in OBJFILE
-   after this function is called.  */
-
-struct cleanup *
-make_cleanup_discard_psymtabs (struct objfile *objfile)
-{
-  struct psymtab_state *state = XNEW (struct psymtab_state);
-
-  state->objfile = objfile;
-  state->save = objfile->psymtabs;
-
-  return make_cleanup_dtor (discard_psymtabs_upto, state, xfree);
-}
-
 \f
 
 /* We need to pass a couple of items to the addrmap_foreach function,