From 3a49427939764f53e196ae10013c72fcffb8c085 Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Tue, 22 Oct 2019 13:37:37 -0500 Subject: [PATCH] Fix compile error & incorrect push I accidentally pushed the wrong version of the patch for commit 7bb43059820c5febb4509b15202a93efde442bc6 (where the review comments were not fixed), and I did a bad conflict resolution for ccb1ba62299edce72053dd567b9d384814e11885 leading to a compile error when libxxhash is available. This fixes both issues. gdb/ChangeLog: 2019-10-22 Christian Biesinger * symtab.c (struct demangled_name_entry): Add a constructor. (free_demangled_name_entry): New function to call the destructor for demangled_name_entry. (create_demangled_names_hash): Pass free_demangled_name_entry to htab_create_alloc. (symbol_set_names): Call placement new for demangled_name_entry. * utils.c: No longer include xxhash.h here, now that fast_hash is inlined in the header. * utils.h: Instead, include it here. Change-Id: If776099d39a65a12733d42efcb859feca1b07a39 --- gdb/ChangeLog | 12 ++++++++++++ gdb/symtab.c | 23 ++++++++++++++++++----- gdb/utils.c | 4 ---- gdb/utils.h | 4 ++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3fac7952add..8255a8540c9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,15 @@ +2019-10-22 Christian Biesinger + + * symtab.c (struct demangled_name_entry): Add a constructor. + (free_demangled_name_entry): New function to call the destructor + for demangled_name_entry. + (create_demangled_names_hash): Pass free_demangled_name_entry to + htab_create_alloc. + (symbol_set_names): Call placement new for demangled_name_entry. + * utils.c: No longer include xxhash.h here, now that fast_hash + is inlined in the header. + * utils.h: Instead, include it here. + 2019-10-22 Christian Biesinger * Makefile.in: Link with libxxhash. diff --git a/gdb/symtab.c b/gdb/symtab.c index dff92ca203c..ed55cecc730 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -715,6 +715,9 @@ symbol_set_language (struct general_symbol_info *gsymbol, /* Objects of this type are stored in the demangled name hash table. */ struct demangled_name_entry { + demangled_name_entry (gdb::string_view mangled_name) + : mangled (mangled_name) {} + gdb::string_view mangled; ENUM_BITFIELD(language) language : LANGUAGE_BITS; char demangled[1]; @@ -744,6 +747,15 @@ eq_demangled_name_entry (const void *a, const void *b) return da->mangled == db->mangled; } +static void +free_demangled_name_entry (void *data) +{ + struct demangled_name_entry *e + = (struct demangled_name_entry *) data; + + e->~demangled_name_entry(); +} + /* Create the hash table used for demangled names. Each hash entry is a pair of strings; one for the mangled name and one for the demangled name. The entry is hashed via just the mangled name. */ @@ -758,7 +770,7 @@ create_demangled_names_hash (struct objfile_per_bfd_storage *per_bfd) per_bfd->demangled_names_hash.reset (htab_create_alloc (256, hash_demangled_name_entry, eq_demangled_name_entry, - NULL, xcalloc, xfree)); + free_demangled_name_entry, xcalloc, xfree)); } /* Try to determine the demangled name for a symbol, based on the @@ -819,7 +831,6 @@ symbol_set_names (struct general_symbol_info *gsymbol, struct demangled_name_entry **slot; /* A 0-terminated copy of the linkage name. */ const char *linkage_name_copy; - struct demangled_name_entry entry; if (gsymbol->language == language_ada) { @@ -857,7 +868,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, else linkage_name_copy = linkage_name; - entry.mangled = gdb::string_view (linkage_name_copy, len); + struct demangled_name_entry entry (gdb::string_view (linkage_name_copy, len)); slot = ((struct demangled_name_entry **) htab_find_slot (per_bfd->demangled_names_hash.get (), &entry, INSERT)); @@ -890,7 +901,8 @@ symbol_set_names (struct general_symbol_info *gsymbol, obstack_alloc (&per_bfd->storage_obstack, offsetof (struct demangled_name_entry, demangled) + demangled_len + 1)); - (*slot)->mangled = gdb::string_view (linkage_name, len); + new (*slot) demangled_name_entry + (gdb::string_view (linkage_name, len)); } else { @@ -906,7 +918,8 @@ symbol_set_names (struct general_symbol_info *gsymbol, + len + demangled_len + 2)); mangled_ptr = &((*slot)->demangled[demangled_len + 1]); strcpy (mangled_ptr, linkage_name_copy); - (*slot)->mangled = gdb::string_view (mangled_ptr, len); + new (*slot) demangled_name_entry + (gdb::string_view (mangled_ptr, len)); } (*slot)->language = gsymbol->language; diff --git a/gdb/utils.c b/gdb/utils.c index 1b62e55b57e..3afb8e5945f 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -36,10 +36,6 @@ #include #endif -#ifdef HAVE_LIBXXHASH -#include -#endif - #include #include "gdbcmd.h" #include "serial.h" diff --git a/gdb/utils.h b/gdb/utils.h index a8ad9d9c862..e837621a2bd 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -25,6 +25,10 @@ #include "gdbsupport/scoped_restore.h" #include +#ifdef HAVE_LIBXXHASH +#include +#endif + struct completion_match_for_lcd; class compiled_regex; -- 2.30.2