aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorPaul N. Hilfinger <hilfinger@adacore.com>2010-10-07 06:53:44 +0000
committerPaul N. Hilfinger <hilfinger@adacore.com>2010-10-07 06:53:44 +0000
commitc4d840bdd6f9e19843bd35835cc08e992fe5e1db (patch)
tree2325091dc2685b2a8c4732104f6e151cce07c486 /gdb/ada-lang.c
parent543ecec77cfc25df40fb60a852f7e08df5317635 (diff)
downloadgdb-c4d840bdd6f9e19843bd35835cc08e992fe5e1db.zip
gdb-c4d840bdd6f9e19843bd35835cc08e992fe5e1db.tar.gz
gdb-c4d840bdd6f9e19843bd35835cc08e992fe5e1db.tar.bz2
Extend hashed symbol dictionaries to work with Ada
This patch allows Ada to speed up symbol lookup by using the facilities in dictionary.[ch] for hashed lookups. First, we generalize dictionary search to allow clients to specify any matching function compatible with the hashing function. Next, we modify the hashing algorithm so that symbols that wild-match a name hash to the same value. Finally, we modify Ada symbol lookup to use these facilities. Because this patch touches on a hashing algorithm used by other languages, I took the precaution of doing a speed test on a list of about 12000 identifiers (repeatedly inserting all of them into a table and then doing a lookup on a million names at random, thus testing the speed of the hashing algorithm and how well it distributed names). There was actually a slight speedup, probably as a result of open- coding some of the tests in msymbol_hash_iw. By design, the revised hashing algorithm produces the same results as the original on most "normal" C identifiers. We considered augmenting the dictionary interface still further by allowing different hashing algorithms for different dictionaries, based on the (supposed) language of the symbols in that dictionary. While this produced better isolation of the changes to Ada programs, the additional flexibility also complicated the dictionary interface. I'd prefer to keep things simple for now. Tested w/o regressions on Linux i686. ChangeLog: gdb/ * ada-lang.c (ada_match_name): Use new API for wild_match. (wild_match): Change API to be consistent with that of strcmp_iw; return 0 for a match, and switch operand order. (full_match): New function. (ada_add_block_symbols): Use dict_iter_match_{first,next} for matching to allow use of hashing. * dictionary.c (struct dict_vector): Generalize iter_name_first, iter_name_next ot iter_match_first, iter_match_next. (iter_name_first_hashed): Replace with iter_match_first_hashed. (iter_name_next_hashed): Replace with iter_match_next_hashed. (iter_name_first_linear): Replace with iter_match_first_linear. (iter_name_next_linear): Replace with iter_match_next_linear. (dict_iter_name_first): Re-implement to use dict_iter_match_first. (dict_iter_name_next): Re-implement to use dict_iter_match_next. (dict_iter_match_first): New function. (dict_iter_match_next): New function. (dict_hash): New function. * dictionary.h (dict_iter_match_first, dict_iter_match_next): Declare. * psymtab.c (ada_lookup_partial_symbol): Use new wild_match API.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 5fdf851..c111e40 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -5062,6 +5062,13 @@ wild_match (const char *name, const char *patn)
}
}
+static int
+full_match (const char *sym_name, const char *search_name)
+{
+ return !ada_match_name (sym_name, search_name, 0);
+}
+
+
/* Add symbols from BLOCK matching identifier NAME in DOMAIN to
vector *defn_symbols, updating the list of symbols in OBSTACKP
(if necessary). If WILD, treat as NAME with a wildcard prefix.
@@ -5086,9 +5093,9 @@ ada_add_block_symbols (struct obstack *obstackp,
found_sym = 0;
if (wild)
{
- struct symbol *sym;
-
- ALL_BLOCK_SYMBOLS (block, iter, sym)
+ for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
+ wild_match, &iter);
+ sym != NULL; sym = dict_iter_match_next (name, wild_match, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain)
@@ -5110,29 +5117,25 @@ ada_add_block_symbols (struct obstack *obstackp,
}
else
{
- ALL_BLOCK_SYMBOLS (block, iter, sym)
+ for (sym = dict_iter_match_first (BLOCK_DICT (block), name,
+ full_match, &iter);
+ sym != NULL; sym = dict_iter_match_next (name, full_match, &iter))
{
if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
SYMBOL_DOMAIN (sym), domain))
{
- int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym), name_len);
-
- if (cmp == 0
- && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len))
- {
- if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
+ if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
+ {
+ if (SYMBOL_IS_ARGUMENT (sym))
+ arg_sym = sym;
+ else
{
- if (SYMBOL_IS_ARGUMENT (sym))
- arg_sym = sym;
- else
- {
- found_sym = 1;
- add_defn_to_vec (obstackp,
- fixup_symbol_section (sym, objfile),
- block);
- }
+ found_sym = 1;
+ add_defn_to_vec (obstackp,
+ fixup_symbol_section (sym, objfile),
+ block);
}
- }
+ }
}
}
}