This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Remove make_cleanup_htab_delete


>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> I have a new patch that fixes this by going a bit further and changing
Tom> these htabs to unordered_set.  I'll send it a bit later.

Here's the new version.

Tom

commit a635cf8fc322c4552982becde365096bc944d3f2
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Nov 20 13:20:32 2016 -0700

    Remove make_cleanup_htab_delete
    
    This removes make_cleanup_htab_delete in favor of destructors,
    building on an earlier patch that added the htab_up typedef.
    
    Testing revealed that more cleanup-removal work was needed in
    dwarf2loc.c, so this version of the patch changes code there to use
    unordered_set and vector, removing some more cleanups.
    
    2016-12-13  Tom Tromey  <tom@tromey.com>
    
    	* utils.h (make_cleanup_htab_delete): Don't declare.
    	* utils.c (do_htab_delete_cleanup, make_cleanup_htab_delete):
    	Remove.
    	* linespec.c (decode_compound_collector): Add constructor,
    	destructor.
    	(lookup_prefix_sym): Remove cleanup.
    	(symtab_collector): Add constructor, destructor.
    	(collect_symtabs_from_filename): Remove cleanup.
    	* disasm.c (do_mixed_source_and_assembly): Use htab_up.
    	* compile/compile-c-symbols.c (generate_c_for_variable_locations):
    	Use htab_up.
    	* gnu-v3-abi.c (gnuv3_print_vtable): Use htab_up.
    	* dwarf2read.c (dw2_expand_symtabs_matching)
    	(dw2_map_symbol_filenames, dwarf_decode_macros)
    	(write_psymtabs_to_index): Use htab_up.
    	* dwarf2loc.c (func_verify_no_selftailcall)
    	(call_site_find_chain_1, func_verify_no_selftailcall)
    	(chain_candidate, call_site_find_chain_1): Use std::unordered_set,
    	std::vector, gdb::unique_xmalloc_ptr.
    	(call_sitep): Remove typedef.
    	(dwarf2_locexpr_baton_eval): Remove unused variable.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7500c25..0addd57 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,29 @@
 2016-12-13  Tom Tromey  <tom@tromey.com>
 
+	* utils.h (make_cleanup_htab_delete): Don't declare.
+	* utils.c (do_htab_delete_cleanup, make_cleanup_htab_delete):
+	Remove.
+	* linespec.c (decode_compound_collector): Add constructor,
+	destructor.
+	(lookup_prefix_sym): Remove cleanup.
+	(symtab_collector): Add constructor, destructor.
+	(collect_symtabs_from_filename): Remove cleanup.
+	* disasm.c (do_mixed_source_and_assembly): Use htab_up.
+	* compile/compile-c-symbols.c (generate_c_for_variable_locations):
+	Use htab_up.
+	* gnu-v3-abi.c (gnuv3_print_vtable): Use htab_up.
+	* dwarf2read.c (dw2_expand_symtabs_matching)
+	(dw2_map_symbol_filenames, dwarf_decode_macros)
+	(write_psymtabs_to_index): Use htab_up.
+	* dwarf2loc.c (func_verify_no_selftailcall)
+	(call_site_find_chain_1, func_verify_no_selftailcall)
+	(chain_candidate, call_site_find_chain_1): Use std::unordered_set,
+	std::vector, gdb::unique_xmalloc_ptr.
+	(call_sitep): Remove typedef.
+	(dwarf2_locexpr_baton_eval): Remove unused variable.
+
+2016-12-13  Tom Tromey  <tom@tromey.com>
+
 	* python/python-internal.h (make_cleanup_py_decref)
 	(make_cleanup_py_xdecref): Don't declare.
 	* python/py-utils.c (py_decref, make_cleanup_py_decref)
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index dcd530d..012fded 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -724,8 +724,7 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler,
 				   const struct block *block,
 				   CORE_ADDR pc)
 {
-  struct cleanup *cleanup, *outer;
-  htab_t symhash;
+  struct cleanup *outer;
   const struct block *static_block = block_static_block (block);
   unsigned char *registers_used;
 
@@ -739,9 +738,8 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler,
 
   /* Ensure that a given name is only entered once.  This reflects the
      reality of shadowing.  */
-  symhash = htab_create_alloc (1, hash_symname, eq_symname, NULL,
-			       xcalloc, xfree);
-  cleanup = make_cleanup_htab_delete (symhash);
+  htab_up symhash (htab_create_alloc (1, hash_symname, eq_symname, NULL,
+				      xcalloc, xfree));
 
   while (1)
     {
@@ -754,7 +752,7 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler,
 	   sym != NULL;
 	   sym = block_iterator_next (&iter))
 	{
-	  if (!symbol_seen (symhash, sym))
+	  if (!symbol_seen (symhash.get (), sym))
 	    generate_c_for_for_one_variable (compiler, stream, gdbarch,
 					     registers_used, pc, sym);
 	}
@@ -766,7 +764,6 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler,
       block = BLOCK_SUPERBLOCK (block);
     }
 
-  do_cleanups (cleanup);
   discard_cleanups (outer);
   return registers_used;
 }
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 07c3abe..3156a4e 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -498,14 +498,12 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
   int i, nlines;
   int num_displayed = 0;
   print_source_lines_flags psl_flags = 0;
-  struct cleanup *cleanups;
   struct cleanup *ui_out_chain;
   struct cleanup *ui_out_tuple_chain;
   struct cleanup *ui_out_list_chain;
   CORE_ADDR pc;
   struct symtab *last_symtab;
   int last_line;
-  htab_t dis_line_table;
 
   gdb_assert (main_symtab != NULL && SYMTAB_LINETABLE (main_symtab) != NULL);
 
@@ -515,8 +513,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
      but if that text is for code that will be disassembled later, then
      we'll want to defer printing it until later with its associated code.  */
 
-  dis_line_table = allocate_dis_line_table ();
-  cleanups = make_cleanup_htab_delete (dis_line_table);
+  htab_up dis_line_table (allocate_dis_line_table ());
 
   pc = low;
 
@@ -548,7 +545,7 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
       pc += length;
 
       if (sal.symtab != NULL)
-	add_dis_line_entry (dis_line_table, sal.symtab, sal.line);
+	add_dis_line_entry (dis_line_table.get (), sal.symtab, sal.line);
     }
 
   /* Second pass: print the disassembly.
@@ -565,9 +562,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
      which is where we put file name and source line contents output.
 
      Cleanup usage:
-     cleanups:
-       For things created at the beginning of this function and need to be
-       kept until the end of this function.
      ui_out_chain
        Handles the outer "asm_insns" list.
      ui_out_tuple_chain
@@ -625,7 +619,8 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
 		     not associated with code that we'll print later.  */
 		  for (l = sal.line - 1; l > last_line; --l)
 		    {
-		      if (line_has_code_p (dis_line_table, sal.symtab, l))
+		      if (line_has_code_p (dis_line_table.get (),
+					   sal.symtab, l))
 			break;
 		    }
 		  if (l < sal.line - 1)
@@ -729,7 +724,6 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
     }
 
   do_cleanups (ui_out_chain);
-  do_cleanups (cleanups);
 }
 
 static void
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index aaf88e4..3aa5d06 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -41,6 +41,7 @@
 #include "selftest.h"
 #include <algorithm>
 #include <vector>
+#include <unordered_set>
 
 extern int dwarf_always_disassemble;
 
@@ -789,33 +790,23 @@ func_addr_to_tail_call_list (struct gdbarch *gdbarch, CORE_ADDR addr)
 static void
 func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr)
 {
-  struct obstack addr_obstack;
-  struct cleanup *old_chain;
   CORE_ADDR addr;
 
-  /* Track here CORE_ADDRs which were already visited.  */
-  htab_t addr_hash;
-
   /* The verification is completely unordered.  Track here function addresses
      which still need to be iterated.  */
-  VEC (CORE_ADDR) *todo = NULL;
+  std::vector<CORE_ADDR> todo;
 
-  obstack_init (&addr_obstack);
-  old_chain = make_cleanup_obstack_free (&addr_obstack);   
-  addr_hash = htab_create_alloc_ex (64, core_addr_hash, core_addr_eq, NULL,
-				    &addr_obstack, hashtab_obstack_allocate,
-				    NULL);
-  make_cleanup_htab_delete (addr_hash);
-
-  make_cleanup (VEC_cleanup (CORE_ADDR), &todo);
+  /* Track here CORE_ADDRs which were already visited.  */
+  std::unordered_set<CORE_ADDR> addr_hash;
 
-  VEC_safe_push (CORE_ADDR, todo, verify_addr);
-  while (!VEC_empty (CORE_ADDR, todo))
+  todo.push_back (verify_addr);
+  while (!todo.empty ())
     {
       struct symbol *func_sym;
       struct call_site *call_site;
 
-      addr = VEC_pop (CORE_ADDR, todo);
+      addr = todo.back ();
+      todo.pop_back ();
 
       func_sym = func_addr_to_tail_call_list (gdbarch, addr);
 
@@ -823,7 +814,6 @@ func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr)
 	   call_site; call_site = call_site->tail_call_next)
 	{
 	  CORE_ADDR target_addr;
-	  void **slot;
 
 	  /* CALLER_FRAME with registers is not available for tail-call jumped
 	     frames.  */
@@ -843,17 +833,13 @@ func_verify_no_selftailcall (struct gdbarch *gdbarch, CORE_ADDR verify_addr)
 			   paddress (gdbarch, verify_addr));
 	    }
 
-	  slot = htab_find_slot (addr_hash, &target_addr, INSERT);
-	  if (*slot == NULL)
+	  if (addr_hash.find (target_addr) == addr_hash.end ())
 	    {
-	      *slot = obstack_copy (&addr_obstack, &target_addr,
-				    sizeof (target_addr));
-	      VEC_safe_push (CORE_ADDR, todo, target_addr);
+	      addr_hash.insert (target_addr);
+	      todo.push_back (target_addr);
 	    }
 	}
     }
-
-  do_cleanups (old_chain);
 }
 
 /* Print user readable form of CALL_SITE->PC to gdb_stdlog.  Used only for
@@ -871,12 +857,6 @@ tailcall_dump (struct gdbarch *gdbarch, const struct call_site *call_site)
 
 }
 
-/* vec.h needs single word type name, typedef it.  */
-typedef struct call_site *call_sitep;
-
-/* Define VEC (call_sitep) functions.  */
-DEF_VEC_P (call_sitep);
-
 /* Intersect RESULTP with CHAIN to keep RESULTP unambiguous, keep in RESULTP
    only top callers and bottom callees which are present in both.  GDBARCH is
    used only for ENTRY_VALUES_DEBUG.  RESULTP is NULL after return if there are
@@ -885,26 +865,27 @@ DEF_VEC_P (call_sitep);
    responsible for xfree of any RESULTP data.  */
 
 static void
-chain_candidate (struct gdbarch *gdbarch, struct call_site_chain **resultp,
-		 VEC (call_sitep) *chain)
+chain_candidate (struct gdbarch *gdbarch,
+		 gdb::unique_xmalloc_ptr<struct call_site_chain> *resultp,
+		 std::vector<struct call_site *> *chain)
 {
-  struct call_site_chain *result = *resultp;
-  long length = VEC_length (call_sitep, chain);
+  long length = chain->size ();
   int callers, callees, idx;
 
-  if (result == NULL)
+  if (*resultp == NULL)
     {
       /* Create the initial chain containing all the passed PCs.  */
 
-      result = ((struct call_site_chain *)
-		xmalloc (sizeof (*result)
-			 + sizeof (*result->call_site) * (length - 1)));
+      struct call_site_chain *result
+	= ((struct call_site_chain *)
+	   xmalloc (sizeof (*result)
+		    + sizeof (*result->call_site) * (length - 1)));
       result->length = length;
       result->callers = result->callees = length;
-      if (!VEC_empty (call_sitep, chain))
-	memcpy (result->call_site, VEC_address (call_sitep, chain),
+      if (!chain->empty ())
+	memcpy (result->call_site, chain->data (),
 		sizeof (*result->call_site) * length);
-      *resultp = result;
+      resultp->reset (result);
 
       if (entry_values_debug)
 	{
@@ -921,58 +902,58 @@ chain_candidate (struct gdbarch *gdbarch, struct call_site_chain **resultp,
     {
       fprintf_unfiltered (gdb_stdlog, "tailcall: compare:");
       for (idx = 0; idx < length; idx++)
-	tailcall_dump (gdbarch, VEC_index (call_sitep, chain, idx));
+	tailcall_dump (gdbarch, chain->at (idx));
       fputc_unfiltered ('\n', gdb_stdlog);
     }
 
   /* Intersect callers.  */
 
-  callers = std::min ((long) result->callers, length);
+  callers = std::min ((long) (*resultp)->callers, length);
   for (idx = 0; idx < callers; idx++)
-    if (result->call_site[idx] != VEC_index (call_sitep, chain, idx))
+    if ((*resultp)->call_site[idx] != chain->at (idx))
       {
-	result->callers = idx;
+	(*resultp)->callers = idx;
 	break;
       }
 
   /* Intersect callees.  */
 
-  callees = std::min ((long) result->callees, length);
+  callees = std::min ((long) (*resultp)->callees, length);
   for (idx = 0; idx < callees; idx++)
-    if (result->call_site[result->length - 1 - idx]
-	!= VEC_index (call_sitep, chain, length - 1 - idx))
+    if ((*resultp)->call_site[(*resultp)->length - 1 - idx]
+	!= chain->at (length - 1 - idx))
       {
-	result->callees = idx;
+	(*resultp)->callees = idx;
 	break;
       }
 
   if (entry_values_debug)
     {
       fprintf_unfiltered (gdb_stdlog, "tailcall: reduced:");
-      for (idx = 0; idx < result->callers; idx++)
-	tailcall_dump (gdbarch, result->call_site[idx]);
+      for (idx = 0; idx < (*resultp)->callers; idx++)
+	tailcall_dump (gdbarch, (*resultp)->call_site[idx]);
       fputs_unfiltered (" |", gdb_stdlog);
-      for (idx = 0; idx < result->callees; idx++)
-	tailcall_dump (gdbarch, result->call_site[result->length
-						  - result->callees + idx]);
+      for (idx = 0; idx < (*resultp)->callees; idx++)
+	tailcall_dump (gdbarch,
+		       (*resultp)->call_site[(*resultp)->length
+					     - (*resultp)->callees + idx]);
       fputc_unfiltered ('\n', gdb_stdlog);
     }
 
-  if (result->callers == 0 && result->callees == 0)
+  if ((*resultp)->callers == 0 && (*resultp)->callees == 0)
     {
       /* There are no common callers or callees.  It could be also a direct
 	 call (which has length 0) with ambiguous possibility of an indirect
 	 call - CALLERS == CALLEES == 0 is valid during the first allocation
 	 but any subsequence processing of such entry means ambiguity.  */
-      xfree (result);
-      *resultp = NULL;
+      resultp->reset (NULL);
       return;
     }
 
   /* See call_site_find_chain_1 why there is no way to reach the bottom callee
      PC again.  In such case there must be two different code paths to reach
      it.  CALLERS + CALLEES equal to LENGTH in the case of self tail-call.  */
-  gdb_assert (result->callers + result->callees <= result->length);
+  gdb_assert ((*resultp)->callers + (*resultp)->callees <= (*resultp)->length);
 }
 
 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC.  All the
@@ -987,19 +968,14 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 			CORE_ADDR callee_pc)
 {
   CORE_ADDR save_callee_pc = callee_pc;
-  struct obstack addr_obstack;
-  struct cleanup *back_to_retval, *back_to_workdata;
-  struct call_site_chain *retval = NULL;
+  gdb::unique_xmalloc_ptr<struct call_site_chain> retval;
   struct call_site *call_site;
 
-  /* Mark CALL_SITEs so we do not visit the same ones twice.  */
-  htab_t addr_hash;
-
   /* CHAIN contains only the intermediate CALL_SITEs.  Neither CALLER_PC's
      call_site nor any possible call_site at CALLEE_PC's function is there.
      Any CALL_SITE in CHAIN will be iterated to its siblings - via
      TAIL_CALL_NEXT.  This is inappropriate for CALLER_PC's call_site.  */
-  VEC (call_sitep) *chain = NULL;
+  std::vector<struct call_site *> chain;
 
   /* We are not interested in the specific PC inside the callee function.  */
   callee_pc = get_pc_function_start (callee_pc);
@@ -1007,16 +983,8 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
     throw_error (NO_ENTRY_VALUE_ERROR, _("Unable to find function for PC %s"),
 		 paddress (gdbarch, save_callee_pc));
 
-  back_to_retval = make_cleanup (free_current_contents, &retval);
-
-  obstack_init (&addr_obstack);
-  back_to_workdata = make_cleanup_obstack_free (&addr_obstack);   
-  addr_hash = htab_create_alloc_ex (64, core_addr_hash, core_addr_eq, NULL,
-				    &addr_obstack, hashtab_obstack_allocate,
-				    NULL);
-  make_cleanup_htab_delete (addr_hash);
-
-  make_cleanup (VEC_cleanup (call_sitep), &chain);
+  /* Mark CALL_SITEs so we do not visit the same ones twice.  */
+  std::unordered_set<CORE_ADDR> addr_hash;
 
   /* Do not push CALL_SITE to CHAIN.  Push there only the first tail call site
      at the target's function.  All the possible tail call sites in the
@@ -1035,7 +1003,7 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 
       if (target_func_addr == callee_pc)
 	{
-	  chain_candidate (gdbarch, &retval, chain);
+	  chain_candidate (gdbarch, &retval, &chain);
 	  if (retval == NULL)
 	    break;
 
@@ -1057,15 +1025,12 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 
 	  if (target_call_site)
 	    {
-	      void **slot;
-
-	      slot = htab_find_slot (addr_hash, &target_call_site->pc, INSERT);
-	      if (*slot == NULL)
+	      if (addr_hash.find (target_call_site->pc) == addr_hash.end ())
 		{
 		  /* Successfully entered TARGET_CALL_SITE.  */
 
-		  *slot = &target_call_site->pc;
-		  VEC_safe_push (call_sitep, chain, target_call_site);
+		  addr_hash.insert (target_call_site->pc);
+		  chain.push_back (target_call_site);
 		  break;
 		}
 	    }
@@ -1075,13 +1040,13 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 	     sibling etc.  */
 
 	  target_call_site = NULL;
-	  while (!VEC_empty (call_sitep, chain))
+	  while (!chain.empty ())
 	    {
-	      call_site = VEC_pop (call_sitep, chain);
+	      call_site = chain.back ();
+	      chain.pop_back ();
 
-	      gdb_assert (htab_find_slot (addr_hash, &call_site->pc,
-					  NO_INSERT) != NULL);
-	      htab_remove_elt (addr_hash, &call_site->pc);
+	      gdb_assert (addr_hash.find (call_site->pc) != addr_hash.end ());
+	      addr_hash.erase (call_site->pc);
 
 	      target_call_site = call_site->tail_call_next;
 	      if (target_call_site)
@@ -1090,10 +1055,10 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 	}
       while (target_call_site);
 
-      if (VEC_empty (call_sitep, chain))
+      if (chain.empty ())
 	call_site = NULL;
       else
-	call_site = VEC_last (call_sitep, chain);
+	call_site = chain.back ();
     }
 
   if (retval == NULL)
@@ -1114,9 +1079,7 @@ call_site_find_chain_1 (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 		   paddress (gdbarch, callee_pc));
     }
 
-  do_cleanups (back_to_workdata);
-  discard_cleanups (back_to_retval);
-  return retval;
+  return retval.release ();
 }
 
 /* Create and return call_site_chain for CALLER_PC and CALLEE_PC.  All the
@@ -2564,7 +2527,6 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
 			   CORE_ADDR *valp)
 {
   struct objfile *objfile;
-  struct cleanup *cleanup;
 
   if (dlbaton == NULL || dlbaton->size == 0)
     return 0;
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index ed10e03..9676d59 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3897,17 +3897,12 @@ dw2_expand_symtabs_matching
 
   if (file_matcher != NULL)
     {
-      struct cleanup *cleanup;
-      htab_t visited_found, visited_not_found;
-
-      visited_found = htab_create_alloc (10,
-					 htab_hash_pointer, htab_eq_pointer,
-					 NULL, xcalloc, xfree);
-      cleanup = make_cleanup_htab_delete (visited_found);
-      visited_not_found = htab_create_alloc (10,
-					     htab_hash_pointer, htab_eq_pointer,
-					     NULL, xcalloc, xfree);
-      make_cleanup_htab_delete (visited_not_found);
+      htab_up visited_found (htab_create_alloc (10, htab_hash_pointer,
+						htab_eq_pointer,
+						NULL, xcalloc, xfree));
+      htab_up visited_not_found (htab_create_alloc (10, htab_hash_pointer,
+						    htab_eq_pointer,
+						    NULL, xcalloc, xfree));
 
       /* The rule is CUs specify all the files, including those used by
 	 any TU, so there's no need to scan TUs here.  */
@@ -3931,9 +3926,9 @@ dw2_expand_symtabs_matching
 	  if (file_data == NULL)
 	    continue;
 
-	  if (htab_find (visited_not_found, file_data) != NULL)
+	  if (htab_find (visited_not_found.get (), file_data) != NULL)
 	    continue;
-	  else if (htab_find (visited_found, file_data) != NULL)
+	  else if (htab_find (visited_found.get (), file_data) != NULL)
 	    {
 	      per_cu->v.quick->mark = 1;
 	      continue;
@@ -3965,13 +3960,11 @@ dw2_expand_symtabs_matching
 	    }
 
 	  slot = htab_find_slot (per_cu->v.quick->mark
-				 ? visited_found
-				 : visited_not_found,
+				 ? visited_found.get ()
+				 : visited_not_found.get (),
 				 file_data, INSERT);
 	  *slot = file_data;
 	}
-
-      do_cleanups (cleanup);
     }
 
   for (iter = 0; iter < index->symbol_table_slots; ++iter)
@@ -4138,11 +4131,9 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
 			  void *data, int need_fullname)
 {
   int i;
-  struct cleanup *cleanup;
-  htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
-				      NULL, xcalloc, xfree);
+  htab_up visited (htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
+				      NULL, xcalloc, xfree));
 
-  cleanup = make_cleanup_htab_delete (visited);
   dw2_setup (objfile);
 
   /* The rule is CUs specify all the files, including those used by
@@ -4155,7 +4146,8 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
 
       if (per_cu->v.quick->compunit_symtab)
 	{
-	  void **slot = htab_find_slot (visited, per_cu->v.quick->file_names,
+	  void **slot = htab_find_slot (visited.get (),
+					per_cu->v.quick->file_names,
 					INSERT);
 
 	  *slot = per_cu->v.quick->file_names;
@@ -4177,7 +4169,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
       if (file_data == NULL)
 	continue;
 
-      slot = htab_find_slot (visited, file_data, INSERT);
+      slot = htab_find_slot (visited.get (), file_data, INSERT);
       if (*slot)
 	{
 	  /* Already visited.  */
@@ -4196,8 +4188,6 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
 	  (*fun) (file_data->file_names[j], this_real_name, data);
 	}
     }
-
-  do_cleanups (cleanup);
 }
 
 static int
@@ -21583,7 +21573,6 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
   unsigned int offset_size = cu->header.offset_size;
   const gdb_byte *opcode_definitions[256];
   struct cleanup *cleanup;
-  htab_t include_hash;
   void **slot;
   struct dwarf2_section_info *section;
   const char *section_name;
@@ -21749,16 +21738,16 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
      command-line macro definitions/undefinitions.  This flag is unset when we
      reach the first DW_MACINFO_start_file entry.  */
 
-  include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
-				    NULL, xcalloc, xfree);
-  cleanup = make_cleanup_htab_delete (include_hash);
+  htab_up include_hash (htab_create_alloc (1, htab_hash_pointer,
+					   htab_eq_pointer,
+					   NULL, xcalloc, xfree));
   mac_ptr = section->buffer + offset;
-  slot = htab_find_slot (include_hash, mac_ptr, INSERT);
+  slot = htab_find_slot (include_hash.get (), mac_ptr, INSERT);
   *slot = (void *) mac_ptr;
   dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end,
 			    current_file, lh, section,
-			    section_is_gnu, 0, offset_size, include_hash);
-  do_cleanups (cleanup);
+			    section_is_gnu, 0, offset_size,
+			    include_hash.get ());
 }
 
 /* Check if the attribute's form is a DW_FORM_block*
@@ -23287,8 +23276,6 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   struct mapped_symtab *symtab;
   offset_type val, size_of_contents, total_len;
   struct stat st;
-  htab_t psyms_seen;
-  htab_t cu_index_htab;
   struct psymtab_cu_index_map *psymtab_cu_index_map;
 
   if (dwarf2_per_objfile->using_index)
@@ -23326,19 +23313,18 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
   obstack_init (&types_cu_list);
   make_cleanup_obstack_free (&types_cu_list);
 
-  psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer,
-				  NULL, xcalloc, xfree);
-  make_cleanup_htab_delete (psyms_seen);
+  htab_up psyms_seen (htab_create_alloc (100, htab_hash_pointer,
+					 htab_eq_pointer,
+					 NULL, xcalloc, xfree));
 
   /* While we're scanning CU's create a table that maps a psymtab pointer
      (which is what addrmap records) to its index (which is what is recorded
      in the index file).  This will later be needed to write the address
      table.  */
-  cu_index_htab = htab_create_alloc (100,
-				     hash_psymtab_cu_index,
-				     eq_psymtab_cu_index,
-				     NULL, xcalloc, xfree);
-  make_cleanup_htab_delete (cu_index_htab);
+  htab_up cu_index_htab (htab_create_alloc (100,
+					    hash_psymtab_cu_index,
+					    eq_psymtab_cu_index,
+					    NULL, xcalloc, xfree));
   psymtab_cu_index_map = XNEWVEC (struct psymtab_cu_index_map,
 				  dwarf2_per_objfile->n_comp_units);
   make_cleanup (xfree, psymtab_cu_index_map);
@@ -23362,12 +23348,13 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
 	continue;
 
       if (psymtab->user == NULL)
-	recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i);
+	recursively_write_psymbols (objfile, psymtab, symtab,
+				    psyms_seen.get (), i);
 
       map = &psymtab_cu_index_map[i];
       map->psymtab = psymtab;
       map->cu_index = i;
-      slot = htab_find_slot (cu_index_htab, map, INSERT);
+      slot = htab_find_slot (cu_index_htab.get (), map, INSERT);
       gdb_assert (slot != NULL);
       gdb_assert (*slot == NULL);
       *slot = map;
@@ -23380,7 +23367,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
     }
 
   /* Dump the address map.  */
-  write_address_map (objfile, &addr_obstack, cu_index_htab);
+  write_address_map (objfile, &addr_obstack, cu_index_htab.get ());
 
   /* Write out the .debug_type entries, if any.  */
   if (dwarf2_per_objfile->signatured_types)
@@ -23390,7 +23377,7 @@ write_psymtabs_to_index (struct objfile *objfile, const char *dir)
       sig_data.objfile = objfile;
       sig_data.symtab = symtab;
       sig_data.types_list = &types_cu_list;
-      sig_data.psyms_seen = psyms_seen;
+      sig_data.psyms_seen = psyms_seen.get ();
       sig_data.cu_index = dwarf2_per_objfile->n_comp_units;
       htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
 			      write_one_signatured_type, &sig_data);
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 9be9cd9..c4f0f8f 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -940,7 +940,6 @@ gnuv3_print_vtable (struct value *value)
   struct type *type;
   struct value *vtable;
   struct value_print_options opts;
-  htab_t offset_hash;
   struct cleanup *cleanup;
   VEC (value_and_voffset_p) *result_vec = NULL;
   struct value_and_voffset *iter;
@@ -976,13 +975,12 @@ gnuv3_print_vtable (struct value *value)
       return;
     }
 
-  offset_hash = htab_create_alloc (1, hash_value_and_voffset,
-				   eq_value_and_voffset,
-				   xfree, xcalloc, xfree);
-  cleanup = make_cleanup_htab_delete (offset_hash);
-  make_cleanup (VEC_cleanup (value_and_voffset_p), &result_vec);
+  htab_up offset_hash (htab_create_alloc (1, hash_value_and_voffset,
+					  eq_value_and_voffset,
+					  xfree, xcalloc, xfree));
+  cleanup = make_cleanup (VEC_cleanup (value_and_voffset_p), &result_vec);
 
-  compute_vtable_size (offset_hash, &result_vec, value);
+  compute_vtable_size (offset_hash.get (), &result_vec, value);
 
   qsort (VEC_address (value_and_voffset_p, result_vec),
 	 VEC_length (value_and_voffset_p, result_vec),
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 1604267..7694635 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2835,6 +2835,18 @@ struct decode_compound_collector
   /* A hash table of all symbols we found.  We use this to avoid
      adding any symbol more than once.  */
   htab_t unique_syms;
+
+  decode_compound_collector ()
+  : symbols (NULL),
+    unique_syms (NULL)
+  {
+  }
+
+  ~decode_compound_collector ()
+  {
+    if (unique_syms != NULL)
+      htab_delete (unique_syms);
+  }
 };
 
 /* A callback for iterate_over_symbols that is used by
@@ -2886,7 +2898,6 @@ lookup_prefix_sym (struct linespec_state *state, VEC (symtab_ptr) *file_symtabs,
   collector.unique_syms = htab_create_alloc (1, htab_hash_pointer,
 					     htab_eq_pointer, NULL,
 					     xcalloc, xfree);
-  cleanup = make_cleanup_htab_delete (collector.unique_syms);
 
   for (ix = 0; VEC_iterate (symtab_ptr, file_symtabs, ix, elt); ++ix)
     {
@@ -2912,7 +2923,6 @@ lookup_prefix_sym (struct linespec_state *state, VEC (symtab_ptr) *file_symtabs,
 	}
     }
 
-  do_cleanups (cleanup);
   discard_cleanups (outer);
   return collector.symbols;
 }
@@ -3129,6 +3139,18 @@ struct symtab_collector
 
   /* This is used to ensure the symtabs are unique.  */
   htab_t symtab_table;
+
+  symtab_collector ()
+  : symtabs (NULL),
+    symtab_table (NULL)
+  {
+  }
+
+  ~symtab_collector ()
+  {
+    if (symtab_table != NULL)
+      htab_delete (symtab_table);
+  }
 };
 
 /* Callback for iterate_over_symtabs.  */
@@ -3164,7 +3186,6 @@ collect_symtabs_from_filename (const char *file,
   collector.symtabs = NULL;
   collector.symtab_table = htab_create (1, htab_hash_pointer, htab_eq_pointer,
 					NULL);
-  cleanups = make_cleanup_htab_delete (collector.symtab_table);
 
   /* Find that file's data.  */
   if (search_pspace == NULL)
@@ -3184,7 +3205,6 @@ collect_symtabs_from_filename (const char *file,
       iterate_over_symtabs (file, add_symtabs_to_list, &collector);
     }
 
-  do_cleanups (cleanups);
   return collector.symtabs;
 }
 
diff --git a/gdb/utils.c b/gdb/utils.c
index 3a88e2a..77c38bf 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -299,24 +299,6 @@ make_cleanup_unpush_target (struct target_ops *ops)
   return make_cleanup (do_unpush_target, ops);
 }
 
-/* Helper for make_cleanup_htab_delete compile time checking the types.  */
-
-static void
-do_htab_delete_cleanup (void *htab_voidp)
-{
-  htab_t htab = (htab_t) htab_voidp;
-
-  htab_delete (htab);
-}
-
-/* Return a new cleanup that deletes HTAB.  */
-
-struct cleanup *
-make_cleanup_htab_delete (htab_t htab)
-{
-  return make_cleanup (do_htab_delete_cleanup, htab);
-}
-
 /* Helper for make_cleanup_value_free_to_mark.  */
 
 static void
diff --git a/gdb/utils.h b/gdb/utils.h
index ecdaf3e..349530e 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -112,8 +112,6 @@ struct htab_deleter
 /* A unique_ptr wrapper for htab_t.  */
 typedef std::unique_ptr<htab, htab_deleter> htab_up;
 
-extern struct cleanup *make_cleanup_htab_delete (htab_t htab);
-
 struct parser_state;
 extern struct cleanup *make_cleanup_clear_parser_state
   (struct parser_state **p);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]