aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.c
diff options
context:
space:
mode:
authorDaniel Jacobowitz <drow@false.org>2003-02-04 18:07:01 +0000
committerDaniel Jacobowitz <drow@false.org>2003-02-04 18:07:01 +0000
commit2de7ced7074964728e66d7a71af0d4fb28f28fa9 (patch)
tree13fb1875f9f0b42bc9ac58a32d828fefb6e7ad11 /gdb/symtab.c
parent266fb683100e69fad79f5bb7ed260de5e2eff655 (diff)
downloadgdb-2de7ced7074964728e66d7a71af0d4fb28f28fa9.zip
gdb-2de7ced7074964728e66d7a71af0d4fb28f28fa9.tar.gz
gdb-2de7ced7074964728e66d7a71af0d4fb28f28fa9.tar.bz2
* defs.h (streq): Add prototype.
* utils.c (streq): New function. * dwarf2read.c (new_symbol): Use SYMBOL_SET_NAMES instead of SYMBOL_NAME and SYMBOL_INIT_DEMANGLED_NAME. * mdebugread.c (new_symbol): Likewise. * stabsread.c (define_symbol): Likewise. * coffread.c (process_coff_symbol): Likewise. * dwarfread.c (new_symbol): Likewise. * minsyms.c (prim_record_minimal_symbol_and_info): Use SYMBOL_SET_NAMES instead of setting SYMBOL_NAME. Set the language here. (install_minimal_symbols): Don't set SYMBOL_LANGUAGE or call SYMBOL_INIT_DEMANGLED_NAME. * objfiles.c: Include "hashtab.h". (allocate_objfile): Call htab_set_functions_ex for the demangled_names_hash. (free_objfile): Call htab_delete for the demangled_names_hash. * objfiles.h (struct htab): Add declaration. (struct objfile): Add demangled_names_hash. * symfile.c: Include "hashtab.h". (reread_symbols): Call htab_delete for the demangled_names_hash. (add_psymbol_to_list): Use SYMBOL_SET_NAMES instead of putting SYMBOL_NAME in the bcache. * symtab.c: Include "hashtab.h". Update comments. (create_demangled_names_hash, symbol_set_names): New functions. (symbol_find_demangled_name): New function, broken out from symbol_init_demangled_names. (symbol_init_demangled_names): Use it. * symtab.h (SYMBOL_INIT_DEMANGLED_NAME): Add missing parentheses. (SYMBOL_SET_NAMES): New macro. (symbol_set_names): Add prototype.
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r--gdb/symtab.c160
1 files changed, 128 insertions, 32 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 9d8bdc0..606a538 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -41,6 +41,8 @@
#include "source.h"
#include "filenames.h" /* for FILENAME_CMP */
+#include "hashtab.h"
+
#include "gdb_obstack.h"
#include <sys/types.h>
@@ -425,22 +427,35 @@ symbol_init_language_specific (struct general_symbol_info *gsymbol,
}
}
-/* Initialize a symbol's mangled name. */
+/* Functions to initialize a symbol's mangled name. */
+
+/* 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. */
-/* Try to initialize the demangled name for a symbol, based on the
+static void
+create_demangled_names_hash (struct objfile *objfile)
+{
+ /* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
+ The hash table code will round this up to the next prime number.
+ Choosing a much larger table size wastes memory, and saves only about
+ 1% in symbol reading. */
+
+ objfile->demangled_names_hash = htab_create_alloc_ex
+ (256, htab_hash_string, (int (*) (const void *, const void *)) streq,
+ NULL, objfile->md, xmcalloc, xmfree);
+}
+
+/* Try to determine the demangled name for a symbol, based on the
language of that symbol. If the language is set to language_auto,
it will attempt to find any demangling algorithm that works and
- then set the language appropriately. If no demangling of any kind
- is found, the language is set back to language_unknown, so we can
- avoid doing this work again the next time we encounter the symbol.
- Any required space to store the name is obtained from the specified
- obstack. */
+ then set the language appropriately. The returned name is allocated
+ by the demangler and should be xfree'd. */
-void
-symbol_init_demangled_name (struct general_symbol_info *gsymbol,
- struct obstack *obstack)
+static char *
+symbol_find_demangled_name (struct general_symbol_info *gsymbol,
+ const char *mangled)
{
- char *mangled = gsymbol->name;
char *demangled = NULL;
if (gsymbol->language == language_unknown)
@@ -449,35 +464,116 @@ symbol_init_demangled_name (struct general_symbol_info *gsymbol,
|| gsymbol->language == language_auto)
{
demangled =
- cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
+ cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
if (demangled != NULL)
- {
- gsymbol->language = language_cplus;
- gsymbol->language_specific.cplus_specific.demangled_name =
- obsavestring (demangled, strlen (demangled), obstack);
- xfree (demangled);
- }
- else
- {
- gsymbol->language_specific.cplus_specific.demangled_name = NULL;
- }
+ {
+ gsymbol->language = language_cplus;
+ return demangled;
+ }
}
if (gsymbol->language == language_java)
{
demangled =
- cplus_demangle (gsymbol->name,
+ cplus_demangle (mangled,
DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
if (demangled != NULL)
- {
- gsymbol->language = language_java;
- gsymbol->language_specific.cplus_specific.demangled_name =
- obsavestring (demangled, strlen (demangled), obstack);
- xfree (demangled);
- }
+ {
+ gsymbol->language = language_java;
+ return demangled;
+ }
+ }
+ return NULL;
+}
+
+/* Set both the mangled and demangled (if any) names for GSYMBOL based on
+ NAME and LEN. The hash table corresponding to OBJFILE is used, and the
+ memory comes from that objfile's symbol_obstack. NAME is copied, so the
+ pointer can be discarded after calling this function. */
+
+void
+symbol_set_names (struct general_symbol_info *gsymbol,
+ const char *name, int len, struct objfile *objfile)
+{
+ char **slot;
+ const char *tmpname;
+
+ if (objfile->demangled_names_hash == NULL)
+ create_demangled_names_hash (objfile);
+
+ /* The stabs reader generally provides names that are not NULL-terminated;
+ most of the other readers don't do this, so we can just use the given
+ copy. */
+ if (name[len] != 0)
+ {
+ char *alloc_name = alloca (len + 1);
+ memcpy (alloc_name, name, len);
+ alloc_name[len] = 0;
+ tmpname = alloc_name;
+ }
+ else
+ tmpname = name;
+
+ slot = (char **) htab_find_slot (objfile->demangled_names_hash, tmpname, INSERT);
+
+ /* If this name is not in the hash table, add it. */
+ if (*slot == NULL)
+ {
+ char *demangled_name = symbol_find_demangled_name (gsymbol, tmpname);
+ int demangled_len = demangled_name ? strlen (demangled_name) : 0;
+
+ /* If there is a demangled name, place it right after the mangled name.
+ Otherwise, just place a second zero byte after the end of the mangled
+ name. */
+ *slot = obstack_alloc (&objfile->symbol_obstack,
+ len + demangled_len + 2);
+ memcpy (*slot, tmpname, len + 1);
+ if (demangled_name)
+ {
+ memcpy (*slot + len + 1, demangled_name, demangled_len + 1);
+ xfree (demangled_name);
+ }
+ else
+ (*slot)[len + 1] = 0;
+ }
+
+ gsymbol->name = *slot;
+ if ((*slot)[len + 1])
+ gsymbol->language_specific.cplus_specific.demangled_name
+ = &(*slot)[len + 1];
+ else
+ gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+}
+
+/* Initialize the demangled name of GSYMBOL if possible. Any required space
+ to store the name is obtained from the specified obstack. The function
+ symbol_set_names, above, should be used instead where possible for more
+ efficient memory usage. */
+
+void
+symbol_init_demangled_name (struct general_symbol_info *gsymbol,
+ struct obstack *obstack)
+{
+ char *mangled = gsymbol->name;
+ char *demangled = NULL;
+
+ demangled = symbol_find_demangled_name (gsymbol, mangled);
+ if (gsymbol->language == language_cplus
+ || gsymbol->language == language_java)
+ {
+ if (demangled)
+ {
+ gsymbol->language_specific.cplus_specific.demangled_name
+ = obsavestring (demangled, strlen (demangled), obstack);
+ xfree (demangled);
+ }
else
- {
- gsymbol->language_specific.cplus_specific.demangled_name = NULL;
- }
+ gsymbol->language_specific.cplus_specific.demangled_name = NULL;
+ }
+ else
+ {
+ /* Unknown language; just clean up quietly. */
+ if (demangled)
+ xfree (demangled);
}
}