diff options
author | Keith Seitz <keiths@redhat.com> | 2014-04-14 15:47:15 -0700 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2014-04-14 15:47:15 -0700 |
commit | b50c861487bb7d71185777193a9246bac81e4f26 (patch) | |
tree | 858f9f12feaafb9ca1aa0e467b9d1149b7f60e9b /gdb/cp-namespace.c | |
parent | 3d567982aca11c85a7fa31f13046de3271d3afc8 (diff) | |
download | gdb-b50c861487bb7d71185777193a9246bac81e4f26.zip gdb-b50c861487bb7d71185777193a9246bac81e4f26.tar.gz gdb-b50c861487bb7d71185777193a9246bac81e4f26.tar.bz2 |
Remove symbol_matches_domain. This fixes
PR c++/16253.
symbol_matches_domain was permitting searches for a VAR_DOMAIN
symbol to also match STRUCT_DOMAIN symbols for languages like C++
where STRUCT_DOMAIN symbols also define a typedef of the same name,
e.g., "struct foo {}" introduces a typedef of the name "foo".
Problems occur if there exists both a VAR_DOMAIN and STRUCT_DOMAIN
symbol of the same name. Then it is essentially a race between which
symbol is found first. The other symbol is obscurred.
[This is a relatively common idiom: enum e { ... } e;]
This patchset moves this "language defines a typedef" logic to
lookup_symbol[_in_language], looking first for a symbol in the given
domain and falling back to searching STRUCT_DOMAIN when/if appropriate.
2014-04-14 Keith Seitz <keiths@redhat.com>
PR c++/16253
* ada-lang.c (ada_symbol_matches_domain): Moved here and renamed
from symbol_matches_domain in symtab.c. All local callers
of symbol_matches_domain updated.
(standard_lookup): If DOMAIN is VAR_DOMAIN and no symbol is found,
search STRUCT_DOMAIN.
(ada_find_any_type_symbol): Do not search STRUCT_DOMAIN
independently. standard_lookup will do that automatically.
* cp-namespace.c (cp_lookup_symbol_nonlocal): Explain when/why
VAR_DOMAIN searches may return a STRUCT_DOMAIN match.
(cp_lookup_symbol_in_namespace): Likewise.
If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN.
(cp_lookup_symbol_exports): Explain when/why VAR_DOMAIN searches
may return a STRUCT_DOMAIN match.
(lookup_symbol_file): Search for the class name in STRUCT_DOMAIN.
* cp-support.c: Include language.h.
(inspect_type): Explicitly search STRUCT_DOMAIN before searching
VAR_DOMAIN.
* psymtab.c (match_partial_symbol): Compare the requested
domain with the symbol's domain directly.
(lookup_partial_symbol): Likewise.
* symtab.c (lookup_symbol_in_language): Explain when/why
VAR_DOMAIN searches may return a STRUCT_DOMAIN match.
If no VAR_DOMAIN symbol is found, search STRUCT_DOMAIN for
appropriate languages.
(symbol_matches_domain): Renamed `ada_symbol_matches_domain'
and moved to ada-lang.c
(lookup_block_symbol): Explain that this function only returns
symbol matching the requested DOMAIN.
Compare the requested domain with the symbol's domain directly.
(iterate_over_symbols): Compare the requested domain with the
symbol's domain directly.
* symtab.h (symbol_matches_domain): Remove.
2014-04-14 Keith Seitz <keiths@redhat.com>
PR c++/16253
* gdb.cp/var-tag.cc: New file.
* gdb.cp/var-tag.exp: New file.
* gdb.dwarf2/dw2-ada-ffffffff.exp: Set the language to C++.
* gdb.dwarf2/dw2-anon-mptr.exp: Likewise.
* gdb.dwarf2/dw2-double-set-die-type.exp: Likewise.
* gdb.dwarf2/dw2-inheritance.exp: Likewise.
Diffstat (limited to 'gdb/cp-namespace.c')
-rw-r--r-- | gdb/cp-namespace.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 03eb6a9..1085556 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -221,7 +221,12 @@ cp_is_anonymous (const char *namespace) we're looking for, BLOCK is the block that we're searching within, DOMAIN says what kind of symbols we're looking for, and if SYMTAB is non-NULL, we should store the symtab where we found the symbol - in it. */ + in it. + + Class, union, and enum tag names may be used in C++ without specifying + class-key or enum. If searching for a VAR_DOMAIN symbol fails, + this function will search STRUCT_DOMAIN. [This is actually done in + cp_lookup_symbol_in_namespace.] */ struct symbol * cp_lookup_symbol_nonlocal (const char *name, @@ -242,7 +247,10 @@ cp_lookup_symbol_nonlocal (const char *name, /* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in cp_lookup_symbol_nonlocal. If SEARCH is non-zero, search - through base classes for a matching symbol. */ + through base classes for a matching symbol. + + If DOMAIN is VAR_DOMAIN and no matching symbol exists in that domain, + this function will search STRUCT_DOMAIN for a match. */ static struct symbol * cp_lookup_symbol_in_namespace (const char *namespace, @@ -252,18 +260,30 @@ cp_lookup_symbol_in_namespace (const char *namespace, { if (namespace[0] == '\0') { - return lookup_symbol_file (name, block, domain, 0, search); + struct symbol *sym = lookup_symbol_file (name, block, domain, 0, search); + + if (sym == NULL && domain == VAR_DOMAIN) + sym = lookup_symbol_file (name, block, STRUCT_DOMAIN, 0, search); + + return sym; } else { + struct symbol *sym; char *concatenated_name = alloca (strlen (namespace) + 2 + strlen (name) + 1); strcpy (concatenated_name, namespace); strcat (concatenated_name, "::"); strcat (concatenated_name, name); - return lookup_symbol_file (concatenated_name, block, domain, - cp_is_anonymous (namespace), search); + sym = lookup_symbol_file (concatenated_name, block, domain, + cp_is_anonymous (namespace), search); + + if (sym == NULL && domain == VAR_DOMAIN) + sym = lookup_symbol_file (concatenated_name, block, STRUCT_DOMAIN, + cp_is_anonymous (namespace), search); + + return sym; } } @@ -516,7 +536,12 @@ cp_lookup_symbol_imports_or_template (const char *scope, /* Searches for NAME in the current namespace, and by applying relevant import statements belonging to BLOCK and its parents. SCOPE is the namespace scope of the context in which the search is - being evaluated. */ + being evaluated. + + Class, union, and enum tag names may be used in C++ without specifying + class-key or enum. If searching for a VAR_DOMAIN symbol fails, + this function will search STRUCT_DOMAIN. [This is done in + cp_lookup_symbol_in_namespace.] */ struct symbol* cp_lookup_symbol_namespace (const char *scope, @@ -688,7 +713,7 @@ lookup_symbol_file (const char *name, /* Lookup a class named KLASS. If none is found, there is nothing more that can be done. */ - klass_sym = lookup_symbol_global (klass, block, domain); + klass_sym = lookup_symbol_global (klass, block, STRUCT_DOMAIN); if (klass_sym == NULL) { do_cleanups (cleanup); |