[1/2] Use gdb::string_set for decoded_names_store

Message ID 20250414-even-more-set-v1-1-be6fd07489d5@tromey.com
State New
Headers
Series Two more htab replacement |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey April 14, 2025, 8:19 p.m. UTC
  This patch changes decoded_names_store to use a gdb::string_set rather
than an htab.
---
 gdb/ada-lang.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
  

Comments

Simon Marchi April 15, 2025, 3:34 p.m. UTC | #1
On 4/14/25 4:19 PM, Tom Tromey wrote:
> @@ -1637,13 +1638,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
>  	     which case, we put the result on the heap.  Since we only
>  	     decode when needed, we hope this usually does not cause a
>  	     significant memory leak (FIXME).  */
> -
> -	  char **slot = (char **) htab_find_slot (decoded_names_store,
> -						  decoded.c_str (), INSERT);
> -
> -	  if (*slot == NULL)
> -	    *slot = xstrdup (decoded.c_str ());
> -	  *resultp = *slot;
> +	  *resultp = decoded_names_store.insert (decoded.c_str ());

.c_str() is not needed.

Otherwise LGTM.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9d354407bc30cb2c9272cc28788f130ea289e499..8e76fd9b7cb2e2a6bf0ae3cfcd33f44c5c36731c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -52,6 +52,7 @@ 
 #include "namespace.h"
 #include "cli/cli-style.h"
 #include "cli/cli-decode.h"
+#include "gdbsupport/string-set.h"
 
 #include "value.h"
 #include "mi/mi-common.h"
@@ -1603,7 +1604,7 @@  ada_decode_tests ()
    storage leak, it should not be significant unless there are massive
    changes in the set of decoded names in successive versions of a 
    symbol table loaded during a single session.  */
-static struct htab *decoded_names_store;
+static gdb::string_set decoded_names_store;
 
 /* Returns the decoded name of GSYMBOL, as for ada_decode, caching it
    in the language-specific part of GSYMBOL, if it has not been
@@ -1637,13 +1638,7 @@  ada_decode_symbol (const struct general_symbol_info *arg)
 	     which case, we put the result on the heap.  Since we only
 	     decode when needed, we hope this usually does not cause a
 	     significant memory leak (FIXME).  */
-
-	  char **slot = (char **) htab_find_slot (decoded_names_store,
-						  decoded.c_str (), INSERT);
-
-	  if (*slot == NULL)
-	    *slot = xstrdup (decoded.c_str ());
-	  *resultp = *slot;
+	  *resultp = decoded_names_store.insert (decoded.c_str ());
 	}
     }
 
@@ -14049,10 +14044,6 @@  When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\
 DWARF attribute."),
      NULL, NULL, &maint_set_ada_cmdlist, &maint_show_ada_cmdlist);
 
-  decoded_names_store = htab_create_alloc (256, htab_hash_string,
-					   htab_eq_string,
-					   NULL, xcalloc, xfree);
-
   /* The ada-lang observers.  */
   gdb::observers::new_objfile.attach (ada_new_objfile_observer, "ada-lang");
   gdb::observers::all_objfiles_removed.attach (ada_clear_symbol_cache,