From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18963 invoked by alias); 9 Mar 2010 18:21:28 -0000 Received: (qmail 18951 invoked by uid 22791); 9 Mar 2010 18:21:23 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,RCVD_IN_DNSWL_HI,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 09 Mar 2010 18:21:13 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29ILB47002622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Mar 2010 13:21:11 -0500 Received: from [10.15.16.55] (toner.yyz.redhat.com [10.15.16.55]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o29ILA6r013622; Tue, 9 Mar 2010 13:21:10 -0500 Message-ID: <4B9690C3.3030008@redhat.com> Date: Tue, 09 Mar 2010 18:21:00 -0000 From: Sami Wagiaalla User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.7) Gecko/20100120 Fedora/3.0.1-1.fc12 Lightning/1.0b1 Thunderbird/3.0.1 MIME-Version: 1.0 To: Tom Tromey CC: gdb-patches@sourceware.org Subject: Re: [patch] Add support for imported declaration and correct search order References: <4B86DA17.5040200@redhat.com> <20100225224145.GA21231@host0.dyn.jankratochvil.net> <4B8ED7C2.6030804@redhat.com> <4B952743.4000501@redhat.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------060907010101080209080006" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg00361.txt.bz2 This is a multi-part message in MIME format. --------------060907010101080209080006 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 17723 On 03/08/2010 01:58 PM, Tom Tromey wrote: >>>>>> "Sami" == Sami Wagiaalla writes: > > Sami> +&& ((!declaration&& !current->declaration) > Sami> + || strcmp (current->declaration, declaration) == 0)) > > I think this check is wrong in the same way as the alias check in the > previous patch. > Corrected and rebased: 2010-03-09 Sami Wagiaalla PR c++/7936: * cp-support.h: Added char *declaration element to using_direct data struct. (cp_add_using): Added char *declaration argument. (cp_add_using_directive): Ditto. (cp_lookup_symbol_imports): made extern. * cp-namespace.c: Updated with the above changes. * dwarf2read.c (read_import_statement): Ditto. (read_namespace): Ditto. (read_import_statement): Support import declarations. * cp-namespace.c (cp_lookup_symbol_imports): Check for imported declarations. Added support for 'declaration_only' search. (cp_lookup_symbol_namespace): Attempt to search for the name as is before consideration of imports. * symtab.c (lookup_symbol_aux_local): Added a 'declaration_only' search at every block level search. Now takes language argument. (lookup_symbol_aux): Updated. 2010-03-03 Sami Wagiaalla * gdb.cp/shadow.exp: Removed kfail; test has been fix. * gdb.cp/nsusing.exp: Ditto. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 7593475..bf7f254 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -117,7 +117,7 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) anonymous namespace. So add symbols in it to the namespace given by the previous component if there is one, or to the global namespace if there isn't. */ - cp_add_using_directive (dest, src, NULL, + cp_add_using_directive (dest, src, NULL, NULL, &SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack); } /* The "+ 2" is for the "::". */ @@ -135,11 +135,15 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) Create a new struct using_direct which imports the namespace SRC into the scope DEST. ALIAS is the name of the imported namespace in the current scope. If ALIAS is NULL then the namespace is known by its original name. - The arguments are copied into newly allocated memory so they can be - temporaries. */ + DECLARATION is the name if the imported varable if this is a declaration + import (Eg. using A::x), otherwise it is NULL. The arguments are copied + into newly allocated memory so they can be temporaries. */ void -cp_add_using_directive (const char *dest, const char *src, const char *alias, +cp_add_using_directive (const char *dest, + const char *src, + const char *alias, + const char *declaration, struct obstack *obstack) { struct using_direct *current; @@ -153,7 +157,10 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias, && strcmp (current->import_dest, dest) == 0 && ((alias == NULL && current->alias == NULL) || (alias != NULL && current->alias != NULL - && strcmp (alias, current->alias) == 0))) + && strcmp (alias, current->alias) == 0)) + && ((declaration == NULL && current->declaration == NULL) + || (declaration != NULL && current->declaration != NULL + && strcmp (declaration, current->declaration) == 0))) return; } @@ -165,6 +172,10 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias, if (alias != NULL) new->alias = obsavestring (alias, strlen (alias), obstack); + if (declaration != NULL) + new->declaration = obsavestring (declaration, strlen (declaration), + obstack); + new->next = using_directives; using_directives = new; } @@ -238,11 +249,10 @@ cp_lookup_symbol_nonlocal (const char *name, if (sym != NULL) return sym; - return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain, - 1); + return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain); } -/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in +/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in cp_lookup_symbol_nonlocal. */ static struct symbol * @@ -280,7 +290,15 @@ reset_directive_searched (void *data) } /* Search for NAME by applying all import statements belonging - to BLOCK which are applicable in SCOPE. + to BLOCK which are applicable in SCOPE. If DECLARATION_ONLY the search + is restricted to using declarations. + Example: + + namespace A{ + int x; + } + using A::x; + If SEARCH_PARENTS the search will include imports which are applicable in parents of SCOPE. Example: @@ -293,26 +311,28 @@ reset_directive_searched (void *data) } If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X - and Y will be considered. If SEARCH_PARENTS is false only the import of Y + and Y will be considered. If SEARCH_PARENTS is false only the import of Y is considered. */ -static struct symbol * +struct symbol * cp_lookup_symbol_imports (const char *scope, const char *name, const char *linkage_name, const struct block *block, const domain_enum domain, + const int declaration_only, const int search_parents) { struct using_direct *current; - struct symbol *sym; + struct symbol *sym = NULL; int len; int directive_match; struct cleanup *searched_cleanup; /* First, try to find the symbol in the given namespace. */ - sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, - domain); + if (!declaration_only) + sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, + domain); if (sym != NULL) return sym; @@ -341,6 +361,31 @@ cp_lookup_symbol_imports (const char *scope, current->searched = 1; searched_cleanup = make_cleanup (reset_directive_searched, current); + /* If there is an import of a single declaration, compare the imported + declaration with the sought out name. If there is a match pass + current->import_src as NAMESPACE to direct the search towards the + imported namespace. */ + if (current->declaration && strcmp (name, current->declaration) == 0) + sym = cp_lookup_symbol_in_namespace (current->import_src, + name, + linkage_name, + block, + domain); + + /* If this is a DECLARATION_ONLY search or a symbol was found or + this import statement was an import declaration, the search + of this import is complete. */ + if (declaration_only || sym != NULL || current->declaration) + { + current->searched = 0; + discard_cleanups (searched_cleanup); + + if (sym != NULL) + return sym; + + continue; + } + if (current->alias != NULL && strcmp (name, current->alias) == 0) /* If the import is creating an alias and the alias matches the sought name. Pass current->import_src as the NAME to direct the @@ -361,6 +406,7 @@ cp_lookup_symbol_imports (const char *scope, linkage_name, block, domain, + 0, 0); } current->searched = 0; @@ -383,16 +429,21 @@ cp_lookup_symbol_namespace (const char *scope, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain, - const int search_parents) + const domain_enum domain) { struct symbol *sym; + /* First, try to find the symbol in the given namespace. */ + sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, + domain); + if (sym != NULL) + return sym; + /* Search for name in namespaces imported to this and parent blocks. */ while (block != NULL) { sym = cp_lookup_symbol_imports (scope, name, linkage_name, block, domain, - search_parents); + 0, 1); if (sym) return sym; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 3921a5f..3fc93a4 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -44,6 +44,11 @@ struct demangle_component; Eg: namespace C = A::B; ALIAS = "C" + DECLARATION is the name of the imported declaration, if this import + statement represents one. + Eg: + using A::x; + Where x is variable in namespace A. DECLARATION is set to x. */ struct using_direct @@ -52,6 +57,7 @@ struct using_direct char *import_dest; char *alias; + char *declaration; struct using_direct *next; @@ -91,6 +97,7 @@ extern int cp_is_anonymous (const char *namespace); extern void cp_add_using_directive (const char *dest, const char *src, const char *alias, + const char *declaration, struct obstack *obstack); extern void cp_initialize_namespace (void); @@ -115,8 +122,15 @@ extern struct symbol *cp_lookup_symbol_namespace (const char *namespace, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain, - const int search_parents); + const domain_enum domain); + +extern struct symbol *cp_lookup_symbol_imports (const char *scope, + const char *name, + const char *linkage_name, + const struct block *block, + const domain_enum domain, + const int declaration_only, + const int search_parents); extern struct type *cp_lookup_nested_type (struct type *parent_type, const char *nested_name, diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 447424e..ac04c68 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3385,10 +3385,12 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) struct dwarf2_cu *imported_cu; const char *imported_name; const char *imported_name_prefix; - char *import_alias; - + const char *canonical_name; + const char *import_alias; + const char *imported_declaration = NULL; const char *import_prefix; - char *canonical_name; + + char *temp; import_attr = dwarf2_attr (die, DW_AT_import, cu); if (import_attr == NULL) @@ -3448,23 +3450,27 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) to the name of the imported die. */ imported_name_prefix = determine_prefix (imported_die, imported_cu); - if (strlen (imported_name_prefix) > 0) + if (imported_die->tag != DW_TAG_namespace) { - canonical_name = alloca (strlen (imported_name_prefix) - + 2 + strlen (imported_name) + 1); - strcpy (canonical_name, imported_name_prefix); - strcat (canonical_name, "::"); - strcat (canonical_name, imported_name); + imported_declaration = imported_name; + canonical_name = imported_name_prefix; } - else + else if (strlen (imported_name_prefix) > 0) { - canonical_name = alloca (strlen (imported_name) + 1); - strcpy (canonical_name, imported_name); + temp = alloca (strlen (imported_name_prefix) + + 2 + strlen (imported_name) + 1); + strcpy (temp, imported_name_prefix); + strcat (temp, "::"); + strcat (temp, imported_name); + canonical_name = temp; } + else + canonical_name = imported_name; cp_add_using_directive (import_prefix, canonical_name, import_alias, + imported_declaration, &cu->objfile->objfile_obstack); } @@ -5625,7 +5631,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu) { const char *previous_prefix = determine_prefix (die, cu); cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, - &objfile->objfile_obstack); + NULL, &objfile->objfile_obstack); } } diff --git a/gdb/eval.c b/gdb/eval.c index e2ceea7..f48b392 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1435,7 +1435,7 @@ evaluate_subexp_standard (struct type *expect_type, function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type), name, NULL, get_selected_block (0), - VAR_DOMAIN, 1); + VAR_DOMAIN); if (function == NULL) error (_("No symbol \"%s\" in namespace \"%s\"."), name, TYPE_TAG_NAME (type)); diff --git a/gdb/symtab.c b/gdb/symtab.c index af4e501..1a8d5ad 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -95,7 +95,8 @@ static struct symbol *lookup_symbol_aux_local (const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain); + const domain_enum domain, + enum language language); static struct symbol *lookup_symbol_aux_symtabs (int block_index, @@ -1354,15 +1355,14 @@ lookup_symbol_aux (const char *name, const char *linkage_name, /* Search specified block and its superiors. Don't search STATIC_BLOCK or GLOBAL_BLOCK. */ - sym = lookup_symbol_aux_local (name, linkage_name, block, domain); + sym = lookup_symbol_aux_local (name, linkage_name, block, domain, language); if (sym != NULL) return sym; /* If requested to do so by the caller and if appropriate for LANGUAGE, - check to see if NAME is a field of `this'. */ + check to see if NAME is a field of `this'. */ langdef = language_def (language); - if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL && block != NULL) { @@ -1430,10 +1430,12 @@ lookup_symbol_aux (const char *name, const char *linkage_name, static struct symbol * lookup_symbol_aux_local (const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + enum language language) { struct symbol *sym; const struct block *static_block = block_static_block (block); + const char *scope = block_scope (block); /* Check if either no block is specified or it's a global block. */ @@ -1446,6 +1448,19 @@ lookup_symbol_aux_local (const char *name, const char *linkage_name, if (sym != NULL) return sym; + if (language == language_cplus) + { + sym = cp_lookup_symbol_imports (scope, + name, + linkage_name, + block, + domain, + 1, + 1); + if (sym != NULL) + return sym; + } + if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block)) break; block = BLOCK_SUPERBLOCK (block); diff --git a/gdb/testsuite/gdb.cp/nsusing.exp b/gdb/testsuite/gdb.cp/nsusing.exp index 72a616e..b060ee2 100644 --- a/gdb/testsuite/gdb.cp/nsusing.exp +++ b/gdb/testsuite/gdb.cp/nsusing.exp @@ -154,7 +154,7 @@ if ![runto marker4] then { perror "couldn't run to breakpoint marker4" continue } -setup_kfail "gdb/7936" "*-*-*" + gdb_test "print dx" "= 4" ############################################ diff --git a/gdb/testsuite/gdb.cp/shadow.cc b/gdb/testsuite/gdb.cp/shadow.cc index 1651510..0520b2a 100644 --- a/gdb/testsuite/gdb.cp/shadow.cc +++ b/gdb/testsuite/gdb.cp/shadow.cc @@ -29,8 +29,10 @@ public: using namespace A; y++; // marker4 - using A::x; - y++; // marker5 + { + using A::x; + y++; // marker5 + } } } } diff --git a/gdb/testsuite/gdb.cp/shadow.exp b/gdb/testsuite/gdb.cp/shadow.exp index 1e5e80b..40c35a4 100644 --- a/gdb/testsuite/gdb.cp/shadow.exp +++ b/gdb/testsuite/gdb.cp/shadow.exp @@ -85,5 +85,4 @@ gdb_test "print x" "= 55" "Print local x not namespace x" gdb_breakpoint [gdb_get_line_number "marker5"] gdb_continue_to_breakpoint "marker5" -setup_kfail "gdb/7936" "*-*-*" gdb_test "print x" "= 11" "Print imported namespace x" diff --git a/gdb/valops.c b/gdb/valops.c index b94c411..b5e47d3 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3119,7 +3119,7 @@ value_maybe_namespace_elt (const struct type *curtype, sym = cp_lookup_symbol_namespace (namespace_name, name, NULL, get_selected_block (0), - VAR_DOMAIN, 1); + VAR_DOMAIN); if (sym == NULL) return NULL; --------------060907010101080209080006 Content-Type: text/plain; name="declaration.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="declaration.patch" Content-length: 17363 2010-03-09 Sami Wagiaalla PR c++/7936: * cp-support.h: Added char *declaration element to using_direct data struct. (cp_add_using): Added char *declaration argument. (cp_add_using_directive): Ditto. (cp_lookup_symbol_imports): made extern. * cp-namespace.c: Updated with the above changes. * dwarf2read.c (read_import_statement): Ditto. (read_namespace): Ditto. (read_import_statement): Support import declarations. * cp-namespace.c (cp_lookup_symbol_imports): Check for imported declarations. Added support for 'declaration_only' search. (cp_lookup_symbol_namespace): Attempt to search for the name as is before consideration of imports. * symtab.c (lookup_symbol_aux_local): Added a 'declaration_only' search at every block level search. Now takes language argument. (lookup_symbol_aux): Updated. 2010-03-03 Sami Wagiaalla * gdb.cp/shadow.exp: Removed kfail; test has been fix. * gdb.cp/nsusing.exp: Ditto. diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 7593475..bf7f254 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -117,7 +117,7 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) anonymous namespace. So add symbols in it to the namespace given by the previous component if there is one, or to the global namespace if there isn't. */ - cp_add_using_directive (dest, src, NULL, + cp_add_using_directive (dest, src, NULL, NULL, &SYMBOL_SYMTAB (symbol)->objfile->objfile_obstack); } /* The "+ 2" is for the "::". */ @@ -135,11 +135,15 @@ cp_scan_for_anonymous_namespaces (const struct symbol *symbol) Create a new struct using_direct which imports the namespace SRC into the scope DEST. ALIAS is the name of the imported namespace in the current scope. If ALIAS is NULL then the namespace is known by its original name. - The arguments are copied into newly allocated memory so they can be - temporaries. */ + DECLARATION is the name if the imported varable if this is a declaration + import (Eg. using A::x), otherwise it is NULL. The arguments are copied + into newly allocated memory so they can be temporaries. */ void -cp_add_using_directive (const char *dest, const char *src, const char *alias, +cp_add_using_directive (const char *dest, + const char *src, + const char *alias, + const char *declaration, struct obstack *obstack) { struct using_direct *current; @@ -153,7 +157,10 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias, && strcmp (current->import_dest, dest) == 0 && ((alias == NULL && current->alias == NULL) || (alias != NULL && current->alias != NULL - && strcmp (alias, current->alias) == 0))) + && strcmp (alias, current->alias) == 0)) + && ((declaration == NULL && current->declaration == NULL) + || (declaration != NULL && current->declaration != NULL + && strcmp (declaration, current->declaration) == 0))) return; } @@ -165,6 +172,10 @@ cp_add_using_directive (const char *dest, const char *src, const char *alias, if (alias != NULL) new->alias = obsavestring (alias, strlen (alias), obstack); + if (declaration != NULL) + new->declaration = obsavestring (declaration, strlen (declaration), + obstack); + new->next = using_directives; using_directives = new; } @@ -238,11 +249,10 @@ cp_lookup_symbol_nonlocal (const char *name, if (sym != NULL) return sym; - return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain, - 1); + return cp_lookup_symbol_namespace (scope, name, linkage_name, block, domain); } -/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in +/* Look up NAME in the C++ namespace NAMESPACE. Other arguments are as in cp_lookup_symbol_nonlocal. */ static struct symbol * @@ -280,7 +290,15 @@ reset_directive_searched (void *data) } /* Search for NAME by applying all import statements belonging - to BLOCK which are applicable in SCOPE. + to BLOCK which are applicable in SCOPE. If DECLARATION_ONLY the search + is restricted to using declarations. + Example: + + namespace A{ + int x; + } + using A::x; + If SEARCH_PARENTS the search will include imports which are applicable in parents of SCOPE. Example: @@ -293,26 +311,28 @@ reset_directive_searched (void *data) } If SCOPE is "A::B" and SEARCH_PARENTS is true the imports of namespaces X - and Y will be considered. If SEARCH_PARENTS is false only the import of Y + and Y will be considered. If SEARCH_PARENTS is false only the import of Y is considered. */ -static struct symbol * +struct symbol * cp_lookup_symbol_imports (const char *scope, const char *name, const char *linkage_name, const struct block *block, const domain_enum domain, + const int declaration_only, const int search_parents) { struct using_direct *current; - struct symbol *sym; + struct symbol *sym = NULL; int len; int directive_match; struct cleanup *searched_cleanup; /* First, try to find the symbol in the given namespace. */ - sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, - domain); + if (!declaration_only) + sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, + domain); if (sym != NULL) return sym; @@ -341,6 +361,31 @@ cp_lookup_symbol_imports (const char *scope, current->searched = 1; searched_cleanup = make_cleanup (reset_directive_searched, current); + /* If there is an import of a single declaration, compare the imported + declaration with the sought out name. If there is a match pass + current->import_src as NAMESPACE to direct the search towards the + imported namespace. */ + if (current->declaration && strcmp (name, current->declaration) == 0) + sym = cp_lookup_symbol_in_namespace (current->import_src, + name, + linkage_name, + block, + domain); + + /* If this is a DECLARATION_ONLY search or a symbol was found or + this import statement was an import declaration, the search + of this import is complete. */ + if (declaration_only || sym != NULL || current->declaration) + { + current->searched = 0; + discard_cleanups (searched_cleanup); + + if (sym != NULL) + return sym; + + continue; + } + if (current->alias != NULL && strcmp (name, current->alias) == 0) /* If the import is creating an alias and the alias matches the sought name. Pass current->import_src as the NAME to direct the @@ -361,6 +406,7 @@ cp_lookup_symbol_imports (const char *scope, linkage_name, block, domain, + 0, 0); } current->searched = 0; @@ -383,16 +429,21 @@ cp_lookup_symbol_namespace (const char *scope, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain, - const int search_parents) + const domain_enum domain) { struct symbol *sym; + /* First, try to find the symbol in the given namespace. */ + sym = cp_lookup_symbol_in_namespace (scope, name, linkage_name, block, + domain); + if (sym != NULL) + return sym; + /* Search for name in namespaces imported to this and parent blocks. */ while (block != NULL) { sym = cp_lookup_symbol_imports (scope, name, linkage_name, block, domain, - search_parents); + 0, 1); if (sym) return sym; diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 3921a5f..3fc93a4 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -44,6 +44,11 @@ struct demangle_component; Eg: namespace C = A::B; ALIAS = "C" + DECLARATION is the name of the imported declaration, if this import + statement represents one. + Eg: + using A::x; + Where x is variable in namespace A. DECLARATION is set to x. */ struct using_direct @@ -52,6 +57,7 @@ struct using_direct char *import_dest; char *alias; + char *declaration; struct using_direct *next; @@ -91,6 +97,7 @@ extern int cp_is_anonymous (const char *namespace); extern void cp_add_using_directive (const char *dest, const char *src, const char *alias, + const char *declaration, struct obstack *obstack); extern void cp_initialize_namespace (void); @@ -115,8 +122,15 @@ extern struct symbol *cp_lookup_symbol_namespace (const char *namespace, const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain, - const int search_parents); + const domain_enum domain); + +extern struct symbol *cp_lookup_symbol_imports (const char *scope, + const char *name, + const char *linkage_name, + const struct block *block, + const domain_enum domain, + const int declaration_only, + const int search_parents); extern struct type *cp_lookup_nested_type (struct type *parent_type, const char *nested_name, diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 447424e..ac04c68 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -3385,10 +3385,12 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) struct dwarf2_cu *imported_cu; const char *imported_name; const char *imported_name_prefix; - char *import_alias; - + const char *canonical_name; + const char *import_alias; + const char *imported_declaration = NULL; const char *import_prefix; - char *canonical_name; + + char *temp; import_attr = dwarf2_attr (die, DW_AT_import, cu); if (import_attr == NULL) @@ -3448,23 +3450,27 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu) to the name of the imported die. */ imported_name_prefix = determine_prefix (imported_die, imported_cu); - if (strlen (imported_name_prefix) > 0) + if (imported_die->tag != DW_TAG_namespace) { - canonical_name = alloca (strlen (imported_name_prefix) - + 2 + strlen (imported_name) + 1); - strcpy (canonical_name, imported_name_prefix); - strcat (canonical_name, "::"); - strcat (canonical_name, imported_name); + imported_declaration = imported_name; + canonical_name = imported_name_prefix; } - else + else if (strlen (imported_name_prefix) > 0) { - canonical_name = alloca (strlen (imported_name) + 1); - strcpy (canonical_name, imported_name); + temp = alloca (strlen (imported_name_prefix) + + 2 + strlen (imported_name) + 1); + strcpy (temp, imported_name_prefix); + strcat (temp, "::"); + strcat (temp, imported_name); + canonical_name = temp; } + else + canonical_name = imported_name; cp_add_using_directive (import_prefix, canonical_name, import_alias, + imported_declaration, &cu->objfile->objfile_obstack); } @@ -5625,7 +5631,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu) { const char *previous_prefix = determine_prefix (die, cu); cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, - &objfile->objfile_obstack); + NULL, &objfile->objfile_obstack); } } diff --git a/gdb/eval.c b/gdb/eval.c index e2ceea7..f48b392 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1435,7 +1435,7 @@ evaluate_subexp_standard (struct type *expect_type, function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type), name, NULL, get_selected_block (0), - VAR_DOMAIN, 1); + VAR_DOMAIN); if (function == NULL) error (_("No symbol \"%s\" in namespace \"%s\"."), name, TYPE_TAG_NAME (type)); diff --git a/gdb/symtab.c b/gdb/symtab.c index af4e501..1a8d5ad 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -95,7 +95,8 @@ static struct symbol *lookup_symbol_aux_local (const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain); + const domain_enum domain, + enum language language); static struct symbol *lookup_symbol_aux_symtabs (int block_index, @@ -1354,15 +1355,14 @@ lookup_symbol_aux (const char *name, const char *linkage_name, /* Search specified block and its superiors. Don't search STATIC_BLOCK or GLOBAL_BLOCK. */ - sym = lookup_symbol_aux_local (name, linkage_name, block, domain); + sym = lookup_symbol_aux_local (name, linkage_name, block, domain, language); if (sym != NULL) return sym; /* If requested to do so by the caller and if appropriate for LANGUAGE, - check to see if NAME is a field of `this'. */ + check to see if NAME is a field of `this'. */ langdef = language_def (language); - if (langdef->la_name_of_this != NULL && is_a_field_of_this != NULL && block != NULL) { @@ -1430,10 +1430,12 @@ lookup_symbol_aux (const char *name, const char *linkage_name, static struct symbol * lookup_symbol_aux_local (const char *name, const char *linkage_name, const struct block *block, - const domain_enum domain) + const domain_enum domain, + enum language language) { struct symbol *sym; const struct block *static_block = block_static_block (block); + const char *scope = block_scope (block); /* Check if either no block is specified or it's a global block. */ @@ -1446,6 +1448,19 @@ lookup_symbol_aux_local (const char *name, const char *linkage_name, if (sym != NULL) return sym; + if (language == language_cplus) + { + sym = cp_lookup_symbol_imports (scope, + name, + linkage_name, + block, + domain, + 1, + 1); + if (sym != NULL) + return sym; + } + if (BLOCK_FUNCTION (block) != NULL && block_inlined_p (block)) break; block = BLOCK_SUPERBLOCK (block); diff --git a/gdb/testsuite/gdb.cp/nsusing.exp b/gdb/testsuite/gdb.cp/nsusing.exp index 72a616e..b060ee2 100644 --- a/gdb/testsuite/gdb.cp/nsusing.exp +++ b/gdb/testsuite/gdb.cp/nsusing.exp @@ -154,7 +154,7 @@ if ![runto marker4] then { perror "couldn't run to breakpoint marker4" continue } -setup_kfail "gdb/7936" "*-*-*" + gdb_test "print dx" "= 4" ############################################ diff --git a/gdb/testsuite/gdb.cp/shadow.cc b/gdb/testsuite/gdb.cp/shadow.cc index 1651510..0520b2a 100644 --- a/gdb/testsuite/gdb.cp/shadow.cc +++ b/gdb/testsuite/gdb.cp/shadow.cc @@ -29,8 +29,10 @@ public: using namespace A; y++; // marker4 - using A::x; - y++; // marker5 + { + using A::x; + y++; // marker5 + } } } } diff --git a/gdb/testsuite/gdb.cp/shadow.exp b/gdb/testsuite/gdb.cp/shadow.exp index 1e5e80b..40c35a4 100644 --- a/gdb/testsuite/gdb.cp/shadow.exp +++ b/gdb/testsuite/gdb.cp/shadow.exp @@ -85,5 +85,4 @@ gdb_test "print x" "= 55" "Print local x not namespace x" gdb_breakpoint [gdb_get_line_number "marker5"] gdb_continue_to_breakpoint "marker5" -setup_kfail "gdb/7936" "*-*-*" gdb_test "print x" "= 11" "Print imported namespace x" diff --git a/gdb/valops.c b/gdb/valops.c index b94c411..b5e47d3 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3119,7 +3119,7 @@ value_maybe_namespace_elt (const struct type *curtype, sym = cp_lookup_symbol_namespace (namespace_name, name, NULL, get_selected_block (0), - VAR_DOMAIN, 1); + VAR_DOMAIN); if (sym == NULL) return NULL; --------------060907010101080209080006--